T6378728.java revision 0:9a66ca7c79fa
1/*
2 * Copyright 2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any 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
32import java.io.File;
33import java.io.IOException;
34import java.io.OutputStreamWriter;
35import java.net.URI;
36import java.util.Arrays;
37import javax.tools.JavaCompiler.CompilationTask;
38
39import javax.tools.*;
40
41
42public 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}
85