test/tools/javac/processing/options/testCommandLineClasses/Test.java

Fri, 21 Dec 2012 08:45:43 -0800

author
darcy
date
Fri, 21 Dec 2012 08:45:43 -0800
changeset 1466
b52a38d4536c
parent 937
a2399c8db703
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8005282: Use @library tag with non-relative path for javac tests
Reviewed-by: jjg

jjg@937 1 /*
jjg@937 2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
jjg@937 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@937 4 *
jjg@937 5 * This code is free software; you can redistribute it and/or modify it
jjg@937 6 * under the terms of the GNU General Public License version 2 only, as
jjg@937 7 * published by the Free Software Foundation.
jjg@937 8 *
jjg@937 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@937 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@937 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@937 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@937 13 * accompanied this code).
jjg@937 14 *
jjg@937 15 * You should have received a copy of the GNU General Public License version
jjg@937 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@937 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@937 18 *
jjg@937 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@937 20 * or visit www.oracle.com if you need additional information or have any
jjg@937 21 * questions.
jjg@937 22 */
jjg@937 23
jjg@937 24 /*
jjg@937 25 * @test
jjg@937 26 * @bug 6930508
jjg@937 27 * @summary Passing nested class names on javac command line interfere with subsequent name -> class lookup
darcy@1466 28 * @library /tools/javac/lib
jjg@937 29 * @build JavacTestingAbstractProcessor p.NestedExamples Test
jjg@937 30 * @run main Test
jjg@937 31 */
jjg@937 32
jjg@937 33 import java.io.*;
jjg@937 34 import java.util.*;
jjg@937 35 import javax.annotation.processing.RoundEnvironment;
jjg@937 36 import javax.lang.model.element.TypeElement;
jjg@937 37 import javax.lang.model.util.ElementFilter;
jjg@937 38 import javax.tools.*;
jjg@937 39
jjg@937 40 import p.NestedExamples;
jjg@937 41
jjg@937 42 public class Test extends JavacTestingAbstractProcessor {
jjg@937 43 public static void main(String... args) throws Exception {
jjg@937 44 new Test().run();
jjg@937 45 }
jjg@937 46
jjg@937 47 void run() throws Exception {
jjg@937 48 NestedExamples e = new NestedExamples();
jjg@937 49 List<String> names = getNames(e.getClasses());
jjg@937 50 test(names);
jjg@937 51 test(reverse(names));
jjg@937 52 names = Arrays.asList(e.getClassNames());
jjg@937 53 test(names);
jjg@937 54 test(reverse(names));
jjg@937 55
jjg@937 56 if (errors > 0)
jjg@937 57 throw new RuntimeException(errors + " errors occurred");
jjg@937 58 }
jjg@937 59
jjg@937 60 List<String> getNames(Class<?>[] classes) {
jjg@937 61 List<String> names = new ArrayList<String>();
jjg@937 62 for (Class<?> c: classes)
jjg@937 63 names.add(c.getName());
jjg@937 64 return names;
jjg@937 65 }
jjg@937 66
jjg@937 67 void test(List<String> names) throws Exception {
jjg@937 68 System.err.println("test: " + names);
jjg@937 69 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
jjg@937 70 StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
jjg@937 71 File testClasses = new File(System.getProperty("test.classes"));
jjg@937 72 fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses));
jjg@937 73 JavaCompiler.CompilationTask task = compiler.getTask(
jjg@937 74 null, null, null, Arrays.asList("-proc:only"), names, null);
jjg@937 75 task.setProcessors(Arrays.asList(new Test()));
jjg@937 76 boolean ok = task.call();
jjg@937 77 if (!ok)
jjg@937 78 error("compilation failed");
jjg@937 79 System.err.println();
jjg@937 80 }
jjg@937 81
jjg@937 82 <T> List<T> reverse(List<T> list) {
jjg@937 83 List<T> newList = new ArrayList<T>(list);
jjg@937 84 Collections.reverse(newList);
jjg@937 85 return newList;
jjg@937 86 }
jjg@937 87
jjg@937 88 int errors = 0;
jjg@937 89
jjg@937 90 void error(String msg) {
jjg@937 91 System.out.println("Error: " + msg);
jjg@937 92 errors++;
jjg@937 93 }
jjg@937 94
jjg@937 95 //----------
jjg@937 96
jjg@937 97 public boolean process(Set<? extends TypeElement> annotations,
jjg@937 98 RoundEnvironment roundEnv) {
jjg@937 99 if (!roundEnv.processingOver()) {
jjg@937 100 for (TypeElement typeElt : ElementFilter.typesIn(roundEnv.getRootElements())) {
jjg@937 101 messager.printMessage(Diagnostic.Kind.NOTE, "processing " + typeElt);
jjg@937 102 }
jjg@937 103 }
jjg@937 104 return true;
jjg@937 105 }
jjg@937 106 }

mercurial