equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
30 * Output: A jar containing compiled classes, placed in a test classes folder |
30 * Output: A jar containing compiled classes, placed in a test classes folder |
31 * @library /open/test/lib |
31 * @library /open/test/lib |
32 */ |
32 */ |
33 |
33 |
34 import jdk.test.lib.JDKToolFinder; |
34 import jdk.test.lib.JDKToolFinder; |
|
35 import jdk.test.lib.compiler.CompilerUtils; |
35 import jdk.test.lib.process.OutputAnalyzer; |
36 import jdk.test.lib.process.OutputAnalyzer; |
36 import jdk.test.lib.process.ProcessTools; |
37 import jdk.test.lib.process.ProcessTools; |
37 import java.io.File; |
38 import java.io.File; |
|
39 import java.nio.file.Path; |
38 import java.util.ArrayList; |
40 import java.util.ArrayList; |
39 import sun.tools.jar.Main; |
41 import sun.tools.jar.Main; |
40 |
42 |
41 public class JarBuilder { |
43 public class JarBuilder { |
42 // to turn DEBUG on via command line: -DJarBuilder.DEBUG=[true, TRUE] |
44 // to turn DEBUG on via command line: -DJarBuilder.DEBUG=[true, TRUE] |
143 args.add(jarclassDir); |
145 args.add(jarclassDir); |
144 args.add(name + ".class"); |
146 args.add(name + ".class"); |
145 } |
147 } |
146 } |
148 } |
147 |
149 |
|
150 public static void createModularJar(String jarPath, |
|
151 String classesDir, |
|
152 String mainClass) throws Exception { |
|
153 ArrayList<String> argList = new ArrayList<String>(); |
|
154 argList.add("--create"); |
|
155 argList.add("--file=" + jarPath); |
|
156 if (mainClass != null) { |
|
157 argList.add("--main-class=" + mainClass); |
|
158 } |
|
159 argList.add("-C"); |
|
160 argList.add(classesDir); |
|
161 argList.add("."); |
|
162 createJar(argList); |
|
163 } |
|
164 |
148 private static void createJar(ArrayList<String> args) { |
165 private static void createJar(ArrayList<String> args) { |
149 if (DEBUG) printIterable("createJar args: ", args); |
166 if (DEBUG) printIterable("createJar args: ", args); |
150 |
167 |
151 Main jarTool = new Main(System.out, System.err, "jar"); |
168 Main jarTool = new Main(System.out, System.err, "jar"); |
152 if (!jarTool.run(args.toArray(new String[1]))) { |
169 if (!jarTool.run(args.toArray(new String[1]))) { |
188 ProcessBuilder pb = new ProcessBuilder(args); |
205 ProcessBuilder pb = new ProcessBuilder(args); |
189 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
206 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
190 output.shouldHaveExitValue(0); |
207 output.shouldHaveExitValue(0); |
191 } |
208 } |
192 |
209 |
|
210 public static void compileModule(Path src, |
|
211 Path dest, |
|
212 String modulePathArg // arg to --module-path |
|
213 ) throws Exception { |
|
214 boolean compiled = false; |
|
215 if (modulePathArg == null) { |
|
216 compiled = CompilerUtils.compile(src, dest); |
|
217 } else { |
|
218 compiled = CompilerUtils.compile(src, dest, |
|
219 "--module-path", modulePathArg); |
|
220 } |
|
221 if (!compiled) { |
|
222 throw new RuntimeException("module did not compile"); |
|
223 } |
|
224 } |
|
225 |
|
226 |
193 public static void signJar() throws Exception { |
227 public static void signJar() throws Exception { |
194 String keyTool = JDKToolFinder.getJDKTool("keytool"); |
228 String keyTool = JDKToolFinder.getJDKTool("keytool"); |
195 String jarSigner = JDKToolFinder.getJDKTool("jarsigner"); |
229 String jarSigner = JDKToolFinder.getJDKTool("jarsigner"); |
196 String classDir = System.getProperty("test.classes"); |
230 String classDir = System.getProperty("test.classes"); |
197 String FS = File.separator; |
231 String FS = File.separator; |