test/tools/javac/processing/6350124/T6350124.java

Fri, 27 Sep 2013 11:34:32 -0700

author
mduigou
date
Fri, 27 Sep 2013 11:34:32 -0700
changeset 2073
4ed8565fa536
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8024842: Define ABS_TEST_OUTPUT_DIR via TEST_OUTPUT_DIR
Reviewed-by: ihse, erikj, vromero

duke@1 1 /*
ohair@554 2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
duke@1 7 * published by the Free Software Foundation.
duke@1 8 *
duke@1 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 13 * accompanied this code).
duke@1 14 *
duke@1 15 * You should have received a copy of the GNU General Public License version
duke@1 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
duke@1 22 */
duke@1 23
duke@1 24 /*
duke@1 25 * @test
duke@1 26 * @bug 6350124 6410012
duke@1 27 * @summary javac -s does not have the generated source files
duke@1 28 */
duke@1 29
duke@1 30 import java.io.File;
duke@1 31 import java.io.PrintWriter;
duke@1 32 import javax.tools.Tool;
duke@1 33 import javax.tools.ToolProvider;
duke@1 34
duke@1 35 public class T6350124 {
duke@1 36 public static void main(String[] args) {
duke@1 37 String classpath = System.getProperty("java.class.path");
duke@1 38 File srcDir = new File(System.getProperty("test.src"));
duke@1 39
duke@1 40 // ensure the output directories are empty
duke@1 41 mkCleanDir(new File("aClasses"));
duke@1 42 mkCleanDir(new File("newClasses"));
duke@1 43 mkCleanDir(new File("newSrc"));
duke@1 44
duke@1 45 // compile the annotation processor
duke@1 46 compile("-cp", classpath,
duke@1 47 "-d", "aClasses", path(srcDir, "HelloWorldAP.java"));
duke@1 48
duke@1 49 // compile the test program, invoking the anotation processor
duke@1 50 compile("-cp", classpath,
duke@1 51 "-sourcepath", srcDir.getPath(),
duke@1 52 "-d", "newClasses",
duke@1 53 "-s", "newSrc",
duke@1 54 "-processorpath", "aClasses",
duke@1 55 "-processor", "HelloWorldAP", // specify processor for simplicity
duke@1 56 "-proc:only",
duke@1 57 path(srcDir, "Marked.java"));
duke@1 58
duke@1 59 File hw = new File("newSrc", "HelloWorld.java");
duke@1 60 if (!hw.exists())
duke@1 61 throw new AssertionError("generated source file not found");
duke@1 62
duke@1 63 File dc = new File("newClasses", "HelloWorldAP.class");
duke@1 64 if (!dc.exists())
duke@1 65 throw new AssertionError("generated class file not found");
duke@1 66 }
duke@1 67
duke@1 68 //--- the following can be considered "library code" for the test
duke@1 69
duke@1 70 // note: jtreg @clean will only clean class files; not source files
duke@1 71 static void clean(File file) {
duke@1 72 if (!file.exists())
duke@1 73 return;
duke@1 74 if (file.isDirectory()) {
duke@1 75 for (File f: file.listFiles())
duke@1 76 clean(f);
duke@1 77 }
duke@1 78 file.delete();
duke@1 79 }
duke@1 80
duke@1 81 static void mkCleanDir(File dir) {
duke@1 82 clean(dir);
duke@1 83 dir.mkdirs();
duke@1 84 }
duke@1 85
duke@1 86 // note: jtreg @compile does not allow -d to be specified
duke@1 87 static void compile(String... args) {
duke@1 88 StringBuffer sb = new StringBuffer("compile:");
duke@1 89 for (String a: args)
duke@1 90 sb.append(' ').append(a);
duke@1 91 System.err.println(sb);
duke@1 92
duke@1 93 Tool t = ToolProvider.getSystemJavaCompiler();
duke@1 94 int rc = t.run(System.in, System.out, System.err, args);
duke@1 95 System.out.flush();
duke@1 96 System.err.flush();
duke@1 97 if (rc != 0)
duke@1 98 throw new Error("compilation failed");
duke@1 99 }
duke@1 100
duke@1 101 static String path(File dir, String name) {
duke@1 102 return new File(dir, name).getPath();
duke@1 103 }
duke@1 104 }

mercurial