CompileExcludingDependency.java revision 2958:27da0c3ac83a
1/*
2 * Copyright (c) 2014, 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.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * @test
28 * @summary Tests compiling class A that depends on class B without compiling class B
29 * @bug 8054689
30 * @author Fredrik O
31 * @author sogoel (rewrite)
32 * @library /tools/lib
33 * @modules jdk.compiler/com.sun.tools.javac.api
34 *          jdk.compiler/com.sun.tools.javac.file
35 *          jdk.compiler/com.sun.tools.javac.main
36 *          jdk.compiler/com.sun.tools.sjavac
37 * @build Wrapper ToolBox
38 * @run main Wrapper CompileExcludingDependency
39 */
40
41import java.util.*;
42import java.nio.file.*;
43
44public class CompileExcludingDependency extends SJavacTester {
45    public static void main(String... args) throws Exception {
46        CompileExcludingDependency ced = new CompileExcludingDependency();
47        ced.test();
48    }
49
50    // Verify that excluding classes from compilation but not from linking works
51    void test() throws Exception {
52        clean(TEST_ROOT);
53        Files.createDirectories(BIN);
54        clean(GENSRC,BIN);
55        Map<String,Long> previous_bin_state = collectState(BIN);
56        ToolBox tb = new ToolBox();
57        tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),
58                     "package alfa.omega; public class A { beta.B b; }");
59        tb.writeFile(GENSRC.resolve("beta/B.java"),
60                     "package beta; public class B { }");
61
62        compile("-x", "beta",
63                "-src", GENSRC.toString(),
64                "-x", "alfa/omega",
65                "-sourcepath", GENSRC.toString(),
66                "-d", BIN.toString(),
67                SERVER_ARG);
68
69        Map<String,Long> new_bin_state = collectState(BIN);
70        verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,
71                                     BIN + "/alfa/omega/A.class",
72                                     BIN + "/javac_state");
73        clean(GENSRC, BIN);
74    }
75}
76