Path: blob/master/test/langtools/tools/sjavac/CompileWithOverrideSources.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 override sources to be compiled26* @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 CompileWithOverrideSources35*/3637import java.util.*;38import java.nio.file.*;3940public class CompileWithOverrideSources extends SJavacTester {41public static void main(String... args) throws Exception {42CompileWithOverrideSources cos = new CompileWithOverrideSources();43cos.test();44}4546// Compile gensrc and gensrc2. However do not compile broken beta.B in gensrc,47// only compile ok beta.B in gensrc248void test() throws Exception {49Files.createDirectories(BIN);5051Map<String,Long> previous_bin_state = collectState(BIN);52tb.writeFile(GENSRC.resolve("alfa/omega/A.java"),53"package alfa.omega; import beta.B; import gamma.C; public class A { B b; C c; }");54tb.writeFile(GENSRC.resolve("beta/B.java"),55"package beta; public class B { broken");56tb.writeFile(GENSRC.resolve("gamma/C.java"),57"package gamma; public class C { }");5859tb.writeFile(GENSRC2.resolve("beta/B.java"),60"package beta; public class B { }");6162compile("-x", "beta/*",63GENSRC.toString(),64GENSRC2.toString(),65"-d", BIN.toString(),66"--state-dir=" + BIN,67"-h", HEADERS.toString(),68"-j", "1");69Map<String,Long> new_bin_state = collectState(BIN);70verifyThatFilesHaveBeenAdded(previous_bin_state, new_bin_state,71BIN + "/alfa/omega/A.class",72BIN + "/beta/B.class",73BIN + "/gamma/C.class",74BIN + "/javac_state");7576System.out.println("----- Compile with exluded beta went well!");77tb.cleanDirectory(BIN);78compileExpectFailure(GENSRC.toString(),79GENSRC2.toString(),80"-d", BIN.toString(),81"--state-dir=" + BIN,82"-h", HEADERS.toString(),83"-j", "1");8485System.out.println("----- Compile without exluded beta failed, as expected! Good!");86}87}888990