Source code: com/memoire/ant/cpp_task.java
1 /*
2 * @file cpp_task.java
3 * @creation 1999-02-10
4 * @modification $Date: 2002/12/16 18:56:24 $
5 * @mail devel@fudaa.org
6 */
7
8
9 package com.memoire.ant;
10
11 import java.io.File;
12 import java.io.InputStream;
13
14 import org.apache.tools.ant.BuildException;
15 import org.apache.tools.ant.Task;
16 import org.apache.tools.ant.DirectoryScanner;
17 import org.apache.tools.ant.types.PatternSet;
18
19 /**
20 * Une molette.
21 *
22 * @version $Id: cpp_task.java,v 1.6 2002/12/16 18:56:24 desnoix Exp $
23 * @author Fred Deniger
24 */
25 public class cpp_task extends Task
26 {
27 protected File destDir_ = null;
28 protected File baseDir_ = null;
29 protected String includesFiles_="*.idl";
30 protected String excludesFiles_="";
31 protected String ext_="";
32
33 //private FileUtils fileUtils;
34
35 public cpp_task() {
36 //fileUtils = FileUtils.newFileUtils();
37 }
38
39 // The method executing the task
40 public void execute()
41 //throws BuildException
42 {
43 if ( destDir_==null ) throw new BuildException("destDir is no set");
44 if( !destDir_.exists() ) throw new BuildException("destDir doesn't exists");
45 if( !destDir_.isDirectory() ) throw new BuildException("destDir is not a directory");
46 DirectoryScanner ds=new DirectoryScanner();
47 ds.setBasedir(baseDir_);
48 ds.setIncludes(new String[]{includesFiles_});
49 ds.setExcludes(new String[]{excludesFiles_});
50 ds.scan();
51 String[] files=ds.getIncludedFiles();
52 String os = System.getProperty("os.name");
53 if(os.startsWith("Win"))
54 {
55 System.err.println("To be done...");
56 }
57 else
58 {
59 for( int i=0;i<files.length;i++ )
60 {
61 String fileName=files[i];
62 if( !"".equals(ext_) )
63 {
64 if( fileName.lastIndexOf(".")>-1)
65 fileName=fileName.substring(0,fileName.lastIndexOf("."))+ext_;
66 }
67 File destFile=new File(destDir_,fileName);
68 File fromFile=new File(baseDir_.getAbsolutePath()+File.separator+files[i]);
69 if( destFile.lastModified()>=fromFile.lastModified()) continue;
70 destFile.getParentFile().mkdirs();
71 String[] param=new String[4];
72 param[0] = "cpp";
73 param[1] = "-I"+baseDir_+File.separator;
74 param[2] = fromFile.getAbsolutePath();
75 param[3] = "-o "+destFile.getAbsolutePath();
76 log(fromFile+" > "+destFile);
77 try
78 {
79 Runtime.getRuntime().exec(param[0]+" "+param[1]+" "+param[2]+" "+param[3]);
80 }
81 catch( java.io.IOException e)
82 { System.err.println("Error while executing "+
83 param[0]+" "+param[1]+" "+param[2]+" "+param[3]);
84 System.err.println(e.getMessage());
85 }
86
87 }
88 }
89 }
90
91 public void setBaseDir(File _file)
92 {
93 if( _file!=null) baseDir_=_file;
94 }
95
96 public void setDestDir(File _file)
97 {
98 if( _file!=null) destDir_=_file;
99 }
100
101 public void setIncludesFiles(String _incFiles)
102 {
103 this.includesFiles_ = _incFiles;
104 }
105
106 public void setExt(String _ext)
107 {
108 if( _ext!=null) ext_=_ext.trim();
109 }
110
111 public void setExcludesFiles(String _excFiles)
112 {
113 this.excludesFiles_ = _excFiles;
114 }
115 }