FileDocCategorySizeDatePackage
AbstractJarSignerTask.javaAPI DocApache Ant 1.7010581Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

AbstractJarSignerTask

public abstract class AbstractJarSignerTask extends org.apache.tools.ant.Task
This is factored out from {@link SignJar}; a base class that can be used for both signing and verifying JAR files using jarsigner

Fields Summary
protected File
jar
The name of the jar file.
protected String
alias
The alias of signer.
protected String
keystore
The url or path of keystore file.
protected String
storepass
password for the store
protected String
storetype
type of store,-storetype param
protected String
keypass
password for the key in the store
protected boolean
verbose
verbose output
protected String
maxMemory
The maximum amount of memory to use for Jar signer
protected Vector
filesets
the filesets of the jars to sign
protected static final String
JARSIGNER_COMMAND
name of JDK program we are looking for
private org.apache.tools.ant.types.RedirectorElement
redirector
redirector used to talk to the jarsigner program
private org.apache.tools.ant.types.Environment
sysProperties
Java declarations -J-Dname=value
public static final String
ERROR_NO_SOURCE
error string for unit test verification: {@value}
private org.apache.tools.ant.types.Path
path
Path holding all non-filesets of filesystem resources we want to sign.
Constructors Summary
Methods Summary
public voidaddFileset(org.apache.tools.ant.types.FileSet set)
Adds a set of files to sign

param
set a set of files to sign
since
Ant 1.4

        filesets.addElement(set);
    
public voidaddSysproperty(Environment.Variable sysp)
Add a system property.

param
sysp system property.

        sysProperties.addVariable(sysp);
    
protected voidaddValue(ExecTask cmd, java.lang.String value)
add a value argument to a command

param
cmd command to manipulate
param
value value to add

        cmd.createArg().setValue(value);
    
protected voidbeginExecution()
init processing logic; this is retained through our execution(s)


        redirector = createRedirector();
    
protected voidbindToKeystore(ExecTask cmd)
bind to a keystore if the attributes are there

param
cmd command to configure

        if (null != keystore) {
            // is the keystore a file
            addValue(cmd, "-keystore");
            String loc;
            File keystoreFile = getProject().resolveFile(keystore);
            if (keystoreFile.exists()) {
                loc = keystoreFile.getPath();
            } else {
                // must be a URL - just pass as is
                loc = keystore;
            }
            addValue(cmd, loc);
        }
        if (null != storetype) {
            addValue(cmd, "-storetype");
            addValue(cmd, storetype);
        }
    
protected ExecTaskcreateJarSigner()
create the jarsigner executable task

return
a task set up with the executable of jarsigner, failonerror=true and bound to our redirector

        final ExecTask cmd = new ExecTask(this);
        cmd.setExecutable(JavaEnvUtils.getJdkExecutable(JARSIGNER_COMMAND));
        cmd.setTaskType(JARSIGNER_COMMAND);
        cmd.setFailonerror(true);
        cmd.addConfiguredRedirector(redirector);
        return cmd;
    
public org.apache.tools.ant.types.PathcreatePath()
Adds a path of files to sign.

return
a path of files to sign.
since
Ant 1.7

        if (path == null) {
            path = new Path(getProject());
        }
        return path.createPath();
    
private org.apache.tools.ant.types.RedirectorElementcreateRedirector()
Create the redirector to use, if any.

return
a configured RedirectorElement.

        RedirectorElement result = new RedirectorElement();
        if (storepass != null) {
            StringBuffer input = new StringBuffer(storepass).append('\n");
            if (keypass != null) {
                input.append(keypass).append('\n");
            }
            result.setInputString(input.toString());
            result.setLogInputString(false);
        }
        return result;
    
protected org.apache.tools.ant.types.PathcreateUnifiedSourcePath()
clone our path and add all explicitly specified FileSets as well, patch in the jar attribute as a new fileset if it is defined.

return
a path that contains all files to sign
since
Ant 1.7

        Path p = path == null ? new Path(getProject()) : (Path) path.clone();
        Vector s = createUnifiedSources();
        Enumeration e = s.elements();
        while (e.hasMoreElements()) {
            p.add((FileSet) e.nextElement());
        }
        return p;
    
protected java.util.VectorcreateUnifiedSources()
clone our filesets vector, and patch in the jar attribute as a new fileset, if is defined

return
a vector of FileSet instances

        Vector sources = (Vector) filesets.clone();
        if (jar != null) {
            //we create a fileset with the source file.
            //this lets us combine our logic for handling output directories,
            //mapping etc.
            FileSet sourceJar = new FileSet();
            sourceJar.setProject(getProject());
            sourceJar.setFile(jar);
            sourceJar.setDir(jar.getParentFile());
            sources.add(sourceJar);
        }
        return sources;
    
protected voiddeclareSysProperty(ExecTask cmd, Environment.Variable property)

param
cmd command to configure
param
property property to set
throws
BuildException if the property is not correctly defined.

        addValue(cmd, "-J-D" + property.getContent());
    
protected voidendExecution()
any cleanup logic

        redirector = null;
    
public org.apache.tools.ant.types.RedirectorElementgetRedirector()
get the redirector. Non-null between invocations of {@link #beginExecution()} and {@link #endExecution()}

return
a redirector or null

        return redirector;
    
protected booleanhasResources()
Has either a path or a fileset been specified?

return
true if a path or fileset has been specified.
since
Ant 1.7

        return path != null || filesets.size() > 0;
    
public voidsetAlias(java.lang.String alias)
the alias to sign under; required

param
alias the alias to sign under

        this.alias = alias;
    
protected voidsetCommonOptions(ExecTask cmd)
these are options common to signing and verifying

param
cmd command to configure

        if (maxMemory != null) {
            addValue(cmd, "-J-Xmx" + maxMemory);
        }

        if (verbose) {
            addValue(cmd, "-verbose");
        }

        //now patch in all system properties
        Vector props = sysProperties.getVariablesVector();
        Enumeration e = props.elements();
        while (e.hasMoreElements()) {
            Environment.Variable variable = (Environment.Variable) e.nextElement();
            declareSysProperty(cmd, variable);
        }
    
public voidsetJar(java.io.File jar)
the jar file to sign; required

param
jar the jar file to sign

        this.jar = jar;
    
public voidsetKeypass(java.lang.String keypass)
password for private key (if different); optional

param
keypass the password for the key (if different)

        this.keypass = keypass;
    
public voidsetKeystore(java.lang.String keystore)
keystore location; required

param
keystore the keystore location

        this.keystore = keystore;
    
public voidsetMaxmemory(java.lang.String max)
Set the maximum memory to be used by the jarsigner process

param
max a string indicating the maximum memory according to the JVM conventions (e.g. 128m is 128 Megabytes)


                                                 
        
        maxMemory = max;
    
public voidsetStorepass(java.lang.String storepass)
password for keystore integrity; required

param
storepass the password for the keystore

        this.storepass = storepass;
    
public voidsetStoretype(java.lang.String storetype)
keystore type; optional

param
storetype the keystore type

        this.storetype = storetype;
    
public voidsetVerbose(boolean verbose)
Enable verbose output when signing ; optional: default false

param
verbose if true enable verbose output

        this.verbose = verbose;