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;
}
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();
}
}
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);
}
}
}
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);
}
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);
}
}
Aggregations