7150579: Moved ant code into a separate package, anttasks.

Wed, 07 Mar 2012 13:11:27 +0100

author
ohrstrom
date
Wed, 07 Mar 2012 13:11:27 +0100
changeset 1224
7245999a0075
parent 1223
f3743b82945e
child 1225
83352b2e2ebc

7150579: Moved ant code into a separate package, anttasks.
Summary: 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

make/build.xml file | annotate | diff | comparison | revisions
make/netbeans/langtools/build.xml file | annotate | diff | comparison | revisions
make/tools/CompileProperties/CompileProperties.java file | annotate | diff | comparison | revisions
make/tools/CompileProperties/CompilePropertiesTask.java file | annotate | diff | comparison | revisions
make/tools/GenStubs/GenStubs.java file | annotate | diff | comparison | revisions
make/tools/SelectTool/SelectToolTask.java file | annotate | diff | comparison | revisions
make/tools/anttasks/CompilePropertiesTask.java file | annotate | diff | comparison | revisions
make/tools/anttasks/GenStubsTask.java file | annotate | diff | comparison | revisions
make/tools/anttasks/SelectToolTask.java file | annotate | diff | comparison | revisions
make/tools/compileproperties/CompileProperties.java file | annotate | diff | comparison | revisions
make/tools/genstubs/GenStubs.java file | annotate | diff | comparison | revisions
     1.1 --- a/make/build.xml	Tue Mar 06 20:27:12 2012 +0000
     1.2 +++ b/make/build.xml	Wed Mar 07 13:11:27 2012 +0100
     1.3 @@ -862,7 +862,8 @@
     1.4                 source="${boot.javac.source}"
     1.5                 target="${boot.javac.target}"
     1.6                 executable="${boot.java.home}/bin/javac"
     1.7 -               srcdir="${make.tools.dir}/CompileProperties"
     1.8 +               srcdir="${make.tools.dir}"
     1.9 +               includes="compileproperties/* anttasks/CompileProperties*"
    1.10                 destdir="${build.toolclasses.dir}/"
    1.11                 classpath="${ant.core.lib}"
    1.12                 bootclasspath="${boot.java.home}/jre/lib/rt.jar"
    1.13 @@ -870,7 +871,7 @@
    1.14              <compilerarg line="${javac.lint.opts}"/>
    1.15          </javac>
    1.16          <taskdef name="pcompile"
    1.17 -                 classname="CompilePropertiesTask"
    1.18 +                 classname="anttasks.CompilePropertiesTask"
    1.19                   classpath="${build.toolclasses.dir}/"/>
    1.20      </target>
    1.21  
    1.22 @@ -880,7 +881,8 @@
    1.23                 source="${boot.javac.source}"
    1.24                 target="${boot.javac.target}"
    1.25                 executable="${boot.java.home}/bin/javac"
    1.26 -               srcdir="${make.tools.dir}/GenStubs"
    1.27 +               srcdir="${make.tools.dir}"
    1.28 +               includes="genstubs/* anttasks/GenStubs*"
    1.29                 destdir="${build.toolclasses.dir}/"
    1.30                 classpath="${ant.core.lib}"
    1.31                 includeantruntime="false">
    1.32 @@ -888,7 +890,7 @@
    1.33              <compilerarg line="${javac.lint.opts}"/>
    1.34          </javac>
    1.35          <taskdef name="genstubs"
    1.36 -                 classname="GenStubs$$Ant"
    1.37 +                 classname="anttasks.GenStubsTask"
    1.38                   classpath="${build.toolclasses.dir}/"/>
    1.39      </target>
    1.40  
     2.1 --- a/make/netbeans/langtools/build.xml	Tue Mar 06 20:27:12 2012 +0000
     2.2 +++ b/make/netbeans/langtools/build.xml	Wed Mar 07 13:11:27 2012 +0100
     2.3 @@ -261,7 +261,8 @@
     2.4  
     2.5      <target name="-def-select-tool">
     2.6          <mkdir dir="${build.toolclasses.dir}"/>
     2.7 -        <javac srcdir="${make.tools.dir}/SelectTool"
     2.8 +        <javac srcdir="${make.tools.dir}"
     2.9 +               includes="anttasks/SelectTool*"
    2.10                 destdir="${build.toolclasses.dir}/"
    2.11                 classpath="${ant.core.lib}"
    2.12                 includeantruntime="false"
    2.13 @@ -270,7 +271,7 @@
    2.14                     <compilerarg line="-Xlint"/>
    2.15          </javac>
    2.16          <taskdef name="select-tool"
    2.17 -                 classname="SelectToolTask"
    2.18 +                 classname="anttasks.SelectToolTask"
    2.19                   classpath="${build.toolclasses.dir}/"/>
    2.20      </target>
    2.21  
     3.1 --- a/make/tools/CompileProperties/CompileProperties.java	Tue Mar 06 20:27:12 2012 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,402 +0,0 @@
     3.4 -/*
     3.5 - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
     3.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 - *
     3.8 - * This code is free software; you can redistribute it and/or modify it
     3.9 - * under the terms of the GNU General Public License version 2 only, as
    3.10 - * published by the Free Software Foundation.  Oracle designates this
    3.11 - * particular file as subject to the "Classpath" exception as provided
    3.12 - * by Oracle in the LICENSE file that accompanied this code.
    3.13 - *
    3.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 - * version 2 for more details (a copy is included in the LICENSE file that
    3.18 - * accompanied this code).
    3.19 - *
    3.20 - * You should have received a copy of the GNU General Public License version
    3.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 - *
    3.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.25 - * or visit www.oracle.com if you need additional information or have any
    3.26 - * questions.
    3.27 - */
    3.28 -
    3.29 -import java.io.BufferedWriter;
    3.30 -import java.io.File;
    3.31 -import java.io.FileInputStream;
    3.32 -import java.io.FileNotFoundException;
    3.33 -import java.io.FileOutputStream;
    3.34 -import java.io.IOException;
    3.35 -import java.io.OutputStreamWriter;
    3.36 -import java.io.Writer;
    3.37 -import java.text.MessageFormat;
    3.38 -import java.util.ArrayList;
    3.39 -import java.util.Collections;
    3.40 -import java.util.Iterator;
    3.41 -import java.util.List;
    3.42 -import java.util.Properties;
    3.43 -
    3.44 -/** Translates a .properties file into a .java file containing the
    3.45 - *  definition of a java.util.Properties subclass which can then be
    3.46 - *  compiled with javac. <P>
    3.47 - *
    3.48 - *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
    3.49 - *
    3.50 - *  Infers the package by looking at the common suffix of the two
    3.51 - *  inputs, eliminating "classes" from it.
    3.52 - *
    3.53 - * @author Scott Violet
    3.54 - * @author Kenneth Russell
    3.55 - */
    3.56 -
    3.57 -public class CompileProperties {
    3.58 -
    3.59 -    public static void main(String[] args) {
    3.60 -        CompileProperties cp = new CompileProperties();
    3.61 -        boolean ok = cp.run(args);
    3.62 -        if ( !ok ) {
    3.63 -            System.exit(1);
    3.64 -        }
    3.65 -    }
    3.66 -
    3.67 -    static interface Log {
    3.68 -        void info(String msg);
    3.69 -        void verbose(String msg);
    3.70 -        void error(String msg, Exception e);
    3.71 -    }
    3.72 -
    3.73 -    private String propfiles[];
    3.74 -    private String outfiles[] ;
    3.75 -    private String supers[]   ;
    3.76 -    private int compileCount = 0;
    3.77 -    private boolean quiet = false;
    3.78 -    private Log log;
    3.79 -
    3.80 -    public void setLog(Log log) {
    3.81 -        this.log = log;
    3.82 -    }
    3.83 -
    3.84 -    public boolean run(String[] args) {
    3.85 -        if (log == null) {
    3.86 -            log = new Log() {
    3.87 -                public void error(String msg, Exception e) {
    3.88 -                    System.err.println("ERROR: CompileProperties: " + msg);
    3.89 -                    if ( e != null ) {
    3.90 -                        System.err.println("EXCEPTION: " + e.toString());
    3.91 -                        e.printStackTrace();
    3.92 -                    }
    3.93 -                }
    3.94 -                public void info(String msg) {
    3.95 -                    System.out.println(msg);
    3.96 -                }
    3.97 -                public void verbose(String msg) {
    3.98 -                    if (!quiet)
    3.99 -                        System.out.println(msg);
   3.100 -                }
   3.101 -            };
   3.102 -        }
   3.103 -
   3.104 -        boolean ok = true;
   3.105 -        /* Original usage */
   3.106 -        if (args.length == 2 && args[0].charAt(0) != '-' ) {
   3.107 -            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
   3.108 -        } else if (args.length == 3) {
   3.109 -            ok = createFile(args[0], args[1], args[2]);
   3.110 -        } else if (args.length == 0) {
   3.111 -            usage(log);
   3.112 -            ok = false;
   3.113 -        } else {
   3.114 -            /* New batch usage */
   3.115 -            ok = parseOptions(args);
   3.116 -            if ( ok && compileCount == 0 ) {
   3.117 -                log.error("options parsed but no files to compile", null);
   3.118 -                ok = false;
   3.119 -            }
   3.120 -            /* Need at least one file. */
   3.121 -            if ( !ok ) {
   3.122 -                usage(log);
   3.123 -            } else {
   3.124 -                /* Process files */
   3.125 -                for ( int i = 0; i < compileCount && ok ; i++ ) {
   3.126 -                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
   3.127 -                }
   3.128 -            }
   3.129 -        }
   3.130 -        return ok;
   3.131 -    }
   3.132 -
   3.133 -    private boolean parseOptions(String args[]) {
   3.134 -        boolean ok = true;
   3.135 -        if ( compileCount > 0 ) {
   3.136 -            String new_propfiles[] = new String[compileCount + args.length];
   3.137 -            String new_outfiles[]  = new String[compileCount + args.length];
   3.138 -            String new_supers[]    = new String[compileCount + args.length];
   3.139 -            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
   3.140 -            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
   3.141 -            System.arraycopy(supers, 0, new_supers, 0, compileCount);
   3.142 -            propfiles = new_propfiles;
   3.143 -            outfiles  = new_outfiles;
   3.144 -            supers    = new_supers;
   3.145 -        } else {
   3.146 -            propfiles = new String[args.length];
   3.147 -            outfiles  = new String[args.length];
   3.148 -            supers    = new String[args.length];
   3.149 -        }
   3.150 -
   3.151 -        for ( int i = 0; i < args.length ; i++ ) {
   3.152 -            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
   3.153 -                propfiles[compileCount] = args[++i];
   3.154 -                outfiles[compileCount]  = args[++i];
   3.155 -                supers[compileCount]    = args[++i];
   3.156 -                compileCount++;
   3.157 -            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
   3.158 -                String filename = args[++i];
   3.159 -                FileInputStream finput = null;
   3.160 -                byte contents[] = null;
   3.161 -                try {
   3.162 -                    finput = new FileInputStream(filename);
   3.163 -                    int byteCount = finput.available();
   3.164 -                    if ( byteCount <= 0 ) {
   3.165 -                        log.error("The -optionsfile file is empty", null);
   3.166 -                        ok = false;
   3.167 -                    } else {
   3.168 -                        contents = new byte[byteCount];
   3.169 -                        int bytesRead = finput.read(contents);
   3.170 -                        if ( byteCount != bytesRead ) {
   3.171 -                            log.error("Cannot read all of -optionsfile file", null);
   3.172 -                            ok = false;
   3.173 -                        }
   3.174 -                    }
   3.175 -                } catch ( IOException e ) {
   3.176 -                    log.error("cannot open " + filename, e);
   3.177 -                    ok = false;
   3.178 -                }
   3.179 -                if ( finput != null ) {
   3.180 -                    try {
   3.181 -                        finput.close();
   3.182 -                    } catch ( IOException e ) {
   3.183 -                        ok = false;
   3.184 -                        log.error("cannot close " + filename, e);
   3.185 -                    }
   3.186 -                }
   3.187 -                if ( ok = true && contents != null ) {
   3.188 -                    String tokens[] = (new String(contents)).split("\\s+");
   3.189 -                    if ( tokens.length > 0 ) {
   3.190 -                        ok = parseOptions(tokens);
   3.191 -                    }
   3.192 -                }
   3.193 -                if ( !ok ) {
   3.194 -                    break;
   3.195 -                }
   3.196 -            } else if ( "-quiet".equals(args[i]) ) {
   3.197 -                quiet = true;
   3.198 -            } else {
   3.199 -                log.error("argument error", null);
   3.200 -                ok = false;
   3.201 -            }
   3.202 -        }
   3.203 -        return ok;
   3.204 -    }
   3.205 -
   3.206 -    private boolean createFile(String propertiesPath, String outputPath,
   3.207 -            String superClass) {
   3.208 -        boolean ok = true;
   3.209 -        log.verbose("parsing: " + propertiesPath);
   3.210 -        Properties p = new Properties();
   3.211 -        try {
   3.212 -            p.load(new FileInputStream(propertiesPath));
   3.213 -        } catch ( FileNotFoundException e ) {
   3.214 -            ok = false;
   3.215 -            log.error("Cannot find file " + propertiesPath, e);
   3.216 -        } catch ( IOException e ) {
   3.217 -            ok = false;
   3.218 -            log.error("IO error on file " + propertiesPath, e);
   3.219 -        }
   3.220 -        if ( ok ) {
   3.221 -            String packageName = inferPackageName(propertiesPath, outputPath);
   3.222 -            log.verbose("inferred package name: " + packageName);
   3.223 -            List<String> sortedKeys = new ArrayList<String>();
   3.224 -            for ( Object key : p.keySet() ) {
   3.225 -                sortedKeys.add((String)key);
   3.226 -            }
   3.227 -            Collections.sort(sortedKeys);
   3.228 -            Iterator<String> keys = sortedKeys.iterator();
   3.229 -
   3.230 -            StringBuffer data = new StringBuffer();
   3.231 -
   3.232 -            while (keys.hasNext()) {
   3.233 -                String key = keys.next();
   3.234 -                data.append("            { \"" + escape(key) + "\", \"" +
   3.235 -                        escape((String)p.get(key)) + "\" },\n");
   3.236 -            }
   3.237 -
   3.238 -            // Get class name from java filename, not the properties filename.
   3.239 -            //   (zh_TW properties might be used to create zh_HK files)
   3.240 -            File file = new File(outputPath);
   3.241 -            String name = file.getName();
   3.242 -            int dotIndex = name.lastIndexOf('.');
   3.243 -            String className;
   3.244 -            if (dotIndex == -1) {
   3.245 -                className = name;
   3.246 -            } else {
   3.247 -                className = name.substring(0, dotIndex);
   3.248 -            }
   3.249 -
   3.250 -            String packageString = "";
   3.251 -            if (packageName != null && !packageName.equals("")) {
   3.252 -                packageString = "package " + packageName + ";\n\n";
   3.253 -            }
   3.254 -
   3.255 -            Writer writer = null;
   3.256 -            try {
   3.257 -                writer = new BufferedWriter(
   3.258 -                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
   3.259 -                MessageFormat format = new MessageFormat(FORMAT);
   3.260 -                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
   3.261 -            } catch ( IOException e ) {
   3.262 -                ok = false;
   3.263 -                log.error("IO error writing to file " + outputPath, e);
   3.264 -            }
   3.265 -            if ( writer != null ) {
   3.266 -                try {
   3.267 -                    writer.flush();
   3.268 -                } catch ( IOException e ) {
   3.269 -                    ok = false;
   3.270 -                    log.error("IO error flush " + outputPath, e);
   3.271 -                }
   3.272 -                try {
   3.273 -                    writer.close();
   3.274 -                } catch ( IOException e ) {
   3.275 -                    ok = false;
   3.276 -                    log.error("IO error close " + outputPath, e);
   3.277 -                }
   3.278 -            }
   3.279 -            log.verbose("wrote: " + outputPath);
   3.280 -        }
   3.281 -        return ok;
   3.282 -    }
   3.283 -
   3.284 -    private static void usage(Log log) {
   3.285 -        log.info("usage:");
   3.286 -        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
   3.287 -        log.info("      -OR-");
   3.288 -        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
   3.289 -        log.info("");
   3.290 -        log.info("Example:");
   3.291 -        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
   3.292 -        log.info("    java CompileProperties -optionsfile option_file");
   3.293 -        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
   3.294 -    }
   3.295 -
   3.296 -    private static String escape(String theString) {
   3.297 -        // This is taken from Properties.saveConvert with changes for Java strings
   3.298 -        int len = theString.length();
   3.299 -        StringBuffer outBuffer = new StringBuffer(len*2);
   3.300 -
   3.301 -        for(int x=0; x<len; x++) {
   3.302 -            char aChar = theString.charAt(x);
   3.303 -            switch(aChar) {
   3.304 -                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
   3.305 -                break;
   3.306 -                case '\t':outBuffer.append('\\'); outBuffer.append('t');
   3.307 -                break;
   3.308 -                case '\n':outBuffer.append('\\'); outBuffer.append('n');
   3.309 -                break;
   3.310 -                case '\r':outBuffer.append('\\'); outBuffer.append('r');
   3.311 -                break;
   3.312 -                case '\f':outBuffer.append('\\'); outBuffer.append('f');
   3.313 -                break;
   3.314 -                default:
   3.315 -                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
   3.316 -                        outBuffer.append('\\');
   3.317 -                        outBuffer.append('u');
   3.318 -                        outBuffer.append(toHex((aChar >> 12) & 0xF));
   3.319 -                        outBuffer.append(toHex((aChar >>  8) & 0xF));
   3.320 -                        outBuffer.append(toHex((aChar >>  4) & 0xF));
   3.321 -                        outBuffer.append(toHex( aChar        & 0xF));
   3.322 -                    } else {
   3.323 -                        if (specialSaveChars.indexOf(aChar) != -1) {
   3.324 -                            outBuffer.append('\\');
   3.325 -                        }
   3.326 -                        outBuffer.append(aChar);
   3.327 -                    }
   3.328 -            }
   3.329 -        }
   3.330 -        return outBuffer.toString();
   3.331 -    }
   3.332 -
   3.333 -    private static String inferPackageName(String inputPath, String outputPath) {
   3.334 -        // Normalize file names
   3.335 -        inputPath  = new File(inputPath).getPath();
   3.336 -        outputPath = new File(outputPath).getPath();
   3.337 -        // Split into components
   3.338 -        String sep;
   3.339 -        if (File.separatorChar == '\\') {
   3.340 -            sep = "\\\\";
   3.341 -        } else {
   3.342 -            sep = File.separator;
   3.343 -        }
   3.344 -        String[] inputs  = inputPath.split(sep);
   3.345 -        String[] outputs = outputPath.split(sep);
   3.346 -        // Match common names, eliminating first "classes" entry from
   3.347 -        // each if present
   3.348 -        int inStart  = 0;
   3.349 -        int inEnd    = inputs.length - 2;
   3.350 -        int outEnd   = outputs.length - 2;
   3.351 -        int i = inEnd;
   3.352 -        int j = outEnd;
   3.353 -        while (i >= 0 && j >= 0) {
   3.354 -            if (!inputs[i].equals(outputs[j]) ||
   3.355 -                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
   3.356 -                ++i;
   3.357 -                ++j;
   3.358 -                break;
   3.359 -            }
   3.360 -            --i;
   3.361 -            --j;
   3.362 -        }
   3.363 -        String result;
   3.364 -        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
   3.365 -            result = "";
   3.366 -        } else {
   3.367 -            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
   3.368 -                ++i;
   3.369 -            }
   3.370 -            inStart = i;
   3.371 -            StringBuffer buf = new StringBuffer();
   3.372 -            for (i = inStart; i <= inEnd; i++) {
   3.373 -                buf.append(inputs[i]);
   3.374 -                if (i < inEnd) {
   3.375 -                    buf.append('.');
   3.376 -                }
   3.377 -            }
   3.378 -            result = buf.toString();
   3.379 -        }
   3.380 -        return result;
   3.381 -    }
   3.382 -
   3.383 -    private static final String FORMAT =
   3.384 -            "{0}" +
   3.385 -            "public final class {1} extends {2} '{'\n" +
   3.386 -            "    protected final Object[][] getContents() '{'\n" +
   3.387 -            "        return new Object[][] '{'\n" +
   3.388 -            "{3}" +
   3.389 -            "        };\n" +
   3.390 -            "    }\n" +
   3.391 -            "}\n";
   3.392 -
   3.393 -    // This comes from Properties
   3.394 -    private static char toHex(int nibble) {
   3.395 -        return hexDigit[(nibble & 0xF)];
   3.396 -    }
   3.397 -
   3.398 -    // This comes from Properties
   3.399 -    private static final char[] hexDigit = {
   3.400 -        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
   3.401 -    };
   3.402 -
   3.403 -    // Note: different from that in Properties
   3.404 -    private static final String specialSaveChars = "\"";
   3.405 -}
     4.1 --- a/make/tools/CompileProperties/CompilePropertiesTask.java	Tue Mar 06 20:27:12 2012 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,97 +0,0 @@
     4.4 -/*
     4.5 - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     4.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 - *
     4.8 - * This code is free software; you can redistribute it and/or modify it
     4.9 - * under the terms of the GNU General Public License version 2 only, as
    4.10 - * published by the Free Software Foundation.  Oracle designates this
    4.11 - * particular file as subject to the "Classpath" exception as provided
    4.12 - * by Oracle in the LICENSE file that accompanied this code.
    4.13 - *
    4.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 - * version 2 for more details (a copy is included in the LICENSE file that
    4.18 - * accompanied this code).
    4.19 - *
    4.20 - * You should have received a copy of the GNU General Public License version
    4.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 - *
    4.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.25 - * or visit www.oracle.com if you need additional information or have any
    4.26 - * questions.
    4.27 - */
    4.28 -
    4.29 -import java.io.File;
    4.30 -import java.util.ArrayList;
    4.31 -import java.util.List;
    4.32 -
    4.33 -import org.apache.tools.ant.BuildException;
    4.34 -import org.apache.tools.ant.DirectoryScanner;
    4.35 -import org.apache.tools.ant.Project;
    4.36 -import org.apache.tools.ant.taskdefs.MatchingTask;
    4.37 -
    4.38 -public class CompilePropertiesTask extends MatchingTask {
    4.39 -    public void setSrcDir(File srcDir) {
    4.40 -        this.srcDir = srcDir;
    4.41 -    }
    4.42 -
    4.43 -    public void setDestDir(File destDir) {
    4.44 -        this.destDir = destDir;
    4.45 -    }
    4.46 -
    4.47 -    public void setSuperclass(String superclass) {
    4.48 -        this.superclass = superclass;
    4.49 -    }
    4.50 -
    4.51 -    @Override
    4.52 -    public void execute() {
    4.53 -        CompileProperties.Log log = new CompileProperties.Log() {
    4.54 -            public void error(String msg, Exception e) {
    4.55 -                log(msg, Project.MSG_ERR);
    4.56 -            }
    4.57 -            public void info(String msg) {
    4.58 -                log(msg, Project.MSG_INFO);
    4.59 -            }
    4.60 -            public void verbose(String msg) {
    4.61 -                log(msg, Project.MSG_VERBOSE);
    4.62 -            }
    4.63 -        };
    4.64 -        List<String> mainOpts = new ArrayList<String>();
    4.65 -        int count = 0;
    4.66 -        DirectoryScanner s = getDirectoryScanner(srcDir);
    4.67 -        for (String path: s.getIncludedFiles()) {
    4.68 -            if (path.endsWith(".properties")) {
    4.69 -                String destPath =
    4.70 -                        path.substring(0, path.length() - ".properties".length()) +
    4.71 -                        ".java";
    4.72 -                File srcFile = new File(srcDir, path);
    4.73 -                File destFile = new File(destDir, destPath);
    4.74 -                // Arguably, the comparison in the next line should be ">", not ">="
    4.75 -                // but that assumes the resolution of the last modified time is fine
    4.76 -                // grained enough; in practice, it is better to use ">=".
    4.77 -                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
    4.78 -                    continue;
    4.79 -                destFile.getParentFile().mkdirs();
    4.80 -                mainOpts.add("-compile");
    4.81 -                mainOpts.add(srcFile.getPath());
    4.82 -                mainOpts.add(destFile.getPath());
    4.83 -                mainOpts.add(superclass);
    4.84 -                count++;
    4.85 -            }
    4.86 -        }
    4.87 -        if (mainOpts.size() > 0) {
    4.88 -            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
    4.89 -            CompileProperties cp = new CompileProperties();
    4.90 -            cp.setLog(log);
    4.91 -            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
    4.92 -            if (!ok)
    4.93 -                throw new BuildException("CompileProperties failed.");
    4.94 -        }
    4.95 -    }
    4.96 -
    4.97 -    private File srcDir;
    4.98 -    private File destDir;
    4.99 -    private String superclass = "java.util.ListResourceBundle";
   4.100 -}
     5.1 --- a/make/tools/GenStubs/GenStubs.java	Tue Mar 06 20:27:12 2012 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,448 +0,0 @@
     5.4 -/*
     5.5 - * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
     5.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 - *
     5.8 - * This code is free software; you can redistribute it and/or modify it
     5.9 - * under the terms of the GNU General Public License version 2 only, as
    5.10 - * published by the Free Software Foundation.  Oracle designates this
    5.11 - * particular file as subject to the "Classpath" exception as provided
    5.12 - * by Oracle in the LICENSE file that accompanied this code.
    5.13 - *
    5.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 - * version 2 for more details (a copy is included in the LICENSE file that
    5.18 - * accompanied this code).
    5.19 - *
    5.20 - * You should have received a copy of the GNU General Public License version
    5.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 - *
    5.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.25 - * or visit www.oracle.com if you need additional information or have any
    5.26 - * questions.
    5.27 - */
    5.28 -
    5.29 -import java.io.*;
    5.30 -import java.util.*;
    5.31 -import javax.tools.JavaFileObject;
    5.32 -import javax.tools.StandardJavaFileManager;
    5.33 -import javax.tools.StandardLocation;
    5.34 -
    5.35 -import org.apache.tools.ant.BuildException;
    5.36 -import org.apache.tools.ant.DirectoryScanner;
    5.37 -import org.apache.tools.ant.taskdefs.MatchingTask;
    5.38 -import org.apache.tools.ant.types.Path;
    5.39 -import org.apache.tools.ant.types.Reference;
    5.40 -
    5.41 -
    5.42 -import com.sun.source.tree.CompilationUnitTree;
    5.43 -import com.sun.source.util.JavacTask;
    5.44 -import com.sun.tools.javac.api.JavacTool;
    5.45 -import com.sun.tools.javac.code.Flags;
    5.46 -import com.sun.tools.javac.code.TypeTags;
    5.47 -import com.sun.tools.javac.tree.JCTree;
    5.48 -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
    5.49 -import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
    5.50 -import com.sun.tools.javac.tree.JCTree.JCIdent;
    5.51 -import com.sun.tools.javac.tree.JCTree.JCImport;
    5.52 -import com.sun.tools.javac.tree.JCTree.JCLiteral;
    5.53 -import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
    5.54 -import com.sun.tools.javac.tree.JCTree.JCModifiers;
    5.55 -import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
    5.56 -import com.sun.tools.javac.tree.Pretty;
    5.57 -import com.sun.tools.javac.tree.TreeMaker;
    5.58 -import com.sun.tools.javac.tree.TreeScanner;
    5.59 -import com.sun.tools.javac.tree.TreeTranslator;
    5.60 -import com.sun.tools.javac.util.Context;
    5.61 -import com.sun.tools.javac.util.ListBuffer;
    5.62 -import com.sun.tools.javac.util.Name;
    5.63 -import javax.tools.JavaFileManager;
    5.64 -
    5.65 -/**
    5.66 - * Generate stub source files by removing implementation details from input files.
    5.67 - *
    5.68 - * This is a special purpose stub generator, specific to the needs of generating
    5.69 - * stub files for JDK 7 API that are needed to compile langtools files that depend
    5.70 - * on that API. The stub generator works by removing as much of the API source code
    5.71 - * as possible without affecting the public signature, in order to reduce the
    5.72 - * transitive closure of the API being referenced. The resulting stubs can be
    5.73 - * put on the langtools sourcepath with -implicit:none to compile the langtools
    5.74 - * files that depend on the JDK 7 API.
    5.75 - *
    5.76 - * Usage:
    5.77 - *  genstubs -s <outdir> -sourcepath <path> <classnames>
    5.78 - *
    5.79 - * The specified class names are looked up on the sourcepath, and corresponding
    5.80 - * stubs are written to the source output directory.
    5.81 - *
    5.82 - * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
    5.83 - * to remove implementation details, and written out in the source output directory.
    5.84 - * Documentation comments and annotations are removed. Method bodies are removed
    5.85 - * and methods are marked native. Private and package-private field definitions
    5.86 - * have their initializers replace with 0, 0.0, false, null as appropriate.
    5.87 - *
    5.88 - * An Ant task, Main$Ant is also provided. Files are specified with an implicit
    5.89 - * fileset, using srcdir as a base directory. The set of files to be included
    5.90 - * is specified with an includes attribute or nested <includes> set. However,
    5.91 - * unlike a normal fileset, an empty includes attribute means "no files" instead
    5.92 - * of "all files".  The Ant task also accepts "fork=true" and classpath attribute
    5.93 - * or nested <classpath> element to run GenStubs in a separate VM with the specified
    5.94 - * path. This is likely necessary if a JDK 7 parser is required to read the
    5.95 - * JDK 7 input files.
    5.96 - */
    5.97 -
    5.98 -public class GenStubs {
    5.99 -    static class Fault extends Exception {
   5.100 -        private static final long serialVersionUID = 0;
   5.101 -        Fault(String message) {
   5.102 -            super(message);
   5.103 -        }
   5.104 -        Fault(String message, Throwable cause) {
   5.105 -            super(message);
   5.106 -            initCause(cause);
   5.107 -        }
   5.108 -    }
   5.109 -
   5.110 -    public static void main(String[] args) {
   5.111 -        boolean ok = new GenStubs().run(args);
   5.112 -        if (!ok)
   5.113 -            System.exit(1);
   5.114 -    }
   5.115 -
   5.116 -    boolean run(String... args) {
   5.117 -        File outdir = null;
   5.118 -        String sourcepath = null;
   5.119 -        List<String> classes = new ArrayList<String>();
   5.120 -        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
   5.121 -            String arg = iter.next();
   5.122 -            if (arg.equals("-s") && iter.hasNext())
   5.123 -                outdir = new File(iter.next());
   5.124 -            else if (arg.equals("-sourcepath") && iter.hasNext())
   5.125 -                sourcepath = iter.next();
   5.126 -            else if (arg.startsWith("-"))
   5.127 -                throw new IllegalArgumentException(arg);
   5.128 -            else {
   5.129 -                classes.add(arg);
   5.130 -                while (iter.hasNext())
   5.131 -                    classes.add(iter.next());
   5.132 -            }
   5.133 -        }
   5.134 -
   5.135 -        return run(sourcepath, outdir, classes);
   5.136 -    }
   5.137 -
   5.138 -    boolean run(String sourcepath, File outdir, List<String> classes) {
   5.139 -        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
   5.140 -        if (sourcepath == null)
   5.141 -            throw new IllegalArgumentException("sourcepath not set");
   5.142 -        if (outdir == null)
   5.143 -            throw new IllegalArgumentException("source output dir not set");
   5.144 -
   5.145 -        JavacTool tool = JavacTool.create();
   5.146 -        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
   5.147 -
   5.148 -        try {
   5.149 -            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
   5.150 -            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
   5.151 -            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
   5.152 -            for (String c: classes) {
   5.153 -                JavaFileObject fo = fm.getJavaFileForInput(
   5.154 -                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
   5.155 -                if (fo == null)
   5.156 -                    error("class not found: " + c);
   5.157 -                else
   5.158 -                    files.add(fo);
   5.159 -            }
   5.160 -
   5.161 -            JavacTask t = tool.getTask(null, fm, null, null, null, files);
   5.162 -            Iterable<? extends CompilationUnitTree> trees = t.parse();
   5.163 -            for (CompilationUnitTree tree: trees) {
   5.164 -                makeStub(fm, tree);
   5.165 -            }
   5.166 -        } catch (IOException e) {
   5.167 -            error("IO error " + e, e);
   5.168 -        }
   5.169 -
   5.170 -        return (errors == 0);
   5.171 -    }
   5.172 -
   5.173 -    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
   5.174 -        CompilationUnitTree tree2 = new StubMaker().translate(tree);
   5.175 -        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
   5.176 -
   5.177 -        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
   5.178 -        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
   5.179 -                className, JavaFileObject.Kind.SOURCE, null);
   5.180 -        // System.err.println("Writing " + className + " to " + fo.getName());
   5.181 -        Writer out = fo.openWriter();
   5.182 -        try {
   5.183 -            new Pretty(out, true).printExpr((JCTree) tree3);
   5.184 -        } finally {
   5.185 -            out.close();
   5.186 -        }
   5.187 -    }
   5.188 -
   5.189 -    List<File> splitPath(String path) {
   5.190 -        List<File> list = new ArrayList<File>();
   5.191 -        for (String p: path.split(File.pathSeparator)) {
   5.192 -            if (p.length() > 0)
   5.193 -                list.add(new File(p));
   5.194 -        }
   5.195 -        return list;
   5.196 -    }
   5.197 -
   5.198 -    void error(String message) {
   5.199 -        System.err.println(message);
   5.200 -        errors++;
   5.201 -    }
   5.202 -
   5.203 -    void error(String message, Throwable cause) {
   5.204 -        error(message);
   5.205 -    }
   5.206 -
   5.207 -    int errors;
   5.208 -
   5.209 -    class StubMaker extends TreeTranslator {
   5.210 -        CompilationUnitTree translate(CompilationUnitTree tree) {
   5.211 -            return super.translate((JCCompilationUnit) tree);
   5.212 -        }
   5.213 -
   5.214 -        /**
   5.215 -         * compilation units: remove javadoc comments
   5.216 -         * -- required, in order to remove @deprecated tags, since we
   5.217 -         * (separately) remove all annotations, including @Deprecated
   5.218 -         */
   5.219 -        public void visitTopLevel(JCCompilationUnit tree) {
   5.220 -            super.visitTopLevel(tree);
   5.221 -            tree.docComments = Collections.emptyMap();
   5.222 -        }
   5.223 -
   5.224 -        /**
   5.225 -         * methods: remove method bodies, make methods native
   5.226 -         */
   5.227 -        @Override
   5.228 -        public void visitMethodDef(JCMethodDecl tree) {
   5.229 -            tree.mods = translate(tree.mods);
   5.230 -            tree.restype = translate(tree.restype);
   5.231 -            tree.typarams = translateTypeParams(tree.typarams);
   5.232 -            tree.params = translateVarDefs(tree.params);
   5.233 -            tree.thrown = translate(tree.thrown);
   5.234 -            if (tree.restype != null && tree.body != null) {
   5.235 -                tree.mods.flags |= Flags.NATIVE;
   5.236 -                tree.body = null;
   5.237 -            }
   5.238 -            result = tree;
   5.239 -        }
   5.240 -
   5.241 -        /**
   5.242 -         * modifiers: remove annotations
   5.243 -         */
   5.244 -        @Override
   5.245 -        public void visitModifiers(JCModifiers tree) {
   5.246 -            tree.annotations = com.sun.tools.javac.util.List.nil();
   5.247 -            result = tree;
   5.248 -        }
   5.249 -
   5.250 -        /**
   5.251 -         * field definitions: replace initializers with 0, 0.0, false etc
   5.252 -         * when possible -- i.e. leave public, protected initializers alone
   5.253 -         */
   5.254 -        @Override
   5.255 -        public void visitVarDef(JCVariableDecl tree) {
   5.256 -            tree.mods = translate(tree.mods);
   5.257 -            tree.vartype = translate(tree.vartype);
   5.258 -            if (tree.init != null) {
   5.259 -                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
   5.260 -                    tree.init = translate(tree.init);
   5.261 -                else {
   5.262 -                    String t = tree.vartype.toString();
   5.263 -                    if (t.equals("boolean"))
   5.264 -                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
   5.265 -                    else if (t.equals("byte"))
   5.266 -                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
   5.267 -                    else if (t.equals("char"))
   5.268 -                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
   5.269 -                    else if (t.equals("double"))
   5.270 -                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
   5.271 -                    else if (t.equals("float"))
   5.272 -                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
   5.273 -                    else if (t.equals("int"))
   5.274 -                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
   5.275 -                    else if (t.equals("long"))
   5.276 -                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
   5.277 -                    else if (t.equals("short"))
   5.278 -                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
   5.279 -                    else
   5.280 -                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
   5.281 -                }
   5.282 -            }
   5.283 -            result = tree;
   5.284 -        }
   5.285 -    }
   5.286 -
   5.287 -    class ImportCleaner extends TreeScanner {
   5.288 -        private Set<Name> names = new HashSet<Name>();
   5.289 -        private TreeMaker m;
   5.290 -
   5.291 -        ImportCleaner(JavaFileManager fm) {
   5.292 -            // ImportCleaner itself doesn't require a filemanager, but instantiating
   5.293 -            // a TreeMaker does, indirectly (via ClassReader, sigh)
   5.294 -            Context c = new Context();
   5.295 -            c.put(JavaFileManager.class, fm);
   5.296 -            m = TreeMaker.instance(c);
   5.297 -        }
   5.298 -
   5.299 -        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
   5.300 -            JCCompilationUnit tree = (JCCompilationUnit) t;
   5.301 -            tree.accept(this);
   5.302 -            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
   5.303 -            for (JCTree def: tree.defs) {
   5.304 -                if (def.getTag() == JCTree.IMPORT) {
   5.305 -                    JCImport imp = (JCImport) def;
   5.306 -                    if (imp.qualid.getTag() == JCTree.SELECT) {
   5.307 -                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
   5.308 -                        if (!qualid.name.toString().equals("*")
   5.309 -                                && !names.contains(qualid.name)) {
   5.310 -                            continue;
   5.311 -                        }
   5.312 -                    }
   5.313 -                }
   5.314 -                defs.add(def);
   5.315 -            }
   5.316 -            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
   5.317 -        }
   5.318 -
   5.319 -        @Override
   5.320 -        public void visitImport(JCImport tree) { } // ignore names found in imports
   5.321 -
   5.322 -        @Override
   5.323 -        public void visitIdent(JCIdent tree) {
   5.324 -            names.add(tree.name);
   5.325 -        }
   5.326 -
   5.327 -        @Override
   5.328 -        public void visitSelect(JCFieldAccess tree) {
   5.329 -            super.visitSelect(tree);
   5.330 -            names.add(tree.name);
   5.331 -        }
   5.332 -    }
   5.333 -
   5.334 -    //---------- Ant Invocation ------------------------------------------------
   5.335 -
   5.336 -    public static class Ant extends MatchingTask {
   5.337 -        private File srcDir;
   5.338 -        private File destDir;
   5.339 -        private boolean fork;
   5.340 -        private Path classpath;
   5.341 -        private String includes;
   5.342 -
   5.343 -        public void setSrcDir(File dir) {
   5.344 -            this.srcDir = dir;
   5.345 -        }
   5.346 -
   5.347 -        public void setDestDir(File dir) {
   5.348 -            this.destDir = dir;
   5.349 -        }
   5.350 -
   5.351 -        public void setFork(boolean v) {
   5.352 -            this.fork = v;
   5.353 -        }
   5.354 -
   5.355 -        public void setClasspath(Path cp) {
   5.356 -            if (classpath == null)
   5.357 -                classpath = cp;
   5.358 -            else
   5.359 -                classpath.append(cp);
   5.360 -        }
   5.361 -
   5.362 -        public Path createClasspath() {
   5.363 -            if (classpath == null) {
   5.364 -                classpath = new Path(getProject());
   5.365 -            }
   5.366 -            return classpath.createPath();
   5.367 -        }
   5.368 -
   5.369 -        public void setClasspathRef(Reference r) {
   5.370 -            createClasspath().setRefid(r);
   5.371 -        }
   5.372 -
   5.373 -        public void setIncludes(String includes) {
   5.374 -            super.setIncludes(includes);
   5.375 -            this.includes = includes;
   5.376 -        }
   5.377 -
   5.378 -        @Override
   5.379 -        public void execute() {
   5.380 -            if (includes != null && includes.trim().isEmpty())
   5.381 -                return;
   5.382 -
   5.383 -            DirectoryScanner s = getDirectoryScanner(srcDir);
   5.384 -            String[] files = s.getIncludedFiles();
   5.385 -//            System.err.println("Ant.execute: srcDir " + srcDir);
   5.386 -//            System.err.println("Ant.execute: destDir " + destDir);
   5.387 -//            System.err.println("Ant.execute: files " + Arrays.asList(files));
   5.388 -
   5.389 -            files = filter(srcDir, destDir, files);
   5.390 -            if (files.length == 0)
   5.391 -                return;
   5.392 -            System.out.println("Generating " + files.length + " stub files to " + destDir);
   5.393 -
   5.394 -            List<String> classNames = new ArrayList<String>();
   5.395 -            for (String file: files) {
   5.396 -                classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
   5.397 -            }
   5.398 -
   5.399 -            if (!fork) {
   5.400 -                GenStubs m = new GenStubs();
   5.401 -                boolean ok = m.run(srcDir.getPath(), destDir, classNames);
   5.402 -                if (!ok)
   5.403 -                    throw new BuildException("genstubs failed");
   5.404 -            } else {
   5.405 -                List<String> cmd = new ArrayList<String>();
   5.406 -                String java_home = System.getProperty("java.home");
   5.407 -                cmd.add(new File(new File(java_home, "bin"), "java").getPath());
   5.408 -                if (classpath != null)
   5.409 -                    cmd.add("-Xbootclasspath/p:" + classpath);
   5.410 -                cmd.add(GenStubs.class.getName());
   5.411 -                cmd.add("-sourcepath");
   5.412 -                cmd.add(srcDir.getPath());
   5.413 -                cmd.add("-s");
   5.414 -                cmd.add(destDir.getPath());
   5.415 -                cmd.addAll(classNames);
   5.416 -                //System.err.println("GenStubs exec " + cmd);
   5.417 -                ProcessBuilder pb = new ProcessBuilder(cmd);
   5.418 -                pb.redirectErrorStream(true);
   5.419 -                try {
   5.420 -                    Process p = pb.start();
   5.421 -                    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
   5.422 -                    try {
   5.423 -                        String line;
   5.424 -                        while ((line = in.readLine()) != null)
   5.425 -                            System.out.println(line);
   5.426 -                    } finally {
   5.427 -                        in.close();
   5.428 -                    }
   5.429 -                    int rc = p.waitFor();
   5.430 -                    if (rc != 0)
   5.431 -                        throw new BuildException("genstubs failed");
   5.432 -                } catch (IOException e) {
   5.433 -                    throw new BuildException("genstubs failed", e);
   5.434 -                } catch (InterruptedException e) {
   5.435 -                    throw new BuildException("genstubs failed", e);
   5.436 -                }
   5.437 -            }
   5.438 -        }
   5.439 -
   5.440 -        String[] filter(File srcDir, File destDir, String[] files) {
   5.441 -            List<String> results = new ArrayList<String>();
   5.442 -            for (String f: files) {
   5.443 -                long srcTime = new File(srcDir, f).lastModified();
   5.444 -                long destTime = new File(destDir, f).lastModified();
   5.445 -                if (srcTime > destTime)
   5.446 -                    results.add(f);
   5.447 -            }
   5.448 -            return results.toArray(new String[results.size()]);
   5.449 -        }
   5.450 -    }
   5.451 -}
     6.1 --- a/make/tools/SelectTool/SelectToolTask.java	Tue Mar 06 20:27:12 2012 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,284 +0,0 @@
     6.4 -/*
     6.5 - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
     6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 - *
     6.8 - * This code is free software; you can redistribute it and/or modify it
     6.9 - * under the terms of the GNU General Public License version 2 only, as
    6.10 - * published by the Free Software Foundation.  Oracle designates this
    6.11 - * particular file as subject to the "Classpath" exception as provided
    6.12 - * by Oracle in the LICENSE file that accompanied this code.
    6.13 - *
    6.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 - * version 2 for more details (a copy is included in the LICENSE file that
    6.18 - * accompanied this code).
    6.19 - *
    6.20 - * You should have received a copy of the GNU General Public License version
    6.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 - *
    6.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.25 - * or visit www.oracle.com if you need additional information or have any
    6.26 - * questions.
    6.27 - */
    6.28 -
    6.29 -import java.awt.GridBagConstraints;
    6.30 -import java.awt.GridBagLayout;
    6.31 -import java.awt.event.ActionEvent;
    6.32 -import java.awt.event.ActionListener;
    6.33 -import java.awt.event.FocusEvent;
    6.34 -import java.awt.event.FocusListener;
    6.35 -import java.awt.event.ItemEvent;
    6.36 -import java.awt.event.ItemListener;
    6.37 -import java.io.BufferedReader;
    6.38 -import java.io.BufferedWriter;
    6.39 -import java.io.File;
    6.40 -import java.io.FileReader;
    6.41 -import java.io.FileWriter;
    6.42 -import java.io.IOException;
    6.43 -import java.io.Reader;
    6.44 -import java.io.Writer;
    6.45 -import java.util.ArrayList;
    6.46 -import java.util.Arrays;
    6.47 -import java.util.List;
    6.48 -import java.util.Properties;
    6.49 -import javax.swing.JButton;
    6.50 -import javax.swing.JCheckBox;
    6.51 -import javax.swing.JComboBox;
    6.52 -import javax.swing.JDialog;
    6.53 -import javax.swing.JLabel;
    6.54 -import javax.swing.JOptionPane;
    6.55 -import javax.swing.JPanel;
    6.56 -import javax.swing.JTextField;
    6.57 -
    6.58 -import javax.swing.SwingUtilities;
    6.59 -import org.apache.tools.ant.BuildException;
    6.60 -import org.apache.tools.ant.Project;
    6.61 -import org.apache.tools.ant.Task;
    6.62 -
    6.63 -/**
    6.64 - * Task to allow the user to control langtools tools built when using NetBeans.
    6.65 - *
    6.66 - * There are two primary modes.
    6.67 - * 1) Property mode. In this mode, property names are provided to get values
    6.68 - * that may be specified by the user, either directly in a GUI dialog, or
    6.69 - * read from a properties file. If the GUI dialog is invoked, values may
    6.70 - * optionally be set for future use.
    6.71 - * 2) Setup mode. In this mode, no property names are provided, and the GUI
    6.72 - * is invoked to allow the user to set or reset values for use in property mode.
    6.73 - */
    6.74 -public class SelectToolTask extends Task {
    6.75 -    /**
    6.76 -     * Set the location of the private properties file used to keep the retain
    6.77 -     * user preferences for this repository.
    6.78 -     */
    6.79 -    public void setPropertyFile(File propertyFile) {
    6.80 -        this.propertyFile = propertyFile;
    6.81 -    }
    6.82 -
    6.83 -    /**
    6.84 -     * Set the name of the property which will be set to the name of the
    6.85 -     * selected tool, if any. If no tool is selected, the property will
    6.86 -     * remain unset.
    6.87 -     */
    6.88 -    public void setToolProperty(String toolProperty) {
    6.89 -        this.toolProperty = toolProperty;
    6.90 -    }
    6.91 -
    6.92 -    /**
    6.93 -     * Set the name of the property which will be set to the execution args of the
    6.94 -     * selected tool, if any. The args default to an empty string.
    6.95 -     */
    6.96 -    public void setArgsProperty(String argsProperty) {
    6.97 -        this.argsProperty = argsProperty;
    6.98 -    }
    6.99 -
   6.100 -    /**
   6.101 -     * Specify whether or not to pop up a dialog if the user has not specified
   6.102 -     * a default value for a property.
   6.103 -     */
   6.104 -    public void setAskIfUnset(boolean askIfUnset) {
   6.105 -        this.askIfUnset = askIfUnset;
   6.106 -    }
   6.107 -
   6.108 -    @Override
   6.109 -    public void execute() {
   6.110 -        Project p = getProject();
   6.111 -
   6.112 -        Properties props = readProperties(propertyFile);
   6.113 -        toolName = props.getProperty("tool.name");
   6.114 -        if (toolName != null) {
   6.115 -            toolArgs = props.getProperty(toolName + ".args", "");
   6.116 -        }
   6.117 -
   6.118 -        if (toolProperty == null ||
   6.119 -            askIfUnset && (toolName == null
   6.120 -                || (argsProperty != null && toolArgs == null))) {
   6.121 -            showGUI(props);
   6.122 -        }
   6.123 -
   6.124 -        // finally, return required values, if any
   6.125 -        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
   6.126 -            p.setProperty(toolProperty, toolName);
   6.127 -
   6.128 -            if (argsProperty != null && toolArgs != null)
   6.129 -                p.setProperty(argsProperty, toolArgs);
   6.130 -        }
   6.131 -    }
   6.132 -
   6.133 -    void showGUI(Properties fileProps) {
   6.134 -        Properties guiProps = new Properties(fileProps);
   6.135 -        JOptionPane p = createPane(guiProps);
   6.136 -        p.createDialog("Select Tool").setVisible(true);
   6.137 -
   6.138 -        toolName = (String) toolChoice.getSelectedItem();
   6.139 -        toolArgs = argsField.getText();
   6.140 -
   6.141 -        if (defaultCheck.isSelected()) {
   6.142 -            if (toolName.equals("")) {
   6.143 -                fileProps.remove("tool.name");
   6.144 -            } else {
   6.145 -                fileProps.put("tool.name", toolName);
   6.146 -                fileProps.put(toolName + ".args", toolArgs);
   6.147 -            }
   6.148 -            writeProperties(propertyFile, fileProps);
   6.149 -        }
   6.150 -    }
   6.151 -
   6.152 -    JOptionPane createPane(final Properties props) {
   6.153 -        JPanel body = new JPanel(new GridBagLayout());
   6.154 -        GridBagConstraints lc = new GridBagConstraints();
   6.155 -        lc.insets.right = 10;
   6.156 -        lc.insets.bottom = 3;
   6.157 -        GridBagConstraints fc = new GridBagConstraints();
   6.158 -        fc.anchor = GridBagConstraints.WEST;
   6.159 -        fc.gridx = 1;
   6.160 -        fc.gridwidth = GridBagConstraints.REMAINDER;
   6.161 -        fc.insets.bottom = 3;
   6.162 -
   6.163 -        JLabel toolLabel = new JLabel("Tool:");
   6.164 -        body.add(toolLabel, lc);
   6.165 -        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
   6.166 -        if (true || toolProperty == null) {
   6.167 -            // include empty value in setup mode
   6.168 -            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
   6.169 -            l.add(0, "");
   6.170 -            toolChoices = l.toArray(new String[l.size()]);
   6.171 -        }
   6.172 -        toolChoice = new JComboBox(toolChoices);
   6.173 -        if (toolName != null)
   6.174 -            toolChoice.setSelectedItem(toolName);
   6.175 -        toolChoice.addItemListener(new ItemListener() {
   6.176 -            public void itemStateChanged(ItemEvent e) {
   6.177 -                String tn = (String) e.getItem();
   6.178 -                argsField.setText(getDefaultArgsForTool(props, tn));
   6.179 -                if (toolProperty != null)
   6.180 -                    okButton.setEnabled(!tn.equals(""));
   6.181 -            }
   6.182 -        });
   6.183 -        body.add(toolChoice, fc);
   6.184 -
   6.185 -        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
   6.186 -        if (toolProperty == null || argsProperty != null) {
   6.187 -            JLabel argsLabel = new JLabel("Args:");
   6.188 -            body.add(argsLabel, lc);
   6.189 -            body.add(argsField, fc);
   6.190 -            argsField.addFocusListener(new FocusListener() {
   6.191 -                public void focusGained(FocusEvent e) {
   6.192 -                }
   6.193 -                public void focusLost(FocusEvent e) {
   6.194 -                    String toolName = (String) toolChoice.getSelectedItem();
   6.195 -                    if (toolName.length() > 0)
   6.196 -                        props.put(toolName + ".args", argsField.getText());
   6.197 -                }
   6.198 -            });
   6.199 -        }
   6.200 -
   6.201 -        defaultCheck = new JCheckBox("Set as default");
   6.202 -        if (toolProperty == null)
   6.203 -            defaultCheck.setSelected(true);
   6.204 -        else
   6.205 -            body.add(defaultCheck, fc);
   6.206 -
   6.207 -        final JOptionPane p = new JOptionPane(body);
   6.208 -        okButton = new JButton("OK");
   6.209 -        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
   6.210 -        okButton.addActionListener(new ActionListener() {
   6.211 -            public void actionPerformed(ActionEvent e) {
   6.212 -                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
   6.213 -                d.setVisible(false);
   6.214 -            }
   6.215 -        });
   6.216 -        p.setOptions(new Object[] { okButton });
   6.217 -
   6.218 -        return p;
   6.219 -    }
   6.220 -
   6.221 -    Properties readProperties(File file) {
   6.222 -        Properties p = new Properties();
   6.223 -        if (file != null && file.exists()) {
   6.224 -            Reader in = null;
   6.225 -            try {
   6.226 -                in = new BufferedReader(new FileReader(file));
   6.227 -                p.load(in);
   6.228 -                in.close();
   6.229 -            } catch (IOException e) {
   6.230 -                throw new BuildException("error reading property file", e);
   6.231 -            } finally {
   6.232 -                if (in != null) {
   6.233 -                    try {
   6.234 -                        in.close();
   6.235 -                    } catch (IOException e) {
   6.236 -                        throw new BuildException("cannot close property file", e);
   6.237 -                    }
   6.238 -                }
   6.239 -            }
   6.240 -        }
   6.241 -        return p;
   6.242 -    }
   6.243 -
   6.244 -    void writeProperties(File file, Properties p) {
   6.245 -        if (file != null) {
   6.246 -            Writer out = null;
   6.247 -            try {
   6.248 -                File dir = file.getParentFile();
   6.249 -                if (dir != null && !dir.exists())
   6.250 -                    dir.mkdirs();
   6.251 -                out = new BufferedWriter(new FileWriter(file));
   6.252 -                p.store(out, "langtools properties");
   6.253 -                out.close();
   6.254 -            } catch (IOException e) {
   6.255 -                throw new BuildException("error writing property file", e);
   6.256 -            } finally {
   6.257 -                if (out != null) {
   6.258 -                    try {
   6.259 -                        out.close();
   6.260 -                    } catch (IOException e) {
   6.261 -                        throw new BuildException("cannot close property file", e);
   6.262 -                    }
   6.263 -                }
   6.264 -            }
   6.265 -        }
   6.266 -    }
   6.267 -
   6.268 -    String getDefaultArgsForTool(Properties props, String tn) {
   6.269 -        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
   6.270 -    }
   6.271 -
   6.272 -    // Ant task parameters
   6.273 -    private boolean askIfUnset;
   6.274 -    private String toolProperty;
   6.275 -    private String argsProperty;
   6.276 -    private File propertyFile;
   6.277 -
   6.278 -    // GUI components
   6.279 -    private JComboBox toolChoice;
   6.280 -    private JTextField argsField;
   6.281 -    private JCheckBox defaultCheck;
   6.282 -    private JButton okButton;
   6.283 -
   6.284 -    // Result values for the client
   6.285 -    private String toolName;
   6.286 -    private String toolArgs;
   6.287 -}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/make/tools/anttasks/CompilePropertiesTask.java	Wed Mar 07 13:11:27 2012 +0100
     7.3 @@ -0,0 +1,101 @@
     7.4 +/*
     7.5 + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.  Oracle designates this
    7.11 + * particular file as subject to the "Classpath" exception as provided
    7.12 + * by Oracle in the LICENSE file that accompanied this code.
    7.13 + *
    7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 + * version 2 for more details (a copy is included in the LICENSE file that
    7.18 + * accompanied this code).
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License version
    7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 + *
    7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.25 + * or visit www.oracle.com if you need additional information or have any
    7.26 + * questions.
    7.27 + */
    7.28 +
    7.29 +package anttasks;
    7.30 +
    7.31 +import compileproperties.CompileProperties;
    7.32 +
    7.33 +import java.io.File;
    7.34 +import java.util.ArrayList;
    7.35 +import java.util.List;
    7.36 +
    7.37 +import org.apache.tools.ant.BuildException;
    7.38 +import org.apache.tools.ant.DirectoryScanner;
    7.39 +import org.apache.tools.ant.Project;
    7.40 +import org.apache.tools.ant.taskdefs.MatchingTask;
    7.41 +
    7.42 +public class CompilePropertiesTask extends MatchingTask {
    7.43 +    public void setSrcDir(File srcDir) {
    7.44 +        this.srcDir = srcDir;
    7.45 +    }
    7.46 +
    7.47 +    public void setDestDir(File destDir) {
    7.48 +        this.destDir = destDir;
    7.49 +    }
    7.50 +
    7.51 +    public void setSuperclass(String superclass) {
    7.52 +        this.superclass = superclass;
    7.53 +    }
    7.54 +
    7.55 +    @Override
    7.56 +    public void execute() {
    7.57 +        CompileProperties.Log log = new CompileProperties.Log() {
    7.58 +            public void error(String msg, Exception e) {
    7.59 +                log(msg, Project.MSG_ERR);
    7.60 +            }
    7.61 +            public void info(String msg) {
    7.62 +                log(msg, Project.MSG_INFO);
    7.63 +            }
    7.64 +            public void verbose(String msg) {
    7.65 +                log(msg, Project.MSG_VERBOSE);
    7.66 +            }
    7.67 +        };
    7.68 +        List<String> mainOpts = new ArrayList<String>();
    7.69 +        int count = 0;
    7.70 +        DirectoryScanner s = getDirectoryScanner(srcDir);
    7.71 +        for (String path: s.getIncludedFiles()) {
    7.72 +            if (path.endsWith(".properties")) {
    7.73 +                String destPath =
    7.74 +                        path.substring(0, path.length() - ".properties".length()) +
    7.75 +                        ".java";
    7.76 +                File srcFile = new File(srcDir, path);
    7.77 +                File destFile = new File(destDir, destPath);
    7.78 +                // Arguably, the comparison in the next line should be ">", not ">="
    7.79 +                // but that assumes the resolution of the last modified time is fine
    7.80 +                // grained enough; in practice, it is better to use ">=".
    7.81 +                if (destFile.exists() && destFile.lastModified() >= srcFile.lastModified())
    7.82 +                    continue;
    7.83 +                destFile.getParentFile().mkdirs();
    7.84 +                mainOpts.add("-compile");
    7.85 +                mainOpts.add(srcFile.getPath());
    7.86 +                mainOpts.add(destFile.getPath());
    7.87 +                mainOpts.add(superclass);
    7.88 +                count++;
    7.89 +            }
    7.90 +        }
    7.91 +        if (mainOpts.size() > 0) {
    7.92 +            log("Generating " + count + " resource files to " + destDir, Project.MSG_INFO);
    7.93 +            CompileProperties cp = new CompileProperties();
    7.94 +            cp.setLog(log);
    7.95 +            boolean ok = cp.run(mainOpts.toArray(new String[mainOpts.size()]));
    7.96 +            if (!ok)
    7.97 +                throw new BuildException("CompileProperties failed.");
    7.98 +        }
    7.99 +    }
   7.100 +
   7.101 +    private File srcDir;
   7.102 +    private File destDir;
   7.103 +    private String superclass = "java.util.ListResourceBundle";
   7.104 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/make/tools/anttasks/GenStubsTask.java	Wed Mar 07 13:11:27 2012 +0100
     8.3 @@ -0,0 +1,162 @@
     8.4 +/*
     8.5 + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
     8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     8.7 + *
     8.8 + * This code is free software; you can redistribute it and/or modify it
     8.9 + * under the terms of the GNU General Public License version 2 only, as
    8.10 + * published by the Free Software Foundation.  Oracle designates this
    8.11 + * particular file as subject to the "Classpath" exception as provided
    8.12 + * by Oracle in the LICENSE file that accompanied this code.
    8.13 + *
    8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    8.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    8.17 + * version 2 for more details (a copy is included in the LICENSE file that
    8.18 + * accompanied this code).
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License version
    8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    8.23 + *
    8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    8.25 + * or visit www.oracle.com if you need additional information or have any
    8.26 + * questions.
    8.27 + */
    8.28 +
    8.29 +package anttasks;
    8.30 +
    8.31 +import genstubs.GenStubs;
    8.32 +
    8.33 +import java.io.*;
    8.34 +import java.util.*;
    8.35 +
    8.36 +import org.apache.tools.ant.BuildException;
    8.37 +import org.apache.tools.ant.DirectoryScanner;
    8.38 +import org.apache.tools.ant.taskdefs.MatchingTask;
    8.39 +import org.apache.tools.ant.types.Path;
    8.40 +import org.apache.tools.ant.types.Reference;
    8.41 +
    8.42 +/**
    8.43 + * Files are specified with an implicit fileset, using srcdir as a base directory.
    8.44 + * The set of files to be included is specified with an includes attribute or
    8.45 + * nested <includes> set. However, unlike a normal fileset, an empty includes attribute
    8.46 + * means "no files" instead of "all files".  The Ant task also accepts "fork=true" and
    8.47 + * classpath attribute or nested <classpath> element to run GenStubs in a separate VM
    8.48 + * with the specified path. This is likely necessary if a JDK 7 parser is required to read the
    8.49 + * JDK 7 input files.
    8.50 + */
    8.51 +public class GenStubsTask extends MatchingTask {
    8.52 +    private File srcDir;
    8.53 +    private File destDir;
    8.54 +    private boolean fork;
    8.55 +    private Path classpath;
    8.56 +    private String includes;
    8.57 +
    8.58 +    public void setSrcDir(File dir) {
    8.59 +        this.srcDir = dir;
    8.60 +    }
    8.61 +
    8.62 +    public void setDestDir(File dir) {
    8.63 +        this.destDir = dir;
    8.64 +    }
    8.65 +
    8.66 +    public void setFork(boolean v) {
    8.67 +        this.fork = v;
    8.68 +    }
    8.69 +
    8.70 +    public void setClasspath(Path cp) {
    8.71 +        if (classpath == null)
    8.72 +            classpath = cp;
    8.73 +        else
    8.74 +            classpath.append(cp);
    8.75 +    }
    8.76 +
    8.77 +    public Path createClasspath() {
    8.78 +        if (classpath == null) {
    8.79 +            classpath = new Path(getProject());
    8.80 +        }
    8.81 +        return classpath.createPath();
    8.82 +    }
    8.83 +
    8.84 +    public void setClasspathRef(Reference r) {
    8.85 +        createClasspath().setRefid(r);
    8.86 +    }
    8.87 +
    8.88 +    public void setIncludes(String includes) {
    8.89 +        super.setIncludes(includes);
    8.90 +        this.includes = includes;
    8.91 +    }
    8.92 +
    8.93 +    @Override
    8.94 +    public void execute() {
    8.95 +        if (includes != null && includes.trim().isEmpty())
    8.96 +            return;
    8.97 +
    8.98 +        DirectoryScanner s = getDirectoryScanner(srcDir);
    8.99 +        String[] files = s.getIncludedFiles();
   8.100 +//            System.err.println("Ant.execute: srcDir " + srcDir);
   8.101 +//            System.err.println("Ant.execute: destDir " + destDir);
   8.102 +//            System.err.println("Ant.execute: files " + Arrays.asList(files));
   8.103 +
   8.104 +        files = filter(srcDir, destDir, files);
   8.105 +        if (files.length == 0)
   8.106 +            return;
   8.107 +        System.out.println("Generating " + files.length + " stub files to " + destDir);
   8.108 +
   8.109 +        List<String> classNames = new ArrayList<String>();
   8.110 +        for (String file: files) {
   8.111 +            classNames.add(file.replaceAll(".java$", "").replace('/', '.'));
   8.112 +        }
   8.113 +
   8.114 +        if (!fork) {
   8.115 +            GenStubs m = new GenStubs();
   8.116 +            boolean ok = m.run(srcDir.getPath(), destDir, classNames);
   8.117 +            if (!ok)
   8.118 +                throw new BuildException("genstubs failed");
   8.119 +        } else {
   8.120 +            List<String> cmd = new ArrayList<String>();
   8.121 +            String java_home = System.getProperty("java.home");
   8.122 +            cmd.add(new File(new File(java_home, "bin"), "java").getPath());
   8.123 +            if (classpath != null)
   8.124 +                cmd.add("-Xbootclasspath/p:" + classpath);
   8.125 +            cmd.add(GenStubs.class.getName());
   8.126 +            cmd.add("-sourcepath");
   8.127 +            cmd.add(srcDir.getPath());
   8.128 +            cmd.add("-s");
   8.129 +            cmd.add(destDir.getPath());
   8.130 +            cmd.addAll(classNames);
   8.131 +            //System.err.println("GenStubs exec " + cmd);
   8.132 +            ProcessBuilder pb = new ProcessBuilder(cmd);
   8.133 +            pb.redirectErrorStream(true);
   8.134 +            try {
   8.135 +                Process p = pb.start();
   8.136 +                BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
   8.137 +                try {
   8.138 +                    String line;
   8.139 +                    while ((line = in.readLine()) != null)
   8.140 +                        System.out.println(line);
   8.141 +                } finally {
   8.142 +                    in.close();
   8.143 +                }
   8.144 +                int rc = p.waitFor();
   8.145 +                if (rc != 0)
   8.146 +                    throw new BuildException("genstubs failed");
   8.147 +            } catch (IOException e) {
   8.148 +                throw new BuildException("genstubs failed", e);
   8.149 +            } catch (InterruptedException e) {
   8.150 +                throw new BuildException("genstubs failed", e);
   8.151 +            }
   8.152 +        }
   8.153 +    }
   8.154 +
   8.155 +    String[] filter(File srcDir, File destDir, String[] files) {
   8.156 +        List<String> results = new ArrayList<String>();
   8.157 +        for (String f: files) {
   8.158 +            long srcTime = new File(srcDir, f).lastModified();
   8.159 +            long destTime = new File(destDir, f).lastModified();
   8.160 +            if (srcTime > destTime)
   8.161 +                results.add(f);
   8.162 +        }
   8.163 +        return results.toArray(new String[results.size()]);
   8.164 +    }
   8.165 +}
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/make/tools/anttasks/SelectToolTask.java	Wed Mar 07 13:11:27 2012 +0100
     9.3 @@ -0,0 +1,286 @@
     9.4 +/*
     9.5 + * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.  Oracle designates this
    9.11 + * particular file as subject to the "Classpath" exception as provided
    9.12 + * by Oracle in the LICENSE file that accompanied this code.
    9.13 + *
    9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.17 + * version 2 for more details (a copy is included in the LICENSE file that
    9.18 + * accompanied this code).
    9.19 + *
    9.20 + * You should have received a copy of the GNU General Public License version
    9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.23 + *
    9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.25 + * or visit www.oracle.com if you need additional information or have any
    9.26 + * questions.
    9.27 + */
    9.28 +
    9.29 +package anttasks;
    9.30 +
    9.31 +import java.awt.GridBagConstraints;
    9.32 +import java.awt.GridBagLayout;
    9.33 +import java.awt.event.ActionEvent;
    9.34 +import java.awt.event.ActionListener;
    9.35 +import java.awt.event.FocusEvent;
    9.36 +import java.awt.event.FocusListener;
    9.37 +import java.awt.event.ItemEvent;
    9.38 +import java.awt.event.ItemListener;
    9.39 +import java.io.BufferedReader;
    9.40 +import java.io.BufferedWriter;
    9.41 +import java.io.File;
    9.42 +import java.io.FileReader;
    9.43 +import java.io.FileWriter;
    9.44 +import java.io.IOException;
    9.45 +import java.io.Reader;
    9.46 +import java.io.Writer;
    9.47 +import java.util.ArrayList;
    9.48 +import java.util.Arrays;
    9.49 +import java.util.List;
    9.50 +import java.util.Properties;
    9.51 +import javax.swing.JButton;
    9.52 +import javax.swing.JCheckBox;
    9.53 +import javax.swing.JComboBox;
    9.54 +import javax.swing.JDialog;
    9.55 +import javax.swing.JLabel;
    9.56 +import javax.swing.JOptionPane;
    9.57 +import javax.swing.JPanel;
    9.58 +import javax.swing.JTextField;
    9.59 +
    9.60 +import javax.swing.SwingUtilities;
    9.61 +import org.apache.tools.ant.BuildException;
    9.62 +import org.apache.tools.ant.Project;
    9.63 +import org.apache.tools.ant.Task;
    9.64 +
    9.65 +/**
    9.66 + * Task to allow the user to control langtools tools built when using NetBeans.
    9.67 + *
    9.68 + * There are two primary modes.
    9.69 + * 1) Property mode. In this mode, property names are provided to get values
    9.70 + * that may be specified by the user, either directly in a GUI dialog, or
    9.71 + * read from a properties file. If the GUI dialog is invoked, values may
    9.72 + * optionally be set for future use.
    9.73 + * 2) Setup mode. In this mode, no property names are provided, and the GUI
    9.74 + * is invoked to allow the user to set or reset values for use in property mode.
    9.75 + */
    9.76 +public class SelectToolTask extends Task {
    9.77 +    /**
    9.78 +     * Set the location of the private properties file used to keep the retain
    9.79 +     * user preferences for this repository.
    9.80 +     */
    9.81 +    public void setPropertyFile(File propertyFile) {
    9.82 +        this.propertyFile = propertyFile;
    9.83 +    }
    9.84 +
    9.85 +    /**
    9.86 +     * Set the name of the property which will be set to the name of the
    9.87 +     * selected tool, if any. If no tool is selected, the property will
    9.88 +     * remain unset.
    9.89 +     */
    9.90 +    public void setToolProperty(String toolProperty) {
    9.91 +        this.toolProperty = toolProperty;
    9.92 +    }
    9.93 +
    9.94 +    /**
    9.95 +     * Set the name of the property which will be set to the execution args of the
    9.96 +     * selected tool, if any. The args default to an empty string.
    9.97 +     */
    9.98 +    public void setArgsProperty(String argsProperty) {
    9.99 +        this.argsProperty = argsProperty;
   9.100 +    }
   9.101 +
   9.102 +    /**
   9.103 +     * Specify whether or not to pop up a dialog if the user has not specified
   9.104 +     * a default value for a property.
   9.105 +     */
   9.106 +    public void setAskIfUnset(boolean askIfUnset) {
   9.107 +        this.askIfUnset = askIfUnset;
   9.108 +    }
   9.109 +
   9.110 +    @Override
   9.111 +    public void execute() {
   9.112 +        Project p = getProject();
   9.113 +
   9.114 +        Properties props = readProperties(propertyFile);
   9.115 +        toolName = props.getProperty("tool.name");
   9.116 +        if (toolName != null) {
   9.117 +            toolArgs = props.getProperty(toolName + ".args", "");
   9.118 +        }
   9.119 +
   9.120 +        if (toolProperty == null ||
   9.121 +            askIfUnset && (toolName == null
   9.122 +                || (argsProperty != null && toolArgs == null))) {
   9.123 +            showGUI(props);
   9.124 +        }
   9.125 +
   9.126 +        // finally, return required values, if any
   9.127 +        if (toolProperty != null && !(toolName == null || toolName.equals(""))) {
   9.128 +            p.setProperty(toolProperty, toolName);
   9.129 +
   9.130 +            if (argsProperty != null && toolArgs != null)
   9.131 +                p.setProperty(argsProperty, toolArgs);
   9.132 +        }
   9.133 +    }
   9.134 +
   9.135 +    void showGUI(Properties fileProps) {
   9.136 +        Properties guiProps = new Properties(fileProps);
   9.137 +        JOptionPane p = createPane(guiProps);
   9.138 +        p.createDialog("Select Tool").setVisible(true);
   9.139 +
   9.140 +        toolName = (String) toolChoice.getSelectedItem();
   9.141 +        toolArgs = argsField.getText();
   9.142 +
   9.143 +        if (defaultCheck.isSelected()) {
   9.144 +            if (toolName.equals("")) {
   9.145 +                fileProps.remove("tool.name");
   9.146 +            } else {
   9.147 +                fileProps.put("tool.name", toolName);
   9.148 +                fileProps.put(toolName + ".args", toolArgs);
   9.149 +            }
   9.150 +            writeProperties(propertyFile, fileProps);
   9.151 +        }
   9.152 +    }
   9.153 +
   9.154 +    JOptionPane createPane(final Properties props) {
   9.155 +        JPanel body = new JPanel(new GridBagLayout());
   9.156 +        GridBagConstraints lc = new GridBagConstraints();
   9.157 +        lc.insets.right = 10;
   9.158 +        lc.insets.bottom = 3;
   9.159 +        GridBagConstraints fc = new GridBagConstraints();
   9.160 +        fc.anchor = GridBagConstraints.WEST;
   9.161 +        fc.gridx = 1;
   9.162 +        fc.gridwidth = GridBagConstraints.REMAINDER;
   9.163 +        fc.insets.bottom = 3;
   9.164 +
   9.165 +        JLabel toolLabel = new JLabel("Tool:");
   9.166 +        body.add(toolLabel, lc);
   9.167 +        String[] toolChoices = { "apt", "javac", "javadoc", "javah", "javap" };
   9.168 +        if (true || toolProperty == null) {
   9.169 +            // include empty value in setup mode
   9.170 +            List<String> l = new ArrayList<String>(Arrays.asList(toolChoices));
   9.171 +            l.add(0, "");
   9.172 +            toolChoices = l.toArray(new String[l.size()]);
   9.173 +        }
   9.174 +        toolChoice = new JComboBox(toolChoices);
   9.175 +        if (toolName != null)
   9.176 +            toolChoice.setSelectedItem(toolName);
   9.177 +        toolChoice.addItemListener(new ItemListener() {
   9.178 +            public void itemStateChanged(ItemEvent e) {
   9.179 +                String tn = (String) e.getItem();
   9.180 +                argsField.setText(getDefaultArgsForTool(props, tn));
   9.181 +                if (toolProperty != null)
   9.182 +                    okButton.setEnabled(!tn.equals(""));
   9.183 +            }
   9.184 +        });
   9.185 +        body.add(toolChoice, fc);
   9.186 +
   9.187 +        argsField = new JTextField(getDefaultArgsForTool(props, toolName), 40);
   9.188 +        if (toolProperty == null || argsProperty != null) {
   9.189 +            JLabel argsLabel = new JLabel("Args:");
   9.190 +            body.add(argsLabel, lc);
   9.191 +            body.add(argsField, fc);
   9.192 +            argsField.addFocusListener(new FocusListener() {
   9.193 +                public void focusGained(FocusEvent e) {
   9.194 +                }
   9.195 +                public void focusLost(FocusEvent e) {
   9.196 +                    String toolName = (String) toolChoice.getSelectedItem();
   9.197 +                    if (toolName.length() > 0)
   9.198 +                        props.put(toolName + ".args", argsField.getText());
   9.199 +                }
   9.200 +            });
   9.201 +        }
   9.202 +
   9.203 +        defaultCheck = new JCheckBox("Set as default");
   9.204 +        if (toolProperty == null)
   9.205 +            defaultCheck.setSelected(true);
   9.206 +        else
   9.207 +            body.add(defaultCheck, fc);
   9.208 +
   9.209 +        final JOptionPane p = new JOptionPane(body);
   9.210 +        okButton = new JButton("OK");
   9.211 +        okButton.setEnabled(toolProperty == null || (toolName != null && !toolName.equals("")));
   9.212 +        okButton.addActionListener(new ActionListener() {
   9.213 +            public void actionPerformed(ActionEvent e) {
   9.214 +                JDialog d = (JDialog) SwingUtilities.getAncestorOfClass(JDialog.class, p);
   9.215 +                d.setVisible(false);
   9.216 +            }
   9.217 +        });
   9.218 +        p.setOptions(new Object[] { okButton });
   9.219 +
   9.220 +        return p;
   9.221 +    }
   9.222 +
   9.223 +    Properties readProperties(File file) {
   9.224 +        Properties p = new Properties();
   9.225 +        if (file != null && file.exists()) {
   9.226 +            Reader in = null;
   9.227 +            try {
   9.228 +                in = new BufferedReader(new FileReader(file));
   9.229 +                p.load(in);
   9.230 +                in.close();
   9.231 +            } catch (IOException e) {
   9.232 +                throw new BuildException("error reading property file", e);
   9.233 +            } finally {
   9.234 +                if (in != null) {
   9.235 +                    try {
   9.236 +                        in.close();
   9.237 +                    } catch (IOException e) {
   9.238 +                        throw new BuildException("cannot close property file", e);
   9.239 +                    }
   9.240 +                }
   9.241 +            }
   9.242 +        }
   9.243 +        return p;
   9.244 +    }
   9.245 +
   9.246 +    void writeProperties(File file, Properties p) {
   9.247 +        if (file != null) {
   9.248 +            Writer out = null;
   9.249 +            try {
   9.250 +                File dir = file.getParentFile();
   9.251 +                if (dir != null && !dir.exists())
   9.252 +                    dir.mkdirs();
   9.253 +                out = new BufferedWriter(new FileWriter(file));
   9.254 +                p.store(out, "langtools properties");
   9.255 +                out.close();
   9.256 +            } catch (IOException e) {
   9.257 +                throw new BuildException("error writing property file", e);
   9.258 +            } finally {
   9.259 +                if (out != null) {
   9.260 +                    try {
   9.261 +                        out.close();
   9.262 +                    } catch (IOException e) {
   9.263 +                        throw new BuildException("cannot close property file", e);
   9.264 +                    }
   9.265 +                }
   9.266 +            }
   9.267 +        }
   9.268 +    }
   9.269 +
   9.270 +    String getDefaultArgsForTool(Properties props, String tn) {
   9.271 +        return (tn == null || tn.equals("")) ? "" : props.getProperty(tn + ".args", "");
   9.272 +    }
   9.273 +
   9.274 +    // Ant task parameters
   9.275 +    private boolean askIfUnset;
   9.276 +    private String toolProperty;
   9.277 +    private String argsProperty;
   9.278 +    private File propertyFile;
   9.279 +
   9.280 +    // GUI components
   9.281 +    private JComboBox toolChoice;
   9.282 +    private JTextField argsField;
   9.283 +    private JCheckBox defaultCheck;
   9.284 +    private JButton okButton;
   9.285 +
   9.286 +    // Result values for the client
   9.287 +    private String toolName;
   9.288 +    private String toolArgs;
   9.289 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/make/tools/compileproperties/CompileProperties.java	Wed Mar 07 13:11:27 2012 +0100
    10.3 @@ -0,0 +1,404 @@
    10.4 +/*
    10.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
    10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 + *
    10.8 + * This code is free software; you can redistribute it and/or modify it
    10.9 + * under the terms of the GNU General Public License version 2 only, as
   10.10 + * published by the Free Software Foundation.  Oracle designates this
   10.11 + * particular file as subject to the "Classpath" exception as provided
   10.12 + * by Oracle in the LICENSE file that accompanied this code.
   10.13 + *
   10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.17 + * version 2 for more details (a copy is included in the LICENSE file that
   10.18 + * accompanied this code).
   10.19 + *
   10.20 + * You should have received a copy of the GNU General Public License version
   10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.23 + *
   10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.25 + * or visit www.oracle.com if you need additional information or have any
   10.26 + * questions.
   10.27 + */
   10.28 +
   10.29 +package compileproperties;
   10.30 +
   10.31 +import java.io.BufferedWriter;
   10.32 +import java.io.File;
   10.33 +import java.io.FileInputStream;
   10.34 +import java.io.FileNotFoundException;
   10.35 +import java.io.FileOutputStream;
   10.36 +import java.io.IOException;
   10.37 +import java.io.OutputStreamWriter;
   10.38 +import java.io.Writer;
   10.39 +import java.text.MessageFormat;
   10.40 +import java.util.ArrayList;
   10.41 +import java.util.Collections;
   10.42 +import java.util.Iterator;
   10.43 +import java.util.List;
   10.44 +import java.util.Properties;
   10.45 +
   10.46 +/** Translates a .properties file into a .java file containing the
   10.47 + *  definition of a java.util.Properties subclass which can then be
   10.48 + *  compiled with javac. <P>
   10.49 + *
   10.50 + *  Usage: java CompileProperties [path to .properties file] [path to .java file to be output] [super class]
   10.51 + *
   10.52 + *  Infers the package by looking at the common suffix of the two
   10.53 + *  inputs, eliminating "classes" from it.
   10.54 + *
   10.55 + * @author Scott Violet
   10.56 + * @author Kenneth Russell
   10.57 + */
   10.58 +
   10.59 +public class CompileProperties {
   10.60 +
   10.61 +    public static void main(String[] args) {
   10.62 +        CompileProperties cp = new CompileProperties();
   10.63 +        boolean ok = cp.run(args);
   10.64 +        if ( !ok ) {
   10.65 +            System.exit(1);
   10.66 +        }
   10.67 +    }
   10.68 +
   10.69 +    public static interface Log {
   10.70 +        void info(String msg);
   10.71 +        void verbose(String msg);
   10.72 +        void error(String msg, Exception e);
   10.73 +    }
   10.74 +
   10.75 +    private String propfiles[];
   10.76 +    private String outfiles[] ;
   10.77 +    private String supers[]   ;
   10.78 +    private int compileCount = 0;
   10.79 +    private boolean quiet = false;
   10.80 +    public Log log;
   10.81 +
   10.82 +    public void setLog(Log log) {
   10.83 +        this.log = log;
   10.84 +    }
   10.85 +
   10.86 +    public boolean run(String[] args) {
   10.87 +        if (log == null) {
   10.88 +            log = new Log() {
   10.89 +                public void error(String msg, Exception e) {
   10.90 +                    System.err.println("ERROR: CompileProperties: " + msg);
   10.91 +                    if ( e != null ) {
   10.92 +                        System.err.println("EXCEPTION: " + e.toString());
   10.93 +                        e.printStackTrace();
   10.94 +                    }
   10.95 +                }
   10.96 +                public void info(String msg) {
   10.97 +                    System.out.println(msg);
   10.98 +                }
   10.99 +                public void verbose(String msg) {
  10.100 +                    if (!quiet)
  10.101 +                        System.out.println(msg);
  10.102 +                }
  10.103 +            };
  10.104 +        }
  10.105 +
  10.106 +        boolean ok = true;
  10.107 +        /* Original usage */
  10.108 +        if (args.length == 2 && args[0].charAt(0) != '-' ) {
  10.109 +            ok = createFile(args[0], args[1], "java.util.ListResourceBundle");
  10.110 +        } else if (args.length == 3) {
  10.111 +            ok = createFile(args[0], args[1], args[2]);
  10.112 +        } else if (args.length == 0) {
  10.113 +            usage(log);
  10.114 +            ok = false;
  10.115 +        } else {
  10.116 +            /* New batch usage */
  10.117 +            ok = parseOptions(args);
  10.118 +            if ( ok && compileCount == 0 ) {
  10.119 +                log.error("options parsed but no files to compile", null);
  10.120 +                ok = false;
  10.121 +            }
  10.122 +            /* Need at least one file. */
  10.123 +            if ( !ok ) {
  10.124 +                usage(log);
  10.125 +            } else {
  10.126 +                /* Process files */
  10.127 +                for ( int i = 0; i < compileCount && ok ; i++ ) {
  10.128 +                    ok = createFile(propfiles[i], outfiles[i], supers[i]);
  10.129 +                }
  10.130 +            }
  10.131 +        }
  10.132 +        return ok;
  10.133 +    }
  10.134 +
  10.135 +    private boolean parseOptions(String args[]) {
  10.136 +        boolean ok = true;
  10.137 +        if ( compileCount > 0 ) {
  10.138 +            String new_propfiles[] = new String[compileCount + args.length];
  10.139 +            String new_outfiles[]  = new String[compileCount + args.length];
  10.140 +            String new_supers[]    = new String[compileCount + args.length];
  10.141 +            System.arraycopy(propfiles, 0, new_propfiles, 0, compileCount);
  10.142 +            System.arraycopy(outfiles, 0, new_outfiles, 0, compileCount);
  10.143 +            System.arraycopy(supers, 0, new_supers, 0, compileCount);
  10.144 +            propfiles = new_propfiles;
  10.145 +            outfiles  = new_outfiles;
  10.146 +            supers    = new_supers;
  10.147 +        } else {
  10.148 +            propfiles = new String[args.length];
  10.149 +            outfiles  = new String[args.length];
  10.150 +            supers    = new String[args.length];
  10.151 +        }
  10.152 +
  10.153 +        for ( int i = 0; i < args.length ; i++ ) {
  10.154 +            if ( "-compile".equals(args[i]) && i+3 < args.length ) {
  10.155 +                propfiles[compileCount] = args[++i];
  10.156 +                outfiles[compileCount]  = args[++i];
  10.157 +                supers[compileCount]    = args[++i];
  10.158 +                compileCount++;
  10.159 +            } else if ( "-optionsfile".equals(args[i]) && i+1 < args.length ) {
  10.160 +                String filename = args[++i];
  10.161 +                FileInputStream finput = null;
  10.162 +                byte contents[] = null;
  10.163 +                try {
  10.164 +                    finput = new FileInputStream(filename);
  10.165 +                    int byteCount = finput.available();
  10.166 +                    if ( byteCount <= 0 ) {
  10.167 +                        log.error("The -optionsfile file is empty", null);
  10.168 +                        ok = false;
  10.169 +                    } else {
  10.170 +                        contents = new byte[byteCount];
  10.171 +                        int bytesRead = finput.read(contents);
  10.172 +                        if ( byteCount != bytesRead ) {
  10.173 +                            log.error("Cannot read all of -optionsfile file", null);
  10.174 +                            ok = false;
  10.175 +                        }
  10.176 +                    }
  10.177 +                } catch ( IOException e ) {
  10.178 +                    log.error("cannot open " + filename, e);
  10.179 +                    ok = false;
  10.180 +                }
  10.181 +                if ( finput != null ) {
  10.182 +                    try {
  10.183 +                        finput.close();
  10.184 +                    } catch ( IOException e ) {
  10.185 +                        ok = false;
  10.186 +                        log.error("cannot close " + filename, e);
  10.187 +                    }
  10.188 +                }
  10.189 +                if ( ok = true && contents != null ) {
  10.190 +                    String tokens[] = (new String(contents)).split("\\s+");
  10.191 +                    if ( tokens.length > 0 ) {
  10.192 +                        ok = parseOptions(tokens);
  10.193 +                    }
  10.194 +                }
  10.195 +                if ( !ok ) {
  10.196 +                    break;
  10.197 +                }
  10.198 +            } else if ( "-quiet".equals(args[i]) ) {
  10.199 +                quiet = true;
  10.200 +            } else {
  10.201 +                log.error("argument error", null);
  10.202 +                ok = false;
  10.203 +            }
  10.204 +        }
  10.205 +        return ok;
  10.206 +    }
  10.207 +
  10.208 +    private boolean createFile(String propertiesPath, String outputPath,
  10.209 +            String superClass) {
  10.210 +        boolean ok = true;
  10.211 +        log.verbose("parsing: " + propertiesPath);
  10.212 +        Properties p = new Properties();
  10.213 +        try {
  10.214 +            p.load(new FileInputStream(propertiesPath));
  10.215 +        } catch ( FileNotFoundException e ) {
  10.216 +            ok = false;
  10.217 +            log.error("Cannot find file " + propertiesPath, e);
  10.218 +        } catch ( IOException e ) {
  10.219 +            ok = false;
  10.220 +            log.error("IO error on file " + propertiesPath, e);
  10.221 +        }
  10.222 +        if ( ok ) {
  10.223 +            String packageName = inferPackageName(propertiesPath, outputPath);
  10.224 +            log.verbose("inferred package name: " + packageName);
  10.225 +            List<String> sortedKeys = new ArrayList<String>();
  10.226 +            for ( Object key : p.keySet() ) {
  10.227 +                sortedKeys.add((String)key);
  10.228 +            }
  10.229 +            Collections.sort(sortedKeys);
  10.230 +            Iterator<String> keys = sortedKeys.iterator();
  10.231 +
  10.232 +            StringBuffer data = new StringBuffer();
  10.233 +
  10.234 +            while (keys.hasNext()) {
  10.235 +                String key = keys.next();
  10.236 +                data.append("            { \"" + escape(key) + "\", \"" +
  10.237 +                        escape((String)p.get(key)) + "\" },\n");
  10.238 +            }
  10.239 +
  10.240 +            // Get class name from java filename, not the properties filename.
  10.241 +            //   (zh_TW properties might be used to create zh_HK files)
  10.242 +            File file = new File(outputPath);
  10.243 +            String name = file.getName();
  10.244 +            int dotIndex = name.lastIndexOf('.');
  10.245 +            String className;
  10.246 +            if (dotIndex == -1) {
  10.247 +                className = name;
  10.248 +            } else {
  10.249 +                className = name.substring(0, dotIndex);
  10.250 +            }
  10.251 +
  10.252 +            String packageString = "";
  10.253 +            if (packageName != null && !packageName.equals("")) {
  10.254 +                packageString = "package " + packageName + ";\n\n";
  10.255 +            }
  10.256 +
  10.257 +            Writer writer = null;
  10.258 +            try {
  10.259 +                writer = new BufferedWriter(
  10.260 +                        new OutputStreamWriter(new FileOutputStream(outputPath), "8859_1"));
  10.261 +                MessageFormat format = new MessageFormat(FORMAT);
  10.262 +                writer.write(format.format(new Object[] { packageString, className, superClass, data }));
  10.263 +            } catch ( IOException e ) {
  10.264 +                ok = false;
  10.265 +                log.error("IO error writing to file " + outputPath, e);
  10.266 +            }
  10.267 +            if ( writer != null ) {
  10.268 +                try {
  10.269 +                    writer.flush();
  10.270 +                } catch ( IOException e ) {
  10.271 +                    ok = false;
  10.272 +                    log.error("IO error flush " + outputPath, e);
  10.273 +                }
  10.274 +                try {
  10.275 +                    writer.close();
  10.276 +                } catch ( IOException e ) {
  10.277 +                    ok = false;
  10.278 +                    log.error("IO error close " + outputPath, e);
  10.279 +                }
  10.280 +            }
  10.281 +            log.verbose("wrote: " + outputPath);
  10.282 +        }
  10.283 +        return ok;
  10.284 +    }
  10.285 +
  10.286 +    private static void usage(Log log) {
  10.287 +        log.info("usage:");
  10.288 +        log.info("    java CompileProperties path_to_properties_file path_to_java_output_file [super_class]");
  10.289 +        log.info("      -OR-");
  10.290 +        log.info("    java CompileProperties {-compile path_to_properties_file path_to_java_output_file super_class} -or- -optionsfile filename");
  10.291 +        log.info("");
  10.292 +        log.info("Example:");
  10.293 +        log.info("    java CompileProperties -compile test.properties test.java java.util.ListResourceBundle");
  10.294 +        log.info("    java CompileProperties -optionsfile option_file");
  10.295 +        log.info("option_file contains: -compile test.properties test.java java.util.ListResourceBundle");
  10.296 +    }
  10.297 +
  10.298 +    private static String escape(String theString) {
  10.299 +        // This is taken from Properties.saveConvert with changes for Java strings
  10.300 +        int len = theString.length();
  10.301 +        StringBuffer outBuffer = new StringBuffer(len*2);
  10.302 +
  10.303 +        for(int x=0; x<len; x++) {
  10.304 +            char aChar = theString.charAt(x);
  10.305 +            switch(aChar) {
  10.306 +                case '\\':outBuffer.append('\\'); outBuffer.append('\\');
  10.307 +                break;
  10.308 +                case '\t':outBuffer.append('\\'); outBuffer.append('t');
  10.309 +                break;
  10.310 +                case '\n':outBuffer.append('\\'); outBuffer.append('n');
  10.311 +                break;
  10.312 +                case '\r':outBuffer.append('\\'); outBuffer.append('r');
  10.313 +                break;
  10.314 +                case '\f':outBuffer.append('\\'); outBuffer.append('f');
  10.315 +                break;
  10.316 +                default:
  10.317 +                    if ((aChar < 0x0020) || (aChar > 0x007e)) {
  10.318 +                        outBuffer.append('\\');
  10.319 +                        outBuffer.append('u');
  10.320 +                        outBuffer.append(toHex((aChar >> 12) & 0xF));
  10.321 +                        outBuffer.append(toHex((aChar >>  8) & 0xF));
  10.322 +                        outBuffer.append(toHex((aChar >>  4) & 0xF));
  10.323 +                        outBuffer.append(toHex( aChar        & 0xF));
  10.324 +                    } else {
  10.325 +                        if (specialSaveChars.indexOf(aChar) != -1) {
  10.326 +                            outBuffer.append('\\');
  10.327 +                        }
  10.328 +                        outBuffer.append(aChar);
  10.329 +                    }
  10.330 +            }
  10.331 +        }
  10.332 +        return outBuffer.toString();
  10.333 +    }
  10.334 +
  10.335 +    private static String inferPackageName(String inputPath, String outputPath) {
  10.336 +        // Normalize file names
  10.337 +        inputPath  = new File(inputPath).getPath();
  10.338 +        outputPath = new File(outputPath).getPath();
  10.339 +        // Split into components
  10.340 +        String sep;
  10.341 +        if (File.separatorChar == '\\') {
  10.342 +            sep = "\\\\";
  10.343 +        } else {
  10.344 +            sep = File.separator;
  10.345 +        }
  10.346 +        String[] inputs  = inputPath.split(sep);
  10.347 +        String[] outputs = outputPath.split(sep);
  10.348 +        // Match common names, eliminating first "classes" entry from
  10.349 +        // each if present
  10.350 +        int inStart  = 0;
  10.351 +        int inEnd    = inputs.length - 2;
  10.352 +        int outEnd   = outputs.length - 2;
  10.353 +        int i = inEnd;
  10.354 +        int j = outEnd;
  10.355 +        while (i >= 0 && j >= 0) {
  10.356 +            if (!inputs[i].equals(outputs[j]) ||
  10.357 +                    (inputs[i].equals("gensrc") && inputs[j].equals("gensrc"))) {
  10.358 +                ++i;
  10.359 +                ++j;
  10.360 +                break;
  10.361 +            }
  10.362 +            --i;
  10.363 +            --j;
  10.364 +        }
  10.365 +        String result;
  10.366 +        if (i < 0 || j < 0 || i >= inEnd || j >= outEnd) {
  10.367 +            result = "";
  10.368 +        } else {
  10.369 +            if (inputs[i].equals("classes") && outputs[j].equals("classes")) {
  10.370 +                ++i;
  10.371 +            }
  10.372 +            inStart = i;
  10.373 +            StringBuffer buf = new StringBuffer();
  10.374 +            for (i = inStart; i <= inEnd; i++) {
  10.375 +                buf.append(inputs[i]);
  10.376 +                if (i < inEnd) {
  10.377 +                    buf.append('.');
  10.378 +                }
  10.379 +            }
  10.380 +            result = buf.toString();
  10.381 +        }
  10.382 +        return result;
  10.383 +    }
  10.384 +
  10.385 +    private static final String FORMAT =
  10.386 +            "{0}" +
  10.387 +            "public final class {1} extends {2} '{'\n" +
  10.388 +            "    protected final Object[][] getContents() '{'\n" +
  10.389 +            "        return new Object[][] '{'\n" +
  10.390 +            "{3}" +
  10.391 +            "        };\n" +
  10.392 +            "    }\n" +
  10.393 +            "}\n";
  10.394 +
  10.395 +    // This comes from Properties
  10.396 +    private static char toHex(int nibble) {
  10.397 +        return hexDigit[(nibble & 0xF)];
  10.398 +    }
  10.399 +
  10.400 +    // This comes from Properties
  10.401 +    private static final char[] hexDigit = {
  10.402 +        '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
  10.403 +    };
  10.404 +
  10.405 +    // Note: different from that in Properties
  10.406 +    private static final String specialSaveChars = "\"";
  10.407 +}
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/make/tools/genstubs/GenStubs.java	Wed Mar 07 13:11:27 2012 +0100
    11.3 @@ -0,0 +1,316 @@
    11.4 +/*
    11.5 + * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
    11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.7 + *
    11.8 + * This code is free software; you can redistribute it and/or modify it
    11.9 + * under the terms of the GNU General Public License version 2 only, as
   11.10 + * published by the Free Software Foundation.  Oracle designates this
   11.11 + * particular file as subject to the "Classpath" exception as provided
   11.12 + * by Oracle in the LICENSE file that accompanied this code.
   11.13 + *
   11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   11.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   11.17 + * version 2 for more details (a copy is included in the LICENSE file that
   11.18 + * accompanied this code).
   11.19 + *
   11.20 + * You should have received a copy of the GNU General Public License version
   11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   11.23 + *
   11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   11.25 + * or visit www.oracle.com if you need additional information or have any
   11.26 + * questions.
   11.27 + */
   11.28 +
   11.29 +package genstubs;
   11.30 +
   11.31 +import java.io.*;
   11.32 +import java.util.*;
   11.33 +import javax.tools.JavaFileObject;
   11.34 +import javax.tools.StandardJavaFileManager;
   11.35 +import javax.tools.StandardLocation;
   11.36 +
   11.37 +import com.sun.source.tree.CompilationUnitTree;
   11.38 +import com.sun.source.util.JavacTask;
   11.39 +import com.sun.tools.javac.api.JavacTool;
   11.40 +import com.sun.tools.javac.code.Flags;
   11.41 +import com.sun.tools.javac.code.TypeTags;
   11.42 +import com.sun.tools.javac.tree.JCTree;
   11.43 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
   11.44 +import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
   11.45 +import com.sun.tools.javac.tree.JCTree.JCIdent;
   11.46 +import com.sun.tools.javac.tree.JCTree.JCImport;
   11.47 +import com.sun.tools.javac.tree.JCTree.JCLiteral;
   11.48 +import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
   11.49 +import com.sun.tools.javac.tree.JCTree.JCModifiers;
   11.50 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
   11.51 +import com.sun.tools.javac.tree.Pretty;
   11.52 +import com.sun.tools.javac.tree.TreeMaker;
   11.53 +import com.sun.tools.javac.tree.TreeScanner;
   11.54 +import com.sun.tools.javac.tree.TreeTranslator;
   11.55 +import com.sun.tools.javac.util.Context;
   11.56 +import com.sun.tools.javac.util.ListBuffer;
   11.57 +import com.sun.tools.javac.util.Name;
   11.58 +import javax.tools.JavaFileManager;
   11.59 +
   11.60 +/**
   11.61 + * Generate stub source files by removing implementation details from input files.
   11.62 + *
   11.63 + * This is a special purpose stub generator, specific to the needs of generating
   11.64 + * stub files for JDK 7 API that are needed to compile langtools files that depend
   11.65 + * on that API. The stub generator works by removing as much of the API source code
   11.66 + * as possible without affecting the public signature, in order to reduce the
   11.67 + * transitive closure of the API being referenced. The resulting stubs can be
   11.68 + * put on the langtools sourcepath with -implicit:none to compile the langtools
   11.69 + * files that depend on the JDK 7 API.
   11.70 + *
   11.71 + * Usage:
   11.72 + *  genstubs -s <outdir> -sourcepath <path> <classnames>
   11.73 + *
   11.74 + * The specified class names are looked up on the sourcepath, and corresponding
   11.75 + * stubs are written to the source output directory.
   11.76 + *
   11.77 + * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator
   11.78 + * to remove implementation details, and written out in the source output directory.
   11.79 + * Documentation comments and annotations are removed. Method bodies are removed
   11.80 + * and methods are marked native. Private and package-private field definitions
   11.81 + * have their initializers replace with 0, 0.0, false, null as appropriate.
   11.82 + */
   11.83 +
   11.84 +public class GenStubs {
   11.85 +    static class Fault extends Exception {
   11.86 +        private static final long serialVersionUID = 0;
   11.87 +        Fault(String message) {
   11.88 +            super(message);
   11.89 +        }
   11.90 +        Fault(String message, Throwable cause) {
   11.91 +            super(message);
   11.92 +            initCause(cause);
   11.93 +        }
   11.94 +    }
   11.95 +
   11.96 +    public static void main(String[] args) {
   11.97 +        boolean ok = new GenStubs().run(args);
   11.98 +        if (!ok)
   11.99 +            System.exit(1);
  11.100 +    }
  11.101 +
  11.102 +    public boolean run(String... args) {
  11.103 +        File outdir = null;
  11.104 +        String sourcepath = null;
  11.105 +        List<String> classes = new ArrayList<String>();
  11.106 +        for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) {
  11.107 +            String arg = iter.next();
  11.108 +            if (arg.equals("-s") && iter.hasNext())
  11.109 +                outdir = new File(iter.next());
  11.110 +            else if (arg.equals("-sourcepath") && iter.hasNext())
  11.111 +                sourcepath = iter.next();
  11.112 +            else if (arg.startsWith("-"))
  11.113 +                throw new IllegalArgumentException(arg);
  11.114 +            else {
  11.115 +                classes.add(arg);
  11.116 +                while (iter.hasNext())
  11.117 +                    classes.add(iter.next());
  11.118 +            }
  11.119 +        }
  11.120 +
  11.121 +        return run(sourcepath, outdir, classes);
  11.122 +    }
  11.123 +
  11.124 +    public boolean run(String sourcepath, File outdir, List<String> classes) {
  11.125 +        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
  11.126 +        if (sourcepath == null)
  11.127 +            throw new IllegalArgumentException("sourcepath not set");
  11.128 +        if (outdir == null)
  11.129 +            throw new IllegalArgumentException("source output dir not set");
  11.130 +
  11.131 +        JavacTool tool = JavacTool.create();
  11.132 +        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
  11.133 +
  11.134 +        try {
  11.135 +            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
  11.136 +            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
  11.137 +            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
  11.138 +            for (String c: classes) {
  11.139 +                JavaFileObject fo = fm.getJavaFileForInput(
  11.140 +                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
  11.141 +                if (fo == null)
  11.142 +                    error("class not found: " + c);
  11.143 +                else
  11.144 +                    files.add(fo);
  11.145 +            }
  11.146 +
  11.147 +            JavacTask t = tool.getTask(null, fm, null, null, null, files);
  11.148 +            Iterable<? extends CompilationUnitTree> trees = t.parse();
  11.149 +            for (CompilationUnitTree tree: trees) {
  11.150 +                makeStub(fm, tree);
  11.151 +            }
  11.152 +        } catch (IOException e) {
  11.153 +            error("IO error " + e, e);
  11.154 +        }
  11.155 +
  11.156 +        return (errors == 0);
  11.157 +    }
  11.158 +
  11.159 +    void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException {
  11.160 +        CompilationUnitTree tree2 = new StubMaker().translate(tree);
  11.161 +        CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2);
  11.162 +
  11.163 +        String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile());
  11.164 +        JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT,
  11.165 +                className, JavaFileObject.Kind.SOURCE, null);
  11.166 +        // System.err.println("Writing " + className + " to " + fo.getName());
  11.167 +        Writer out = fo.openWriter();
  11.168 +        try {
  11.169 +            new Pretty(out, true).printExpr((JCTree) tree3);
  11.170 +        } finally {
  11.171 +            out.close();
  11.172 +        }
  11.173 +    }
  11.174 +
  11.175 +    List<File> splitPath(String path) {
  11.176 +        List<File> list = new ArrayList<File>();
  11.177 +        for (String p: path.split(File.pathSeparator)) {
  11.178 +            if (p.length() > 0)
  11.179 +                list.add(new File(p));
  11.180 +        }
  11.181 +        return list;
  11.182 +    }
  11.183 +
  11.184 +    void error(String message) {
  11.185 +        System.err.println(message);
  11.186 +        errors++;
  11.187 +    }
  11.188 +
  11.189 +    void error(String message, Throwable cause) {
  11.190 +        error(message);
  11.191 +    }
  11.192 +
  11.193 +    int errors;
  11.194 +
  11.195 +    class StubMaker extends TreeTranslator {
  11.196 +        CompilationUnitTree translate(CompilationUnitTree tree) {
  11.197 +            return super.translate((JCCompilationUnit) tree);
  11.198 +        }
  11.199 +
  11.200 +        /**
  11.201 +         * compilation units: remove javadoc comments
  11.202 +         * -- required, in order to remove @deprecated tags, since we
  11.203 +         * (separately) remove all annotations, including @Deprecated
  11.204 +         */
  11.205 +        public void visitTopLevel(JCCompilationUnit tree) {
  11.206 +            super.visitTopLevel(tree);
  11.207 +            tree.docComments = Collections.emptyMap();
  11.208 +        }
  11.209 +
  11.210 +        /**
  11.211 +         * methods: remove method bodies, make methods native
  11.212 +         */
  11.213 +        @Override
  11.214 +        public void visitMethodDef(JCMethodDecl tree) {
  11.215 +            tree.mods = translate(tree.mods);
  11.216 +            tree.restype = translate(tree.restype);
  11.217 +            tree.typarams = translateTypeParams(tree.typarams);
  11.218 +            tree.params = translateVarDefs(tree.params);
  11.219 +            tree.thrown = translate(tree.thrown);
  11.220 +            if (tree.restype != null && tree.body != null) {
  11.221 +                tree.mods.flags |= Flags.NATIVE;
  11.222 +                tree.body = null;
  11.223 +            }
  11.224 +            result = tree;
  11.225 +        }
  11.226 +
  11.227 +        /**
  11.228 +         * modifiers: remove annotations
  11.229 +         */
  11.230 +        @Override
  11.231 +        public void visitModifiers(JCModifiers tree) {
  11.232 +            tree.annotations = com.sun.tools.javac.util.List.nil();
  11.233 +            result = tree;
  11.234 +        }
  11.235 +
  11.236 +        /**
  11.237 +         * field definitions: replace initializers with 0, 0.0, false etc
  11.238 +         * when possible -- i.e. leave public, protected initializers alone
  11.239 +         */
  11.240 +        @Override
  11.241 +        public void visitVarDef(JCVariableDecl tree) {
  11.242 +            tree.mods = translate(tree.mods);
  11.243 +            tree.vartype = translate(tree.vartype);
  11.244 +            if (tree.init != null) {
  11.245 +                if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0)
  11.246 +                    tree.init = translate(tree.init);
  11.247 +                else {
  11.248 +                    String t = tree.vartype.toString();
  11.249 +                    if (t.equals("boolean"))
  11.250 +                        tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { };
  11.251 +                    else if (t.equals("byte"))
  11.252 +                        tree.init = new JCLiteral(TypeTags.BYTE, 0) { };
  11.253 +                    else if (t.equals("char"))
  11.254 +                        tree.init = new JCLiteral(TypeTags.CHAR, 0) { };
  11.255 +                    else if (t.equals("double"))
  11.256 +                        tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { };
  11.257 +                    else if (t.equals("float"))
  11.258 +                        tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { };
  11.259 +                    else if (t.equals("int"))
  11.260 +                        tree.init = new JCLiteral(TypeTags.INT, 0) { };
  11.261 +                    else if (t.equals("long"))
  11.262 +                        tree.init = new JCLiteral(TypeTags.LONG, 0) { };
  11.263 +                    else if (t.equals("short"))
  11.264 +                        tree.init = new JCLiteral(TypeTags.SHORT, 0) { };
  11.265 +                    else
  11.266 +                        tree.init = new JCLiteral(TypeTags.BOT, null) { };
  11.267 +                }
  11.268 +            }
  11.269 +            result = tree;
  11.270 +        }
  11.271 +    }
  11.272 +
  11.273 +    class ImportCleaner extends TreeScanner {
  11.274 +        private Set<Name> names = new HashSet<Name>();
  11.275 +        private TreeMaker m;
  11.276 +
  11.277 +        ImportCleaner(JavaFileManager fm) {
  11.278 +            // ImportCleaner itself doesn't require a filemanager, but instantiating
  11.279 +            // a TreeMaker does, indirectly (via ClassReader, sigh)
  11.280 +            Context c = new Context();
  11.281 +            c.put(JavaFileManager.class, fm);
  11.282 +            m = TreeMaker.instance(c);
  11.283 +        }
  11.284 +
  11.285 +        CompilationUnitTree removeRedundantImports(CompilationUnitTree t) {
  11.286 +            JCCompilationUnit tree = (JCCompilationUnit) t;
  11.287 +            tree.accept(this);
  11.288 +            ListBuffer<JCTree> defs = new ListBuffer<JCTree>();
  11.289 +            for (JCTree def: tree.defs) {
  11.290 +                if (def.getTag() == JCTree.Tag.IMPORT) {
  11.291 +                    JCImport imp = (JCImport) def;
  11.292 +                    if (imp.qualid.getTag() == JCTree.Tag.SELECT) {
  11.293 +                        JCFieldAccess qualid = (JCFieldAccess) imp.qualid;
  11.294 +                        if (!qualid.name.toString().equals("*")
  11.295 +                                && !names.contains(qualid.name)) {
  11.296 +                            continue;
  11.297 +                        }
  11.298 +                    }
  11.299 +                }
  11.300 +                defs.add(def);
  11.301 +            }
  11.302 +            return m.TopLevel(tree.packageAnnotations, tree.pid, defs.toList());
  11.303 +        }
  11.304 +
  11.305 +        @Override
  11.306 +        public void visitImport(JCImport tree) { } // ignore names found in imports
  11.307 +
  11.308 +        @Override
  11.309 +        public void visitIdent(JCIdent tree) {
  11.310 +            names.add(tree.name);
  11.311 +        }
  11.312 +
  11.313 +        @Override
  11.314 +        public void visitSelect(JCFieldAccess tree) {
  11.315 +            super.visitSelect(tree);
  11.316 +            names.add(tree.name);
  11.317 +        }
  11.318 +    }
  11.319 +}

mercurial