Path: blob/master/test/langtools/tools/sjavac/CompileWithInvisibleSources.java
41144 views
/*1* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @summary Verify that we can make sources invisible to linking (sourcepath)26* @bug 805468927* @author Fredrik O28* @author sogoel (rewrite)29* @library /tools/lib30* @modules jdk.compiler/com.sun.tools.javac.api31* jdk.compiler/com.sun.tools.javac.main32* jdk.compiler/com.sun.tools.sjavac33* @build Wrapper toolbox.ToolBox34* @run main Wrapper CompileWithInvisibleSources35*/3637import java.util.*;38import java.nio.file.*;3940public class CompileWithInvisibleSources extends SJavacTester {41public static void main(String... args) throws Exception {42CompileWithInvisibleSources cis = new CompileWithInvisibleSources();43cis.test();44}4546// Compile gensrc and link against gensrc2 and gensrc347// gensrc2 contains broken code in beta.B, thus exclude that package48// gensrc3 contains a proper beta.B49void test() throws Exception {50Files.createDirectories(BIN);5152Map<String,Long> previous_bin_state = collectState(BIN);5354tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),55"package alfa.omega; import beta.B; import gamma.C; public class A { B b; C c; }");56tb.writeFile(GENSRC2.resolve("beta/B.java"),57"package beta; public class B { broken");58tb.writeFile(GENSRC2.resolve("gamma/C.java"),59"package gamma; public class C { }");60tb.writeFile(GENSRC3.resolve("beta/B.java"),61"package beta; public class B { }");6263compile(GENSRC.toString(),64"-x", "beta/*",65"-sourcepath", GENSRC2.toString(),66"-sourcepath", GENSRC3.toString(),67"-d", BIN.toString(),68"--state-dir=" + BIN,69"-h", HEADERS.toString(),70"-j", "1");7172System.out.println("The first compile went well!");73Map<String,Long> new_bin_state = collectState(BIN);74verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,75BIN + "/alfa/omega/A.class",76BIN + "/javac_state");7778System.out.println("----- Compile with exluded beta went well!");79tb.cleanDirectory(BIN);80compileExpectFailure(GENSRC.toString(),81"-sourcepath", GENSRC2.toString(),82"-sourcepath", GENSRC3.toString(),83"-d", BIN.toString(),84"--state-dir=" + BIN,85"-h", HEADERS.toString(),86"-j", "1");8788System.out.println("----- Compile without exluded beta failed, as expected! Good!");89}90}919293