public class Capsule extends Object implements Runnable
This API is to be used by custom capsules to programmatically (rather than declaratively) configure the capsule and possibly provide custom behavior.
All non-final protected methods may be overridden by custom capsules. These methods will usually be called once, but they must be idempotent,
i.e. if called numerous times they must always return the same value, and produce the same effect as if called once. The only exception to this
rule is the launch method.
Overridden methods need not be thread-safe, and are guaranteed to be called by a single thread at a time.
Final methods implement various utility or accessors, which may be freely used by custom capsules.
| Modifier and Type | Field and Description |
|---|---|
protected static int |
LOG_DEBUG |
protected static int |
LOG_NONE |
protected static int |
LOG_QUIET |
protected static int |
LOG_VERBOSE |
| Modifier | Constructor and Description |
|---|---|
protected |
Capsule(Path jarFile,
Path cacheDir)
Constructs a capsule from the given JAR file
|
| Modifier and Type | Method and Description |
|---|---|
protected String |
buildAppId()
Computes and returns application's ID
|
protected List<String> |
buildArgs(List<String> args)
Returns a list of command line arguments to pass to the application.
|
protected List<Path> |
buildBootClassPath()
Compiles and returns the application's boot classpath as a list of paths.
|
protected List<Path> |
buildBootClassPathA()
Compiles and returns the paths to be appended to the application's boot classpath.
|
protected List<Path> |
buildBootClassPathP()
Compiles and returns the paths to be prepended to the application's boot classpath.
|
protected List<Path> |
buildClassPath()
Compiles and returns the application's classpath as a list of paths.
|
protected void |
buildEnvironmentVariables(Map<String,String> env)
Returns a map of environment variables (property-value pairs).
|
protected List<String> |
buildJVMArgs()
Returns a list of JVM arguments.
|
protected Map<String,String> |
buildSystemProperties()
Returns a map of system properties (property-value pairs).
|
protected Path |
chooseJavaHome()
Chooses which Java installation to use for running the app.
|
protected int |
chooseLogLevel()
Chooses and returns the capsules log level.
|
protected String |
chooseMode()
Chooses this capsule's mode.
|
protected Object |
clone()
Throws a
CloneNotSupportedException |
boolean |
equals(Object obj) |
protected String |
expand(String str)
Expands occurrences of
$VARNAME in attribute values. |
protected Path |
getAppCache()
This capsule's cache directory, or
null if capsule has been configured not to extract. |
protected String |
getAppId(List<String> args)
Returns the app's ID.
|
protected String |
getAttribute(String attr)
Returns the value of the given manifest attribute with consideration to the capsule's mode.
|
protected List<String> |
getDependencies()
Returns a list of dependencies, each in the format
groupId:artifactId:version[:classifier] (classifier is optional) |
protected Path |
getJarFile()
This capsule's JAR file.
|
protected Path |
getJavaHome()
The path to the Java installation this capsule's app will use.
|
protected static Map<String,Path> |
getJavaHomes()
Returns all found Java installations.
|
protected List<String> |
getListAttribute(String attr)
Returns the value of the given attribute (with consideration to the capsule's mode) as a list.
|
protected Map<String,String> |
getMapAttribute(String attr,
String defaultValue)
Returns the value of the given attribute (with consideration to the capsule's mode) as a map.
|
protected String |
getMode()
This capsule's current mode.
|
protected String |
getModeDescription(String mode)
Returns the description of the given mode.
|
protected Set<String> |
getModes()
Returns the names of all modes defined in this capsule's manifest.
|
protected List<String> |
getNativeDependencies()
Constructs this capsule's native dependency list.
|
protected boolean |
hasAttribute(String attr)
Tests whether the given attribute is found in the manifest.
|
int |
hashCode() |
protected boolean |
isEmptyCapsule()
Tests if this is an empty capsule.
|
protected boolean |
isLogging(int level)
Tests id the given log level is currently being logged
|
protected static boolean |
isMac()
Tests whether the current OS is MacOS.
|
protected static boolean |
isUnix()
Tests whether the current OS is UNIX/Linux.
|
protected static boolean |
isWindows()
Tests whether the current OS is Windows.
|
protected static String |
join(Collection<?> coll,
String separator)
Joins a collections into a string, separating elements with the given separator string.
|
protected Process |
launch(List<String> args)
Creates the
Process this capsule will launch. |
protected static List<Path> |
listDir(Path dir)
Returns the contents of a directory
|
static void |
main(String[] args0)
Launches the capsule
|
protected static Map<String,String> |
mapSplit(String map,
char kvSeparator,
String separator,
String defaultValue)
Splits a string into a map
|
protected static Capsule |
myCapsule() |
protected static List<String> |
split(String str,
String separator)
Splits a string into a list using a regex separator
|
String |
toString() |
protected static final int LOG_DEBUG
protected static final int LOG_NONE
protected static final int LOG_QUIET
protected static final int LOG_VERBOSE
protected String buildAppId()
protected List<String> buildArgs(List<String> args)
args - The command line arguments passed to the capsule at launchprotected List<Path> buildBootClassPath()
protected List<Path> buildBootClassPathA()
protected List<Path> buildBootClassPathP()
protected List<Path> buildClassPath()
protected void buildEnvironmentVariables(Map<String,String> env)
env - the current environmentprotected Map<String,String> buildSystemProperties()
protected Path chooseJavaHome()
null if the current JVM is to be used.protected int chooseLogLevel()
protected String chooseMode()
protected final Object clone() throws CloneNotSupportedException
CloneNotSupportedExceptionclone in class ObjectCloneNotSupportedExceptionprotected String expand(String str)
$VARNAME in attribute values.str - the original stringprotected final Path getAppCache()
null if capsule has been configured not to extract.protected final String getAppId(List<String> args)
args - the command line arguments; may be null.protected final String getAttribute(String attr)
attr - the attributeprotected List<String> getDependencies()
groupId:artifactId:version[:classifier] (classifier is optional)protected final Path getJarFile()
protected final Path getJavaHome()
protected static Map<String,Path> getJavaHomes()
protected final List<String> getListAttribute(String attr)
attr - the attributeprotected final Map<String,String> getMapAttribute(String attr, String defaultValue)
attr - the attributeprotected final String getMode()
protected final String getModeDescription(String mode)
mode - null if no description is found.protected final Set<String> getModes()
protected List<String> getNativeDependencies()
groupId:artifactId:version[:classifier][,renameTo]
(classifier and renameTo are optional).protected final boolean hasAttribute(String attr)
attr - the attributeprotected final boolean isEmptyCapsule()
protected final boolean isLogging(int level)
level - protected static final boolean isMac()
protected static final boolean isUnix()
protected static final boolean isWindows()
protected static final String join(Collection<?> coll, String separator)
protected Process launch(List<String> args) throws IOException, InterruptedException
Process this capsule will launch.
Custom capsules may override this method to display a message prior to launch, or to configure the process's IO streams.args - the application's command-line arguments (does not include JVM args)IOExceptionInterruptedExceptionprotected static final List<Path> listDir(Path dir)
dir - the directorypublic static final void main(String[] args0)
protected static final Map<String,String> mapSplit(String map, char kvSeparator, String separator, String defaultValue)
map - the stringkvSeparator - the character separating each key from its corresponding valueseparator - a regex separator between key-value pairsdefaultValue - A default value to use for keys without a value, or null if such an event should throw an exceptionprotected static Capsule myCapsule()
protected static final List<String> split(String str, String separator)