Top Description Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class SignJar

extends AbstractJarSignerTask
Class Inheritance
Imports
java.io.File, .IOException, org.apache.tools.ant.BuildException, .Project, org.apache.tools.ant.taskdefs.condition.IsSigned, org.apache.tools.ant.types.Path, .Resource, org.apache.tools.ant.types.resources.FileProvider, .FileResource, org.apache.tools.ant.util.FileNameMapper, .FileUtils, .IdentityMapper, .ResourceUtils

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 signature support is based on Java 8
Since
Ant 1.1
See Also
documentation

Field Summary

Modifier and TypeField and Description
protected File
destDir

the output directory when using paths.

private String
digestAlg

digest algorithm

public static final String
ERROR_BAD_MAP

error string for unit test verification: Cannot map source file to anything sensible:

public static final String
ERROR_MAPPER_WITHOUT_DEST

error string for unit test verification: The destDir attribute is required if a mapper is set

public static final String
ERROR_NO_ALIAS

error string for unit test verification: alias attribute must be set

public static final String
ERROR_NO_STOREPASS

error string for unit test verification: storepass attribute must be set

public static final String
ERROR_SIGNEDJAR_AND_PATHS

error string for unit test verification You cannot specify the signed JAR when using paths or filesets

public static final String
ERROR_TODIR_AND_SIGNEDJAR

error string for unit test verification: \'destdir\' and \'signedjar\' cannot both be set

public static final String
ERROR_TOO_MANY_MAPPERS

error string for unit test verification: Too many mappers

private static final FileUtils
private boolean
force

force signing even if the jar is already signed.

protected boolean
internalsf

flag for internal sf signing

protected boolean
lazy

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

private FileNameMapper
mapper

mapper for todir work

private boolean
preserveLastModified

flag to preserve timestamp on modified files

protected boolean
sectionsonly

sign sections only?

private String
sigAlg

signature algorithm

protected String
sigfile

name to a signature file

protected File
signedjar

name of a single jar

protected String
tsacert

alias for the TSA in the keystore

private String
tsaDigestAlg

tsa digest algorithm

protected String
tsaproxyhost

Proxy host to be used when connecting to TSA server

protected String
tsaproxyport

Proxy port to be used when connecting to TSA server

protected String
tsaurl

URL for a tsa; null implies no tsa support

Inherited from org.apache.tools.ant.taskdefs.AbstractJarSignerTask:
aliasERROR_NO_SOURCEfilesetsjarJARSIGNER_COMMANDkeypasskeystoremaxMemorystorepassstoretypestrictverbose

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
add(FileNameMapper
the mapper to add.
newMapper
)

add a mapper to determine file naming policy.

private void
addProxyFor(final ExecTask cmd, final String scheme)

private void
addTimestampAuthorityCommands(final ExecTask
the exec task.
cmd
)

If the tsa parameters are set, this passes them to the command.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

sign the jar(s)
public String

Returns:

String
getDigestAlg
()

Digest Algorithm; optional

public FileNameMapper

Returns:

mapper or null
getMapper
()

get the active mapper; may be null

public String

Returns:

String
getSigAlg
()

Signature Algorithm; optional

public String

Returns:

a certificate alias or null
getTsacert
()

get the -tsacert option

public String

Returns:

String
getTSADigestAlg
()

TSA Digest Algorithm; optional

public String

Returns:

url or null
getTsaproxyhost
()

Get the proxy host to be used when connecting to the TSA url

public String

Returns:

url or null
getTsaproxyport
()

Get the proxy host to be used when connecting to the TSA url

public String

Returns:

url or null
getTsaurl
()

get the -tsaurl url

public boolean

Returns:

boolean
isForce
()

Should the task force signing of a jar even it is already signed?

protected boolean

Returns:

true if the file is signed
isSigned
(File
the file to be checked
file
)

test for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.

protected boolean

Returns:

true if the signedjarFile is considered up to date
isUpToDate
(File
the unsigned jar file
jarFile
,
File
the result signed jar file
signedjarFile
)

Compare a jar file with its corresponding signed jar.

public void
setDestDir(File
the directory in which to place signed jars
destDir
)

Optionally sets the output directory to be used.

public void
setDigestAlg(String
the digest algorithm
digestAlg
)

Digest Algorithm; optional

public void
setForce(boolean
boolean
b
)

Whether to force signing of a jar even it is already signed.

public void
setInternalsf(final boolean
if true include the .SF file inside the signature
internalsf
)

Flag to include the .SF file inside the signature; optional; default false

public void
setLazy(final boolean
flag to control whether the presence of a signature
lazy
)

flag to control whether the presence of a signature file means a JAR is signed; optional, default false

public void
setPreserveLastModified(boolean
if true preserve the last modified time
preserveLastModified
)

true to indicate that the signed jar modification date remains the same as the original.

public void
setSectionsonly(final boolean
flag to compute hash of entire manifest
sectionsonly
)

flag to compute hash of entire manifest; optional, default false

public void
setSigAlg(String
the signature algorithm
sigAlg
)

Signature Algorithm; optional

public void
setSigfile(final String
the name of the .SF/.DSA file
sigfile
)

name of .SF/.DSA file; optional

public void
setSignedjar(final File
the name of the signed jar file
signedjar
)

name of signed JAR file; optional

public void
setTsacert(String
the cert alias.
tsacert
)

set the alias in the keystore of the TSA to use;

public void
setTSADigestAlg(String
the tsa digest algorithm
digestAlg
)

TSA Digest Algorithm; optional

public void
setTsaproxyhost(String
the proxy host to be used when connecting to the TSA.
tsaproxyhost
)

public void
setTsaproxyport(String
the proxy port to be used when connecting to the TSA.
tsaproxyport
)

public void
setTsaurl(String
the tsa url.
tsaurl
)

private void
signOneJar(File
source to sign
jarSource
,
File
target; may be null
jarTarget
)

Sign one jar.

Inherited from org.apache.tools.ant.taskdefs.AbstractJarSignerTask:
addArgaddArgumentaddFilesetaddSyspropertyaddValuebeginExecutionbindToKeystorecreateJarSignercreatePathcreateUnifiedSourcePathcreateUnifiedSourcesdeclareSysPropertyendExecutiongetRedirectorhasResourcessetAliassetCommonOptionssetExecutablesetJarsetKeypasssetKeystoresetMaxmemorysetProviderArgsetProviderClasssetProviderNamesetStorepasssetStoretypesetStrictsetVerbose

Field Detail

destDirback to summary
protected File destDir

the output directory when using paths.

digestAlgback to summary
private String digestAlg

digest algorithm

ERROR_BAD_MAPback to summary
public static final String ERROR_BAD_MAP

error string for unit test verification: Cannot map source file to anything sensible:

ERROR_MAPPER_WITHOUT_DESTback to summary
public static final String ERROR_MAPPER_WITHOUT_DEST

error string for unit test verification: The destDir attribute is required if a mapper is set

ERROR_NO_ALIASback to summary
public static final String ERROR_NO_ALIAS

error string for unit test verification: alias attribute must be set

ERROR_NO_STOREPASSback to summary
public static final String ERROR_NO_STOREPASS

error string for unit test verification: storepass attribute must be set

ERROR_SIGNEDJAR_AND_PATHSback to summary
public static final String ERROR_SIGNEDJAR_AND_PATHS

error string for unit test verification You cannot specify the signed JAR when using paths or filesets

ERROR_TODIR_AND_SIGNEDJARback to summary
public static final String ERROR_TODIR_AND_SIGNEDJAR

error string for unit test verification: \'destdir\' and \'signedjar\' cannot both be set

ERROR_TOO_MANY_MAPPERSback to summary
public static final String ERROR_TOO_MANY_MAPPERS

error string for unit test verification: Too many mappers

FILE_UTILSback to summary
private static final FileUtils FILE_UTILS
forceback to summary
private boolean force

force signing even if the jar is already signed.

internalsfback to summary
protected boolean internalsf

flag for internal sf signing

lazyback to summary
protected boolean lazy

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

mapperback to summary
private FileNameMapper mapper

mapper for todir work

preserveLastModifiedback to summary
private boolean preserveLastModified

flag to preserve timestamp on modified files

sectionsonlyback to summary
protected boolean sectionsonly

sign sections only?

sigAlgback to summary
private String sigAlg

signature algorithm

sigfileback to summary
protected String sigfile

name to a signature file

signedjarback to summary
protected File signedjar

name of a single jar

tsacertback to summary
protected String tsacert

alias for the TSA in the keystore

tsaDigestAlgback to summary
private String tsaDigestAlg

tsa digest algorithm

tsaproxyhostback to summary
protected String tsaproxyhost

Proxy host to be used when connecting to TSA server

tsaproxyportback to summary
protected String tsaproxyport

Proxy port to be used when connecting to TSA server

tsaurlback to summary
protected String tsaurl

URL for a tsa; null implies no tsa support

Constructor Detail

SignJarback to summary
public SignJar()

Method Detail

addback to summary
public void add(FileNameMapper newMapper)

add a mapper to determine file naming policy. Only used with toDir processing.

Parameters
newMapper:FileNameMapper

the mapper to add.

Since
Ant 1.7
addProxyForback to summary
private void addProxyFor(final ExecTask cmd, final String scheme)
addTimestampAuthorityCommandsback to summary
private void addTimestampAuthorityCommands(final ExecTask cmd)

If the tsa parameters are set, this passes them to the command. There is no validation of java version, as third party JDKs may implement this on earlier/later jarsigner implementations.

Parameters
cmd:ExecTask

the exec task.

executeback to summary
public void execute() throws BuildException

Overrides org.apache.tools.ant.Task.execute.

sign the jar(s)

Annotations
@Override
Exceptions
BuildException:
on errors
getDigestAlgback to summary
public String getDigestAlg()

Digest Algorithm; optional

Returns:String

String

getMapperback to summary
public FileNameMapper getMapper()

get the active mapper; may be null

Returns:FileNameMapper

mapper or null

Since
Ant 1.7
getSigAlgback to summary
public String getSigAlg()

Signature Algorithm; optional

Returns:String

String

getTsacertback to summary
public String getTsacert()

get the -tsacert option

Returns:String

a certificate alias or null

Since
Ant 1.7
getTSADigestAlgback to summary
public String getTSADigestAlg()

TSA Digest Algorithm; optional

Returns:String

String

Since
Ant 1.10.2
getTsaproxyhostback to summary
public String getTsaproxyhost()

Get the proxy host to be used when connecting to the TSA url

Returns:String

url or null

Since
Ant 1.9.5
getTsaproxyportback to summary
public String getTsaproxyport()

Get the proxy host to be used when connecting to the TSA url

Returns:String

url or null

Since
Ant 1.9.5
getTsaurlback to summary
public String getTsaurl()

get the -tsaurl url

Returns:String

url or null

Since
Ant 1.7
isForceback to summary
public boolean isForce()

Should the task force signing of a jar even it is already signed?

Returns:boolean

boolean

Since
Ant 1.8.0
isSignedback to summary
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:File

the file to be checked

Returns:boolean

true if the file is signed

See Also
IsSigned#isSigned(File, String)
isUpToDateback to summary
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 doesn't exist, or the destfile has an out of date timestamp, then the return value is false.

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

Parameters
jarFile:File

the unsigned jar file

signedjarFile:File

the result signed jar file

Returns:boolean

true if the signedjarFile is considered up to date

setDestDirback to summary
public void setDestDir(File destDir)

Optionally sets the output directory to be used.

Parameters
destDir:File

the directory in which to place signed jars

Since
Ant 1.7
setDigestAlgback to summary
public void setDigestAlg(String digestAlg)

Digest Algorithm; optional

Parameters
digestAlg:String

the digest algorithm

setForceback to summary
public void setForce(boolean b)

Whether to force signing of a jar even it is already signed.

Parameters
b:boolean

boolean

Since
Ant 1.8.0
setInternalsfback to summary
public void setInternalsf(final boolean internalsf)

Flag to include the .SF file inside the signature; optional; default false

Parameters
internalsf:boolean

if true include the .SF file inside the signature

setLazyback to summary
public void setLazy(final boolean lazy)

flag to control whether the presence of a signature file means a JAR is signed; optional, default false

Parameters
lazy:boolean

flag to control whether the presence of a signature

setPreserveLastModifiedback to summary
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:boolean

if true preserve the last modified time

setSectionsonlyback to summary
public void setSectionsonly(final boolean sectionsonly)

flag to compute hash of entire manifest; optional, default false

Parameters
sectionsonly:boolean

flag to compute hash of entire manifest

setSigAlgback to summary
public void setSigAlg(String sigAlg)

Signature Algorithm; optional

Parameters
sigAlg:String

the signature algorithm

setSigfileback to summary
public void setSigfile(final String sigfile)

name of .SF/.DSA file; optional

Parameters
sigfile:String

the name of the .SF/.DSA file

setSignedjarback to summary
public void setSignedjar(final File signedjar)

name of signed JAR file; optional

Parameters
signedjar:File

the name of the signed jar file

setTsacertback to summary
public void setTsacert(String tsacert)

set the alias in the keystore of the TSA to use;

Parameters
tsacert:String

the cert alias.

setTSADigestAlgback to summary
public void setTSADigestAlg(String digestAlg)

TSA Digest Algorithm; optional

Parameters
digestAlg:String

the tsa digest algorithm

Since
Ant 1.10.2
setTsaproxyhostback to summary
public void setTsaproxyhost(String tsaproxyhost)
Parameters
tsaproxyhost:String

the proxy host to be used when connecting to the TSA.

Since
Ant 1.9.5
setTsaproxyportback to summary
public void setTsaproxyport(String tsaproxyport)
Parameters
tsaproxyport:String

the proxy port to be used when connecting to the TSA.

Since
Ant 1.9.5
setTsaurlback to summary
public void setTsaurl(String tsaurl)
Parameters
tsaurl:String

the tsa url.

Since
Ant 1.7
signOneJarback to summary
private void signOneJar(File jarSource, File jarTarget) throws BuildException

Sign one jar.

The signing only takes place if isUpToDate(File, File) indicates that it is needed.

Parameters
jarSource:File

source to sign

jarTarget:File

target; may be null

Exceptions
BuildException:
if something goes wrong