< prev index next >

test/jdk/tools/launcher/modules/addexports/manifest/AddExportsAndOpensInManifest.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 30,60 **** --- 30,72 ---- * @run testng AddExportsAndOpensInManifest * @summary Basic test for Add-Exports and Add-Opens attributes in the * manifest of a main application JAR */ + import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.jar.Attributes; import java.util.jar.Manifest; import jdk.testlibrary.OutputAnalyzer; import jdk.testlibrary.ProcessTools; + import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import static org.testng.Assert.*; @Test public class AddExportsAndOpensInManifest { + private String testName; + private int testCaseNum; + + @BeforeMethod + public void getTestName(Method m){ + testName = m.getName(); + testCaseNum = 0; + } + /** * Package Test1 and Test2 into a JAR file with the given attributes * in the JAR manifest, then execute the JAR file with `java -jar`. */ private OutputAnalyzer runTest(String attributes) throws Exception { + testCaseNum++; Manifest man = new Manifest(); Attributes attrs = man.getMainAttributes(); attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); for (String nameAndValue : attributes.split(",")) {
*** 65,75 **** String value = s[1]; attrs.put(new Attributes.Name(name), value); } // create the JAR file with Test1 and Test2 ! Path jarfile = Paths.get("test.jar"); Files.deleteIfExists(jarfile); Path classes = Paths.get(System.getProperty("test.classes", "")); JarUtils.createJarFile(jarfile, man, classes, Paths.get("Test1.class"), Paths.get("Test2.class")); --- 77,87 ---- String value = s[1]; attrs.put(new Attributes.Name(name), value); } // create the JAR file with Test1 and Test2 ! Path jarfile = Paths.get(String.format("%s-%s.jar", testName, testCaseNum)); Files.deleteIfExists(jarfile); Path classes = Paths.get(System.getProperty("test.classes", "")); JarUtils.createJarFile(jarfile, man, classes, Paths.get("Test1.class"), Paths.get("Test2.class"));
*** 170,176 **** // Add-Opens with bad package name attrs = "Main-Class=Test1,Add-Opens=java.base/jdk.internal.DoesNotExit"; runExpectingFail(attrs, "IllegalAccessError"); } - } --- 182,187 ----
< prev index next >