Skip to content

Commit 51e8201

Browse files
author
Andy Herrick
committed
8267764: jpackage cannot handle window screensaver files when EXE renamed as SCR
Reviewed-by: asemenyuk, almatvee
1 parent f9b593d commit 51e8201

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/jdk.jpackage/windows/native/common/WinFileUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,10 @@ void FileWriter::finalize() {
660660

661661
tstring stripExeSuffix(const tstring& path) {
662662
// for windows - there is a ".exe" suffix to remove
663-
const tstring::size_type pos = path.rfind(_T(".exe"));
664-
if (pos == tstring::npos) {
663+
// allow for ".*" (last dot beyond the last slash)
664+
const tstring::size_type pos = path.rfind(_T("."));
665+
const tstring::size_type spos = path.rfind(_T("\\/"));
666+
if (pos == tstring::npos || (spos > pos && spos != tstring::npos)) {
665667
return path;
666668
}
667669
return path.substr(0, pos);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2021, 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.IOException;
25+
import java.nio.file.Path;
26+
import java.nio.file.Files;
27+
import jdk.jpackage.test.HelloApp;
28+
import jdk.jpackage.test.TKit;
29+
import jdk.jpackage.test.Functional.ThrowingConsumer;
30+
import jdk.jpackage.test.JPackageCommand;
31+
import jdk.jpackage.test.Annotations.Test;
32+
33+
/*
34+
* @test
35+
* @summary jpackage test app can run after changing executable's extension
36+
* @library ../helpers
37+
* @key jpackagePlatformPackage
38+
* @build jdk.jpackage.test.*
39+
* @build WinRenameTest
40+
* @requires (os.family == "windows")
41+
* @modules jdk.jpackage/jdk.jpackage.internal
42+
* @run main/othervm/timeout=360 -Xmx512m jdk.jpackage.test.Main
43+
* --jpt-run=WinRenameTest
44+
*/
45+
public class WinRenameTest {
46+
47+
@Test
48+
public static void test() throws IOException {
49+
String javaAppDesc = "com.hello/com.hello.Hello";
50+
JPackageCommand cmd = JPackageCommand.helloAppImage(javaAppDesc);
51+
52+
cmd.executeAndAssertImageCreated();
53+
54+
Path launcherPath = cmd.appLauncherPath();
55+
HelloApp.assertApp(launcherPath).executeAndVerifyOutput();
56+
57+
String lp = launcherPath.toString();
58+
TKit.assertTrue(lp.endsWith(".exe"), "UNexpected launcher path: " + lp);
59+
60+
Path newLauncherPath = Path.of(lp.replaceAll(".exe", ".anything"));
61+
Files.move(launcherPath, newLauncherPath);
62+
63+
HelloApp.assertApp(newLauncherPath).executeAndVerifyOutput();
64+
}
65+
}

0 commit comments

Comments
 (0)