57307
|
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 |
|
58416
|
24 |
import java.nio.file.Path;
|
|
25 |
import java.util.List;
|
|
26 |
import jdk.jpackage.test.TKit;
|
|
27 |
import jdk.jpackage.test.HelloApp;
|
|
28 |
import jdk.jpackage.test.Functional.ThrowingConsumer;
|
|
29 |
import jdk.jpackage.test.JPackageCommand;
|
|
30 |
import jdk.jpackage.test.Annotations.*;
|
|
31 |
|
|
32 |
|
|
33 |
/*
|
|
34 |
* Tricky arguments used in the test require a bunch of levels of character
|
|
35 |
* escaping for proper encoding them in a single string to be used as a value of
|
|
36 |
* `--arguments` option. String with encoded arguments doesn't go through the
|
|
37 |
* system to jpackage executable as is because OS is interpreting escape
|
|
38 |
* characters. This is true for Windows at least.
|
|
39 |
*
|
|
40 |
* String mapping performed by the system corrupts the string and jpackage exits
|
|
41 |
* with error. There is no problem with string corruption when jpackage is used
|
|
42 |
* as tool provider. This is not jpackage issue, so just always run this test
|
|
43 |
* with jpackage used as tool provider.
|
|
44 |
* /
|
|
45 |
|
57307
|
46 |
/*
|
|
47 |
* @test
|
|
48 |
* @summary jpackage create image with --arguments test
|
|
49 |
* @library ../helpers
|
58416
|
50 |
* @build jdk.jpackage.test.*
|
58648
|
51 |
* @modules jdk.jpackage/jdk.jpackage.internal
|
58416
|
52 |
* @compile ArgumentsTest.java
|
|
53 |
* @run main/othervm -Xmx512m jdk.jpackage.test.Main
|
|
54 |
* --jpt-run=ArgumentsTest
|
57307
|
55 |
*/
|
57446
|
56 |
public class ArgumentsTest {
|
58648
|
57 |
|
|
58 |
@BeforeEach
|
|
59 |
public static void useJPackageToolProvider() {
|
|
60 |
JPackageCommand.useToolProviderByDefault();
|
|
61 |
}
|
|
62 |
|
58416
|
63 |
@Test
|
|
64 |
@Parameter("Goodbye")
|
|
65 |
@Parameter("com.hello/com.hello.Hello")
|
|
66 |
public static void testApp(String javaAppDesc) {
|
|
67 |
testIt(javaAppDesc, null);
|
57307
|
68 |
}
|
|
69 |
|
58416
|
70 |
private static void testIt(String javaAppDesc,
|
|
71 |
ThrowingConsumer<JPackageCommand> initializer) {
|
|
72 |
|
|
73 |
JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc).addArguments(
|
|
74 |
"--arguments", JPackageCommand.escapeAndJoin(TRICKY_ARGUMENTS));
|
|
75 |
if (initializer != null) {
|
|
76 |
ThrowingConsumer.toConsumer(initializer).accept(cmd);
|
|
77 |
}
|
|
78 |
|
|
79 |
cmd.executeAndAssertImageCreated();
|
|
80 |
|
58648
|
81 |
Path launcherPath = cmd.appLauncherPath();
|
|
82 |
if (!cmd.isFakeRuntime(String.format(
|
58416
|
83 |
"Not running [%s] launcher", launcherPath))) {
|
|
84 |
HelloApp.executeAndVerifyOutput(launcherPath, TRICKY_ARGUMENTS);
|
|
85 |
}
|
|
86 |
}
|
|
87 |
|
|
88 |
private final static List<String> TRICKY_ARGUMENTS = List.of(
|
|
89 |
"argument",
|
|
90 |
"Some Arguments",
|
|
91 |
"Value \"with\" quotes"
|
|
92 |
);
|
57307
|
93 |
}
|