ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Conor MacNeill" <co...@m64.com>
Subject [PATCH] Support for multiple source paths in javac
Date Wed, 22 Mar 2000 13:38:09 GMT
Hi,

The following patch allows the srcDir attribute of Javac to have a comma
separated list of source paths. I need this for a particular project which
is spread over multiple source trees (Don't ask me why :-). This behaviour
is supported by the javac compiler and this makes it available in ant. I
have tested it on 1.1 and 1.2.2 under NT. It also affects the jikes compile
but I haven't tested that. Existing build files do not need to be changed.

Cheers
Conor


Index: src/main/org/apache/tools/ant/taskdefs/Javac.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.jav
a,v
retrieving revision 1.10
diff -u -r1.10 Javac.java
--- src/main/org/apache/tools/ant/taskdefs/Javac.java   2000/03/04 20:07:02
1.10
+++ src/main/org/apache/tools/ant/taskdefs/Javac.java   2000/03/22 13:26:50
@@ -86,7 +86,7 @@

 public class Javac extends MatchingTask {

-    private File srcDir;
+    private Vector srcDirs;
     private File destDir;
     private String compileClasspath;
     private boolean debug = false;
@@ -103,8 +103,13 @@
     /**
      * Set the source dir to find the source Java files.
      */
-    public void setSrcdir(String srcDirName) {
-        srcDir = project.resolveFile(srcDirName);
+    public void setSrcdir(String srcDirList) {
+        // use a string tokenizer to get the list of directories
+        StringTokenizer tokenizer = new StringTokenizer(srcDirList, ",",
false);
+        srcDirs = new Vector();
+        while (tokenizer.hasMoreTokens()) {
+
srcDirs.addElement(project.resolveFile(tokenizer.nextToken().trim()));
+        }
     }

     /**
@@ -180,11 +185,14 @@
     public void execute() throws BuildException {
         // first off, make sure that we've got a srcdir and destdir

-        if (srcDir == null) {
+        if (srcDirs == null) {
             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!");
@@ -193,11 +201,17 @@
         // scan source and dest dirs to build up both copy lists and
         // compile lists

-        DirectoryScanner ds = this.getDirectoryScanner(srcDir);
+        // go through all src directories looking for files
+        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

@@ -247,6 +261,14 @@
     }

     /**
+     * Clear the compileList and the fileCopyList.
+     */
+    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.
@@ -254,9 +276,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++) {
@@ -342,6 +361,19 @@

     }

+    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.
@@ -357,15 +389,16 @@

         argList.addElement("-d");
         argList.addElement(destDir.getAbsolutePath());
+
         argList.addElement("-classpath");
         // 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);
@@ -460,7 +493,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();


--
Conor MacNeill
conor@m64.com
M64 Pty Limited


Mime
View raw message