FileDocCategorySizeDatePackage
VerifyJar.javaAPI DocApache Ant 1.706180Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.taskdefs

VerifyJar

public class VerifyJar extends AbstractJarSignerTask
JAR verification task. For every JAR passed in, we fork jarsigner to verify that it is correctly signed. This is more rigorous than just checking for the existence of a signature; the entire certification chain is tested
since
Ant 1.7

Fields Summary
public static final String
ERROR_NO_FILE
no file message {@value}
private static final String
VERIFIED_TEXT
The string we look for in the text to indicate direct verification
private boolean
certificates
certification flag
private BufferingOutputFilter
outputCache
public static final String
ERROR_NO_VERIFY
Error output if there is a failure to verify the jar.
Constructors Summary
Methods Summary
public voidexecute()
verify our jar files

throws
BuildException on error.

        //validation logic
        final boolean hasJar = jar != null;

        if (!hasJar && !hasResources()) {
            throw new BuildException(ERROR_NO_SOURCE);
        }

        beginExecution();

        //patch the redirector to save output to a file
        RedirectorElement redirector = getRedirector();
        redirector.setAlwaysLog(true);
        FilterChain outputFilterChain = redirector.createOutputFilterChain();
        outputFilterChain.add(outputCache);

        try {
            Path sources = createUnifiedSourcePath();
            Iterator iter = sources.iterator();
            while (iter.hasNext()) {
                FileResource fr = (FileResource) iter.next();
                verifyOneJar(fr.getFile());
            }

        } finally {
            endExecution();
        }

    
public voidsetCertificates(boolean certificates)
Ask for certificate information to be printed

param
certificates if true print certificates.


                      
        
        this.certificates = certificates;
    
private voidverifyOneJar(java.io.File jar)
verify a JAR.

param
jar the jar to verify.
throws
BuildException if the file could not be verified

        if (!jar.exists()) {
            throw new BuildException(ERROR_NO_FILE + jar);
        }
        final ExecTask cmd = createJarSigner();

        setCommonOptions(cmd);
        bindToKeystore(cmd);

        //verify special operations
        addValue(cmd, "-verify");

        if (certificates) {
            addValue(cmd, "-certs");
        }

        //JAR  is required
        addValue(cmd, jar.getPath());

        log("Verifying JAR: " + jar.getAbsolutePath());
        outputCache.clear();
        BuildException ex = null;
        try {
            cmd.execute();
        } catch (BuildException e) {
            ex = e;
        }
        String results = outputCache.toString();
        //deal with jdk1.4.2 bug:
        if (ex != null) {
            if (results.indexOf("zip file closed") >= 0) {
                log("You are running " + JARSIGNER_COMMAND + " against a JVM with"
                    + " a known bug that manifests as an IllegalStateException.",
                    Project.MSG_WARN);
            } else {
                throw ex;
            }
        }
        if (results.indexOf(VERIFIED_TEXT) < 0) {
            throw new BuildException(ERROR_NO_VERIFY + jar);
        }