Path: blob/master/test/jdk/tools/jpackage/share/ArgumentsTest.java
41149 views
/*1* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.nio.file.Path;24import java.util.List;25import jdk.jpackage.test.HelloApp;26import jdk.jpackage.test.Functional.ThrowingConsumer;27import jdk.jpackage.test.JPackageCommand;28import jdk.jpackage.test.Annotations.BeforeEach;29import jdk.jpackage.test.Annotations.Test;30import jdk.jpackage.test.Annotations.Parameter;313233/*34* Tricky arguments used in the test require a bunch of levels of character35* escaping for proper encoding them in a single string to be used as a value of36* `--arguments` option. String with encoded arguments doesn't go through the37* system to jpackage executable as is because OS is interpreting escape38* characters. This is true for Windows at least.39*40* String mapping performed by the system corrupts the string and jpackage exits41* with error. There is no problem with string corruption when jpackage is used42* as tool provider. This is not jpackage issue, so just always run this test43* with jpackage used as tool provider.44* /4546/*47* @test48* @summary jpackage create image with --arguments test49* @library ../helpers50* @build jdk.jpackage.test.*51* @modules jdk.jpackage/jdk.jpackage.internal52* @compile ArgumentsTest.java53* @run main/othervm -Xmx512m jdk.jpackage.test.Main54* --jpt-run=ArgumentsTest55*/56public class ArgumentsTest {5758@BeforeEach59public static void useJPackageToolProvider() {60JPackageCommand.useToolProviderByDefault();61}6263@Test64@Parameter("Goodbye")65@Parameter("com.hello/com.hello.Hello")66public static void testApp(String javaAppDesc) {67testIt(javaAppDesc, null);68}6970private static void testIt(String javaAppDesc,71ThrowingConsumer<JPackageCommand> initializer) {7273JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc).addArguments(74"--arguments", JPackageCommand.escapeAndJoin(TRICKY_ARGUMENTS));75if (initializer != null) {76ThrowingConsumer.toConsumer(initializer).accept(cmd);77}7879cmd.executeAndAssertImageCreated();8081Path launcherPath = cmd.appLauncherPath();82if (!cmd.isFakeRuntime(String.format(83"Not running [%s] launcher", launcherPath))) {84HelloApp.assertApp(launcherPath)85.addDefaultArguments(TRICKY_ARGUMENTS)86.executeAndVerifyOutput();87}88}8990private final static List<String> TRICKY_ARGUMENTS = List.of(91"argument",92"Some Arguments",93"Value \"with\" quotes"94);95}969798