Search in sources :

Example 6 with IdentityMapper

use of org.apache.tools.ant.util.IdentityMapper in project ant by apache.

the class Image method execute.

/**
 * Executes the Task.
 * @throws BuildException on error.
 */
@Override
public void execute() throws BuildException {
    validateAttributes();
    try {
        File dest = (destDir != null) ? destDir : srcDir;
        int writeCount = 0;
        // build mapper
        final FileNameMapper mapper = mapperElement == null ? new IdentityMapper() : mapperElement.getImplementation();
        // deal with specified srcDir
        if (srcDir != null) {
            writeCount += processDir(srcDir, super.getDirectoryScanner(srcDir).getIncludedFiles(), dest, mapper);
        }
        // deal with the filesets
        for (FileSet fs : filesets) {
            writeCount += processDir(fs.getDir(getProject()), fs.getDirectoryScanner(getProject()).getIncludedFiles(), dest, mapper);
        }
        if (writeCount > 0) {
            log("Processed " + writeCount + (writeCount == 1 ? " image." : " images."));
        }
    } catch (Exception err) {
        log(StringUtils.getStackTrace(err), Project.MSG_ERR);
        throw new BuildException(err.getMessage());
    }
}
Also used : IdentityMapper(org.apache.tools.ant.util.IdentityMapper) FileSet(org.apache.tools.ant.types.FileSet) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) IOException(java.io.IOException) BuildException(org.apache.tools.ant.BuildException)

Example 7 with IdentityMapper

use of org.apache.tools.ant.util.IdentityMapper 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());
}
Also used : DataType(org.apache.tools.ant.types.DataType) Mapper(org.apache.tools.ant.types.Mapper) Resource(org.apache.tools.ant.types.Resource) Iterator(java.util.Iterator) Collection(java.util.Collection) BuildException(org.apache.tools.ant.BuildException) ResourceCollection(org.apache.tools.ant.types.ResourceCollection) FileNameMapper(org.apache.tools.ant.util.FileNameMapper) IdentityMapper(org.apache.tools.ant.util.IdentityMapper) Collectors(java.util.stream.Collectors) File(java.io.File) Stack(java.util.Stack) Objects(java.util.Objects) MergingMapper(org.apache.tools.ant.util.MergingMapper) Stream(java.util.stream.Stream) Project(org.apache.tools.ant.Project) Reference(org.apache.tools.ant.types.Reference) IdentityMapper(org.apache.tools.ant.util.IdentityMapper) Objects(java.util.Objects) FileNameMapper(org.apache.tools.ant.util.FileNameMapper)

Aggregations

BuildException (org.apache.tools.ant.BuildException)7 IdentityMapper (org.apache.tools.ant.util.IdentityMapper)7 FileNameMapper (org.apache.tools.ant.util.FileNameMapper)6 Resource (org.apache.tools.ant.types.Resource)5 File (java.io.File)4 FileResource (org.apache.tools.ant.types.resources.FileResource)3 ResourceCollection (org.apache.tools.ant.types.ResourceCollection)2 ArchiveResource (org.apache.tools.ant.types.resources.ArchiveResource)2 FileProvider (org.apache.tools.ant.types.resources.FileProvider)2 ZipResource (org.apache.tools.ant.types.resources.ZipResource)2 MergingMapper (org.apache.tools.ant.util.MergingMapper)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Objects (java.util.Objects)1 Stack (java.util.Stack)1 StringTokenizer (java.util.StringTokenizer)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1