|
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 */ |
|
23 |
|
24 /* @test |
|
25 * @bug 6378728 |
|
26 * @summary Verify -proc:only doesn't produce class files |
|
27 * @author Joseph D. Darcy |
|
28 * @compile T6378728.java |
|
29 * @run main T6378728 |
|
30 */ |
|
31 |
|
32 import java.io.File; |
|
33 import java.io.IOException; |
|
34 import java.io.OutputStreamWriter; |
|
35 import java.net.URI; |
|
36 import java.util.Arrays; |
|
37 import javax.tools.JavaCompiler.CompilationTask; |
|
38 |
|
39 import javax.tools.*; |
|
40 |
|
41 |
|
42 public class T6378728 { |
|
43 private static class ExceptionalFileManager extends ForwardingJavaFileManager { |
|
44 public ExceptionalFileManager(JavaFileManager wrapped) { |
|
45 super(wrapped); |
|
46 } |
|
47 |
|
48 @Override |
|
49 public FileObject getFileForOutput(Location location, |
|
50 String packageName, |
|
51 String relativeName, |
|
52 FileObject sibling) |
|
53 { |
|
54 throw new IllegalArgumentException("No files for you!"); |
|
55 } |
|
56 |
|
57 @Override |
|
58 public JavaFileObject getJavaFileForOutput(Location location, |
|
59 String className, |
|
60 JavaFileObject.Kind kind, |
|
61 FileObject sibling) |
|
62 { |
|
63 throw new IllegalArgumentException("No files for you!"); |
|
64 } |
|
65 } |
|
66 |
|
67 public static void main(String[] args) { |
|
68 // Get a compiler tool |
|
69 JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
70 String srcdir = System.getProperty("test.src"); |
|
71 File source = new File(srcdir, "T6378728.java"); |
|
72 StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null); |
|
73 |
|
74 CompilationTask task = |
|
75 compiler.getTask(null, |
|
76 new ExceptionalFileManager(fm), |
|
77 null, |
|
78 Arrays.asList("-proc:only"), |
|
79 null, |
|
80 fm.getJavaFileObjectsFromFiles(Arrays.asList(source))); |
|
81 if (!task.call()) |
|
82 throw new RuntimeException("Unexpected compilation failure"); |
|
83 } |
|
84 } |