Skip to content

Commit 10cfba4

Browse files
Fix installation directory name for macos packages
1 parent 3e7451b commit 10cfba4

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/jdk.jpackage/share/classes/jdk/jpackage/internal/PackageBuilder.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@
2424
*/
2525
package jdk.jpackage.internal;
2626

27-
import jdk.jpackage.internal.model.Package;
28-
import jdk.jpackage.internal.model.Application;
27+
import static jdk.jpackage.internal.I18N.buildConfigException;
28+
2929
import java.nio.file.Path;
3030
import java.util.Objects;
3131
import java.util.Optional;
32-
import static jdk.jpackage.internal.I18N.buildConfigException;
32+
import jdk.jpackage.internal.model.Application;
3333
import jdk.jpackage.internal.model.ConfigException;
34+
import jdk.jpackage.internal.model.Package;
3435
import jdk.jpackage.internal.model.Package.Stub;
3536
import jdk.jpackage.internal.model.PackageType;
3637
import jdk.jpackage.internal.model.StandardPackageType;
37-
import static jdk.jpackage.internal.model.StandardPackageType.LINUX_DEB;
38-
import static jdk.jpackage.internal.model.StandardPackageType.LINUX_RPM;
39-
import static jdk.jpackage.internal.model.StandardPackageType.MAC_DMG;
40-
import static jdk.jpackage.internal.model.StandardPackageType.MAC_PKG;
41-
import static jdk.jpackage.internal.model.StandardPackageType.WIN_EXE;
42-
import static jdk.jpackage.internal.model.StandardPackageType.WIN_MSI;
4338

4439
final class PackageBuilder {
4540

@@ -55,24 +50,23 @@ Package create() throws ConfigException {
5550
if (installDir != null) {
5651
var normalizedInstallDir = mapInstallDir(installDir, type);
5752
if (type instanceof StandardPackageType stdType) {
58-
boolean addPackageName = true;
53+
Optional<Path> installDirName = Optional.of(Path.of(effectiveName));
5954
switch (stdType) {
6055
case LINUX_DEB, LINUX_RPM -> {
6156
switch (normalizedInstallDir.toString()) {
6257
case "/usr", "/usr/local" -> {
63-
addPackageName = false;
58+
installDirName = Optional.empty();
6459
}
6560
}
6661
}
6762
case WIN_EXE, WIN_MSI -> {
68-
addPackageName = false;
63+
installDirName = Optional.empty();
6964
}
7065
case MAC_DMG,MAC_PKG -> {
66+
installDirName = Optional.of(app.appImageDirName());
7167
}
7268
}
73-
if (addPackageName) {
74-
normalizedInstallDir = normalizedInstallDir.resolve(effectiveName);
75-
}
69+
normalizedInstallDir = installDirName.map(normalizedInstallDir::resolve).orElse(normalizedInstallDir);
7670
}
7771
relativeInstallDir = normalizedInstallDir;
7872
} else if (type instanceof StandardPackageType stdType) {
@@ -82,7 +76,7 @@ Package create() throws ConfigException {
8276
}
8377

8478
if (relativeInstallDir.isAbsolute()) {
85-
relativeInstallDir = Path.of("/").relativize(relativeInstallDir);
79+
relativeInstallDir = relativeInstallDir.getRoot().relativize(relativeInstallDir);
8680
}
8781

8882
return new Stub(
@@ -178,19 +172,17 @@ private static Path mapInstallDir(Path installDir, PackageType pkgType)
178172
private static Path defaultInstallDir(StandardPackageType pkgType, String pkgName, Application app) {
179173
switch (pkgType) {
180174
case WIN_EXE, WIN_MSI -> {
181-
return Path.of(app.name());
175+
return app.appImageDirName();
182176
}
183177
case LINUX_DEB, LINUX_RPM -> {
184178
return Path.of("/opt").resolve(pkgName);
185179
}
186180
case MAC_DMG, MAC_PKG -> {
181+
final Path dirName = app.appImageDirName();
187182
final Path base;
188-
final String dirName;
189183
if (app.isRuntime()) {
190-
dirName = pkgName;
191184
base = Path.of("/Library/Java/JavaVirtualMachines");
192185
} else {
193-
dirName = pkgName + ".app";
194186
base = Path.of("/Applications");
195187
}
196188
return base.resolve(dirName);

0 commit comments

Comments
 (0)