Path: blob/master/test/jdk/tools/jar/multiRelease/Basic1.java
41149 views
/*1* Copyright (c) 2016, 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* @library /test/lib26* @modules java.base/jdk.internal.misc27* jdk.compiler28* jdk.jartool29* @build jdk.test.lib.Utils30* jdk.test.lib.Asserts31* jdk.test.lib.JDKToolFinder32* jdk.test.lib.JDKToolLauncher33* jdk.test.lib.Platform34* jdk.test.lib.process.*35* MRTestBase36* @run testng Basic137*/3839import org.testng.annotations.*;4041import java.nio.file.*;42import java.util.*;4344public class Basic1 extends MRTestBase {4546@BeforeTest47public void setup() throws Throwable {48String test = "test01";49Path classes = Paths.get("classes");5051Path base = classes.resolve("base");52Files.createDirectories(base);53Path source = Paths.get(src, "data", test, "base", "version");54javac(base, source.resolve("Main.java"), source.resolve("Version.java"));5556Path v9 = classes.resolve("v9");57Files.createDirectories(v9);58source = Paths.get(src, "data", test, "v9", "version");59javac(v9, source.resolve("Version.java"));6061Path v10 = classes.resolve("v10");62Files.createDirectories(v10);63source = Paths.get(src, "data", test, "v10", "version");64javac(v10, source.resolve("Version.java"));6566Path v10_1 = classes.resolve("v10_1").resolve("META-INF").resolve("versions").resolve("v10");67Files.createDirectories(v10_1);68source = Paths.get(src, "data", test, "v10", "version");69javac(v10_1, source.resolve("Version.java"));70}7172@Test73public void test() throws Throwable {74String jarfile = "test.jar";75Path classes = Paths.get("classes");7677Path base = classes.resolve("base");78Path v9 = classes.resolve("v9");79Path v10 = classes.resolve("v10");8081jar("cf", jarfile, "-C", base.toString(), ".",82"--release", "9", "-C", v9.toString(), ".",83"--release", "10", "-C", v10.toString(), ".")84.shouldHaveExitValue(SUCCESS);8586checkMultiRelease(jarfile, true);8788Map<String, String[]> names = Map.of(89"version/Main.class",90new String[]{"base", "version", "Main.class"},9192"version/Version.class",93new String[]{"base", "version", "Version.class"},9495"META-INF/versions/9/version/Version.class",96new String[] {"v9", "version", "Version.class"},9798"META-INF/versions/10/version/Version.class",99new String[] {"v10", "version", "Version.class"}100);101102compare(jarfile, names);103}104105@Test106public void testFail() throws Throwable {107String jarfile = "test.jar";108Path classes = Paths.get("classes");109Path base = classes.resolve("base");110Path v10 = classes.resolve("v10_1");111112jar("cf", jarfile, "-C", base.toString(), ".",113"--release", "10", "-C", v10.toString(), ".")114.shouldNotHaveExitValue(SUCCESS)115.shouldContain("unexpected versioned entry META-INF/versions/");116}117}118119120