author | jlaskey |
Tue, 19 Feb 2013 09:47:02 -0400 | |
changeset 16248 | e4bcc4b4f897 |
parent 15682 | 793a36de151d |
permissions | -rw-r--r-- |
15682
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
1 |
/* |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
4 |
* |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
8 |
* |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
13 |
* accompanied this code). |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
14 |
* |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
18 |
* |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
21 |
* questions. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
22 |
*/ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
23 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
24 |
/** |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
25 |
* @test |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
26 |
* @bug 8003255 |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
27 |
* @compile -XDignore.symbol.file Basic.java Main.java Logging.java |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
28 |
* @run main Basic |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
29 |
* @summary Test the launcher checks the Profile attribute of executable JAR |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
30 |
* files. Also checks that libraries that specify the Profile attribute |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
31 |
* are not loaded if the runtime does not support the required profile. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
32 |
*/ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
33 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
34 |
import java.io.*; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
35 |
import java.util.jar.*; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
36 |
import static java.util.jar.JarFile.MANIFEST_NAME; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
37 |
import java.util.zip.*; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
38 |
import java.nio.file.*; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
39 |
import java.nio.file.attribute.BasicFileAttributes; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
40 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
41 |
public class Basic { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
42 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
43 |
static final String MANIFEST_DIR = "META-INF/"; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
44 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
45 |
static final String JAVA_HOME = System.getProperty("java.home"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
46 |
static final String OS_NAME = System.getProperty("os.name"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
47 |
static final String OS_ARCH = System.getProperty("os.arch"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
48 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
49 |
static final String JAVA_CMD = |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
50 |
OS_NAME.startsWith("Windows") ? "java.exe" : "java"; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
51 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
52 |
static final boolean NEED_D64 = |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
53 |
OS_NAME.equals("SunOS") && |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
54 |
(OS_ARCH.equals("sparcv9") || OS_ARCH.equals("amd64")); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
55 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
56 |
/** |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
57 |
* Creates a JAR file with the given attributes and the given entries. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
58 |
* Class files are assumed to be in ${test.classes}. Note that this this |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
59 |
* method cannot use the "jar" tool as it may not be present in the image. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
60 |
*/ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
61 |
static void createJarFile(String jarfile, |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
62 |
String mainAttributes, |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
63 |
String... entries) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
64 |
throws IOException |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
65 |
{ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
66 |
// create Manifest |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
67 |
Manifest manifest = new Manifest(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
68 |
Attributes jarAttrs = manifest.getMainAttributes(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
69 |
jarAttrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
70 |
if (mainAttributes.length() > 0) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
71 |
for (String attr: mainAttributes.split(",")) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
72 |
String[] s = attr.split("="); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
73 |
jarAttrs.put(new Attributes.Name(s[0]), s[1]); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
74 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
75 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
76 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
77 |
try (OutputStream out = Files.newOutputStream(Paths.get(jarfile)); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
78 |
ZipOutputStream zos = new JarOutputStream(out)) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
79 |
{ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
80 |
// add manifest directory and manifest file |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
81 |
ZipEntry e = new JarEntry(MANIFEST_DIR); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
82 |
e.setTime(System.currentTimeMillis()); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
83 |
e.setSize(0); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
84 |
e.setCrc(0); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
85 |
zos.putNextEntry(e); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
86 |
e = new ZipEntry(MANIFEST_NAME); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
87 |
e.setTime(System.currentTimeMillis()); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
88 |
zos.putNextEntry(e); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
89 |
manifest.write(zos); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
90 |
zos.closeEntry(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
91 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
92 |
// entries in JAR file |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
93 |
for (String entry: entries) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
94 |
e = new JarEntry(entry); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
95 |
Path path; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
96 |
if (entry.endsWith(".class")) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
97 |
path = Paths.get(System.getProperty("test.classes"), entry); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
98 |
} else { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
99 |
path = Paths.get(entry); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
100 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
101 |
BasicFileAttributes attrs = |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
102 |
Files.readAttributes(path, BasicFileAttributes.class); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
103 |
e.setTime(attrs.lastModifiedTime().toMillis()); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
104 |
if (attrs.size() == 0) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
105 |
e.setMethod(ZipEntry.STORED); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
106 |
e.setSize(0); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
107 |
e.setCrc(0); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
108 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
109 |
zos.putNextEntry(e); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
110 |
if (attrs.isRegularFile()) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
111 |
Files.copy(path, zos); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
112 |
zos.closeEntry(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
113 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
114 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
115 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
116 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
117 |
/** |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
118 |
* Execute the given executable JAR file with the given arguments. This |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
119 |
* method blocks until the launched VM terminates. Any output or error |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
120 |
* message from the launched VM are printed to System.out. Returns the |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
121 |
* exit value. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
122 |
*/ |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
123 |
static int exec(String jf, String... args) throws IOException { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
124 |
StringBuilder sb = new StringBuilder(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
125 |
sb.append(Paths.get(JAVA_HOME, "bin", JAVA_CMD).toString()); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
126 |
if (NEED_D64) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
127 |
sb.append(" -d64"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
128 |
sb.append(" -jar "); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
129 |
sb.append(Paths.get(jf).toAbsolutePath()); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
130 |
for (String arg: args) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
131 |
sb.append(' '); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
132 |
sb.append(arg); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
133 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
134 |
String[] cmd = sb.toString().split(" "); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
135 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
136 |
pb.redirectErrorStream(true); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
137 |
Process p = pb.start(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
138 |
BufferedReader reader = |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
139 |
new BufferedReader(new InputStreamReader(p.getInputStream())); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
140 |
String line; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
141 |
while ((line = reader.readLine()) != null) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
142 |
System.out.println(line); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
143 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
144 |
try { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
145 |
return p.waitFor(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
146 |
} catch (InterruptedException e) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
147 |
throw new RuntimeException("Should not happen"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
148 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
149 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
150 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
151 |
static void checkRun(String jf, String... args) throws IOException { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
152 |
if (exec(jf) != 0) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
153 |
throw new RuntimeException(jf + " failed!!!"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
154 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
155 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
156 |
static void checkRunFail(String jf, String... args) throws IOException { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
157 |
if (exec(jf) == 0) |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
158 |
throw new RuntimeException(jf + " did not fail!!!"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
159 |
System.out.println("Failed as expected"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
160 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
161 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
162 |
public static void main(String[] args) throws IOException { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
163 |
// ## replace this if there is a standard way to determine the profile |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
164 |
String profile = sun.misc.Version.profileName(); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
165 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
166 |
int thisProfile = 4; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
167 |
if ("compact1".equals(profile)) thisProfile = 1; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
168 |
if ("compact2".equals(profile)) thisProfile = 2; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
169 |
if ("compact3".equals(profile)) thisProfile = 3; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
170 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
171 |
// "library" JAR file used by the test |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
172 |
createJarFile("Logging.jar", "", "Logging.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
173 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
174 |
// Executable JAR file without the Profile attribute |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
175 |
if (thisProfile <= 3) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
176 |
createJarFile("Main.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
177 |
"Main-Class=Main,Class-Path=Logging.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
178 |
"Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
179 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
180 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
181 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
182 |
// Executable JAR file with Profile attribute, Library JAR file without |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
183 |
for (int p=1; p<=3; p++) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
184 |
String attrs = "Main-Class=Main,Class-Path=Logging.jar" + |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
185 |
",Profile=compact" + p; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
186 |
createJarFile("Main.jar", attrs, "Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
187 |
if (p <= thisProfile) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
188 |
checkRun("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
189 |
} else { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
190 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
191 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
192 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
193 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
194 |
// Executable JAR file with Profile attribute that has invalid profile |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
195 |
// name, including incorrect case. |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
196 |
createJarFile("Main.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
197 |
"Main-Class=Main,Class-Path=Logging.jar,Profile=BadName", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
198 |
"Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
199 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
200 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
201 |
createJarFile("Main.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
202 |
"Main-Class=Main,Class-Path=Logging.jar,Profile=Compact1", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
203 |
"Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
204 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
205 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
206 |
// Executable JAR file and Librrary JAR file with Profile attribute |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
207 |
createJarFile("Main.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
208 |
"Main-Class=Main,Class-Path=Logging.jar,Profile=compact1", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
209 |
"Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
210 |
for (int p=1; p<=3; p++) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
211 |
String attrs = "Profile=compact" + p; |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
212 |
createJarFile("Logging.jar", attrs, "Logging.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
213 |
if (p <= thisProfile) { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
214 |
checkRun("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
215 |
} else { |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
216 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
217 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
218 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
219 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
220 |
// Executable JAR file and Library JAR with Profile attribute, value |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
221 |
// of Profile not recognized |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
222 |
createJarFile("Logging.jar", "Profile=BadName", "Logging.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
223 |
createJarFile("Main.jar", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
224 |
"Main-Class=Main,Class-Path=Logging.jar,Profile=compact1", |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
225 |
"Main.class"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
226 |
checkRunFail("Main.jar"); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
227 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
228 |
System.out.println("TEST PASSED."); |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
229 |
} |
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
230 |
|
793a36de151d
8003255: (profiles) Update JAR file specification to support profiles
alanb
parents:
diff
changeset
|
231 |
} |