Sign a JAR file using a key in a keystore.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.jdk.jarsigner |
Category: | Archiving tasks |
Since: | 0.7 |
EntityFS-aware? | No* |
Implements: | ActionTaskFactory |
Produces: | File (the target property). |
Description:
Sign a JAR file using the jarsigner
command launched in an external
process. Unlike jarsigner
, this task always requires a target file.
(The default behavior for jarsigner
is to overwrite the source file.)
The following strategy is used for locating the jarsigner
command
to use:
- Use the value of the jarsignerExecutable property, if set
- Use the file
bin/jarsigner[.exe]
relative to the javaHome property, if set - Use the file
bin/jarsigner[.exe]
relative to theJAVA_HOME
environment variable, if set - Search for
jarsigner[.exe]
in the directories listed in thePATH
environment variable.
For more documentation on the different properties, see Java's
jarsigner
tool documentation.
Required properties
Properties
altSignerClass | top |
Class name for an alternate signing class
Corresponds to jarsigner
's -altSigner
parameter.
- Setter method:
setAltSignerClass(String s)
parameters:s
– The name of the alternate signing class.- See also:
- altSignerPath
altSignerPath | top |
Class path to use for the altSignerClass.
Corresponds to jarsigner
's -altSignerPath
parameter.
- Setter method:
addAltSignerPath(Object o)
Add one or several path entries.parameters:- Setter method:
addAltSignerPaths(Object o)
Add one or several path entries.parameters:- Setter method:
clearAltSignerPaths()
Clear the alt signer class path.- See also:
- altSignerClass
arguments | top |
Arguments to the program. The arguments will be given to the program in the order that they are added.
- Setter method:
addArgument(String arg)
Add one program argument.parameters:arg
– The program argument, for instance-f out.txt
.- Setter method:
addArguments(Object o)
Add one program argument or an array or a collection of program arguments.parameters:o
– One program argument or an array or collection of program arguments (strings).- Setter method:
clearArguments()
Clear the list of program arguments.
digestAlgorithm | top |
The name of the digest algorithm to use for digesting the entries of the JAR file.
Corresponds to jarsigner
's -digestalg
parameter.
- Setter method:
setDigestAlgorithm(String s)
parameters:s
– The name of the digest algorithm.
environmentVariables | top |
Environment variables for the program. By default, the variables set are added
to the environment of the Schmant script. See the
inheritEnvironmentVariables
property.
- Setter method:
addEnvironmentVariable(String name, String value)
parameters:name
– The environment variable name, for instancePATH
.value
– The value of the variable.- Setter method:
addEnvironmentVariables(Object o)
Add one or several environment variables.parameters:o
– A string or an array or collection of strings. Each string must have the formatNAME=VALUE
.- Setter method:
clearEnvironmentVariables()
Clear the collection of environment variables.- See also:
- inheritEnvironmentVariables
failOnErrors | top |
If the program exits with an error (an exit code != 0), should the task fail? See also ErrorIgnoringTF.
- Setter method:
setFailOnErrors(boolean b)
parameters:b
– Should the task fail on errors?- Default value:
-
true
(fails on errors)
inheritEnvironmentVariables | top |
Should the environment variables of the Schmant script be inherited?
- Setter method:
setInheritEnvironmentVariables(boolean b)
parameters:b
– Should environment variables be inherited?- Default value:
true
(environment variables are inherited)- See also:
- environmentVariables
jarsignerExecutable | top |
Path to the jarsigner
executable to use for
running the task. See the description above of how the jarsigner
command is found.
- Setter method:
setJarsignerExecutable(Object o)
parameters:
javaHome | top |
The base directory of the Java installation whose
jarsigner
command should be used. See the description above of how
the jarsigner
command is found.
- Setter method:
setJavaHome(Object o)
parameters:
jvmOptions | top |
A list of options to give to the JVM running the
jarsigner
command.
Corresponds to giving jarsigner
's -J
argument for
each option.
- Setter method:
addJvmOption(String s)
Add one JVM option.parameters:s
– The option- Setter method:
addJvmOptions(Object o)
Add one or several JVM options.parameters:o
– One JVM option or an array or collection of JVM options (strings).- Setter method:
clearJvmOptions()
Clear the list of JVM options.
keyAlias (required) | top |
The alias, in the keystore, of the key that should be used for signing.
- Setter method:
setKeyAlias(String s)
parameters:s
– The alias.
keyPass | top |
The signing key's password.
Corresponds to jarsigner
's -keypass
parameter.
- Setter method:
setKeyPass(String s)
parameters:s
– The password.- Setter method:
setKeyPass(char[] c)
parameters:c
– The password.
keystore (required) | top |
The keystore that contains the key that should be used for signing.
- Setter method:
setKeystore(Object o)
parameters:
keystorePass | top |
The keystore's password.
Corresponds to jarsigner
's -storepass
parameter.
- Setter method:
setKeystorePass(String s)
parameters:s
– The password.- Setter method:
setKeystorePass(char[] c)
parameters:c
– The password.
keystoreType | top |
The type of keystore.
Corresponds to jarsigner
's -storetype
parameter.
- Setter method:
setKeystoreType(String s)
parameters:s
– The keystore type.
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
overwriteStrategy | top |
The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.
If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.
Non-empty directories are never overwritten, regardless of the chosen strategy.
- Setter method:
setOverwrite(boolean b)
Setting this to a value ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.b
– Should an existing entity be overwritten?- Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.parameters:strat
– The overwrite strategy.- Default value:
- DontOverwriteAndThrowException
- See also:
- target
protected | top |
If this is set to true
a password must
be given via a protected authentication path.
Corresponds to jarsigner
's -protected
parameter.
- Setter method:
setProtected(boolean b)
parameters:b
– Should a protected authentication path be required for passwords?
provider | top |
Fully qualified class name of the cryptographic service provider to use for signing the JAR.
Corresponds to jarsigner
's -provider
parameter.
- Setter method:
setProvider(String s)
parameters:s
– The provider class name.- See also:
- providerName
- providerArg
providerArg | top |
Optional arguments given to the cryptographic provider given with the provider argument.
Corresponds to jarsigner
's -providerArg
parameter
- Setter method:
setProviderArg(String s)
parameters:s
– The provider argument.- See also:
- provider
providerName | top |
Specify which one of several possible cryptographic providers to use.
Corresponds to jarsigner
's -providerName
parameter.
- Setter method:
setProviderName(String s)
parameters:s
– The provider name.- See also:
- provider
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sigFile | top |
Base file name to use for the generated .SF
and .DSA
files.
Corresponds to jarsigner
's -sigfile
parameter.
- Setter method:
setSigFile(String s)
parameters:s
– The file name prefix.
signatureAlgorithm | top |
The name of the signature algorithm to use for signing the JAR file.
Corresponds to jarsigner
's -sigalg
parameter.
- Setter method:
setSignatureAlgorithm(String s)
parameters:s
– The name of the signature algorithm.
source (required) | top |
The JAR file to sign.
- Setter method:
setSource(Object o)
parameters:
stderrStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stderr
.
- Setter method:
setStderrStrategy(ProcessOutputStrategy s)
parameters:s
– Thestderr
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.SEVERE
- See also:
- stdoutStrategy
stdoutStrategy | top |
A ProcessOutputStrategy
for handling the program's output to stdout
.
- Setter method:
setStdoutStrategy(ProcessOutputStrategy s)
parameters:s
– Thestdout
strategy.- Default value:
- A LoggingProcessOutputStrategy
that logs output to the
Level.INFO
- See also:
- stderrStrategy
target (required) | top |
The place to put the signed JAR file in.
Corresponds to jarsigner
's -signedjar
parameter, but
unlike that parameter, this is mandatory.
- Setter method:
setTarget(Object o)
parameters:- See also:
- overwriteStrategy
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
tsa | top |
Location of a Time Stamping Authority.
Corresponds to jarsigner
's -tsa
parameter.
- Setter method:
setTsa(String s)
parameters:s
– The Time Stamping Authority URL.
tsaCert | top |
Alias for the Time Stamping Authority's public key in the keystore.
Corresponds to jarsigner
's -tsaCert
parameter.
- Setter method:
setTsaCert(String s)
parameters:s
– The TSA cert alias.
verbose | top |
Should the jarsigner
command be verbose?
Corresponds to jarsigner
's -verbose
flag.
- Setter method:
setVerbose(boolean b)
parameters:b
– Shouldjarsigner
be verbose?
workingDirectory | top |
The working directory for the program. (The directory that the program is started in.)
- Setter method:
setWorkingDirectory(Object o)
parameters:- Default value:
- The Schmant process' working directory. The Schmant launcher scripts sets this to the directory where the current script file is.
Examples
Example 1
Sign the JAR file project.jar
using the private
key with the alias signerkey
in the PKCS#12 file signer.p12
.
JavaScript
* That a task is not EntityFS-aware means that it is not aware of DirectoryView filters (it uses them as plain Directory:s) and also that it usually requires that the entities it takes as arguments are in a File-based file file system. (That they are ECFileResolvable.) A non File-resolvable entity can be made so by using the SchmantFileSystems.makeFileResolvable(org.entityfs.EFile) method.