langtools/test/tools/javac/options/T7022337.java
author akulyakh
Thu, 21 May 2015 11:41:04 -0700
changeset 30730 d3ce7619db2c
parent 25445 603f0c93d5c9
child 34752 9c262a013456
permissions -rw-r--r--
8076543: Add @modules as needed to the langtools tests Reviewed-by: jjg, shurailine
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
/*
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    26
 * @test
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    27
 * @bug 7022337
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    28
 * @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
    29
 * @library /tools/javac/lib
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 25445
diff changeset
    30
 * @modules jdk.compiler
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    31
 * @build JavacTestingAbstractProcessor T7022337
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    32
 * @run main T7022337
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
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    35
import java.io.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    36
import java.util.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    37
import javax.annotation.processing.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    38
import javax.lang.model.element.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    39
import javax.tools.*;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    40
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    41
public class T7022337 extends JavacTestingAbstractProcessor {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    42
    public static void main(String... args) throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    43
        new T7022337().run();
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
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    46
    void run() throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    47
        String myName = T7022337.class.getSimpleName();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    48
        File testSrc = new File(System.getProperty("test.src"));
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    49
        File file = new File(testSrc, myName + ".java");
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    50
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    51
        String out = compile(
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    52
            "-XDrawDiagnostics",
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    53
            "-d", ".",
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    54
            "-processor", myName,
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 14963
diff changeset
    55
            "-source", "8", // explicit use of older source value without bootclasspath
8618
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    56
            file.getPath());
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    57
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    58
        int count = 0;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    59
        for (String line: out.split("[\r\n]+")) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    60
            if (line.contains("compiler.warn.source.no.bootclasspath"))
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    61
                count++;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    62
        }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    63
        if (count != 1)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    64
            throw new Exception("unexpected number of warnings found: " + count + ", expected: 1");
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
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    67
    String compile(String... args) throws Exception {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    68
        StringWriter sw = new StringWriter();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    69
        PrintWriter pw = new PrintWriter(sw);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    70
        int rc = com.sun.tools.javac.Main.compile(args, pw);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    71
        pw.close();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    72
        String out = sw.toString();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    73
        if (!out.isEmpty())
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    74
            System.err.println(out);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    75
        if (rc != 0)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    76
            throw new Exception("compilation failed unexpectedly: rc=" + rc);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    77
        return out;
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
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    82
    int round = 0;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    83
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    84
    @Override
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    85
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    86
        round++;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    87
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    88
        final int MAXROUNDS = 3;
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    89
        if (round < MAXROUNDS)
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    90
            generate("Gen" + round);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    91
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    92
        return true;
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
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    95
    void generate(String name) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    96
        try {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    97
            JavaFileObject fo = filer.createSourceFile(name);
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    98
            Writer out = fo.openWriter();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
    99
            try {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   100
                out.write("class " + name + " { }");
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   101
            } finally {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   102
                out.close();
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   103
            }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   104
        } catch (IOException e) {
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   105
            throw new Error(e);
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
    }
913fb63a554b 7022337: repeated warnings about bootclasspath not set
jjg
parents:
diff changeset
   108
}