Path: blob/master/test/langtools/tools/jdeps/modules/upgrademodulepath/UpgradeModulePathTest.java
41153 views
/*1* Copyright (c) 2017, 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* @bug 818744926* @summary Tests jdeps --upgrade-module-path27* @library ../../lib28* @build CompilerUtils29* @modules jdk.jartool30* jdk.jdeps/com.sun.tools.jdeps31* @run testng UpgradeModulePathTest32*/3334import java.io.BufferedWriter;35import java.io.PrintWriter;36import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;39import java.util.spi.ToolProvider;40import java.util.stream.Stream;4142import org.testng.annotations.BeforeTest;43import org.testng.annotations.Test;4445import static org.testng.Assert.assertFalse;46import static org.testng.Assert.assertTrue;4748public class UpgradeModulePathTest {49private static final ToolProvider JAR = ToolProvider.findFirst("jar")50.orElseThrow(() -> new RuntimeException("jar not found"));5152private static final String TEST_SRC = System.getProperty("test.src");5354private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");55private static final Path MODS_DIR = Paths.get("mods");5657private static final String JAVA_COMPILER = "java.compiler";5859/**60* Compiles classes used by the test61*/62@BeforeTest63public void compileAll() throws Exception {64CompilerUtils.cleanDir(MODS_DIR);65assertTrue(CompilerUtils.compileModule(SRC_DIR, MODS_DIR, JAVA_COMPILER));6667Path dir = MODS_DIR.resolve(JAVA_COMPILER);6869// create a modular JAR file for java.compiler70JAR.run(System.out, System.err,71"cf", "java.compiler.jar", "-C", dir.toString(), ".");7273// create a JAR file with AUTOMATIC-MODULE-NAME74try (BufferedWriter bw = Files.newBufferedWriter(Paths.get("manifest"));75PrintWriter writer = new PrintWriter(bw)) {76writer.println("AUTOMATIC-MODULE-NAME: java.compiler");77}7879JAR.run(System.out, System.err,80"cfm", "auto.jar", "manifest", "-C", dir.toString(), "javax");81}8283@Test84public void testSystemModule() throws Exception {85JdepsRunner jdepsRunner =86JdepsRunner.run(Stream.of("-m", "java.compiler").toArray(String[]::new));8788assertTrue(jdepsRunner.outputContains("javax.tools"));89assertTrue(jdepsRunner.outputContains("javax.lang.model"));90assertTrue(jdepsRunner.outputContains("javax.annotation.processing"));91}9293@Test94public void testUpgradedModule() throws Exception {95JdepsRunner jdepsRunner =96JdepsRunner.run(Stream.of("--upgrade-module-path", "java.compiler.jar",97"-m", "java.compiler").toArray(String[]::new));9899assertTrue(jdepsRunner.outputContains("javax.tools"));100assertFalse(jdepsRunner.outputContains("javax.lang.model"));101assertFalse(jdepsRunner.outputContains("javax.annotation.processing"));102}103104@Test105public void testAutomaticModule() throws Exception {106JdepsRunner jdepsRunner =107JdepsRunner.run(Stream.of("--upgrade-module-path", "auto.jar",108"-m", "java.compiler").toArray(String[]::new));109110assertTrue(jdepsRunner.outputContains("javax.tools"));111assertFalse(jdepsRunner.outputContains("javax.lang.model"));112assertFalse(jdepsRunner.outputContains("javax.annotation.processing"));113}114}115116117