org.apache.tools.ant.taskdefsClass SignJar
- java.lang.Object
- org.apache.tools.ant.ProjectComponent
- org.apache.tools.ant.Task
- org.apache.tools.ant.taskdefs.AbstractJarSignerTask
- org.apache.tools.ant.taskdefs.SignJar
- All Implemented Interfaces:
- java.lang.Cloneable
public class SignJar extends AbstractJarSignerTaskSigns 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
Field Summary
Fields Modifier and Type Field and Description protected java.io.FiledestDirthe output directory when using paths.static java.lang.StringERROR_BAD_MAPerror string for unit test verification: "Cannot map source file to anything sensible: "static java.lang.StringERROR_MAPPER_WITHOUT_DESTerror string for unit test verification: "The destDir attribute is required if a mapper is set"static java.lang.StringERROR_NO_ALIASerror string for unit test verification: "alias attribute must be set"static java.lang.StringERROR_NO_STOREPASSerror string for unit test verification: "storepass attribute must be set"static java.lang.StringERROR_SIGNEDJAR_AND_PATHSerror string for unit test verification "You cannot specify the signed JAR when using paths or filesets"static java.lang.StringERROR_TODIR_AND_SIGNEDJARerror string for unit test verification: "\'destdir\' and \'signedjar\' cannot both be set"static java.lang.StringERROR_TOO_MANY_MAPPERSerror string for unit test verification: "Too many mappers"protected booleaninternalsfflag for internal sf signingprotected booleanlazyWhether to assume a jar which has an appropriate .SF file in is already signed.protected booleansectionsonlysign sections only?protected java.lang.Stringsigfilename to a signature fileprotected java.io.Filesignedjarname of a single jarprotected java.lang.Stringtsacertalias for the TSA in the keystoreprotected java.lang.StringtsaproxyhostProxy host to be used when connecting to TSA serverprotected java.lang.StringtsaproxyportProxy port to be used when connecting to TSA serverprotected java.lang.StringtsaurlURL for a tsa; null implies no tsa support
Fields inherited from class org.apache.tools.ant.taskdefs.AbstractJarSignerTask
alias, ERROR_NO_SOURCE, filesets, jar, JARSIGNER_COMMAND, keypass, keystore, maxMemory, storepass, storetype, strict, verbose
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
Constructor Summary
Constructors Constructor and Description SignJar()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(FileNameMapper newMapper)add a mapper to determine file naming policy.voidexecute()sign the jar(s)java.lang.StringgetDigestAlg()Digest Algorithm; optionalFileNameMappergetMapper()get the active mapper; may be nulljava.lang.StringgetSigAlg()Signature Algorithm; optionaljava.lang.StringgetTsacert()get the -tsacert optionjava.lang.StringgetTsaproxyhost()Get the proxy host to be used when connecting to the TSA urljava.lang.StringgetTsaproxyport()Get the proxy host to be used when connecting to the TSA urljava.lang.StringgetTsaurl()get the -tsaurl urlbooleanisForce()Should the task force signing of a jar even it is already signed?protected booleanisSigned(java.io.File file)test for a file being signed, by looking for a signature in the META-INF directory with our alias/sigfile.protected booleanisUpToDate(java.io.File jarFile, java.io.File signedjarFile)Compare a jar file with its corresponding signed jar.voidsetDestDir(java.io.File destDir)Optionally sets the output directory to be used.voidsetDigestAlg(java.lang.String digestAlg)Digest Algorithm; optionalvoidsetForce(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 falsevoidsetLazy(boolean lazy)flag to control whether the presence of a signature file means a JAR is signed; optional, default falsevoidsetPreserveLastModified(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 falsevoidsetSigAlg(java.lang.String sigAlg)Signature Algorithm; optionalvoidsetSigfile(java.lang.String sigfile)name of .SF/.DSA file; optionalvoidsetSignedjar(java.io.File signedjar)name of signed JAR file; optionalvoidsetTsacert(java.lang.String tsacert)set the alias in the keystore of the TSA to use;voidsetTsaproxyhost(java.lang.String tsaproxyhost)voidsetTsaproxyport(java.lang.String tsaproxyport)voidsetTsaurl(java.lang.String tsaurl)
Methods inherited from class org.apache.tools.ant.taskdefs.AbstractJarSignerTask
addArg, addArgument, addFileset, addSysproperty, addValue, beginExecution, bindToKeystore, createJarSigner, createPath, createUnifiedSourcePath, createUnifiedSources, declareSysProperty, endExecution, getRedirector, hasResources, setAlias, setCommonOptions, setExecutable, setJar, setKeypass, setKeystore, setMaxmemory, setProviderArg, setProviderClass, setProviderName, setStorepass, setStoretype, setStrict, setVerbose
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation, setProject
Field Detail
sigfile
protected java.lang.String sigfilename to a signature file
signedjar
protected java.io.File signedjarname of a single jar
internalsf
protected boolean internalsfflag for internal sf signing
sectionsonly
protected boolean sectionsonlysign sections only?
lazy
protected boolean lazyWhether to assume a jar which has an appropriate .SF file in is already signed.
destDir
protected java.io.File destDirthe output directory when using paths.
tsaurl
protected java.lang.String tsaurlURL for a tsa; null implies no tsa support
tsaproxyhost
protected java.lang.String tsaproxyhostProxy host to be used when connecting to TSA server
tsaproxyport
protected java.lang.String tsaproxyportProxy port to be used when connecting to TSA server
tsacert
protected java.lang.String tsacertalias for the TSA in the keystore
ERROR_TODIR_AND_SIGNEDJAR
public static final java.lang.String ERROR_TODIR_AND_SIGNEDJARerror string for unit test verification: "\'destdir\' and \'signedjar\' cannot both be set"
- See Also:
- Constant Field Values
ERROR_TOO_MANY_MAPPERS
public static final java.lang.String ERROR_TOO_MANY_MAPPERSerror string for unit test verification: "Too many mappers"
- See Also:
- Constant Field Values
ERROR_SIGNEDJAR_AND_PATHS
public static final java.lang.String ERROR_SIGNEDJAR_AND_PATHSerror string for unit test verification "You cannot specify the signed JAR when using paths or filesets"
- See Also:
- Constant Field Values
ERROR_BAD_MAP
public static final java.lang.String ERROR_BAD_MAPerror string for unit test verification: "Cannot map source file to anything sensible: "
- See Also:
- Constant Field Values
ERROR_MAPPER_WITHOUT_DEST
public static final java.lang.String ERROR_MAPPER_WITHOUT_DESTerror string for unit test verification: "The destDir attribute is required if a mapper is set"
- See Also:
- Constant Field Values
ERROR_NO_ALIAS
public static final java.lang.String ERROR_NO_ALIASerror string for unit test verification: "alias attribute must be set"
- See Also:
- Constant Field Values
ERROR_NO_STOREPASS
public static final java.lang.String ERROR_NO_STOREPASSerror string for unit test verification: "storepass attribute must be set"
- See Also:
- Constant Field Values
Method Detail
setSigfile
public void setSigfile(java.lang.String sigfile)name of .SF/.DSA file; optional
- Parameters:
sigfile- the name of the .SF/.DSA file
setSignedjar
public void setSignedjar(java.io.File signedjar)name of signed JAR file; optional
- Parameters:
signedjar- the name of the signed jar file
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
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
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
setDestDir
public void setDestDir(java.io.File destDir)Optionally sets the output directory to be used.
- Parameters:
destDir- the directory in which to place signed jars- Since:
- Ant 1.7
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
getMapper
public FileNameMapper getMapper()get the active mapper; may be null
- Returns:
- mapper or null
- Since:
- Ant 1.7
getTsaurl
public java.lang.String getTsaurl()get the -tsaurl url
- Returns:
- url or null
- Since:
- Ant 1.7
setTsaurl
public void setTsaurl(java.lang.String tsaurl)
- Parameters:
tsaurl- the tsa url.- Since:
- Ant 1.7
getTsaproxyhost
public java.lang.String getTsaproxyhost()Get the proxy host to be used when connecting to the TSA url
- Returns:
- url or null
- Since:
- Ant 1.9.5
setTsaproxyhost
public void setTsaproxyhost(java.lang.String tsaproxyhost)
- Parameters:
tsaproxyhost- the proxy host to be used when connecting to the TSA.- Since:
- Ant 1.9.5
getTsaproxyport
public java.lang.String getTsaproxyport()Get the proxy host to be used when connecting to the TSA url
- Returns:
- url or null
- Since:
- Ant 1.9.5
setTsaproxyport
public void setTsaproxyport(java.lang.String tsaproxyport)
- Parameters:
tsaproxyport- the proxy port to be used when connecting to the TSA.- Since:
- Ant 1.9.5
getTsacert
public java.lang.String getTsacert()get the -tsacert option
- Returns:
- a certificate alias or null
- Since:
- Ant 1.7
setTsacert
public void setTsacert(java.lang.String tsacert)set the alias in the keystore of the TSA to use;
- Parameters:
tsacert- the cert alias.
setForce
public void setForce(boolean b)Whether to force signing of a jar even it is already signed.
- Parameters:
b- boolean- Since:
- Ant 1.8.0
isForce
public boolean isForce()Should the task force signing of a jar even it is already signed?
- Returns:
- boolean
- Since:
- Ant 1.8.0
setSigAlg
public void setSigAlg(java.lang.String sigAlg)Signature Algorithm; optional
- Parameters:
sigAlg- the signature algorithm
getSigAlg
public java.lang.String getSigAlg()Signature Algorithm; optional
- Returns:
- String
setDigestAlg
public void setDigestAlg(java.lang.String digestAlg)Digest Algorithm; optional
- Parameters:
digestAlg- the digest algorithm
getDigestAlg
public java.lang.String getDigestAlg()Digest Algorithm; optional
- Returns:
- String
execute
public void execute() throws BuildExceptionsign the jar(s)
- Overrides:
executein classTask- Throws:
BuildException- on errors
isUpToDate
protected boolean isUpToDate(java.io.File jarFile, java.io.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- the unsigned jar filesignedjarFile- the result signed jar file- Returns:
- true if the signedjarFile is considered up to date
isSigned
protected boolean isSigned(java.io.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.isSigned(File, String)
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