42 public class T6412669 extends AbstractProcessor { |
42 public class T6412669 extends AbstractProcessor { |
43 public static void main(String... args) throws Exception { |
43 public static void main(String... args) throws Exception { |
44 File testSrc = new File(System.getProperty("test.src", ".")); |
44 File testSrc = new File(System.getProperty("test.src", ".")); |
45 File testClasses = new File(System.getProperty("test.classes", ".")); |
45 File testClasses = new File(System.getProperty("test.classes", ".")); |
46 |
46 |
47 // Determine location of necessary tools classes. Assume all in one place. |
|
48 // Likely candidates are typically tools.jar (when testing JDK build) |
|
49 // or build/classes or dist/javac.jar (when testing langtools, using -Xbootclasspath/p:) |
|
50 File toolsClasses; |
|
51 URL u = T6412669.class.getClassLoader().getResource("com/sun/source/util/JavacTask.class"); |
|
52 switch (u.getProtocol()) { |
|
53 case "file": |
|
54 toolsClasses = new File(u.toURI()); |
|
55 break; |
|
56 case "jar": |
|
57 String s = u.getFile(); // will be file:path!/entry |
|
58 int sep = s.indexOf("!"); |
|
59 toolsClasses = new File(new URI(s.substring(0, sep))); |
|
60 break; |
|
61 default: |
|
62 throw new AssertionError("Cannot locate tools classes"); |
|
63 } |
|
64 //System.err.println("toolsClasses: " + toolsClasses); |
|
65 |
|
66 JavacTool tool = JavacTool.create(); |
47 JavacTool tool = JavacTool.create(); |
67 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
48 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
68 fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses, toolsClasses)); |
49 fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(testClasses)); |
69 Iterable<? extends JavaFileObject> files = |
50 Iterable<? extends JavaFileObject> files = |
70 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java"))); |
51 fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6412669.class.getName()+".java"))); |
71 String[] opts = { "-proc:only", "-processor", T6412669.class.getName()}; |
52 String[] opts = { "-proc:only", "-processor", T6412669.class.getName()}; |
72 StringWriter sw = new StringWriter(); |
53 StringWriter sw = new StringWriter(); |
73 JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files); |
54 JavacTask task = tool.getTask(sw, fm, null, Arrays.asList(opts), null, files); |