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