test/tools/javac/options/T7022337.java

changeset 897
9029f694e5df
child 1466
b52a38d4536c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/options/T7022337.java	Mon Feb 28 12:19:18 2011 -0800
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +
    1.28 +/*
    1.29 + * @test
    1.30 + * @bug 7022337
    1.31 + * @summary repeated warnings about bootclasspath not set
    1.32 + * @library ../lib
    1.33 + * @build JavacTestingAbstractProcessor T7022337
    1.34 + * @run main T7022337
    1.35 + */
    1.36 +
    1.37 +import java.io.*;
    1.38 +import java.util.*;
    1.39 +import javax.annotation.processing.*;
    1.40 +import javax.lang.model.element.*;
    1.41 +import javax.tools.*;
    1.42 +
    1.43 +public class T7022337 extends JavacTestingAbstractProcessor {
    1.44 +    public static void main(String... args) throws Exception {
    1.45 +        new T7022337().run();
    1.46 +    }
    1.47 +
    1.48 +    void run() throws Exception {
    1.49 +        String myName = T7022337.class.getSimpleName();
    1.50 +        File testSrc = new File(System.getProperty("test.src"));
    1.51 +        File file = new File(testSrc, myName + ".java");
    1.52 +
    1.53 +        String out = compile(
    1.54 +            "-XDrawDiagnostics",
    1.55 +            "-d", ".",
    1.56 +            "-processor", myName,
    1.57 +            "-source", "6", // explicit use of older source value without bootclasspath
    1.58 +            file.getPath());
    1.59 +
    1.60 +        int count = 0;
    1.61 +        for (String line: out.split("[\r\n]+")) {
    1.62 +            if (line.contains("compiler.warn.source.no.bootclasspath"))
    1.63 +                count++;
    1.64 +        }
    1.65 +        if (count != 1)
    1.66 +            throw new Exception("unexpected number of warnings found: " + count + ", expected: 1");
    1.67 +    }
    1.68 +
    1.69 +    String compile(String... args) throws Exception {
    1.70 +        StringWriter sw = new StringWriter();
    1.71 +        PrintWriter pw = new PrintWriter(sw);
    1.72 +        int rc = com.sun.tools.javac.Main.compile(args, pw);
    1.73 +        pw.close();
    1.74 +        String out = sw.toString();
    1.75 +        if (!out.isEmpty())
    1.76 +            System.err.println(out);
    1.77 +        if (rc != 0)
    1.78 +            throw new Exception("compilation failed unexpectedly: rc=" + rc);
    1.79 +        return out;
    1.80 +    }
    1.81 +
    1.82 +    // ----------
    1.83 +
    1.84 +    int round = 0;
    1.85 +
    1.86 +    @Override
    1.87 +    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    1.88 +        round++;
    1.89 +
    1.90 +        final int MAXROUNDS = 3;
    1.91 +        if (round < MAXROUNDS)
    1.92 +            generate("Gen" + round);
    1.93 +
    1.94 +        return true;
    1.95 +    }
    1.96 +
    1.97 +    void generate(String name) {
    1.98 +        try {
    1.99 +            JavaFileObject fo = filer.createSourceFile(name);
   1.100 +            Writer out = fo.openWriter();
   1.101 +            try {
   1.102 +                out.write("class " + name + " { }");
   1.103 +            } finally {
   1.104 +                out.close();
   1.105 +            }
   1.106 +        } catch (IOException e) {
   1.107 +            throw new Error(e);
   1.108 +        }
   1.109 +    }
   1.110 +}

mercurial