Search in sources :

Example 1 with RedirectorElement

use of org.apache.tools.ant.types.RedirectorElement in project ant by apache.

the class VerifyJar method execute.

/**
 * verify our jar files
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {
    // 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();
        for (Resource r : sources) {
            FileProvider fr = r.as(FileProvider.class);
            verifyOneJar(fr.getFile());
        }
    } finally {
        endExecution();
    }
}
Also used : Path(org.apache.tools.ant.types.Path) RedirectorElement(org.apache.tools.ant.types.RedirectorElement) FilterChain(org.apache.tools.ant.types.FilterChain) FileProvider(org.apache.tools.ant.types.resources.FileProvider) Resource(org.apache.tools.ant.types.Resource) BuildException(org.apache.tools.ant.BuildException)

Example 2 with RedirectorElement

use of org.apache.tools.ant.types.RedirectorElement in project ant by apache.

the class AbstractJarSignerTask method createRedirector.

/**
 * Create the redirector to use, if any.
 *
 * @return a configured RedirectorElement.
 */
private RedirectorElement createRedirector() {
    RedirectorElement result = new RedirectorElement();
    if (storepass != null) {
        StringBuilder input = new StringBuilder(storepass).append('\n');
        if (keypass != null) {
            input.append(keypass).append('\n');
        }
        result.setInputString(input.toString());
        result.setLogInputString(false);
        // Try to avoid showing password prompts on log output, as they would be confusing.
        LineContainsRegExp filter = new LineContainsRegExp();
        RegularExpression rx = new RegularExpression();
        // TODO only handles English locale, not ja or zh_CN
        rx.setPattern("^(Enter Passphrase for keystore: |Enter key password for .+: )$");
        filter.addConfiguredRegexp(rx);
        filter.setNegate(true);
        result.createErrorFilterChain().addLineContainsRegExp(filter);
    }
    return result;
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression) RedirectorElement(org.apache.tools.ant.types.RedirectorElement) LineContainsRegExp(org.apache.tools.ant.filters.LineContainsRegExp)

Aggregations

RedirectorElement (org.apache.tools.ant.types.RedirectorElement)2 BuildException (org.apache.tools.ant.BuildException)1 LineContainsRegExp (org.apache.tools.ant.filters.LineContainsRegExp)1 FilterChain (org.apache.tools.ant.types.FilterChain)1 Path (org.apache.tools.ant.types.Path)1 RegularExpression (org.apache.tools.ant.types.RegularExpression)1 Resource (org.apache.tools.ant.types.Resource)1 FileProvider (org.apache.tools.ant.types.resources.FileProvider)1