langtools/test/tools/javac/options/T7022337.java
author lana
Thu, 21 Jan 2016 09:46:01 -0800
changeset 35340 38f7386ed942
parent 34752 9c262a013456
permissions -rw-r--r--
Added tag jdk-9+102 for changeset 7e3feb2ba5b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 25445
diff changeset
     2
 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     4
 *
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     8
 *
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    13
 * accompanied this code).
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    14
 *
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    18
 *
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    21
 * questions.
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    22
 */
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    23
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    24
/*
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    25
 * @test
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    26
 * @bug 7022337
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    27
 * @summary repeated warnings about bootclasspath not set
14963
974d4423c999 8005282: Use @library tag with non-relative path for javac tests
darcy
parents: 8618
diff changeset
    28
 * @library /tools/javac/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 25445
diff changeset
    29
 * @modules jdk.compiler
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    30
 * @build JavacTestingAbstractProcessor T7022337
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    31
 * @run main T7022337
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    32
 */
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    33
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    34
import java.io.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    35
import java.util.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    36
import javax.annotation.processing.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    37
import javax.lang.model.element.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    38
import javax.tools.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    39
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    40
public class T7022337 extends JavacTestingAbstractProcessor {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    41
    public static void main(String... args) throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    42
        new T7022337().run();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    43
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    44
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    45
    void run() throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    46
        String myName = T7022337.class.getSimpleName();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    47
        File testSrc = new File(System.getProperty("test.src"));
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    48
        File file = new File(testSrc, myName + ".java");
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    49
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    50
        String out = compile(
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    51
            "-XDrawDiagnostics",
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    52
            "-d", ".",
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    53
            "-processor", myName,
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 14963
diff changeset
    54
            "-source", "8", // explicit use of older source value without bootclasspath
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    55
            file.getPath());
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    56
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    57
        int count = 0;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    58
        for (String line: out.split("[\r\n]+")) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    59
            if (line.contains("compiler.warn.source.no.bootclasspath"))
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    60
                count++;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    61
        }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    62
        if (count != 1)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    63
            throw new Exception("unexpected number of warnings found: " + count + ", expected: 1");
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    64
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    65
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    66
    String compile(String... args) throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    67
        StringWriter sw = new StringWriter();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    68
        PrintWriter pw = new PrintWriter(sw);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    69
        int rc = com.sun.tools.javac.Main.compile(args, pw);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    70
        pw.close();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    71
        String out = sw.toString();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    72
        if (!out.isEmpty())
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    73
            System.err.println(out);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    74
        if (rc != 0)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    75
            throw new Exception("compilation failed unexpectedly: rc=" + rc);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    76
        return out;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    77
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    78
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    79
    // ----------
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    80
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    81
    int round = 0;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    82
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    83
    @Override
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    84
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    85
        round++;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    86
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    87
        final int MAXROUNDS = 3;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    88
        if (round < MAXROUNDS)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    89
            generate("Gen" + round);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    90
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    91
        return true;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    92
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    93
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    94
    void generate(String name) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    95
        try {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    96
            JavaFileObject fo = filer.createSourceFile(name);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    97
            Writer out = fo.openWriter();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    98
            try {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    99
                out.write("class " + name + " { }");
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   100
            } finally {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   101
                out.close();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   102
            }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   103
        } catch (IOException e) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   104
            throw new Error(e);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   105
        }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   106
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   107
}