1
1
package dev .dirs ;
2
2
3
- import static dev .dirs .Util .*;
3
+ import dev .dirs .impl .Linux ;
4
+ import dev .dirs .impl .MacOs ;
5
+ import dev .dirs .impl .Util ;
6
+ import dev .dirs .impl .Windows ;
7
+
8
+ import java .util .Objects ;
4
9
5
10
/** {@code ProjectDirectories} computes the location of cache, config or data directories for a specific application,
6
11
* which are derived from the standard directories and the name of the project/organization.
@@ -28,7 +33,7 @@ private ProjectDirectories(
28
33
final String preferenceDir ,
29
34
final String runtimeDir ) {
30
35
31
- requireNonNull (projectPath );
36
+ Objects . requireNonNull (projectPath );
32
37
33
38
this .projectPath = projectPath ;
34
39
this .cacheDir = cacheDir ;
@@ -230,40 +235,39 @@ public static ProjectDirectories fromPath(String path) {
230
235
String dataLocalDir ;
231
236
String preferenceDir ;
232
237
String runtimeDir = null ;
233
- switch (operatingSystem ) {
234
- case LIN :
235
- case BSD :
236
- case SOLARIS :
237
- case IBMI :
238
- case AIX :
238
+ switch (Constants . operatingSystem ) {
239
+ case Constants . LIN :
240
+ case Constants . BSD :
241
+ case Constants . SOLARIS :
242
+ case Constants . IBMI :
243
+ case Constants . AIX :
239
244
homeDir = System .getProperty ("user.home" );
240
- cacheDir = defaultIfNullOrEmptyExtended (System .getenv ("XDG_CACHE_HOME" ), path , homeDir + "/.cache/" , path );
241
- configDir = defaultIfNullOrEmptyExtended (System .getenv ("XDG_CONFIG_HOME" ), path , homeDir + "/.config/" , path );
242
- dataDir = defaultIfNullOrEmptyExtended (System .getenv ("XDG_DATA_HOME" ), path , homeDir + "/.local/share/" , path );
245
+ cacheDir = Util . defaultIfNullOrEmptyExtended (System .getenv ("XDG_CACHE_HOME" ), path , homeDir + "/.cache/" , path );
246
+ configDir = Util . defaultIfNullOrEmptyExtended (System .getenv ("XDG_CONFIG_HOME" ), path , homeDir + "/.config/" , path );
247
+ dataDir = Util . defaultIfNullOrEmptyExtended (System .getenv ("XDG_DATA_HOME" ), path , homeDir + "/.local/share/" , path );
243
248
dataLocalDir = dataDir ;
244
249
preferenceDir = configDir ;
245
- runtimeDir = linuxRuntimeDir (path );
250
+ runtimeDir = Linux . runtimeDir (path );
246
251
break ;
247
- case MAC :
252
+ case Constants . MAC :
248
253
homeDir = System .getProperty ("user.home" );
249
254
cacheDir = homeDir + "/Library/Caches/" + path ;
250
255
configDir = homeDir + "/Library/Application Support/" + path ;
251
256
dataDir = homeDir + "/Library/Application Support/" + path ;
252
257
dataLocalDir = dataDir ;
253
258
preferenceDir = homeDir + "/Library/Preferences/" + path ;
254
259
break ;
255
- case WIN :
256
- String [] winDirs = getWinDirs ("3EB685DB-65F9-4CF6-A03A-E3EF65729F3D" , "F1B32785-6FBA-4FCF-9D55-7B8E7F157091" );
257
- String appDataRoaming = winDirs [0 ] + '\\' + path ;
258
- String appDataLocal = winDirs [1 ] + '\\' + path ;
260
+ case Constants .WIN :
261
+ String appDataRoaming = Windows .getRoamingAppDataDir () + '\\' + path ;
262
+ String appDataLocal = Windows .getLocalAppDataDir () + '\\' + path ;
259
263
dataDir = appDataRoaming + "\\ data" ;
260
264
dataLocalDir = appDataLocal + "\\ data" ;
261
265
configDir = appDataRoaming + "\\ config" ;
262
266
cacheDir = appDataLocal + "\\ cache" ;
263
267
preferenceDir = configDir ;
264
268
break ;
265
269
default :
266
- throw new UnsupportedOperatingSystemException ("Project directories are not supported on " + operatingSystemName );
270
+ throw new UnsupportedOperatingSystemException ("Project directories are not supported on " + Constants . operatingSystemName );
267
271
}
268
272
return new ProjectDirectories (path , cacheDir , configDir , dataDir , dataLocalDir , preferenceDir , runtimeDir );
269
273
}
@@ -289,32 +293,32 @@ public static ProjectDirectories fromPath(String path) {
289
293
* {@code qualifier}, {@code organization} and {@code application} arguments.
290
294
*/
291
295
public static ProjectDirectories from (String qualifier , String organization , String application ) {
292
- if (isNullOrEmpty (organization ) && isNullOrEmpty (application ))
296
+ if (Util . isNullOrEmpty (organization ) && Util . isNullOrEmpty (application ))
293
297
throw new UnsupportedOperationException ("organization and application arguments cannot both be null/empty" );
294
298
String path ;
295
- switch (operatingSystem ) {
296
- case LIN :
297
- case BSD :
298
- case SOLARIS :
299
- case IBMI :
300
- case AIX :
301
- path = trimLowercaseReplaceWhitespace (application , "" , true );
299
+ switch (Constants . operatingSystem ) {
300
+ case Constants . LIN :
301
+ case Constants . BSD :
302
+ case Constants . SOLARIS :
303
+ case Constants . IBMI :
304
+ case Constants . AIX :
305
+ path = Util . trimLowercaseReplaceWhitespace (application , "" , true );
302
306
break ;
303
- case MAC :
304
- path = macOSApplicationPath (qualifier , organization , application );
307
+ case Constants . MAC :
308
+ path = MacOs . applicationPath (qualifier , organization , application );
305
309
break ;
306
- case WIN :
307
- path = windowsApplicationPath (qualifier , organization , application );
310
+ case Constants . WIN :
311
+ path = Windows . applicationPath (qualifier , organization , application );
308
312
break ;
309
313
default :
310
- throw new UnsupportedOperatingSystemException ("Project directories are not supported on " + operatingSystemName );
314
+ throw new UnsupportedOperatingSystemException ("Project directories are not supported on " + Constants . operatingSystemName );
311
315
}
312
316
return fromPath (path );
313
317
}
314
318
315
319
@ Override
316
320
public String toString () {
317
- return "ProjectDirectories (" + operatingSystemName + "):\n " +
321
+ return "ProjectDirectories (" + Constants . operatingSystemName + "):\n " +
318
322
" projectPath = '" + projectPath + "'\n " +
319
323
" cacheDir = '" + cacheDir + "'\n " +
320
324
" configDir = '" + configDir + "'\n " +
0 commit comments