langtools/test/tools/javac/api/T6430241.java
author jjg
Wed, 29 Oct 2014 17:25:23 -0700
changeset 27319 030080f03e4f
parent 8034 d3b29ef9c062
child 27579 d1a63c99cdd5
permissions -rw-r--r--
8062348: langtools tests should close file manager (group 1) Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     1
    /*
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
     2
     * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     3
     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     4
     *
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     5
     * This code is free software; you can redistribute it and/or modify it
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     6
     * under the terms of the GNU General Public License version 2 only, as
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     7
     * published by the Free Software Foundation.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     8
     *
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
     9
     * This code is distributed in the hope that it will be useful, but WITHOUT
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    10
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    11
     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    12
     * version 2 for more details (a copy is included in the LICENSE file that
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    13
     * accompanied this code).
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    14
     *
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    15
     * You should have received a copy of the GNU General Public License version
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    16
     * 2 along with this work; if not, write to the Free Software Foundation,
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    17
     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    18
     *
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    19
     * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    20
     * or visit www.oracle.com if you need additional information or have any
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    21
     * questions.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    22
     */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    23
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    24
    /*
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    25
     * @test
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    26
     * @bug 6430241
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    27
     * @summary Hard to disable symbol file feature through API
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    28
     */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    29
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    30
    import java.io.*;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    31
    import java.util.*;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    32
    import javax.tools.*;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    33
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    34
    import com.sun.source.util.JavacTask;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    35
    import com.sun.tools.javac.api.JavacTool;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    36
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    37
    public class T6430241 {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    38
        public static void main(String... args) throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    39
            new T6430241().run();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    40
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    41
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    42
        void run() throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    43
            setup();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    44
            testCommandLine();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    45
            testSimpleAPI();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    46
            testTaskAPI();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    47
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    48
            if (errors > 0)
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    49
                throw new Exception(errors + " errors found");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    50
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    51
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    52
        void setup() throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    53
            classesDir = new File("classes");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    54
            classesDir.mkdirs();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    55
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    56
            emptyDir = new File("empty");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    57
            emptyDir.mkdirs();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    58
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    59
            bootClassPath = System.getProperty("sun.boot.class.path");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    60
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    61
            File srcDir = new File("src");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    62
            String test = "import sun.misc.Unsafe; class Test { }";
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    63
            testFile = writeFile(srcDir, "Test.java", test);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    64
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    65
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    66
        //----- tests for command line invocation
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    67
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    68
        void testCommandLine() throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    69
            testCommandLine(true);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    70
            testCommandLine(true,  "-Xbootclasspath/p:" + emptyDir);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    71
            testCommandLine(false, "-Xbootclasspath:" + bootClassPath);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    72
            testCommandLine(true,  "-Xbootclasspath/a:" + emptyDir);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    73
            testCommandLine(false, "-XDignore.symbol.file");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    74
            System.err.println();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    75
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    76
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    77
        void testCommandLine(boolean expectWarnings, String... opts) throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    78
            System.err.println("test command line: " + Arrays.asList(opts));
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    79
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    80
            String[] args = initArgs(opts);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    81
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    82
            StringWriter sw = new StringWriter();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    83
            PrintWriter pw = new PrintWriter(sw);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    84
            int rc = com.sun.tools.javac.Main.compile(args, pw);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    85
            String out = showOutput(sw.toString());
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    86
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    87
            checkCompilationOK(rc);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    88
            checkOutput(out, expectWarnings);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    89
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    90
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    91
        //----- tests for simple API invocation
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    92
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    93
        void testSimpleAPI() {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    94
            testSimpleAPI(true);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    95
            testSimpleAPI(true,  "-Xbootclasspath/p:" + emptyDir);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    96
            testSimpleAPI(false, "-Xbootclasspath:" + bootClassPath);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    97
            testSimpleAPI(true,  "-Xbootclasspath/a:" + emptyDir);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    98
            testSimpleAPI(false, "-XDignore.symbol.file");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
    99
            System.err.println();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   100
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   101
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   102
        void testSimpleAPI(boolean expectWarnings, String... opts) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   103
            System.err.println("test simple API: " + Arrays.asList(opts));
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   104
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   105
            String[] args = initArgs(opts);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   106
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   107
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   108
            PrintStream ps = new PrintStream(baos);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   109
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   110
            JavacTool tool = JavacTool.create();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   111
            int rc = tool.run(null, null, ps, args);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   112
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   113
            String out = showOutput(baos.toString());
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   114
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   115
            checkCompilationOK(rc);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   116
            checkOutput(out, expectWarnings);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   117
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   118
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   119
        //----- tests for CompilationTask API invocation
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   120
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   121
        void testTaskAPI() throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   122
            List<File> bcp = new ArrayList<File>();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   123
            for (String f: bootClassPath.split(File.pathSeparator)) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   124
                if (!f.isEmpty())
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   125
                    bcp.add(new File(f));
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   126
            }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   127
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   128
            testTaskAPI(true, null);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   129
            testTaskAPI(false, bcp);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   130
            System.err.println();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   131
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   132
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   133
        void testTaskAPI(boolean expectWarnings, Iterable<? extends File> pcp) throws Exception {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   134
            System.err.println("test task API: " + pcp);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   135
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   136
            JavacTool tool = JavacTool.create();
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   137
            try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) {
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   138
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   139
                if (pcp != null)
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   140
                    fm.setLocation(StandardLocation.PLATFORM_CLASS_PATH, pcp);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   141
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   142
                Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(testFile);
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   143
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   144
                StringWriter sw = new StringWriter();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   145
                PrintWriter pw = new PrintWriter(sw);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   146
                JavacTask task = tool.getTask(pw, fm, null, null, null, files);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   147
                boolean ok = task.call();
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   148
                String out = showOutput(sw.toString());
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   149
27319
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   150
                checkCompilationOK(ok);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   151
                checkOutput(out, expectWarnings);
030080f03e4f 8062348: langtools tests should close file manager (group 1)
jjg
parents: 8034
diff changeset
   152
            }
8034
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   153
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   154
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   155
        //----- utility methods
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   156
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   157
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   158
         * Create a file with given content.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   159
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   160
        File writeFile(File dir, String path, String content) throws IOException {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   161
            File f = new File(dir, path);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   162
            f.getParentFile().mkdirs();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   163
            FileWriter out = new FileWriter(f);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   164
            try {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   165
                out.write(content);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   166
            } finally {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   167
                out.close();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   168
            }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   169
            return f;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   170
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   171
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   172
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   173
         * Initialize args for compilation with given opts.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   174
         * @return opts -d classesDir testFile
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   175
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   176
        String[] initArgs(String[] opts) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   177
            List<String> args = new ArrayList<String>();
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   178
            args.addAll(Arrays.asList(opts));
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   179
            args.add("-d");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   180
            args.add(classesDir.getPath());
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   181
            args.add(testFile.getPath());
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   182
            return args.toArray(new String[args.size()]);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   183
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   184
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   185
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   186
         * Show output from compilation if non empty.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   187
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   188
        String showOutput(String out) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   189
            if (!out.isEmpty())
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   190
                System.err.println(out);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   191
            return out;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   192
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   193
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   194
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   195
         * Verify compilation succeeeded.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   196
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   197
        void checkCompilationOK(boolean ok) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   198
            if (!ok)
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   199
                error("compilation failed");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   200
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   201
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   202
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   203
         * Verify compilation succeeeded.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   204
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   205
        void checkCompilationOK(int rc) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   206
            if (rc != 0)
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   207
                error("compilation failed, rc: " + rc);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   208
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   209
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   210
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   211
         * Check whether output contains warnings if and only if warnings
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   212
         * are expected.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   213
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   214
        void checkOutput(String out, boolean expectWarnings) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   215
            boolean foundWarnings = out.contains("warning");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   216
            if (foundWarnings) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   217
                if (!expectWarnings)
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   218
                    error("unexpected warnings found");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   219
            } else {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   220
                if (expectWarnings)
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   221
                    error("expected warnings not found");
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   222
            }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   223
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   224
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   225
        /**
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   226
         * Report an error.
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   227
         */
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   228
        void error(String msg) {
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   229
            System.err.println("error: " + msg);
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   230
            errors++;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   231
        }
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   232
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   233
        String bootClassPath;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   234
        File classesDir;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   235
        File emptyDir;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   236
        File testFile;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   237
        int errors;
d3b29ef9c062 6430241: Hard to disable symbol file feature through API
jjg
parents:
diff changeset
   238
    }