diff options
author | alanb <none@none> | 2013-08-15 11:54:05 +0100 |
---|---|---|
committer | alanb <none@none> | 2013-08-15 11:54:05 +0100 |
commit | 5fc726c31bf7783203290e5022c49ecd17a4b07b (patch) | |
tree | 21ef49263e3e0ac4cd8de5a27077ed9c299df32f /test/tools | |
parent | 5889a090da3d19ece6d61caab25a574290017442 (diff) | |
download | jdk8u_jdk-5fc726c31bf7783203290e5022c49ecd17a4b07b.tar.gz |
8022921: Remove experimental Profile attribute
Reviewed-by: mchung, chegar
Diffstat (limited to 'test/tools')
-rw-r--r-- | test/tools/jar/AddAndUpdateProfile.java | 129 | ||||
-rw-r--r-- | test/tools/launcher/profiles/Basic.java | 231 | ||||
-rw-r--r-- | test/tools/launcher/profiles/Logging.java | 30 | ||||
-rw-r--r-- | test/tools/launcher/profiles/Main.java | 30 | ||||
-rw-r--r-- | test/tools/launcher/profiles/VersionCheck.java | 169 |
5 files changed, 0 insertions, 589 deletions
diff --git a/test/tools/jar/AddAndUpdateProfile.java b/test/tools/jar/AddAndUpdateProfile.java deleted file mode 100644 index e8eabd4a7c..0000000000 --- a/test/tools/jar/AddAndUpdateProfile.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* @test - * @bug 8003255 - * @compile -XDignore.symbol.file AddAndUpdateProfile.java - * @run main AddAndUpdateProfile - * @summary Basic test of jar tool "p" option to add or update the Profile - * attribute in the main manifest of a JAR file - */ - -import java.util.jar.*; -import static java.util.jar.Attributes.Name.*; -import java.nio.file.*; -import java.io.IOException; - -import sun.tools.jar.Main; - -public class AddAndUpdateProfile { - static boolean doJar(String... args) { - System.out.print("jar"); - for (String arg: args) - System.out.print(" " + arg); - System.out.println(""); - - Main jartool = new Main(System.out, System.err, "jar"); - return jartool.run(args); - } - - static void jar(String... args) { - if (!doJar(args)) - throw new RuntimeException("jar command failed"); - } - - static void jarExpectingFail(String... args) { - if (doJar(args)) - throw new RuntimeException("jar command not expected to succeed"); - } - - static void checkMainAttribute(String jarfile, Attributes.Name name, - String expectedValue) - throws IOException - { - try (JarFile jf = new JarFile(jarfile)) { - Manifest mf = jf.getManifest(); - if (mf == null && expectedValue != null) - throw new RuntimeException("Manifest not found"); - if (mf != null) { - String actual = mf.getMainAttributes().getValue(name); - if (actual != null) { - if (!actual.equals(expectedValue)) - throw new RuntimeException("Profile attribute has unexpected value"); - } else { - if (expectedValue != null) - throw new RuntimeException("Profile attribute should not be present"); - } - } - } - } - - public static void main(String[] args) throws Exception { - Path entry = Files.createFile(Paths.get("xfoo")); - String jarfile = "xFoo.jar"; - try { - - // create JAR file with Profile attribute - jar("cfp", jarfile, "compact1", entry.toString()); - checkMainAttribute(jarfile, PROFILE, "compact1"); - - // attempt to create JAR file with Profile attribute and bad value - jarExpectingFail("cfp", jarfile, "garbage", entry.toString()); - jarExpectingFail("cfp", jarfile, "Compact1", entry.toString()); - jarExpectingFail("cfp", jarfile, "COMPACT1", entry.toString()); - - // update value of Profile attribute - jar("ufp", jarfile, "compact2"); - checkMainAttribute(jarfile, PROFILE, "compact2"); - - // attempt to update value of Profile attribute to bad value - // (update should not change the JAR file) - jarExpectingFail("ufp", jarfile, "garbage"); - checkMainAttribute(jarfile, PROFILE, "compact2"); - jarExpectingFail("ufp", jarfile, "COMPACT1"); - checkMainAttribute(jarfile, PROFILE, "compact2"); - - // create JAR file with both a Main-Class and Profile attribute - jar("cfep", jarfile, "Foo", "compact1", entry.toString()); - checkMainAttribute(jarfile, MAIN_CLASS, "Foo"); - checkMainAttribute(jarfile, PROFILE, "compact1"); - - // update value of Profile attribute - jar("ufp", jarfile, "compact2"); - checkMainAttribute(jarfile, PROFILE, "compact2"); - - // create JAR file without Profile attribute - jar("cf", jarfile, entry.toString()); - checkMainAttribute(jarfile, PROFILE, null); - - // update value of Profile attribute - jar("ufp", jarfile, "compact3"); - checkMainAttribute(jarfile, PROFILE, "compact3"); - - } finally { - Files.deleteIfExists(Paths.get(jarfile)); - Files.delete(entry); - } - } - -} diff --git a/test/tools/launcher/profiles/Basic.java b/test/tools/launcher/profiles/Basic.java deleted file mode 100644 index a794c3f972..0000000000 --- a/test/tools/launcher/profiles/Basic.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 8003255 - * @compile -XDignore.symbol.file Basic.java Main.java Logging.java - * @run main Basic - * @summary Test the launcher checks the Profile attribute of executable JAR - * files. Also checks that libraries that specify the Profile attribute - * are not loaded if the runtime does not support the required profile. - */ - -import java.io.*; -import java.util.jar.*; -import static java.util.jar.JarFile.MANIFEST_NAME; -import java.util.zip.*; -import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; - -public class Basic { - - static final String MANIFEST_DIR = "META-INF/"; - - static final String JAVA_HOME = System.getProperty("java.home"); - static final String OS_NAME = System.getProperty("os.name"); - static final String OS_ARCH = System.getProperty("os.arch"); - - static final String JAVA_CMD = - OS_NAME.startsWith("Windows") ? "java.exe" : "java"; - - static final boolean NEED_D64 = - OS_NAME.equals("SunOS") && - (OS_ARCH.equals("sparcv9") || OS_ARCH.equals("amd64")); - - /** - * Creates a JAR file with the given attributes and the given entries. - * Class files are assumed to be in ${test.classes}. Note that this this - * method cannot use the "jar" tool as it may not be present in the image. - */ - static void createJarFile(String jarfile, - String mainAttributes, - String... entries) - throws IOException - { - // create Manifest - Manifest manifest = new Manifest(); - Attributes jarAttrs = manifest.getMainAttributes(); - jarAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); - if (mainAttributes.length() > 0) { - for (String attr: mainAttributes.split(",")) { - String[] s = attr.split("="); - jarAttrs.put(new Attributes.Name(s[0]), s[1]); - } - } - - try (OutputStream out = Files.newOutputStream(Paths.get(jarfile)); - ZipOutputStream zos = new JarOutputStream(out)) - { - // add manifest directory and manifest file - ZipEntry e = new JarEntry(MANIFEST_DIR); - e.setTime(System.currentTimeMillis()); - e.setSize(0); - e.setCrc(0); - zos.putNextEntry(e); - e = new ZipEntry(MANIFEST_NAME); - e.setTime(System.currentTimeMillis()); - zos.putNextEntry(e); - manifest.write(zos); - zos.closeEntry(); - - // entries in JAR file - for (String entry: entries) { - e = new JarEntry(entry); - Path path; - if (entry.endsWith(".class")) { - path = Paths.get(System.getProperty("test.classes"), entry); - } else { - path = Paths.get(entry); - } - BasicFileAttributes attrs = - Files.readAttributes(path, BasicFileAttributes.class); - e.setTime(attrs.lastModifiedTime().toMillis()); - if (attrs.size() == 0) { - e.setMethod(ZipEntry.STORED); - e.setSize(0); - e.setCrc(0); - } - zos.putNextEntry(e); - if (attrs.isRegularFile()) - Files.copy(path, zos); - zos.closeEntry(); - } - } - } - - /** - * Execute the given executable JAR file with the given arguments. This - * method blocks until the launched VM terminates. Any output or error - * message from the launched VM are printed to System.out. Returns the - * exit value. - */ - static int exec(String jf, String... args) throws IOException { - StringBuilder sb = new StringBuilder(); - sb.append(Paths.get(JAVA_HOME, "bin", JAVA_CMD).toString()); - if (NEED_D64) - sb.append(" -d64"); - sb.append(" -jar "); - sb.append(Paths.get(jf).toAbsolutePath()); - for (String arg: args) { - sb.append(' '); - sb.append(arg); - } - String[] cmd = sb.toString().split(" "); - ProcessBuilder pb = new ProcessBuilder(cmd); - pb.redirectErrorStream(true); - Process p = pb.start(); - BufferedReader reader = - new BufferedReader(new InputStreamReader(p.getInputStream())); - String line; - while ((line = reader.readLine()) != null) { - System.out.println(line); - } - try { - return p.waitFor(); - } catch (InterruptedException e) { - throw new RuntimeException("Should not happen"); - } - } - - static void checkRun(String jf, String... args) throws IOException { - if (exec(jf) != 0) - throw new RuntimeException(jf + " failed!!!"); - } - - static void checkRunFail(String jf, String... args) throws IOException { - if (exec(jf) == 0) - throw new RuntimeException(jf + " did not fail!!!"); - System.out.println("Failed as expected"); - } - - public static void main(String[] args) throws IOException { - // ## replace this if there is a standard way to determine the profile - String profile = sun.misc.Version.profileName(); - - int thisProfile = 4; - if ("compact1".equals(profile)) thisProfile = 1; - if ("compact2".equals(profile)) thisProfile = 2; - if ("compact3".equals(profile)) thisProfile = 3; - - // "library" JAR file used by the test - createJarFile("Logging.jar", "", "Logging.class"); - - // Executable JAR file without the Profile attribute - if (thisProfile <= 3) { - createJarFile("Main.jar", - "Main-Class=Main,Class-Path=Logging.jar", - "Main.class"); - checkRunFail("Main.jar"); - } - - // Executable JAR file with Profile attribute, Library JAR file without - for (int p=1; p<=3; p++) { - String attrs = "Main-Class=Main,Class-Path=Logging.jar" + - ",Profile=compact" + p; - createJarFile("Main.jar", attrs, "Main.class"); - if (p <= thisProfile) { - checkRun("Main.jar"); - } else { - checkRunFail("Main.jar"); - } - } - - // Executable JAR file with Profile attribute that has invalid profile - // name, including incorrect case. - createJarFile("Main.jar", - "Main-Class=Main,Class-Path=Logging.jar,Profile=BadName", - "Main.class"); - checkRunFail("Main.jar"); - - createJarFile("Main.jar", - "Main-Class=Main,Class-Path=Logging.jar,Profile=Compact1", - "Main.class"); - checkRunFail("Main.jar"); - - // Executable JAR file and Librrary JAR file with Profile attribute - createJarFile("Main.jar", - "Main-Class=Main,Class-Path=Logging.jar,Profile=compact1", - "Main.class"); - for (int p=1; p<=3; p++) { - String attrs = "Profile=compact" + p; - createJarFile("Logging.jar", attrs, "Logging.class"); - if (p <= thisProfile) { - checkRun("Main.jar"); - } else { - checkRunFail("Main.jar"); - } - } - - // Executable JAR file and Library JAR with Profile attribute, value - // of Profile not recognized - createJarFile("Logging.jar", "Profile=BadName", "Logging.class"); - createJarFile("Main.jar", - "Main-Class=Main,Class-Path=Logging.jar,Profile=compact1", - "Main.class"); - checkRunFail("Main.jar"); - - System.out.println("TEST PASSED."); - } - -} diff --git a/test/tools/launcher/profiles/Logging.java b/test/tools/launcher/profiles/Logging.java deleted file mode 100644 index 56174a97bf..0000000000 --- a/test/tools/launcher/profiles/Logging.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -public class Logging { - private Logging() { } - - public static void log(String msg) { - System.out.println(msg); - } -} diff --git a/test/tools/launcher/profiles/Main.java b/test/tools/launcher/profiles/Main.java deleted file mode 100644 index 49c09a811c..0000000000 --- a/test/tools/launcher/profiles/Main.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -public class Main { - private Main() { } - - public static void main(String[] args) { - Logging.log("main running"); - } -} diff --git a/test/tools/launcher/profiles/VersionCheck.java b/test/tools/launcher/profiles/VersionCheck.java deleted file mode 100644 index fc3a5f7041..0000000000 --- a/test/tools/launcher/profiles/VersionCheck.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (c) 2012, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 8003256 - * @compile -XDignore.symbol.file VersionCheck.java - * @run main VersionCheck - * @summary Tests that "java -version" includes the name of the profile and that - * it matches the name in the release file - */ - -import java.nio.file.*; -import java.io.*; -import java.util.Properties; - -public class VersionCheck { - - static final String JAVA_HOME = System.getProperty("java.home"); - static final String OS_NAME = System.getProperty("os.name"); - static final String OS_ARCH = System.getProperty("os.arch"); - - static final String JAVA_CMD = - OS_NAME.startsWith("Windows") ? "java.exe" : "java"; - - static final boolean NEED_D64 = - OS_NAME.equals("SunOS") && - (OS_ARCH.equals("sparcv9") || OS_ARCH.equals("amd64")); - - /** - * Returns {@code true} if the given class is present. - */ - static boolean isPresent(String cn) { - try { - Class.forName(cn); - return true; - } catch (ClassNotFoundException ignore) { - return false; - } - } - - /** - * Determines the profile by checking whether specific classes are present. - * Returns the empty string if this runtime does not appear to be a profile - * of Java SE. - */ - static String probeProfile() { - if (isPresent("java.awt.Window")) - return ""; - if (isPresent("java.lang.management.ManagementFactory")) - return "compact3"; - if (isPresent("java.sql.DriverManager")) - return "compact2"; - return "compact1"; - } - - /** - * Execs java with the given parameters. The method blocks until the - * process terminates. Returns a {@code ByteArrayOutputStream} with any - * stdout or stderr from the process. - */ - static ByteArrayOutputStream execJava(String... args) - throws IOException - { - StringBuilder sb = new StringBuilder(); - sb.append(Paths.get(JAVA_HOME, "bin", JAVA_CMD).toString()); - if (NEED_D64) - sb.append(" -d64"); - for (String arg: args) { - sb.append(' '); - sb.append(arg); - } - String[] cmd = sb.toString().split(" "); - ProcessBuilder pb = new ProcessBuilder(cmd); - pb.redirectErrorStream(true); - Process p = pb.start(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - byte[] buf = new byte[1024]; - int n; - do { - n = p.getInputStream().read(buf); - if (n > 0) - baos.write(buf, 0, n); - } while (n > 0); - try { - int exitCode = p.waitFor(); - if (exitCode != 0) - throw new RuntimeException("Exit code: " + exitCode); - } catch (InterruptedException e) { - throw new RuntimeException("Should not happen"); - } - return baos; - } - - public static void main(String[] args) throws IOException { - String reported = sun.misc.Version.profileName(); - String probed = probeProfile(); - if (!reported.equals(probed)) { - throw new RuntimeException("sun.misc.Version reports: " + reported - + ", but probing reports: " + probed); - } - - String profile = probed; - boolean isFullJre = (profile.length() == 0); - - // check that java -version includes "profile compactN" - String expected = "profile " + profile; - System.out.println("Checking java -version ..."); - ByteArrayOutputStream baos = execJava("-version"); - ByteArrayInputStream bain = new ByteArrayInputStream(baos.toByteArray()); - BufferedReader reader = new BufferedReader(new InputStreamReader(bain)); - boolean found = false; - String line; - while ((line = reader.readLine()) != null) { - if (line.contains(expected)) { - found = true; - break; - } - } - if (found && isFullJre) - throw new RuntimeException(expected + " found in java -version output"); - if (!found && !isFullJre) - throw new RuntimeException("java -version did not include " + expected); - - // check that the profile name matches the release file - System.out.println("Checking release file ..."); - Properties props = new Properties(); - - Path home = Paths.get(JAVA_HOME); - if (home.getFileName().toString().equals("jre")) - home = home.getParent(); - Path release = home.resolve("release"); - try (InputStream in = Files.newInputStream(release)) { - props.load(in); - } - String value = props.getProperty("JAVA_PROFILE"); - if (isFullJre) { - if (value != null) - throw new RuntimeException("JAVA_PROFILE should not be present"); - } else { - if (value == null) - throw new RuntimeException("JAVA_PROFILE not present in release file"); - if (!value.equals("\"" + profile + "\"")) - throw new RuntimeException("Unexpected value of JAVA_PROFILE: " + value); - } - - System.out.println("Test passed."); - } -} |