24
24
*/
25
25
package jdk .jpackage .internal ;
26
26
27
- import jdk .jpackage .internal .model . Package ;
28
- import jdk . jpackage . internal . model . Application ;
27
+ import static jdk .jpackage .internal .I18N . buildConfigException ;
28
+
29
29
import java .nio .file .Path ;
30
30
import java .util .Objects ;
31
31
import java .util .Optional ;
32
- import static jdk .jpackage .internal .I18N . buildConfigException ;
32
+ import jdk .jpackage .internal .model . Application ;
33
33
import jdk .jpackage .internal .model .ConfigException ;
34
+ import jdk .jpackage .internal .model .Package ;
34
35
import jdk .jpackage .internal .model .Package .Stub ;
35
36
import jdk .jpackage .internal .model .PackageType ;
36
37
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 ;
43
38
44
39
final class PackageBuilder {
45
40
@@ -55,24 +50,23 @@ Package create() throws ConfigException {
55
50
if (installDir != null ) {
56
51
var normalizedInstallDir = mapInstallDir (installDir , type );
57
52
if (type instanceof StandardPackageType stdType ) {
58
- boolean addPackageName = true ;
53
+ Optional < Path > installDirName = Optional . of ( Path . of ( effectiveName )) ;
59
54
switch (stdType ) {
60
55
case LINUX_DEB , LINUX_RPM -> {
61
56
switch (normalizedInstallDir .toString ()) {
62
57
case "/usr" , "/usr/local" -> {
63
- addPackageName = false ;
58
+ installDirName = Optional . empty () ;
64
59
}
65
60
}
66
61
}
67
62
case WIN_EXE , WIN_MSI -> {
68
- addPackageName = false ;
63
+ installDirName = Optional . empty () ;
69
64
}
70
65
case MAC_DMG ,MAC_PKG -> {
66
+ installDirName = Optional .of (app .appImageDirName ());
71
67
}
72
68
}
73
- if (addPackageName ) {
74
- normalizedInstallDir = normalizedInstallDir .resolve (effectiveName );
75
- }
69
+ normalizedInstallDir = installDirName .map (normalizedInstallDir ::resolve ).orElse (normalizedInstallDir );
76
70
}
77
71
relativeInstallDir = normalizedInstallDir ;
78
72
} else if (type instanceof StandardPackageType stdType ) {
@@ -82,7 +76,7 @@ Package create() throws ConfigException {
82
76
}
83
77
84
78
if (relativeInstallDir .isAbsolute ()) {
85
- relativeInstallDir = Path . of ( "/" ).relativize (relativeInstallDir );
79
+ relativeInstallDir = relativeInstallDir . getRoot ( ).relativize (relativeInstallDir );
86
80
}
87
81
88
82
return new Stub (
@@ -178,19 +172,17 @@ private static Path mapInstallDir(Path installDir, PackageType pkgType)
178
172
private static Path defaultInstallDir (StandardPackageType pkgType , String pkgName , Application app ) {
179
173
switch (pkgType ) {
180
174
case WIN_EXE , WIN_MSI -> {
181
- return Path . of ( app .name () );
175
+ return app .appImageDirName ( );
182
176
}
183
177
case LINUX_DEB , LINUX_RPM -> {
184
178
return Path .of ("/opt" ).resolve (pkgName );
185
179
}
186
180
case MAC_DMG , MAC_PKG -> {
181
+ final Path dirName = app .appImageDirName ();
187
182
final Path base ;
188
- final String dirName ;
189
183
if (app .isRuntime ()) {
190
- dirName = pkgName ;
191
184
base = Path .of ("/Library/Java/JavaVirtualMachines" );
192
185
} else {
193
- dirName = pkgName + ".app" ;
194
186
base = Path .of ("/Applications" );
195
187
}
196
188
return base .resolve (dirName );
0 commit comments