--- Javac.java.orig	Sat May 06 16:53:27 2000
+++ Javac.java	Sat May 06 19:25:31 2000
@@ -1,4 +1,4 @@
-/*
+/* 
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 1999 The Apache Software Foundation.  All rights
@@ -55,6 +55,8 @@
 package org.apache.tools.ant.taskdefs;
 
 import org.apache.tools.ant.*;
+import org.apache.tools.analyzer.*;
+import org.apache.tools.analyzer.info.*;
 
 import java.io.*;
 import java.util.*;
@@ -84,27 +86,39 @@
  * @author James Davidson <a href="mailto:duncan@x180.com">duncan@x180.com</a>
  */
 
-public class Javac extends MatchingTask {
+public class Javac extends MatchingTask implements IStatusListener{
 
-    private File srcDir;
+    private String[] srcDirS; 
+    private File[] srcDir;
     private File destDir;
+    private File sourcePath;
+    private String sourcePathS;
     private String compileClasspath;
     private boolean debug = false;
     private boolean optimize = false;
     private boolean deprecation = false;
     private boolean filtering = false;
+    private boolean dependingTrack = false;
     private String target;
     private String bootclasspath;
     private String extdirs;
-
-    protected Vector compileList = new Vector();
+                                       
+    protected UniqueVector compileList = new UniqueVector();
     protected Hashtable filecopyList = new Hashtable();
 
     /**
      * Set the source dir to find the source Java files.
      */
     public void setSrcdir(String srcDirName) {
-        srcDir = project.resolveFile(srcDirName);
+      StringTokenizer srcPath = new StringTokenizer(srcDirName,";");
+      srcDir = new File[srcPath.countTokens()];
+      srcDirS = new String[srcPath.countTokens()];
+      int i=0;
+      while(srcPath.hasMoreTokens()) {
+        srcDirS[i]=srcPath.nextToken().trim();
+		srcDir[i] = project.resolveFile(srcDirS[i]);
+        i++;
+      }
     }
 
     /**
@@ -123,6 +137,15 @@
     }
 
     /**
+     * Sets the -sourcepath option.
+     */
+
+    public void setSourcepath(String sourcepath) {
+      sourcePathS = sourcepath;
+      sourcePath = project.resolveFile(sourcepath);
+    }
+
+    /**
      * Sets the bootclasspath that will be used to compile the classes
      * against.
      */
@@ -174,16 +197,20 @@
         filtering = Project.toBoolean(filter);
     }
 
+    public void setDependence(String dependence) {
+        dependingTrack = Project.toBoolean(dependence);
+    }
+
     /**
      * Executes the task.
      */
     public void execute() throws BuildException {
         // first off, make sure that we've got a srcdir and destdir
 
-        if (srcDir == null) {
+        if (srcDir[0] == null) {
             throw new BuildException("srcdir attribute must be set!");
         }
-        if (!srcDir.exists()) {
+        if (!srcDir[0].exists()) {
             throw new BuildException("srcdir does not exist!");
         }
         if (destDir == null) {
@@ -193,11 +220,15 @@
         // scan source and dest dirs to build up both copy lists and
         // compile lists
 
-        DirectoryScanner ds = this.getDirectoryScanner(srcDir);
+        prepareCompileList();
 
-        String[] files = ds.getIncludedFiles();
+        for(int counter=0; counter<srcDir.length; counter++) {
+            DirectoryScanner ds = this.getDirectoryScanner(srcDir[counter]);
 
-        scanDir(srcDir, destDir, files);
+            String[] files = ds.getIncludedFiles();
+     
+            scanDir(counter, destDir, files);
+        }
 
         // compile the source files
 
@@ -252,18 +283,29 @@
      * class variables compileList and filecopyList.
      */
 
-    protected void scanDir(File srcDir, File destDir, String files[]) {
-
+    protected void prepareCompileList() {
         compileList.removeAllElements();
         filecopyList.clear();
+    }
 
+    protected void scanDir(int nDir, File destDir, String files[]) {
+        
         long now = (new Date()).getTime();
+        UniqueVector loadItems = new UniqueVector();
+        HashedVector fullUnits = new HashedVector(true, 300, 100);
+        AnalyzerUtilities.setUnits(fullUnits);
+        ClassLoad loader = new ClassLoad(fullUnits, this);
+        loader.fileList = new UniqueVector();
+        Vector classFiles = new Vector();
 
         for (int i = 0; i < files.length; i++) {
-            File srcFile = new File(srcDir, files[i]);
+            File classFile;
+            File srcFile = new File(srcDir[nDir], files[i]);
             if (files[i].endsWith(".java")) {
-                File classFile = new File(destDir, files[i].substring(0,
-                        files[i].indexOf(".java"))
+                classFile = new File(destDir,
+                        srcDirS[nDir].substring(sourcePathS.length())+
+                        File.separator+
+                        files[i].substring(0,files[i].indexOf(".java"))
                                                     + ".class");
 
                     if (srcFile.lastModified() > now) {
@@ -271,18 +313,56 @@
                             files[i], project.MSG_WARN);
                     }
 
-                    if (srcFile.lastModified() > classFile.lastModified()) {
-                        compileList.addElement(srcFile.getAbsolutePath());
+                    boolean forceAddClass = false;
+                    if(dependingTrack) {
+                        if(classFile.exists()) {
+                            LoadItem item = new LoadItem(
+                                   destDir+File.separator+srcDirS[nDir].substring(sourcePathS.length())+
+                                   File.separator+
+                                   files[i].substring(0,files[i].indexOf(".java"))
+                                   + ".class", false);
+                            loadItems.addElement(item);
+                            forceAddClass = true;
+                        }
+                        if (srcFile.lastModified() > classFile.lastModified()) {
+                            compileList.addElement(srcFile.getAbsolutePath());
+                            if(forceAddClass) 
+                                classFiles.addElement(classFile);
+                        }
                     }
+                    else
+                      compileList.addElement(srcFile.getAbsolutePath());
                 } else {
-                File destFile = new File(destDir, files[i]);
+                    File destFile = new File(destDir,
+                        srcDirS[nDir].substring(sourcePathS.length())+
+                        File.separator+
+                        files[i]);
                     if (srcFile.lastModified() > destFile.lastModified()) {
                         filecopyList.put(srcFile.getAbsolutePath(),
                                          destFile.getAbsolutePath());
                 }
             }
         }
-    }
+        if(dependingTrack) {
+            if ( !loader.loadAllClassesFromSet(loadItems) )
+                return;
+            for(int k=0; k<fullUnits.size(); k++) {
+                ((ClassInfo)fullUnits.get(k)).addReferencedClasses();
+            }
+            for(int k=0; k<classFiles.size(); k++){
+                String classFilePath = ((File)classFiles.get(k)).getAbsolutePath();
+                String pathToClass = classFilePath.substring(destDir.getAbsolutePath().length()+1, classFilePath.indexOf(".class"));
+
+                ClassInfo ci = (ClassInfo) fullUnits.get(pathToClass.replace('\\','/')); 
+                for(int j=0; j<ci.classesThatRefMe.size(); j++) {
+                    ClassInfo cli = (ClassInfo) ci.classesThatRefMe.get(j);
+                    if(ci!=cli){
+                        compileList.addUnique((sourcePathS.length()!=0?sourcePathS+File.separator:"")+cli.getCompleteDisplayName()+".java");
+                    }
+                }
+            }
+        }
+    }                  
 
     /**
      * Builds the compilation classpath.
@@ -361,11 +441,11 @@
         // Just add "sourcepath" to classpath ( for JDK1.1 )
         if (Project.getJavaVersion().startsWith("1.1")) {
             argList.addElement(classpath + File.pathSeparator +
-                               srcDir.getAbsolutePath());
+                               sourcePath.getAbsolutePath());
         } else {
             argList.addElement(classpath);
             argList.addElement("-sourcepath");
-            argList.addElement(srcDir.getAbsolutePath());
+            argList.addElement(sourcePath.getAbsolutePath());
             if (target != null) {
                 argList.addElement("-target");
                 argList.addElement(target);
@@ -460,7 +540,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(srcDir[0].getAbsolutePath());
 
         Vector argList = new Vector();
 
@@ -476,6 +556,14 @@
         argList.addElement("-classpath");
         argList.addElement(classpath.toString());
 
+        if(!dependingTrack) { // Full dependence tracking wil be performed by JIKES 
+	        argList.addElement("+F"); 
+	        argList.addElement("+M");
+	        argList.addElement("+DR=makefile");
+        }
+
+
+
         if (debug) {
             argList.addElement("-g");
         }
@@ -600,5 +688,12 @@
            }
        }
     }
+
+    /**
+     * Here we can catch class file parser error and status messages.
+     */
+    public void status(String s) {
+    }
+
 }
 
