0N/A/*
553N/A * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 6348193
0N/A * @summary AS8.1 UR2 BAT test failure with "javac"
0N/A * @compile -proc:none T6348193.java
0N/A * @run main/othervm T6348193
0N/A */
0N/A
0N/Aimport java.io.*;
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/Aimport javax.annotation.processing.*;
0N/Aimport javax.lang.model.element.*;
0N/Aimport javax.tools.*;
0N/Aimport com.sun.tools.javac.api.JavacTool;
0N/A
0N/A@SupportedAnnotationTypes({"*"})
0N/Apublic class T6348193 extends AbstractProcessor
0N/A{
0N/A private static final boolean verbose = true;
0N/A
0N/A enum NoYes { NO, YES };
0N/A enum NoGoodBad { NO, GOOD, BAD};
0N/A
0N/A public static final String myName = T6348193.class.getName();
0N/A
0N/A public static void main(String... args) throws IOException {
0N/A if (System.getSecurityManager() != null)
0N/A throw new AssertionError("unexpected security manager");
0N/A
0N/A for (NoYes secMgr: EnumSet.allOf(NoYes.class))
0N/A for (NoGoodBad config: EnumSet.allOf(NoGoodBad.class))
0N/A for (NoYes proc: EnumSet.allOf(NoYes.class))
0N/A test(secMgr, config, proc);
0N/A }
0N/A
0N/A private static File processed = new File("processed");
0N/A
0N/A public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException {
0N/A if (verbose)
0N/A System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc);
0N/A
0N/A if (secMgr == NoYes.YES && System.getSecurityManager() == null)
0N/A System.setSecurityManager(new NoLoaderSecurityManager());
0N/A
0N/A installConfigFile(config);
0N/A
0N/A processed.delete();
0N/A
0N/A List<String> args = new ArrayList<String>();
0N/A //args.add("-XprintRounds");
0N/A if (proc == NoYes.YES) {
0N/A args.add("-processor");
0N/A args.add(myName);
0N/A }
0N/A args.add("-processorpath");
0N/A args.add(System.getProperty("java.class.path"));
0N/A args.add("-d");
0N/A args.add(".");
0N/A
0N/A JavacTool t = JavacTool.create(); // avoid using class loader
0N/A
0N/A MyDiagListener dl = new MyDiagListener();
0N/A PrintWriter out = new PrintWriter(System.err, true);
0N/A StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null);
0N/A File file = new File(System.getProperty("test.src"), myName+".java");
0N/A Iterable<? extends JavaFileObject> files =
0N/A fm.getJavaFileObjectsFromFiles(Arrays.asList(file));
0N/A boolean ok = t.getTask(out, null, dl, args, null, files).call();
0N/A
0N/A if (config == NoGoodBad.GOOD || proc == NoYes.YES) {
0N/A if (secMgr == NoYes.YES) {
0N/A if (dl.last == null)
0N/A throw new AssertionError("Security manager installed, and processors present, "
0N/A + " but no diagnostic received");
0N/A }
0N/A else {
0N/A if (!processed.exists())
0N/A throw new AssertionError("No security manager installed, and processors present, "
0N/A + " but no processing occurred");
0N/A }
0N/A }
0N/A else if (config == NoGoodBad.BAD) {
0N/A // TODO: should verify that no compiler crash occurred
0N/A // needs revised JSR199 spec
0N/A }
0N/A else {
0N/A if (processed.exists())
0N/A throw new AssertionError("No processors present, but processing occurred!");
0N/A }
0N/A
0N/A if (verbose)
0N/A System.err.println("OK");
0N/A }
0N/A
0N/A // set up or remove a service configuration file
0N/A static void installConfigFile(NoGoodBad type) throws IOException {
142N/A File f = new File(System.getProperty("test.classes", "."));
0N/A for (String s: new String[] { "META-INF", "services", Processor.class.getName() })
0N/A f = new File(f, s);
0N/A BufferedWriter out;
0N/A switch (type) {
0N/A case GOOD:
0N/A f.getParentFile().mkdirs();
0N/A out = new BufferedWriter(new FileWriter(f));
0N/A out.write(myName);
0N/A out.newLine();
0N/A out.close();
0N/A break;
0N/A case BAD:
0N/A f.getParentFile().mkdirs();
0N/A out = new BufferedWriter(new FileWriter(f));
0N/A out.write("This is not a valid line");
0N/A out.newLine();
0N/A out.close();
0N/A break;
0N/A case NO:
0N/A f.delete();
0N/A }
0N/A
0N/A
0N/A }
0N/A
0N/A // annotation processor method
0N/A public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv )
0N/A {
0N/A try {
0N/A // touch a file to indicate we have run
0N/A new FileWriter(processed).close();
0N/A } catch (IOException e) {
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A static class MyDiagListener implements DiagnosticListener<JavaFileObject>
0N/A {
0N/A public void report(Diagnostic<? extends JavaFileObject> message) {
0N/A if (verbose)
0N/A System.err.println(message);
0N/A last = message;
0N/A }
0N/A
0N/A Diagnostic<? extends JavaFileObject> last;
0N/A }
0N/A
0N/A static class NoLoaderSecurityManager extends SecurityManager
0N/A {
0N/A public void checkCreateClassLoader() {
0N/A throw new SecurityException("Not today, thanks you!");
0N/A }
0N/A
0N/A public void checkPropertyAccess(String key) { /*OK*/ }
0N/A
0N/A public void checkDelete(String file) { /*OK*/ }
0N/A public void checkRead(FileDescriptor fd) { /*OK*/ }
0N/A public void checkRead(String file) { /*OK*/ }
0N/A public void checkRead(String file, Object context) { /*OK*/ }
0N/A public void checkWrite(String file) { /*OK*/ }
0N/A
0N/A }
0N/A}