Package dev.dirs
Class ProjectDirectories
- java.lang.Object
-
- dev.dirs.ProjectDirectories
-
public final class ProjectDirectories extends java.lang.ObjectProjectDirectoriescomputes the location of cache, config or data directories for a specific application, which are derived from the standard directories and the name of the project/organization.Examples
All examples on this page are computed with a user named Alice, and aProjectDirectoriesinstance created with the following information:ProjectDirectories.from("com", "Foo Corp", "Bar App")Example of
configDirvalue in different operating systems:- Linux/BSD:
/home/alice/.config/barapp - macOS:
/Users/Alice/Library/Preferences/com.Foo-Corp.Bar-App - Windows:
C:\Users\Alice\AppData\Roaming\Foo Corp\Bar App
- Linux/BSD:
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.StringcacheDirReturns the path to the project's cache directory, in which<project_path>is the value ofprojectPath.java.lang.StringconfigDirReturns the path to the project's configuration directory, in which<project_path>is the value ofprojectPath.java.lang.StringdataDirReturns the path to the project's data directory, in which<project_path>is the value ofprojectPath.java.lang.StringdataLocalDirReturns the path to the project's local data directory, in which<project_path>is the value ofprojectPath.java.lang.StringpreferenceDirReturns the path to the project's preference directory, in which<project_path>is the value ofprojectPath.java.lang.StringprojectPathReturns the project path fragment used to compute the project's cache/config/data directories.java.lang.StringruntimeDirReturns the path to the project's runtime directory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)static ProjectDirectoriesfrom(java.lang.String qualifier, java.lang.String organization, java.lang.String application)Creates aProjectDirectoriesinstance from values describing the project.static ProjectDirectoriesfromPath(java.lang.String path)Creates aProjectDirectoriesinstance directly from a path.inthashCode()java.lang.StringtoString()
-
-
-
Field Detail
-
projectPath
public final java.lang.String projectPath
Returns the project path fragment used to compute the project's cache/config/data directories.The value is derived from the arguments provided to the
from(java.lang.String, java.lang.String, java.lang.String)call and is platform-dependent.
-
cacheDir
public final java.lang.String cacheDir
Returns the path to the project's cache directory, in which<project_path>is the value ofprojectPath.
Platform Value Example Linux/BSD $XDG_CACHE_HOME/<project_path>or$HOME/.cache/<project_path>/home/alice/.cache/barapp macOS $HOME/Library/Caches/<project_path>/Users/Alice/Library/Caches/com.Foo-Corp.Bar-App Windows {FOLDERID_LocalAppData}\<project_path>\cacheC:\Users\Alice\AppData\Local\Foo Corp\Bar App\cache
-
configDir
public final java.lang.String configDir
Returns the path to the project's configuration directory, in which<project_path>is the value ofprojectPath.
Platform Value Example Linux/BSD $XDG_CONFIG_HOME/<project_path>or$HOME/.config/<project_path>/home/alice/.config/barapp macOS $HOME/Library/Application Support/<project_path>/Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App Windows {FOLDERID_RoamingAppData}\<project_path>\configC:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
-
dataDir
public final java.lang.String dataDir
Returns the path to the project's data directory, in which<project_path>is the value ofprojectPath.
Platform Value Example Linux/BSD $XDG_DATA_HOME/<project_path>or$HOME/.local/share/<project_path>/home/alice/.local/share/barapp macOS $HOME/Library/Application Support/<project_path>/Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App Windows {FOLDERID_RoamingAppData}\<project_path>\dataC:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\data
-
dataLocalDir
public final java.lang.String dataLocalDir
Returns the path to the project's local data directory, in which<project_path>is the value ofprojectPath.
Platform Value Example Linux/BSD $XDG_DATA_HOME/<project_path>or$HOME/.local/share/<project_path>/home/alice/.local/share/barapp macOS $HOME/Library/Application Support/<project_path>/Users/Alice/Library/Application Support/com.Foo-Corp.Bar-App Windows {FOLDERID_LocalAppData}\<project_path>\dataC:\Users\Alice\AppData\Local\Foo Corp\Bar App\data
-
preferenceDir
public final java.lang.String preferenceDir
Returns the path to the project's preference directory, in which<project_path>is the value ofprojectPath.
Platform Value Example Linux/BSD $XDG_CONFIG_HOME/<project_path>or$HOME/.config/<project_path>/home/alice/.config/barapp macOS $HOME/Library/Preferences/<project_path>/Users/Alice/Library/Preferences/com.Foo-Corp.Bar-App Windows {FOLDERID_RoamingAppData}\<project_path>\configC:\Users\Alice\AppData\Roaming\Foo Corp\Bar App\config
-
runtimeDir
public final java.lang.String runtimeDir
Returns the path to the project's runtime directory.
Platform Value Example Linux/BSD $XDG_RUNTIME_DIR/run/user/1001/barapp macOS – nullWindows – null
-
-
Method Detail
-
fromPath
public static ProjectDirectories fromPath(java.lang.String path)
Creates aProjectDirectoriesinstance directly from a path.The argument is used verbatim and is not adapted to operating system standards. The use of
fromPath(java.lang.String)is strongly discouraged, as its results will not follow operating system standards on at least two of three platforms.- Parameters:
path- A string used verbatim as the path fragment to derive the directory field values.- Returns:
- A new
ProjectDirectoriesinstance, whose directory field values are directly derived from thepathargument.
-
from
public static ProjectDirectories from(java.lang.String qualifier, java.lang.String organization, java.lang.String application)
Creates aProjectDirectoriesinstance from values describing the project.The use of
from(java.lang.String, java.lang.String, java.lang.String)– instead offromPath(java.lang.String)– is strongly encouraged, as its results will follow operating system standards on Linux, macOS and Windows.- Parameters:
qualifier- The reverse domain name notation of the application, excluding the organization or application name itself.
An empty string can be passed if no qualifier should be used (only affects macOS).
Example values:"com.example","org","uk.co","io",""organization- The name of the organization that develops this application, or for which the application is developed.
An empty string can be passed if no organization should be used (only affects macOS and Windows).
Example values:"Foo Corp","Alice and Bob Inc",""application- The name of the application itself.
Example values:"Bar App","ExampleProgram","Unicorn-Programme"- Returns:
- An instance of
ProjectDirectories, whose directory field values are based on thequalifier,organizationandapplicationarguments.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-