< prev index next >

test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java

Print this page


   1 /*
   2  * Copyright (c) 2015, 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  * @bug 8132734 8144062 8165723
  27  * @summary Test the extended API and the aliasing additions in JarFile that
  28  *          support multi-release jar files
  29  * @library /lib/testlibrary/java/util/jar /test/lib
  30  * @build jdk.test.lib.RandomFactory
  31  *        Compiler JarBuilder CreateMultiReleaseTestJars
  32  * @run testng MultiReleaseJarAPI
  33  */
  34 
  35 import java.io.File;
  36 import java.io.IOException;
  37 import java.io.InputStream;
  38 import java.nio.charset.StandardCharsets;
  39 import java.nio.file.Files;
  40 import java.util.Arrays;
  41 import java.util.Map;
  42 import java.util.Random;
  43 import java.util.concurrent.atomic.AtomicInteger;
  44 import java.util.jar.JarFile;
  45 import java.util.zip.ZipEntry;
  46 import java.util.zip.ZipFile;


 135     }
 136 
 137     private static final AtomicInteger JAR_COUNT = new AtomicInteger(0);
 138 
 139     private void testCustomMultiReleaseValue(String value,
 140             Map<String, String> extraAttributes, boolean expected)
 141             throws Exception {
 142         String fileName = "custom-mr" + JAR_COUNT.incrementAndGet() + ".jar";
 143         creator.buildCustomMultiReleaseJar(fileName, value, extraAttributes);
 144         File custom = new File(userdir, fileName);
 145         try (JarFile jf = new JarFile(custom, true, ZipFile.OPEN_READ, Runtime.version())) {
 146             Assert.assertEquals(jf.isMultiRelease(), expected);
 147         }
 148         Files.delete(custom.toPath());
 149     }
 150 
 151     @DataProvider(name = "versions")
 152     public Object[][] createVersionData() throws Exception {
 153         return new Object[][]{
 154                 {JarFile.baseVersion(), 8},
 155                 {JarFile.runtimeVersion(), Runtime.version().major()},
 156                 {Runtime.version(), Runtime.version().major()},
 157                 {Runtime.Version.parse("7.1"), JarFile.baseVersion().major()},
 158                 {Runtime.Version.parse("9"), 9},
 159                 {Runtime.Version.parse("9.1.5-ea+200"), 9}

 160         };
 161     }
 162 
 163     @Test(dataProvider="versions")
 164     public void testVersioning(Runtime.Version value, int xpected) throws Exception {
 165         Runtime.Version expected = Runtime.Version.parse(String.valueOf(xpected));
 166         Runtime.Version base = JarFile.baseVersion();
 167 
 168         // multi-release jar, opened as unversioned
 169         try (JarFile jar = new JarFile(multirelease)) {
 170             Assert.assertEquals(jar.getVersion(), base);
 171         }
 172 
 173         System.err.println("test versioning for Release " + value);
 174         try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, value)) {
 175             Assert.assertEquals(jf.getVersion(), expected);
 176         }
 177 
 178         // regular, unversioned, jar
 179         try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, value)) {


   1 /*
   2  * Copyright (c) 2015, 2018, 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  * @bug 8132734 8144062 8165723 8194070
  27  * @summary Test the extended API and the aliasing additions in JarFile that
  28  *          support multi-release jar files
  29  * @library /lib/testlibrary/java/util/jar /test/lib
  30  * @build jdk.test.lib.RandomFactory
  31  *        Compiler JarBuilder CreateMultiReleaseTestJars
  32  * @run testng MultiReleaseJarAPI
  33  */
  34 
  35 import java.io.File;
  36 import java.io.IOException;
  37 import java.io.InputStream;
  38 import java.nio.charset.StandardCharsets;
  39 import java.nio.file.Files;
  40 import java.util.Arrays;
  41 import java.util.Map;
  42 import java.util.Random;
  43 import java.util.concurrent.atomic.AtomicInteger;
  44 import java.util.jar.JarFile;
  45 import java.util.zip.ZipEntry;
  46 import java.util.zip.ZipFile;


 135     }
 136 
 137     private static final AtomicInteger JAR_COUNT = new AtomicInteger(0);
 138 
 139     private void testCustomMultiReleaseValue(String value,
 140             Map<String, String> extraAttributes, boolean expected)
 141             throws Exception {
 142         String fileName = "custom-mr" + JAR_COUNT.incrementAndGet() + ".jar";
 143         creator.buildCustomMultiReleaseJar(fileName, value, extraAttributes);
 144         File custom = new File(userdir, fileName);
 145         try (JarFile jf = new JarFile(custom, true, ZipFile.OPEN_READ, Runtime.version())) {
 146             Assert.assertEquals(jf.isMultiRelease(), expected);
 147         }
 148         Files.delete(custom.toPath());
 149     }
 150 
 151     @DataProvider(name = "versions")
 152     public Object[][] createVersionData() throws Exception {
 153         return new Object[][]{
 154                 {JarFile.baseVersion(), 8},
 155                 // {JarFile.runtimeVersion(), Runtime.version().major()},
 156                 // {Runtime.version(), Runtime.version().major()},
 157                 {Runtime.Version.parse("7.1"), JarFile.baseVersion().major()},
 158                 {Runtime.Version.parse("9"), 9},
 159                 {Runtime.Version.parse("9.1.5-ea+200"), 9},
 160                 {Runtime.Version.parse("10"), 10},
 161         };
 162     }
 163 
 164     @Test(dataProvider="versions")
 165     public void testVersioning(Runtime.Version value, int xpected) throws Exception {
 166         Runtime.Version expected = Runtime.Version.parse(String.valueOf(xpected));
 167         Runtime.Version base = JarFile.baseVersion();
 168 
 169         // multi-release jar, opened as unversioned
 170         try (JarFile jar = new JarFile(multirelease)) {
 171             Assert.assertEquals(jar.getVersion(), base);
 172         }
 173 
 174         System.err.println("test versioning for Release " + value);
 175         try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, value)) {
 176             Assert.assertEquals(jf.getVersion(), expected);
 177         }
 178 
 179         // regular, unversioned, jar
 180         try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, value)) {


< prev index next >