ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <co...@locus.apache.org>
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Javac.java
Date Thu, 06 Jul 2000 12:30:50 GMT
conor       00/07/06 05:30:50

  Modified:    docs     index.html
               src/main/org/apache/tools/ant/taskdefs Javac.java
  Log:
  Add support for multiple source paths to Javac
  These can either be specified as path strings or nested elements. The path
  strings use the same separator conventions as other paths in Ant.
  
  When using nested elements, each component can be specified in a separate
  <src> element.
  
  Revision  Changes    Path
  1.37      +47 -2     jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- index.html	2000/07/04 09:30:05	1.36
  +++ index.html	2000/07/06 12:30:49	1.37
  @@ -1572,6 +1572,7 @@
           fork=&quot;yes&quot;
           jvmargs=&quot;-Xrunhprof:cpu=samples,file=log.txt,depth=3&quot;
     /&gt;</pre>
  +
   <hr>
   <h2><a name="javac">Javac</a></h2>
   <h3>Description</h3>
  @@ -1614,7 +1615,7 @@
     <tr>
       <td valign="top">srcdir</td>
       <td valign="top">location of the java files.</td>
  -    <td align="center" valign="top">Yes</td>
  +    <td align="center" valign="top">Yes, unless nested <code>&lt;src&gt;</code>
elements are present.</td>
     </tr>
     <tr>
       <td valign="top">destdir</td>
  @@ -1695,6 +1696,30 @@
       <td align="center" valign="top">No</td>
     </tr>
   </table>
  +
  +<h3>Parameters specified as nested elements</h3>
  +Being a directory based task, Javac supports the <code>&lt;include&gt;</code>
and 
  +<code>&lt;exclude&gt;</code> nested elements common to a number of
Ant tasks. Javac also supports a 
  +nested <code>&lt;src&gt;</code> element. This is used to specify multiple
source paths. 
  +Multiple <code>src</code> elements may be present and each specifies a source
path which will be 
  +searched by Javac for classes to compile.
  +
  +<h4>src</h4>
  +Define a source path to be search for source files.
  +<H4>Parameters</h4>
  +<table width="60%" border="1" cellpadding="2" cellspacing="0">
  +  <tr>
  +    <td valign="top"><b>Attribute</b></td>
  +    <td valign="top"><b>Description</b></td>
  +    <td align="center" valign="top"><b>Required</b></td>
  +  </tr>
  +  <tr>
  +    <td valign="top">src</td>
  +    <td valign="top">A source path. It may contain multiple elements separated with
either a ';' or a ':'</td>
  +    <td align="center" valign="top">Yes</td>
  +  </tr>
  +</table>
  +
   <h3>Examples</h3>
   <pre>  &lt;javac srcdir=&quot;${src}&quot;
            destdir=&quot;${build}&quot;
  @@ -1720,6 +1745,26 @@
   used. Files in the <code>mypackage/p1/testpackage</code> directory are excluded
   form compilation and copy.</p>
   
  +<pre>  &lt;javac srcdir=&quot;${src}:${src2}&quot;
  +         destdir=&quot;${build}&quot;
  +         includes=&quot;mypackage/p1/**,mypackage/p2/**&quot;
  +         excludes=&quot;mypackage/p1/testpackage/**&quot;
  +         classpath=&quot;xyz.jar&quot;
  +         debug=&quot;on&quot;
  +  /&gt;</pre>
  +
  +<p>is the same as the previous example with the addition of a second source path,
defined by
  +the propery <code>src2</code>. This can also be represented using nested elements
as follows
  +
  +<pre>  &lt;javac destdir=&quot;${build}&quot;
  +         classpath=&quot;xyz.jar&quot;
  +         debug=&quot;on&quot;&gt;
  +    &lt;src path=&quot;${src}&quot; /&gt;
  +    &lt;src path=&quot;${src2}&quot; /&gt;
  +    &lt;include name=&quot;mypackage/p1/**,mypackage/p2/**&quot; /&gt;
  +    &lt;exclude name=&quot;mypackage/p1/testpackage/**&quot; /&gt;
  +  &lt;/javac&gt;</pre>
  +
   <hr>
   <h2><a name="javadoc">Javadoc/Javadoc2</a></h2>
   <h3>Description</h3>
  @@ -2028,7 +2073,7 @@
     </tr>
   </table>
   
  -<h3>Parameters specified as subelements</h3>
  +<h3>Parameters specified as nested elements</h3>
   Two parameters of the Javadoc task may be specified as nested elements of the
   Javadoc task element: link and group.
   When present, there can be any number of each of these elements.
  
  
  
  1.17      +108 -19   jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
  
  Index: Javac.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Javac.java	2000/07/04 10:03:37	1.16
  +++ Javac.java	2000/07/06 12:30:50	1.17
  @@ -88,13 +88,26 @@
   
   public class Javac extends MatchingTask {
   
  +    public class SourcePathElement {
  +        private String path;
  +        
  +        public void setPath(String path) {
  +            this.path = path;
  +        }
  +        
  +        public String getPath() {
  +            return path;
  +        }
  +    };
  +
       /**
        * Integer returned by the "Modern" jdk1.3 compiler to indicate success.
        */
       private static final int
           MODERN_COMPILER_SUCCESS = 0;
   
  -    private File srcDir;
  +    private Vector srcPathElements = new Vector();
  +    private Vector srcDirs= new Vector();
       private File destDir;
       private String compileClasspath;
       private boolean debug = false;
  @@ -108,11 +121,49 @@
       protected Vector compileList = new Vector();
       protected Hashtable filecopyList = new Hashtable();
   
  +    /**
  +     * Create a nested <src ...> element for multiple source path
  +     * support.
  +     *
  +     * @return a nexted src element.
  +     */
  +    public SourcePathElement createSrc() {
  +        SourcePathElement element = new SourcePathElement();
  +        srcPathElements.addElement(element);
  +        return element;
  +    }
  +
  +    /**
  +     * Add a single directory to the collection of directories that
  +     * make up the source path.
  +     *
  +     * @param srcDirName the name of the directory to add to the list of source directories.
  +     */
  +    private void addSrcDir(String srcDirName) {
  +        srcDirs.addElement(project.resolveFile(srcDirName));
  +    }
  +
  +    /**
  +     * Add a set of source directories specified as path.
  +     *
  +     * @param srcPath the list of source directories.
  +     */
  +    private void addSrcPath(String srcPath) {
  +        // use a Path tokenizer to find the paths and add them to 
  +        // the vector of source paths.
  +        PathTokenizer tokenizer = new PathTokenizer(srcPath);
  +        while (tokenizer.hasMoreTokens()) {
  +            addSrcDir(tokenizer.nextToken());
  +        }
  +    }        
  +
       /**
  -     * Set the source dir to find the source Java files.
  +     * Set the source dirs to find the source Java files.
        */
  -    public void setSrcdir(String srcDirName) {
  -        srcDir = project.resolveFile(srcDirName);
  +    public void setSrcdir(String srcPath) {
  +        // clean out the list of source dirs
  +        srcDirs = new Vector();
  +        addSrcPath(srcPath);
       }
   
       /**
  @@ -188,24 +239,38 @@
       public void execute() throws BuildException {
           // first off, make sure that we've got a srcdir and destdir
   
  -        if (srcDir == null) {
  +        // process the source elements into the srcDirs collection
  +        for (Enumeration e = srcPathElements.elements(); e.hasMoreElements(); ) {
  +            SourcePathElement element = (SourcePathElement)e.nextElement();
  +            addSrcPath(element.getPath());
  +        }
  +
  +        if (srcDirs.size() == 0) {
               throw new BuildException("srcdir attribute must be set!");
           }
  -        if (!srcDir.exists()) {
  -            throw new BuildException("srcdir does not exist!");
  +        
  +        for (Enumeration e = srcDirs.elements(); e.hasMoreElements(); ) {
  +            File srcDir = (File)e.nextElement();
  +            if (!srcDir.exists()) {
  +                throw new BuildException("srcdir " + srcDir.getPath() + " does not exist!");
  +            }
           }
  +
           if (destDir == null) {
               throw new BuildException("destdir attribute must be set!");
           }
   
  -        // scan source and dest dirs to build up both copy lists and
  +        // scan source directories and dest directory to build up both copy lists and
           // compile lists
  -
  -        DirectoryScanner ds = this.getDirectoryScanner(srcDir);
  +        resetFileLists();
  +        for (Enumeration e = srcDirs.elements(); e.hasMoreElements(); ) {
  +            File srcDir = (File)e.nextElement();
  +            DirectoryScanner ds = this.getDirectoryScanner(srcDir);
   
  -        String[] files = ds.getIncludedFiles();
  +            String[] files = ds.getIncludedFiles();
   
  -        scanDir(srcDir, destDir, files);
  +            scanDir(srcDir, destDir, files);
  +        }
   
           // compile the source files
   
  @@ -259,6 +324,14 @@
       }
   
       /**
  +     * Clear the list of files to be compiled and copied.. 
  +     */
  +    protected void resetFileLists() {
  +        compileList.removeAllElements();
  +        filecopyList.clear();
  +    }
  +
  +    /**
        * Scans the directory looking for source files to be compiled and
        * support files to be copied.  The results are returned in the
        * class variables compileList and filecopyList.
  @@ -266,9 +339,6 @@
   
       protected void scanDir(File srcDir, File destDir, String files[]) {
   
  -        compileList.removeAllElements();
  -        filecopyList.clear();
  -
           long now = (new Date()).getTime();
   
           for (int i = 0; i < files.length; i++) {
  @@ -373,6 +443,25 @@
       }
   
       /**
  +     * Get the list of source directories separated by a platform specific
  +     * path separator.
  +     *
  +     * @return the current source directories in a single path separated using the 
  +     * platform specific path separator.
  +     */
  +    private String getSourcePath() {
  +        String sourcePath = "";
  +        for (Enumeration e = srcDirs.elements(); e.hasMoreElements(); ) {
  +            File srcDir = (File)e.nextElement();
  +            if (sourcePath.length() != 0) {
  +                sourcePath += File.pathSeparator;
  +            }
  +            sourcePath += srcDir.getAbsolutePath();
  +        }
  +        return sourcePath;
  +    }
  +
  +    /**
        * Peforms a copmile using the classic compiler that shipped with
        * JDK 1.1 and 1.2.
        */
  @@ -391,11 +480,11 @@
           // Just add "sourcepath" to classpath ( for JDK1.1 )
           if (Project.getJavaVersion().startsWith("1.1")) {
               argList.addElement(classpath + File.pathSeparator +
  -                               srcDir.getAbsolutePath());
  +                               getSourcePath());
           } else {
               argList.addElement(classpath);
               argList.addElement("-sourcepath");
  -            argList.addElement(srcDir.getAbsolutePath());
  +            argList.addElement(getSourcePath());
               if (target != null) {
                   argList.addElement("-target");
                   argList.addElement(target);
  @@ -471,7 +560,7 @@
           argList.addElement("-classpath");
           argList.addElement(classpath);
           argList.addElement("-sourcepath");
  -        argList.addElement(srcDir.getAbsolutePath());
  +        argList.addElement(getSourcePath());
           if (target != null) {
               argList.addElement("-target");
               argList.addElement(target);
  @@ -566,7 +655,7 @@
           // Jikes has no option for source-path so we
           // will add it to classpath.
           classpath.append(File.pathSeparator);
  -        classpath.append(srcDir.getAbsolutePath());
  +        classpath.append(getSourcePath());
   
           Vector argList = new Vector();
   
  
  
  

Mime
View raw message