@@ -44,13 +44,13 @@ final class PackageBuilder {
44
44
}
45
45
46
46
Package create () throws ConfigException {
47
- final var effectiveName = Optional . ofNullable ( name ). orElseGet ( app :: name );
47
+ final var validatedName = validatedName ( );
48
48
49
49
Path relativeInstallDir ;
50
50
if (installDir != null ) {
51
51
var normalizedInstallDir = mapInstallDir (installDir , type );
52
52
if (type instanceof StandardPackageType stdType ) {
53
- Optional <Path > installDirName = Optional .of (Path .of (effectiveName ));
53
+ Optional <Path > installDirName = Optional .of (Path .of (validatedName ));
54
54
switch (stdType ) {
55
55
case LINUX_DEB , LINUX_RPM -> {
56
56
switch (normalizedInstallDir .toString ()) {
@@ -69,10 +69,8 @@ Package create() throws ConfigException {
69
69
normalizedInstallDir = installDirName .map (normalizedInstallDir ::resolve ).orElse (normalizedInstallDir );
70
70
}
71
71
relativeInstallDir = normalizedInstallDir ;
72
- } else if (type instanceof StandardPackageType stdType ) {
73
- relativeInstallDir = defaultInstallDir (stdType , effectiveName , app );
74
72
} else {
75
- throw new UnsupportedOperationException ( );
73
+ relativeInstallDir = defaultInstallDir (). orElseThrow ( UnsupportedOperationException :: new );
76
74
}
77
75
78
76
if (relativeInstallDir .isAbsolute ()) {
@@ -82,7 +80,7 @@ Package create() throws ConfigException {
82
80
return new Stub (
83
81
app ,
84
82
type ,
85
- effectiveName ,
83
+ validatedName ,
86
84
Optional .ofNullable (description ).orElseGet (app ::description ),
87
85
version = Optional .ofNullable (version ).orElseGet (app ::version ),
88
86
Optional .ofNullable (aboutURL ),
@@ -95,42 +93,86 @@ PackageBuilder name(String v) {
95
93
name = v ;
96
94
return this ;
97
95
}
96
+
97
+ Optional <String > name () {
98
+ return Optional .ofNullable (name );
99
+ }
98
100
99
101
PackageBuilder fileName (Path v ) {
100
102
fileName = v ;
101
103
return this ;
102
104
}
105
+
106
+ Optional <Path > fileName () {
107
+ return Optional .ofNullable (fileName );
108
+ }
103
109
104
110
PackageBuilder description (String v ) {
105
111
description = v ;
106
112
return this ;
107
113
}
108
114
115
+ Optional <String > description () {
116
+ return Optional .ofNullable (description );
117
+ }
118
+
109
119
PackageBuilder version (String v ) {
110
120
version = v ;
111
121
return this ;
112
122
}
113
123
124
+ Optional <String > version () {
125
+ return Optional .ofNullable (version );
126
+ }
127
+
114
128
PackageBuilder aboutURL (String v ) {
115
129
aboutURL = v ;
116
130
return this ;
117
131
}
118
132
133
+ Optional <String > aboutURL () {
134
+ return Optional .ofNullable (aboutURL );
135
+ }
136
+
119
137
PackageBuilder licenseFile (Path v ) {
120
138
licenseFile = v ;
121
139
return this ;
122
140
}
123
141
142
+ Optional <Path > licenseFile () {
143
+ return Optional .ofNullable (licenseFile );
144
+ }
145
+
124
146
PackageBuilder predefinedAppImage (Path v ) {
125
147
predefinedAppImage = v ;
126
148
return this ;
127
149
}
128
150
151
+ Optional <Path > predefinedAppImage () {
152
+ return Optional .ofNullable (predefinedAppImage );
153
+ }
154
+
129
155
PackageBuilder installDir (Path v ) {
130
156
installDir = v ;
131
157
return this ;
132
158
}
133
159
160
+ Optional <Path > installDir () {
161
+ return Optional .ofNullable (installDir );
162
+ }
163
+
164
+ Optional <Path > defaultInstallDir () {
165
+ if (type instanceof StandardPackageType stdType ) {
166
+ return defaultInstallDir (stdType , validatedName (), app );
167
+ } else {
168
+ return Optional .empty ();
169
+ }
170
+ }
171
+
172
+ private String validatedName () {
173
+ return name ().orElseGet (app ::name );
174
+ }
175
+
134
176
private static Path mapInstallDir (Path installDir , PackageType pkgType )
135
177
throws ConfigException {
136
178
var ex = buildConfigException ("error.invalid-install-dir" , installDir ).create ();
@@ -169,13 +211,13 @@ private static Path mapInstallDir(Path installDir, PackageType pkgType)
169
211
return installDir ;
170
212
}
171
213
172
- private static Path defaultInstallDir (StandardPackageType pkgType , String pkgName , Application app ) {
214
+ private static Optional < Path > defaultInstallDir (StandardPackageType pkgType , String pkgName , Application app ) {
173
215
switch (pkgType ) {
174
216
case WIN_EXE , WIN_MSI -> {
175
- return app .appImageDirName ();
217
+ return Optional . of ( app .appImageDirName () );
176
218
}
177
219
case LINUX_DEB , LINUX_RPM -> {
178
- return Path .of ("/opt" ).resolve (pkgName );
220
+ return Optional . of ( Path .of ("/opt" ).resolve (pkgName ) );
179
221
}
180
222
case MAC_DMG , MAC_PKG -> {
181
223
final Path dirName = app .appImageDirName ();
@@ -185,10 +227,10 @@ private static Path defaultInstallDir(StandardPackageType pkgType, String pkgNam
185
227
} else {
186
228
base = Path .of ("/Applications" );
187
229
}
188
- return base .resolve (dirName );
230
+ return Optional . of ( base .resolve (dirName ) );
189
231
}
190
232
default -> {
191
- throw new UnsupportedOperationException ();
233
+ return Optional . empty ();
192
234
}
193
235
}
194
236
}
0 commit comments