Search in sources :

Example 1 with FilterChain

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

the class Copy method createFilterChain.

/**
 * Add a FilterChain.
 * @return a filter chain object.
 */
public FilterChain createFilterChain() {
    final FilterChain filterChain = new FilterChain();
    filterChains.addElement(filterChain);
    return filterChain;
}
Also used : FilterChain(org.apache.tools.ant.types.FilterChain)

Example 2 with FilterChain

use of org.apache.tools.ant.types.FilterChain 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 3 with FilterChain

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

the class FixCRLF method processFile.

private void processFile(String file) throws BuildException {
    File srcFile = new File(srcDir, file);
    long lastModified = srcFile.lastModified();
    File destD = destDir == null ? srcDir : destDir;
    if (fcv == null) {
        FilterChain fc = new FilterChain();
        fc.add(filter);
        fcv = new Vector<>(1);
        fcv.add(fc);
    }
    File tmpFile = FILE_UTILS.createTempFile("fixcrlf", "", null, true, true);
    try {
        FILE_UTILS.copyFile(srcFile, tmpFile, null, fcv, true, false, encoding, outputEncoding == null ? encoding : outputEncoding, getProject());
        File destFile = new File(destD, file);
        boolean destIsWrong = true;
        if (destFile.exists()) {
            // Compare the destination with the temp file
            log("destFile " + destFile + " exists", Project.MSG_DEBUG);
            destIsWrong = !FILE_UTILS.contentEquals(destFile, tmpFile);
            log(destFile + (destIsWrong ? " is being written" : " is not written, as the contents are identical"), Project.MSG_DEBUG);
        }
        if (destIsWrong) {
            FILE_UTILS.rename(tmpFile, destFile);
            if (preserveLastModified) {
                log("preserved lastModified for " + destFile, Project.MSG_DEBUG);
                FILE_UTILS.setFileLastModified(destFile, lastModified);
            }
        }
    } catch (IOException e) {
        throw new BuildException("error running fixcrlf on file " + srcFile, e);
    } finally {
        if (tmpFile != null && tmpFile.exists()) {
            FILE_UTILS.tryHardToDelete(tmpFile);
        }
    }
}
Also used : FilterChain(org.apache.tools.ant.types.FilterChain) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException) File(java.io.File)

Example 4 with FilterChain

use of org.apache.tools.ant.types.FilterChain in project ant-ivy by apache.

the class IvyExtractFromSources method configureConcat.

private void configureConcat() {
    concat.setProject(getProject());
    concat.setTaskName(getTaskName());
    FilterChain filterChain = new FilterChain();
    LineContainsRegExp lcre = new LineContainsRegExp();
    RegularExpression regexp = new RegularExpression();
    regexp.setPattern("^import .+;");
    lcre.addConfiguredRegexp(regexp);
    filterChain.add(lcre);
    TokenFilter tf = new TokenFilter();
    TokenFilter.ReplaceRegex rre = new TokenFilter.ReplaceRegex();
    rre.setPattern("import (.+);.*");
    rre.setReplace("\\1");
    tf.add(rre);
    filterChain.add(tf);
    concat.addFilterChain(filterChain);
}
Also used : RegularExpression(org.apache.tools.ant.types.RegularExpression) LineContainsRegExp(org.apache.tools.ant.filters.LineContainsRegExp) FilterChain(org.apache.tools.ant.types.FilterChain) TokenFilter(org.apache.tools.ant.filters.TokenFilter)

Example 5 with FilterChain

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

the class FilterMapper method mapFileName.

/**
 * Return the result of the filters on the sourcefilename.
 * @param sourceFileName the filename to map
 * @return  a one-element array of converted filenames, or null if
 *          the filterchain returns an empty string.
 */
@Override
public String[] mapFileName(String sourceFileName) {
    if (sourceFileName == null) {
        return null;
    }
    try {
        Reader stringReader = new StringReader(sourceFileName);
        ChainReaderHelper helper = new ChainReaderHelper();
        helper.setBufferSize(BUFFER_SIZE);
        helper.setPrimaryReader(stringReader);
        helper.setProject(getProject());
        Vector<FilterChain> filterChains = new Vector<>();
        filterChains.add(this);
        helper.setFilterChains(filterChains);
        String result = FileUtils.safeReadFully(helper.getAssembledReader());
        if (result.isEmpty()) {
            return null;
        }
        return new String[] { result };
    } catch (BuildException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new BuildException(ex);
    }
}
Also used : FilterChain(org.apache.tools.ant.types.FilterChain) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) ChainReaderHelper(org.apache.tools.ant.filters.util.ChainReaderHelper) BuildException(org.apache.tools.ant.BuildException) Vector(java.util.Vector) UnsupportedAttributeException(org.apache.tools.ant.UnsupportedAttributeException) BuildException(org.apache.tools.ant.BuildException)

Aggregations

FilterChain (org.apache.tools.ant.types.FilterChain)7 BuildException (org.apache.tools.ant.BuildException)5 Reader (java.io.Reader)2 File (java.io.File)1 FilterReader (java.io.FilterReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 Vector (java.util.Vector)1 AntClassLoader (org.apache.tools.ant.AntClassLoader)1 UnsupportedAttributeException (org.apache.tools.ant.UnsupportedAttributeException)1 BaseFilterReader (org.apache.tools.ant.filters.BaseFilterReader)1 ChainableReader (org.apache.tools.ant.filters.ChainableReader)1 LineContainsRegExp (org.apache.tools.ant.filters.LineContainsRegExp)1 TokenFilter (org.apache.tools.ant.filters.TokenFilter)1 ChainReaderHelper (org.apache.tools.ant.filters.util.ChainReaderHelper)1 AntFilterReader (org.apache.tools.ant.types.AntFilterReader)1 Path (org.apache.tools.ant.types.Path)1 RedirectorElement (org.apache.tools.ant.types.RedirectorElement)1 Reference (org.apache.tools.ant.types.Reference)1