1 /* 2 * Copyright (c) 2014, 2017, 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. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /** 25 * @test 26 * @library /lib/testlibrary /test/lib 27 * @modules java.transaction 28 * jdk.compiler 29 * @build UpgradeModulePathTest jdk.testlibrary.* 30 * jdk.test.lib.compiler.CompilerUtils 31 * @run testng UpgradeModulePathTest 32 * @summary Basic test for java --upgrade-module-path 33 */ 34 35 import java.io.File; 36 import java.nio.file.Path; 37 import java.nio.file.Paths; 38 39 import jdk.test.lib.compiler.CompilerUtils; 40 import static jdk.testlibrary.ProcessTools.executeTestJava; 41 42 import org.testng.annotations.BeforeTest; 43 import org.testng.annotations.Test; 44 import static org.testng.Assert.*; 45 46 /** 47 * This test upgrades module java.transaction. The upgraded module has a 48 * dependency on module java.enterprise that is deployed on the application 49 * modue path. 50 */ 51 52 @Test 53 public class UpgradeModulePathTest { 54 55 private static final String TEST_SRC = System.getProperty("test.src"); 56 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src"); 57 private static final Path MODS_DIR = Paths.get("mods"); 58 private static final Path UPGRADEDMODS_DIR = Paths.get("upgradedmods"); 59 60 61 @BeforeTest 62 public void setup() throws Exception { 63 64 // javac -d mods/java.enterprise src/java.enterprise/** 65 boolean compiled = CompilerUtils.compile( 66 SRC_DIR.resolve("java.enterprise"), 67 MODS_DIR.resolve("java.enterprise")); 68 assertTrue(compiled); 69 70 // javac -d upgrademods/java.transaction --module-path mods src/java.transaction/** 71 compiled = CompilerUtils.compile( 72 SRC_DIR.resolve("java.transaction"), 73 UPGRADEDMODS_DIR.resolve("java.transaction"), 74 "--module-path", MODS_DIR.toString()); 75 assertTrue(compiled); 76 77 // javac -d mods --upgrade-module-path upgrademods --module-path mods src/test/** 78 compiled = CompilerUtils.compile( 79 SRC_DIR.resolve("test"), 80 MODS_DIR.resolve("test"), 81 "--upgrade-module-path", UPGRADEDMODS_DIR.toString(), 82 "--module-path", MODS_DIR.toString()); 83 assertTrue(compiled); 84 85 } 86 87 88 /** 89 * Run the test with an upgraded java.transaction module. 90 */ 91 public void testWithUpgradedModule() throws Exception { 92 93 String mid = "test/jdk.test.Main"; 94 95 int exitValue 96 = executeTestJava( 97 "--upgrade-module-path", UPGRADEDMODS_DIR.toString(), 98 "--module-path", MODS_DIR.toString(), 99 "-m", mid) 100 .outputTo(System.out) 101 .errorTo(System.out) 102 .getExitValue(); 103 104 assertTrue(exitValue == 0); 105 106 } 107 108 109 /** 110 * Run the test with a non-existent file on the upgrade module path. 111 * It should be silently ignored. 112 */ 113 public void testRunWithNonExistentEntry() throws Exception { 114 115 String upgrademodulepath 116 = "DoesNotExit" + File.pathSeparator + UPGRADEDMODS_DIR.toString(); 117 String mid = "test/jdk.test.Main"; 118 119 int exitValue 120 = executeTestJava( 121 "--upgrade-module-path", upgrademodulepath, 122 "--module-path", MODS_DIR.toString(), 123 "-m", mid) 124 .outputTo(System.out) 125 .errorTo(System.out) 126 .getExitValue(); 127 128 assertTrue(exitValue == 0); 129 130 } 131 132 }