author | tschatzl |
Wed, 19 Aug 2015 13:47:40 +0200 | |
changeset 32377 | 5ee15c417d02 |
parent 32179 | 246b2ef581b2 |
child 32615 | b6c0aafd6945 |
permissions | -rw-r--r-- |
32179
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
1 |
/* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
4 |
* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
8 |
* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
13 |
* accompanied this code). |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
14 |
* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
18 |
* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
21 |
* questions. |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
22 |
*/ |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
23 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
24 |
/* |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
25 |
* @summary Simple jar builder |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
26 |
* Input: jarName className1 className2 ... |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
27 |
* do not specify extensions, just the names |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
28 |
* E.g. prot_domain ProtDomainA ProtDomainB |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
29 |
* Output: A jar containing compiled classes, placed in a test classes folder |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
30 |
*/ |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
31 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
32 |
import jdk.test.lib.*; |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
33 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
34 |
import java.io.File; |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
35 |
import java.util.ArrayList; |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
36 |
import sun.tools.jar.Main; |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
37 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
38 |
public class BasicJarBuilder { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
39 |
private static final String classDir = System.getProperty("test.classes"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
40 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
41 |
public static void build(String jarName, String ...classNames) |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
42 |
throws Exception { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
43 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
44 |
createSimpleJar(classDir, classDir + File.separator + jarName + |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
45 |
".jar", classNames); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
46 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
47 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
48 |
private static void createSimpleJar(String jarclassDir, String jarName, |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
49 |
String[] classNames) throws Exception { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
50 |
ArrayList<String> args = new ArrayList<String>(); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
51 |
args.add("cf"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
52 |
args.add(jarName); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
53 |
addClassArgs(args, jarclassDir, classNames); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
54 |
createJar(args); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
55 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
56 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
57 |
private static void addClassArgs(ArrayList<String> args, String jarclassDir, |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
58 |
String[] classNames) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
59 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
60 |
for (String name : classNames) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
61 |
args.add("-C"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
62 |
args.add(jarclassDir); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
63 |
args.add(name + ".class"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
64 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
65 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
66 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
67 |
private static void createJar(ArrayList<String> args) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
68 |
Main jarTool = new Main(System.out, System.err, "jar"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
69 |
if (!jarTool.run(args.toArray(new String[1]))) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
70 |
throw new RuntimeException("jar operation failed"); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
71 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
72 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
73 |
|
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
74 |
// helpers |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
75 |
public static String getTestJar(String jar) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
76 |
File dir = new File(System.getProperty("test.classes", ".")); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
77 |
File jarFile = new File(dir, jar); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
78 |
if (!jarFile.exists()) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
79 |
throw new RuntimeException("Cannot find " + jarFile.getPath()); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
80 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
81 |
if (!jarFile.isFile()) { |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
82 |
throw new RuntimeException("Not a regular file: " + jarFile.getPath()); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
83 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
84 |
return jarFile.getPath(); |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
85 |
} |
246b2ef581b2
8132214: [TESTBUG] Create basic shared strings test for CDS archive
mseledtsov
parents:
diff
changeset
|
86 |
} |