7150579: Moved ant code into a separate package, anttasks

To allow langtools to be built without ant, the ant tasks were moved to a separated package. The packages were also renamed to proper lower case package names.

Reviewed-by: jjg
diff --git a/langtools/make/build.xml b/langtools/make/build.xml
index 152be98..52b13b7 100644
--- a/langtools/make/build.xml
+++ b/langtools/make/build.xml
@@ -862,7 +862,8 @@
                source="${boot.javac.source}"
                target="${boot.javac.target}"
                executable="${boot.java.home}/bin/javac"
-               srcdir="${make.tools.dir}/CompileProperties"
+               srcdir="${make.tools.dir}"
+               includes="compileproperties/* anttasks/CompileProperties*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                bootclasspath="${boot.java.home}/jre/lib/rt.jar"
@@ -870,7 +871,7 @@
             <compilerarg line="${javac.lint.opts}"/>
         </javac>
         <taskdef name="pcompile"
-                 classname="CompilePropertiesTask"
+                 classname="anttasks.CompilePropertiesTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
@@ -880,7 +881,8 @@
                source="${boot.javac.source}"
                target="${boot.javac.target}"
                executable="${boot.java.home}/bin/javac"
-               srcdir="${make.tools.dir}/GenStubs"
+               srcdir="${make.tools.dir}"
+               includes="genstubs/* anttasks/GenStubs*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                includeantruntime="false">
@@ -888,7 +890,7 @@
             <compilerarg line="${javac.lint.opts}"/>
         </javac>
         <taskdef name="genstubs"
-                 classname="GenStubs$$Ant"
+                 classname="anttasks.GenStubsTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
diff --git a/langtools/make/netbeans/langtools/build.xml b/langtools/make/netbeans/langtools/build.xml
index d7e8f37..dd2caf9 100644
--- a/langtools/make/netbeans/langtools/build.xml
+++ b/langtools/make/netbeans/langtools/build.xml
@@ -261,7 +261,8 @@
 
     <target name="-def-select-tool">
         <mkdir dir="${build.toolclasses.dir}"/>
-        <javac srcdir="${make.tools.dir}/SelectTool"
+        <javac srcdir="${make.tools.dir}"
+               includes="anttasks/SelectTool*"
                destdir="${build.toolclasses.dir}/"
                classpath="${ant.core.lib}"
                includeantruntime="false"
@@ -270,7 +271,7 @@
                    <compilerarg line="-Xlint"/>
         </javac>
         <taskdef name="select-tool"
-                 classname="SelectToolTask"
+                 classname="anttasks.SelectToolTask"
                  classpath="${build.toolclasses.dir}/"/>
     </target>
 
diff --git a/langtools/make/tools/CompileProperties/CompilePropertiesTask.java b/langtools/make/tools/anttasks/CompilePropertiesTask.java
similarity index 98%
rename from langtools/make/tools/CompileProperties/CompilePropertiesTask.java
rename to langtools/make/tools/anttasks/CompilePropertiesTask.java
index 8bf3303..4615bd4 100644
--- a/langtools/make/tools/CompileProperties/CompilePropertiesTask.java
+++ b/langtools/make/tools/anttasks/CompilePropertiesTask.java
@@ -23,6 +23,10 @@
  * questions.
  */
 
+package anttasks;
+
+import compileproperties.CompileProperties;
+
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
diff --git a/langtools/make/tools/anttasks/GenStubsTask.java b/langtools/make/tools/anttasks/GenStubsTask.java
new file mode 100644
index 0000000..7212dc1
--- /dev/null
+++ b/langtools/make/tools/anttasks/GenStubsTask.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package anttasks;
+
+import genstubs.GenStubs;
+
+import java.io.*;
+import java.util.*;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.MatchingTask;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.Reference;
+
+/**
+ * Files are specified with an implicit fileset, using srcdir as a base directory.
+ * The set of files to be included is specified with an includes attribute or
+ * nested <includes> set. However, unlike a normal fileset, an empty includes attribute
+ * means "no files" instead of "all files".  The Ant task also accepts "fork=true" and
+ * classpath attribute or nested <classpath> element to run GenStubs in a separate VM
+ * with the specified path. This is likely necessary if a JDK 7 parser is required to read the
+ * JDK 7 input files.
+ */
+public class GenStubsTask extends MatchingTask {
+    private File srcDir;
+    private File destDir;
+    private boolean fork;
+    private Path classpath;
+    private String includes;
+
+    public void setSrcDir(File dir) {
+        this.srcDir = dir;
+    }
+
+    public void setDestDir(File dir) {
+        this.destDir = dir;
+    }
+
+    public void setFork(boolean v) {
+        this.fork = v;
+    }
+
+    public void setClasspath(Path cp) {
+        if (classpath == null)
+            classpath = cp;
+        else
+            classpath.append(cp);
+    }
+
+    public Path createClasspath() {
+        if (classpath == null) {
+            classpath = new Path(getProject());
+        }
+        return classpath.createPath();
+    }
+
+    public void setClasspathRef(Reference r) {
+        createClasspath().setRefid(r);
+    }
+
+    public void setIncludes(String includes) {
+        super.setIncludes(includes);
+        this.includes = includes;
+    }
+
+    @Override
+    public void execute() {
+        if (includes != null && includes.trim().isEmpty())
+            return;
+
+        DirectoryScanner s = getDirectoryScanner(srcDir);
+        String[] files = s.getIncludedFiles();
+//            System.err.println("Ant.execute: srcDir " + srcDir);
+//            System.err.println("Ant.execute: destDir " + destDir);
+//            System.err.println("Ant.execute: files " + Arrays.asList(files));
+
+        files = filter(srcDir, destDir, files);
+        if (files.length == 0)
+            return;
+        System.out.println("Generating " + files.length + " stub files to " + destDir);
+
+        List<String> classNames = new ArrayList<String>();
+        for (String file: files) {
+            classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
+        }
+
+        if (!fork) {
+            GenStubs m = new GenStubs();
+            boolean ok = m.run(srcDir.getPath(), destDir, classNames);
+            if (!ok)
+                throw new BuildException("genstubs failed");
+        } else {
+            List<String> cmd = new ArrayList<String>();
+            String java_home = System.getProperty("java.home");
+            cmd.add(new File(new File(java_home, "bin"), "java").getPath());
+            if (classpath != null)
+                cmd.add("-Xbootclasspath/p:" + classpath);
+            cmd.add(GenStubs.class.getName());
+            cmd.add("-sourcepath");
+            cmd.add(srcDir.getPath());
+            cmd.add("-s");
+            cmd.add(destDir.getPath());
+            cmd.addAll(classNames);
+            //System.err.println("GenStubs exec " + cmd);
+            ProcessBuilder pb = new ProcessBuilder(cmd);
+            pb.redirectErrorStream(true);
+            try {
+                Process p = pb.start();
+                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+                try {
+                    String line;
+                    while ((line = in.readLine()) != null)
+                        System.out.println(line);
+                } finally {
+                    in.close();
+                }
+                int rc = p.waitFor();
+                if (rc != 0)
+                    throw new BuildException("genstubs failed");
+            } catch (IOException e) {
+                throw new BuildException("genstubs failed", e);
+            } catch (InterruptedException e) {
+                throw new BuildException("genstubs failed", e);
+            }
+        }
+    }
+
+    String[] filter(File srcDir, File destDir, String[] files) {
+        List<String> results = new ArrayList<String>();
+        for (String f: files) {
+            long srcTime = new File(srcDir, f).lastModified();
+            long destTime = new File(destDir, f).lastModified();
+            if (srcTime > destTime)
+                results.add(f);
+        }
+        return results.toArray(new String[results.size()]);
+    }
+}
diff --git a/langtools/make/tools/SelectTool/SelectToolTask.java b/langtools/make/tools/anttasks/SelectToolTask.java
similarity index 99%
rename from langtools/make/tools/SelectTool/SelectToolTask.java
rename to langtools/make/tools/anttasks/SelectToolTask.java
index b182b49..1fe21c4 100644
--- a/langtools/make/tools/SelectTool/SelectToolTask.java
+++ b/langtools/make/tools/anttasks/SelectToolTask.java
@@ -23,6 +23,8 @@
  * questions.
  */
 
+package anttasks;
+
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.event.ActionEvent;
diff --git a/langtools/make/tools/CompileProperties/CompileProperties.java b/langtools/make/tools/compileproperties/CompileProperties.java
similarity index 99%
rename from langtools/make/tools/CompileProperties/CompileProperties.java
rename to langtools/make/tools/compileproperties/CompileProperties.java
index c4654bf..9a40592 100644
--- a/langtools/make/tools/CompileProperties/CompileProperties.java
+++ b/langtools/make/tools/compileproperties/CompileProperties.java
@@ -23,6 +23,8 @@
  * questions.
  */
 
+package compileproperties;
+
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
@@ -61,7 +63,7 @@
         }
     }
 
-    static interface Log {
+    public static interface Log {
         void info(String msg);
         void verbose(String msg);
         void error(String msg, Exception e);
@@ -72,7 +74,7 @@
     private String supers[]   ;
     private int compileCount = 0;
     private boolean quiet = false;
-    private Log log;
+    public Log log;
 
     public void setLog(Log log) {
         this.log = log;
diff --git a/langtools/make/tools/GenStubs/GenStubs.java b/langtools/make/tools/genstubs/GenStubs.java
similarity index 69%
rename from langtools/make/tools/GenStubs/GenStubs.java
rename to langtools/make/tools/genstubs/GenStubs.java
index b7caee2..f43df55 100644
--- a/langtools/make/tools/GenStubs/GenStubs.java
+++ b/langtools/make/tools/genstubs/GenStubs.java
@@ -23,19 +23,14 @@
  * questions.
  */
 
+package genstubs;
+
 import java.io.*;
 import java.util.*;
 import javax.tools.JavaFileObject;
 import javax.tools.StandardJavaFileManager;
 import javax.tools.StandardLocation;
 
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.taskdefs.MatchingTask;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Reference;
-
-
 import com.sun.source.tree.CompilationUnitTree;
 import com.sun.source.util.JavacTask;
 import com.sun.tools.javac.api.JavacTool;
@@ -81,15 +76,6 @@
  * Documentation comments and annotations are removed. Method bodies are removed
  * and methods are marked native. Private and package-private field definitions
  * have their initializers replace with 0, 0.0, false, null as appropriate.
- *
- * An Ant task, Main$Ant is also provided. Files are specified with an implicit
- * fileset, using srcdir as a base directory. The set of files to be included
- * is specified with an includes attribute or nested <includes> set. However,
- * unlike a normal fileset, an empty includes attribute means "no files" instead
- * of "all files".  The Ant task also accepts "fork=true" and classpath attribute
- * or nested <classpath> element to run GenStubs in a separate VM with the specified
- * path. This is likely necessary if a JDK 7 parser is required to read the
- * JDK 7 input files.
  */
 
 public class GenStubs {
@@ -110,7 +96,7 @@
             System.exit(1);
     }
 
-    boolean run(String... args) {
+    public boolean run(String... args) {
         File outdir = null;
         String sourcepath = null;
         List<String> classes = new ArrayList<String>();
@@ -132,7 +118,7 @@
         return run(sourcepath, outdir, classes);
     }
 
-    boolean run(String sourcepath, File outdir, List<String> classes) {
+    public boolean run(String sourcepath, File outdir, List<String> classes) {
         //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
         if (sourcepath == null)
             throw new IllegalArgumentException("sourcepath not set");
@@ -298,9 +284,9 @@
             tree.accept(this);
             ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
             for (JCTree def: tree.defs) {
-                if (def.getTag() == JCTree.IMPORT) {
+                if (def.getTag() == JCTree.Tag.IMPORT) {
                     JCImport imp = (JCImport) def;
-                    if (imp.qualid.getTag() == JCTree.SELECT) {
+                    if (imp.qualid.getTag() == JCTree.Tag.SELECT) {
                         JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
                         if (!qualid.name.toString().equals("*")
                                 && !names.contains(qualid.name)) {
@@ -327,122 +313,4 @@
             names.add(tree.name);
         }
     }
-
-    //---------- Ant Invocation ------------------------------------------------
-
-    public static class Ant extends MatchingTask {
-        private File srcDir;
-        private File destDir;
-        private boolean fork;
-        private Path classpath;
-        private String includes;
-
-        public void setSrcDir(File dir) {
-            this.srcDir = dir;
-        }
-
-        public void setDestDir(File dir) {
-            this.destDir = dir;
-        }
-
-        public void setFork(boolean v) {
-            this.fork = v;
-        }
-
-        public void setClasspath(Path cp) {
-            if (classpath == null)
-                classpath = cp;
-            else
-                classpath.append(cp);
-        }
-
-        public Path createClasspath() {
-            if (classpath == null) {
-                classpath = new Path(getProject());
-            }
-            return classpath.createPath();
-        }
-
-        public void setClasspathRef(Reference r) {
-            createClasspath().setRefid(r);
-        }
-
-        public void setIncludes(String includes) {
-            super.setIncludes(includes);
-            this.includes = includes;
-        }
-
-        @Override
-        public void execute() {
-            if (includes != null && includes.trim().isEmpty())
-                return;
-
-            DirectoryScanner s = getDirectoryScanner(srcDir);
-            String[] files = s.getIncludedFiles();
-//            System.err.println("Ant.execute: srcDir " + srcDir);
-//            System.err.println("Ant.execute: destDir " + destDir);
-//            System.err.println("Ant.execute: files " + Arrays.asList(files));
-
-            files = filter(srcDir, destDir, files);
-            if (files.length == 0)
-                return;
-            System.out.println("Generating " + files.length + " stub files to " + destDir);
-
-            List<String> classNames = new ArrayList<String>();
-            for (String file: files) {
-                classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
-            }
-
-            if (!fork) {
-                GenStubs m = new GenStubs();
-                boolean ok = m.run(srcDir.getPath(), destDir, classNames);
-                if (!ok)
-                    throw new BuildException("genstubs failed");
-            } else {
-                List<String> cmd = new ArrayList<String>();
-                String java_home = System.getProperty("java.home");
-                cmd.add(new File(new File(java_home, "bin"), "java").getPath());
-                if (classpath != null)
-                    cmd.add("-Xbootclasspath/p:" + classpath);
-                cmd.add(GenStubs.class.getName());
-                cmd.add("-sourcepath");
-                cmd.add(srcDir.getPath());
-                cmd.add("-s");
-                cmd.add(destDir.getPath());
-                cmd.addAll(classNames);
-                //System.err.println("GenStubs exec " + cmd);
-                ProcessBuilder pb = new ProcessBuilder(cmd);
-                pb.redirectErrorStream(true);
-                try {
-                    Process p = pb.start();
-                    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
-                    try {
-                        String line;
-                        while ((line = in.readLine()) != null)
-                            System.out.println(line);
-                    } finally {
-                        in.close();
-                    }
-                    int rc = p.waitFor();
-                    if (rc != 0)
-                        throw new BuildException("genstubs failed");
-                } catch (IOException e) {
-                    throw new BuildException("genstubs failed", e);
-                } catch (InterruptedException e) {
-                    throw new BuildException("genstubs failed", e);
-                }
-            }
-        }
-
-        String[] filter(File srcDir, File destDir, String[] files) {
-            List<String> results = new ArrayList<String>();
-            for (String f: files) {
-                long srcTime = new File(srcDir, f).lastModified();
-                long destTime = new File(destDir, f).lastModified();
-                if (srcTime > destTime)
-                    results.add(f);
-            }
-            return results.toArray(new String[results.size()]);
-        }
-    }
 }