use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class MappedResourceCollection method getCollection.
private Collection<Resource> getCollection() {
FileNameMapper m = mapper == null ? new IdentityMapper() : mapper.getImplementation();
Stream<MappedResource> stream;
if (enableMultipleMappings) {
stream = nested.stream().flatMap(r -> Stream.of(m.mapFileName(r.getName())).filter(Objects::nonNull).map(MergingMapper::new).map(mm -> new MappedResource(r, mm)));
} else {
stream = nested.stream().map(r -> new MappedResource(r, m));
}
return stream.collect(Collectors.toList());
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class MapperTest method testNested.
@Test
public void testNested() {
Mapper mapper1 = new Mapper(project);
Mapper.MapperType mt = new Mapper.MapperType();
mt.setValue("glob");
mapper1.setType(mt);
mapper1.setFrom("from*");
mapper1.setTo("to*");
// mix element types
FileNameMapper mapper2 = new FlatFileNameMapper();
FileNameMapper mapper3 = new MergingMapper();
mapper3.setTo("mergefile");
Mapper container = new Mapper(project);
container.addConfiguredMapper(mapper1);
container.add(mapper2);
container.add(mapper3);
FileNameMapper fileNameMapper = container.getImplementation();
String[] targets = fileNameMapper.mapFileName("fromfilename");
assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 3, targets.length);
List list = Arrays.asList(targets);
assertTrue("cannot find expected target \"tofilename\"", list.contains("tofilename"));
assertTrue("cannot find expected target \"fromfilename\"", list.contains("fromfilename"));
assertTrue("cannot find expected target \"mergefile\"", list.contains("mergefile"));
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class MapperTest method testChained.
@Test
public void testChained() {
// a --> b --> c --- def
// \-- ghi
FileNameMapper mapperAB = new GlobPatternMapper();
mapperAB.setFrom("a");
mapperAB.setTo("b");
FileNameMapper mapperBC = new GlobPatternMapper();
mapperBC.setFrom("b");
mapperBC.setTo("c");
// implicit composite
Mapper mapperCX = new Mapper(project);
FileNameMapper mapperDEF = new GlobPatternMapper();
mapperDEF.setFrom("c");
mapperDEF.setTo("def");
FileNameMapper mapperGHI = new GlobPatternMapper();
mapperGHI.setFrom("c");
mapperGHI.setTo("ghi");
mapperCX.add(mapperDEF);
mapperCX.add(mapperGHI);
Mapper chained = new Mapper(project);
chained.setClassname(ChainedMapper.class.getName());
chained.add(mapperAB);
chained.add(mapperBC);
chained.addConfiguredMapper(mapperCX);
FileNameMapper fileNameMapper = chained.getImplementation();
String[] targets = fileNameMapper.mapFileName("a");
assertNotNull("no filenames mapped", targets);
assertEquals("wrong number of filenames mapped", 2, targets.length);
List list = Arrays.asList(targets);
assertTrue("cannot find expected target \"def\"", list.contains("def"));
assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
targets = fileNameMapper.mapFileName("z");
assertNull(targets);
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class Untar method expandStream.
/**
* @since Ant 1.7
*/
private void expandStream(String name, InputStream stream, File dir) throws IOException {
try (TarInputStream tis = new TarInputStream(compression.decompress(name, new BufferedInputStream(stream)), getEncoding())) {
log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
boolean empty = true;
FileNameMapper mapper = getMapper();
TarEntry te;
while ((te = tis.getNextEntry()) != null) {
empty = false;
extractFile(FileUtils.getFileUtils(), null, dir, tis, te.getName(), te.getModTime(), te.isDirectory(), mapper);
}
if (empty && getFailOnEmptyArchive()) {
throw new BuildException("archive '%s' is empty", name);
}
log("expand complete", Project.MSG_VERBOSE);
}
}
use of org.apache.tools.ant.util.FileNameMapper in project ant by apache.
the class UpToDate method scanDir.
/**
* Scan a directory for files to check for "up to date"ness
* @param srcDir the directory
* @param files the files to scan for
* @return true if the files are up to date
*/
protected boolean scanDir(File srcDir, String[] files) {
SourceFileScanner sfs = new SourceFileScanner(this);
FileNameMapper mapper = getMapper();
File dir = srcDir;
if (mapperElement == null) {
dir = null;
}
return sfs.restrict(files, srcDir, dir, mapper).length == 0;
}
Aggregations