org.apache.tools.ant.taskdefs

Class SignJar

public class SignJar extends AbstractJarSignerTask

Signs JAR or ZIP files with the javasign command line tool. The tool detailed dependency checking: files are only signed if they are not signed. The signjar attribute can point to the file to generate; if this file exists then its modification date is used as a cue as to whether to resign any JAR file. Timestamp driven signing is based on the unstable and inadequately documented information in the Java1.5 docs

Since: Ant 1.1

See Also: beta documentation

UNKNOWN: category="java"

Field Summary
protected FiledestDir
the output directory when using paths.
static StringERROR_BAD_MAP
error string for unit test verification:
static StringERROR_MAPPER_WITHOUT_DEST
error string for unit test verification:
static StringERROR_NO_ALIAS
error string for unit test verification:
static StringERROR_NO_STOREPASS
error string for unit test verification:
static StringERROR_SIGNEDJAR_AND_PATHS
error string for unit test verification
static StringERROR_TODIR_AND_SIGNEDJAR
error string for unit test verification:
static StringERROR_TOO_MANY_MAPPERS
error string for unit test verification:
protected booleaninternalsf
flag for internal sf signing
protected booleanlazy
Whether to assume a jar which has an appropriate .SF file in is already signed.
protected booleansectionsonly
sign sections only?
protected Stringsigfile
name to a signature file
protected Filesignedjar
name of a single jar
protected Stringtsacert
alias for the TSA in the keystore
protected Stringtsaurl
URL for a tsa; null implies no tsa support
Method Summary
voidadd(FileNameMapper newMapper)
add a mapper to determine file naming policy.
voidexecute()
sign the jar(s)
FileNameMappergetMapper()
get the active mapper; may be null
StringgetTsacert()
get the -tsacert option
StringgetTsaurl()
get the -tsaurl url
booleanisForce()
Should the task force signing of a jar even it is already signed?
protected booleanisSigned(File file)
test for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.
protected booleanisUpToDate(File jarFile, File signedjarFile)
Compare a jar file with its corresponding signed jar.
voidsetDestDir(File destDir)
Optionally sets the output directory to be used.
voidsetForce(boolean b)
Whether to force signing of a jar even it is already signed.
voidsetInternalsf(boolean internalsf)
Flag to include the .SF file inside the signature; optional; default false
voidsetLazy(boolean lazy)
flag to control whether the presence of a signature file means a JAR is signed; optional, default false
voidsetPreserveLastModified(boolean preserveLastModified)
true to indicate that the signed jar modification date remains the same as the original.
voidsetSectionsonly(boolean sectionsonly)
flag to compute hash of entire manifest; optional, default false
voidsetSigfile(String sigfile)
name of .SF/.DSA file; optional
voidsetSignedjar(File signedjar)
name of signed JAR file; optional
voidsetTsacert(String tsacert)
set the alias in the keystore of the TSA to use;
voidsetTsaurl(String tsaurl)

Field Detail

destDir

protected File destDir
the output directory when using paths.

ERROR_BAD_MAP

public static final String ERROR_BAD_MAP
error string for unit test verification: {@value }

ERROR_MAPPER_WITHOUT_DEST

public static final String ERROR_MAPPER_WITHOUT_DEST
error string for unit test verification: {@value }

ERROR_NO_ALIAS

public static final String ERROR_NO_ALIAS
error string for unit test verification: {@value }

ERROR_NO_STOREPASS

public static final String ERROR_NO_STOREPASS
error string for unit test verification: {@value }

ERROR_SIGNEDJAR_AND_PATHS

public static final String ERROR_SIGNEDJAR_AND_PATHS
error string for unit test verification {@value }

ERROR_TODIR_AND_SIGNEDJAR

public static final String ERROR_TODIR_AND_SIGNEDJAR
error string for unit test verification: {@value }

ERROR_TOO_MANY_MAPPERS

public static final String ERROR_TOO_MANY_MAPPERS
error string for unit test verification: {@value }

internalsf

protected boolean internalsf
flag for internal sf signing

lazy

protected boolean lazy
Whether to assume a jar which has an appropriate .SF file in is already signed.

sectionsonly

protected boolean sectionsonly
sign sections only?

sigfile

protected String sigfile
name to a signature file

signedjar

protected File signedjar
name of a single jar

tsacert

protected String tsacert
alias for the TSA in the keystore

tsaurl

protected String tsaurl
URL for a tsa; null implies no tsa support

Method Detail

add

public void add(FileNameMapper newMapper)
add a mapper to determine file naming policy. Only used with toDir processing.

Parameters: newMapper the mapper to add.

Since: Ant 1.7

execute

public void execute()
sign the jar(s)

Throws: BuildException on errors

getMapper

public FileNameMapper getMapper()
get the active mapper; may be null

Returns: mapper or null

Since: Ant 1.7

getTsacert

public String getTsacert()
get the -tsacert option

Returns: a certificate alias or null

Since: Ant 1.7

getTsaurl

public String getTsaurl()
get the -tsaurl url

Returns: url or null

Since: Ant 1.7

isForce

public boolean isForce()
Should the task force signing of a jar even it is already signed?

Since: Ant 1.8.0

isSigned

protected boolean isSigned(File file)
test for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.

Parameters: file the file to be checked

Returns: true if the file is signed

See Also: IsSigned

isUpToDate

protected boolean isUpToDate(File jarFile, File signedjarFile)
Compare a jar file with its corresponding signed jar. The logic for this is complex, and best explained in the source itself. Essentially if either file doesnt exist, or the destfile has an out of date timestamp, then the return value is false.

If we are signing ourself, the check isSigned is used to trigger the process.

Parameters: jarFile the unsigned jar file signedjarFile the result signed jar file

Returns: true if the signedjarFile is considered up to date

setDestDir

public void setDestDir(File destDir)
Optionally sets the output directory to be used.

Parameters: destDir the directory in which to place signed jars

Since: Ant 1.7

setForce

public void setForce(boolean b)
Whether to force signing of a jar even it is already signed.

Since: Ant 1.8.0

setInternalsf

public void setInternalsf(boolean internalsf)
Flag to include the .SF file inside the signature; optional; default false

Parameters: internalsf if true include the .SF file inside the signature

setLazy

public void setLazy(boolean lazy)
flag to control whether the presence of a signature file means a JAR is signed; optional, default false

Parameters: lazy flag to control whether the presence of a signature

setPreserveLastModified

public void setPreserveLastModified(boolean preserveLastModified)
true to indicate that the signed jar modification date remains the same as the original. Defaults to false

Parameters: preserveLastModified if true preserve the last modified time

setSectionsonly

public void setSectionsonly(boolean sectionsonly)
flag to compute hash of entire manifest; optional, default false

Parameters: sectionsonly flag to compute hash of entire manifest

setSigfile

public void setSigfile(String sigfile)
name of .SF/.DSA file; optional

Parameters: sigfile the name of the .SF/.DSA file

setSignedjar

public void setSignedjar(File signedjar)
name of signed JAR file; optional

Parameters: signedjar the name of the signed jar file

setTsacert

public void setTsacert(String tsacert)
set the alias in the keystore of the TSA to use;

Parameters: tsacert the cert alias.

setTsaurl

public void setTsaurl(String tsaurl)

Parameters: tsaurl the tsa url.

Since: Ant 1.7