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