1 /* |
|
2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
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 |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 import java.io.BufferedWriter; |
|
25 import java.io.File; |
|
26 import java.io.FileWriter; |
|
27 import java.io.PrintWriter; |
|
28 |
|
29 /* |
|
30 * @test |
|
31 * @summary jpackage create image input/files test |
|
32 * @library ../helpers |
|
33 * @build JPackageHelper |
|
34 * @build JPackagePath |
|
35 * @modules jdk.jpackage |
|
36 * @run main/othervm -Xmx512m JPackageCreateImageInputFilesTest |
|
37 */ |
|
38 public class JPackageCreateImageInputFilesTest { |
|
39 private static final String OUTPUT = "output"; |
|
40 private static final String inputFile = |
|
41 "input" + File.separator + "input.txt"; |
|
42 private static final String jarFile = |
|
43 "input" + File.separator + "hello.jar"; |
|
44 private static final String appInputFilePath; |
|
45 private static final String appJarFilePath; |
|
46 |
|
47 static { |
|
48 appInputFilePath = JPackagePath.getAppWorkingDir() + File.separator + "input.txt"; |
|
49 appJarFilePath = JPackagePath.getAppWorkingDir() + File.separator + "hello.jar"; |
|
50 } |
|
51 |
|
52 private static final String [] CMD_1 = { |
|
53 "create-image", |
|
54 "--input", "input", |
|
55 "--output", OUTPUT, |
|
56 "--name", "test", |
|
57 "--main-jar", "hello.jar", |
|
58 "--main-class", "Hello"}; |
|
59 |
|
60 private static final String [] CMD_2 = { |
|
61 "create-image", |
|
62 "--input", "input", |
|
63 "--output", OUTPUT, |
|
64 "--name", "test", |
|
65 "--main-jar", "hello.jar", |
|
66 "--main-class", "Hello", |
|
67 "--files", "hello.jar"}; |
|
68 |
|
69 private static void validate1() throws Exception { |
|
70 File input = new File(appInputFilePath); |
|
71 if (!input.exists()) { |
|
72 throw new AssertionError("Unexpected file does not exist: " |
|
73 + input.getAbsolutePath()); |
|
74 } |
|
75 |
|
76 File jar = new File(appJarFilePath); |
|
77 if (!jar.exists()) { |
|
78 throw new AssertionError("Unexpected file does not exist: " |
|
79 + jar.getAbsolutePath()); |
|
80 } |
|
81 } |
|
82 |
|
83 private static void validate2() throws Exception { |
|
84 File input = new File(appInputFilePath); |
|
85 if (input.exists()) { |
|
86 throw new AssertionError("Unexpected file exist: " |
|
87 + input.getAbsolutePath()); |
|
88 } |
|
89 |
|
90 File jar = new File(appJarFilePath); |
|
91 if (!jar.exists()) { |
|
92 throw new AssertionError("Unexpected file does not exist: " |
|
93 + jar.getAbsolutePath()); |
|
94 } |
|
95 } |
|
96 |
|
97 private static void testCreateImage() throws Exception { |
|
98 JPackageHelper.executeCLI(true, CMD_1); |
|
99 validate1(); |
|
100 |
|
101 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
102 JPackageHelper.executeCLI(true, CMD_2); |
|
103 validate2(); |
|
104 } |
|
105 |
|
106 private static void testCreateImageToolProvider() throws Exception { |
|
107 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
108 JPackageHelper.executeToolProvider(true, CMD_1); |
|
109 validate1(); |
|
110 |
|
111 JPackageHelper.deleteOutputFolder(OUTPUT); |
|
112 JPackageHelper.executeToolProvider(true, CMD_2); |
|
113 validate2(); |
|
114 } |
|
115 |
|
116 private static void createInputFile() throws Exception { |
|
117 try (PrintWriter out = new PrintWriter( |
|
118 new BufferedWriter(new FileWriter(inputFile)))) { |
|
119 out.println("jpackgaer resource file"); |
|
120 } |
|
121 } |
|
122 |
|
123 public static void main(String[] args) throws Exception { |
|
124 JPackageHelper.createHelloImageJar(); |
|
125 |
|
126 createInputFile(); |
|
127 |
|
128 testCreateImage(); |
|
129 testCreateImageToolProvider(); |
|
130 } |
|
131 |
|
132 } |
|