use of org.apache.tools.ant.types.Mapper in project ant by apache.
the class Copy method buildMap.
/**
* Create a map of resources to copy.
*
* @param fromResources The source resources.
* @param toDir the destination directory.
* @param mapper a <code>FileNameMapper</code> value.
* @return a map of source resource to array of destination files.
* @since Ant 1.7
*/
protected Map<Resource, String[]> buildMap(final Resource[] fromResources, final File toDir, final FileNameMapper mapper) {
final Map<Resource, String[]> map = new HashMap<>();
Resource[] toCopy;
if (forceOverwrite) {
final List<Resource> v = new ArrayList<>();
for (Resource rc : fromResources) {
if (mapper.mapFileName(rc.getName()) != null) {
v.add(rc);
}
}
toCopy = v.toArray(new Resource[v.size()]);
} else {
toCopy = ResourceUtils.selectOutOfDateSources(this, fromResources, mapper, name -> new FileResource(toDir, name), granularity);
}
for (Resource rc : toCopy) {
final String[] mappedFiles = mapper.mapFileName(rc.getName());
if (mappedFiles == null || mappedFiles.length == 0) {
throw new BuildException("Can't copy a resource without a" + " name if the mapper doesn't" + " provide one.");
}
if (!enableMultipleMappings) {
map.put(rc, new String[] { new File(toDir, mappedFiles[0]).getAbsolutePath() });
} else {
// reuse the array created by the mapper
for (int k = 0; k < mappedFiles.length; k++) {
mappedFiles[k] = new File(toDir, mappedFiles[k]).getAbsolutePath();
}
map.put(rc, mappedFiles);
}
}
return map;
}
use of org.apache.tools.ant.types.Mapper in project ant by apache.
the class XSLTProcess method add.
/**
* Adds a nested filenamemapper.
* @param fileNameMapper the mapper to add
* @exception BuildException if more than one mapper is defined
* @since Ant 1.7.0
*/
public void add(final FileNameMapper fileNameMapper) throws BuildException {
final Mapper mapper = new Mapper(getProject());
mapper.add(fileNameMapper);
addMapper(mapper);
}
use of org.apache.tools.ant.types.Mapper in project ant by apache.
the class MappedResourceCollection method createMapper.
/**
* Define the mapper to map source to destination files.
* @return a mapper to be configured.
* @exception BuildException if more than one mapper is defined.
*/
public Mapper createMapper() throws BuildException {
if (isReference()) {
throw noChildrenAllowed();
}
if (mapper != null) {
throw new BuildException("Cannot define more than one mapper", getLocation());
}
setChecked(false);
mapper = new Mapper(getProject());
cachedColl = null;
return mapper;
}
use of org.apache.tools.ant.types.Mapper in project ant by apache.
the class PresentSelectorTest method testSelectionBehaviour.
/**
* Tests to make sure that the selector is selecting files correctly.
*/
@Test
public void testSelectionBehaviour() {
PresentSelector s;
String results;
Mapper m;
Mapper.MapperType identity = new Mapper.MapperType();
identity.setValue("identity");
Mapper.MapperType glob = new Mapper.MapperType();
glob.setValue("glob");
Mapper.MapperType merge = new Mapper.MapperType();
merge.setValue("merge");
Mapper.MapperType flatten = new Mapper.MapperType();
flatten.setValue("flatten");
File beddir = selectorRule.getBeddir();
s = new PresentSelector();
s.setTargetdir(beddir);
results = selectorRule.selectionString(s);
assertEquals("TTTTTTTTTTTT", results);
s = new PresentSelector();
s.setTargetdir(beddir);
m = s.createMapper();
m.setType(identity);
results = selectorRule.selectionString(s);
assertEquals("TTTTTTTTTTTT", results);
s = new PresentSelector();
File subdir = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/expected");
s.setTargetdir(subdir);
m = s.createMapper();
m.setType(flatten);
results = selectorRule.selectionString(s);
assertEquals("TTTTTTTTTTTF", results);
s = new PresentSelector();
s.setTargetdir(beddir);
m = s.createMapper();
m.setType(merge);
m.setTo("asf-logo.gif.gz");
results = selectorRule.selectionString(s);
assertEquals("TTTTTTTTTTTT", results);
s = new PresentSelector();
subdir = new File(beddir, "tar/bz2");
s.setTargetdir(subdir);
m = s.createMapper();
m.setType(glob);
m.setFrom("*.bz2");
m.setTo("*.tar.bz2");
results = selectorRule.selectionString(s);
assertEquals("FFTFFFFFFFFF", results);
s = new PresentSelector();
subdir = new File(selectorRule.getOutputDir(), "selectortest2");
s.setTargetdir(subdir);
results = selectorRule.selectionString(s);
assertEquals("TTTFFTTTTTTT", results);
results = selectorRule.selectionString(s);
assertEquals("TTTFFTTTTTTT", results);
}
use of org.apache.tools.ant.types.Mapper in project ant by apache.
the class DependSelectorTest method testMergeMapper2.
@Test
public void testMergeMapper2() {
DependSelector s = new DependSelector();
s.setTargetdir(selectorRule.getBeddir());
Mapper.MapperType merge = new Mapper.MapperType();
merge.setValue("merge");
Mapper m = s.createMapper();
m.setType(merge);
m.setTo("asf-logo.gif.bz2");
String results = selectorRule.selectionString(s);
assertEquals("TTFTTTTTTTTT", results);
}
Aggregations