Skip to content

Commit c35e1a2

Browse files
author
Alexander Matveev
committed
8255947: [macos] Signed macOS jpackage app doesn't filter spurious '-psn' argument
Reviewed-by: herrick, asemenyuk
1 parent 30a2ad5 commit c35e1a2

File tree

5 files changed

+103
-13
lines changed

5 files changed

+103
-13
lines changed

src/jdk.jpackage/linux/native/common/LinuxSysInfo.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <limits.h>
2727
#include <unistd.h>
28+
#include "UnixSysInfo.h"
2829
#include "FileUtils.h"
2930
#include "ErrorHandling.h"
3031

@@ -42,4 +43,12 @@ tstring getProcessModulePath() {
4243
return tstring(buffer, len);
4344
}
4445

46+
tstring_array getCommandArgs(CommandArgProgramNameMode progNameMode) {
47+
tstring_array result;
48+
for (int i = progNameMode == ExcludeProgramName ? 1 : 0; i < argc; i++) {
49+
result.push_back(argv[i]);
50+
}
51+
return result;
52+
}
53+
4554
} // end of namespace SysInfo

src/jdk.jpackage/macosx/native/common/MacSysInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sys/stat.h>
2727
#include <unistd.h>
2828
#include <mach-o/dyld.h>
29+
#include "UnixSysInfo.h"
2930
#include "FileUtils.h"
3031
#include "ErrorHandling.h"
3132

@@ -77,4 +78,16 @@ tstring getProcessModulePath() {
7778
return FileUtils::toAbsolutePath(reply);
7879
}
7980

81+
tstring_array getCommandArgs(CommandArgProgramNameMode progNameMode) {
82+
tstring_array result;
83+
const tstring psnArgPrefix = "-psn_";
84+
for (int i = progNameMode == ExcludeProgramName ? 1 : 0; i < argc; i++) {
85+
const tstring arg = argv[i];
86+
if (!tstrings::startsWith(arg, psnArgPrefix)) {
87+
result.push_back(arg);
88+
}
89+
}
90+
return result;
91+
}
92+
8093
} // end of namespace SysInfo

src/jdk.jpackage/unix/native/common/UnixSysInfo.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,6 @@ bool isEnvVariableSet(const tstring& name) {
5656
}
5757

5858

59-
tstring_array getCommandArgs(CommandArgProgramNameMode progNameMode) {
60-
tstring_array result;
61-
for (int i = progNameMode == ExcludeProgramName ? 1 : 0; i < argc; i++) {
62-
result.push_back(argv[i]);
63-
}
64-
return result;
65-
}
66-
67-
6859
int argc = 0;
6960
char** argv = 0;
7061

test/jdk/tools/jpackage/helpers/jdk/jpackage/test/HelloApp.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,15 @@ public void executeAndVerifyOutput(String... args) {
397397
executeAndVerifyOutput(false, args);
398398
}
399399

400-
public void executeAndVerifyOutput(boolean removePath, String... args) {
401-
getExecutor(args).dumpOutput().setRemovePath(removePath).execute();
400+
public void executeAndVerifyOutput(boolean removePath,
401+
List<String> launcherArgs, List<String> appArgs) {
402+
getExecutor(launcherArgs.toArray(new String[0])).dumpOutput()
403+
.setRemovePath(removePath).execute();
404+
Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME);
405+
verifyOutputFile(outputFile, appArgs, params);
406+
}
402407

408+
public void executeAndVerifyOutput(boolean removePath, String... args) {
403409
final List<String> launcherArgs = List.of(args);
404410
final List<String> appArgs;
405411
if (launcherArgs.isEmpty()) {
@@ -408,8 +414,7 @@ public void executeAndVerifyOutput(boolean removePath, String... args) {
408414
appArgs = launcherArgs;
409415
}
410416

411-
Path outputFile = TKit.workDir().resolve(OUTPUT_FILENAME);
412-
verifyOutputFile(outputFile, appArgs, params);
417+
executeAndVerifyOutput(removePath, launcherArgs, appArgs);
413418
}
414419

415420
public Executor.Result executeOnly(boolean removePath, String...args) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2020, 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.nio.file.Path;
25+
import java.util.List;
26+
import java.util.ArrayList;
27+
import jdk.jpackage.test.JPackageCommand;
28+
import jdk.jpackage.test.HelloApp;
29+
import jdk.jpackage.test.Annotations.Test;
30+
31+
/**
32+
* Tests generation of app image and then launches app by passing -psn_1_1
33+
* argument via command line and checks that -psn_1_1 is not passed to
34+
* application. Second test app image is generated -psn_2_2 and then app is
35+
* launched with -psn_1_1 and we should filter -psn_1_1 and keep -psn_2_2.
36+
* See JDK-8255947.
37+
*/
38+
39+
/*
40+
* @test
41+
* @summary jpackage with -psn
42+
* @library ../helpers
43+
* @build jdk.jpackage.test.*
44+
* @modules jdk.jpackage/jdk.jpackage.internal
45+
* @compile ArgumentsFilteringTest.java
46+
* @requires (os.family == "mac")
47+
* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
48+
* --jpt-run=ArgumentsFilteringTest
49+
*/
50+
public class ArgumentsFilteringTest {
51+
52+
@Test
53+
public void test1() {
54+
JPackageCommand cmd = JPackageCommand.helloAppImage();
55+
cmd.executeAndAssertHelloAppImageCreated();
56+
Path launcherPath = cmd.appLauncherPath();
57+
HelloApp.assertApp(launcherPath)
58+
.executeAndVerifyOutput(false, List.of("-psn_1_1"),
59+
new ArrayList<>());
60+
}
61+
62+
@Test
63+
public void test2() {
64+
JPackageCommand cmd = JPackageCommand.helloAppImage()
65+
.addArguments("--arguments", "-psn_2_2");
66+
cmd.executeAndAssertHelloAppImageCreated();
67+
Path launcherPath = cmd.appLauncherPath();
68+
HelloApp.assertApp(launcherPath)
69+
.executeAndVerifyOutput(false, List.of("-psn_1_1"),
70+
List.of("-psn_2_2"));
71+
}
72+
}

0 commit comments

Comments
 (0)