use of org.apache.tools.ant.types.FilterChain in project ant by apache.
the class ResourceListTest method testEmptyElementWithReference.
@Test
public void testEmptyElementWithReference() {
ResourceList rl = new ResourceList();
rl.setEncoding("foo");
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with encoding attribute set.");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", be.getMessage());
}
rl = new ResourceList();
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.setEncoding("foo");
fail("Can set encoding in ResourceList that is a reference");
} catch (BuildException be) {
assertEquals("You must not specify more than one attribute when using refid", be.getMessage());
}
rl = new ResourceList();
rl.add(new FileResource(buildRule.getProject(), "."));
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with nested resource collection.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid", be.getMessage());
}
rl = new ResourceList();
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.add(new FileResource(buildRule.getProject(), "."));
fail("Can add reference to ResourceList with nested resource collection.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid", be.getMessage());
}
rl = new ResourceList();
rl.addFilterChain(new FilterChain());
try {
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
fail("Can add reference to ResourceList with nested filter chain.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid", be.getMessage());
}
rl = new ResourceList();
rl.setRefid(new Reference(buildRule.getProject(), "dummyref"));
try {
rl.addFilterChain(new FilterChain());
fail("Can add reference to ResourceList with nested filter chain.");
} catch (BuildException be) {
assertEquals("You must not specify nested elements when using refid", be.getMessage());
}
}
use of org.apache.tools.ant.types.FilterChain in project ant by apache.
the class ChainReaderHelper method getAssembledReader.
/**
* Assemble the reader
* @return the assembled reader
* @exception BuildException if an error occurs
*/
public ChainReader getAssembledReader() throws BuildException {
if (primaryReader == null) {
throw new BuildException("primaryReader must not be null.");
}
Reader instream = primaryReader;
final List<AntClassLoader> classLoadersToCleanUp = new ArrayList<>();
final List<Object> finalFilters = filterChains.stream().map(FilterChain::getFilterReaders).flatMap(Collection::stream).collect(Collectors.toList());
if (!finalFilters.isEmpty()) {
boolean success = false;
try {
for (Object o : finalFilters) {
if (o instanceof AntFilterReader) {
instream = expandReader((AntFilterReader) o, instream, classLoadersToCleanUp);
} else if (o instanceof ChainableReader) {
setProjectOnObject(o);
instream = ((ChainableReader) o).chain(instream);
setProjectOnObject(instream);
}
}
success = true;
} finally {
if (!success && !classLoadersToCleanUp.isEmpty()) {
cleanUpClassLoaders(classLoadersToCleanUp);
}
}
}
return new ChainReader(instream, classLoadersToCleanUp);
}
Aggregations