1 /* 2 * Copyright (c) 2016, 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 /test/lib 27 * @modules java.base/jdk.internal.misc 28 * jdk.compiler 29 * jdk.jartool 30 * @build jdk.test.lib.util.FileUtils 31 * jdk.test.lib.Utils 32 * jdk.test.lib.Asserts 33 * jdk.test.lib.JDKToolFinder 34 * jdk.test.lib.JDKToolLauncher 35 * jdk.test.lib.Platform 36 * jdk.test.lib.process.* 37 * MRTestBase 38 * @run testng Basic1 39 */ 40 41 import org.testng.annotations.*; 42 43 import java.nio.file.*; 44 import java.util.*; 45 46 public class Basic1 extends MRTestBase { 47 48 @BeforeTest 49 public void setup() throws Throwable { 50 String test = "test01"; 51 Path classes = Paths.get("classes"); 52 53 Path base = classes.resolve("base"); 54 Files.createDirectories(base); 55 Path source = Paths.get(src, "data", test, "base", "version"); 56 javac(base, source.resolve("Main.java"), source.resolve("Version.java")); 57 58 Path v9 = classes.resolve("v9"); 59 Files.createDirectories(v9); 60 source = Paths.get(src, "data", test, "v9", "version"); 61 javac(v9, source.resolve("Version.java")); 62 63 Path v10 = classes.resolve("v10"); 64 Files.createDirectories(v10); 65 source = Paths.get(src, "data", test, "v10", "version"); 66 javac(v10, source.resolve("Version.java")); 67 68 Path v10_1 = classes.resolve("v10_1").resolve("META-INF").resolve("versions").resolve("v10"); 69 Files.createDirectories(v10_1); 70 source = Paths.get(src, "data", test, "v10", "version"); 71 javac(v10_1, source.resolve("Version.java")); 72 } 73 74 @Test 75 public void test() throws Throwable { 76 String jarfile = "test.jar"; 77 Path classes = Paths.get("classes"); 78 79 Path base = classes.resolve("base"); 80 Path v9 = classes.resolve("v9"); 81 Path v10 = classes.resolve("v10"); 82 83 jar("cf", jarfile, "-C", base.toString(), ".", 84 "--release", "9", "-C", v9.toString(), ".", 85 "--release", "10", "-C", v10.toString(), ".") 86 .shouldHaveExitValue(SUCCESS); 87 88 checkMultiRelease(jarfile, true); 89 90 Map<String, String[]> names = Map.of( 91 "version/Main.class", 92 new String[]{"base", "version", "Main.class"}, 93 94 "version/Version.class", 95 new String[]{"base", "version", "Version.class"}, 96 97 "META-INF/versions/9/version/Version.class", 98 new String[] {"v9", "version", "Version.class"}, 99 100 "META-INF/versions/10/version/Version.class", 101 new String[] {"v10", "version", "Version.class"} 102 ); 103 104 compare(jarfile, names); 105 } 106 107 @Test 108 public void testFail() throws Throwable { 109 String jarfile = "test.jar"; 110 Path classes = Paths.get("classes"); 111 Path base = classes.resolve("base"); 112 Path v10 = classes.resolve("v10_1"); 113 114 jar("cf", jarfile, "-C", base.toString(), ".", 115 "--release", "10", "-C", v10.toString(), ".") 116 .shouldNotHaveExitValue(SUCCESS) 117 .shouldContain("unexpected versioned entry META-INF/versions/"); 118 } 119 }