Package org.apache.tools.ant.util

Examples of org.apache.tools.ant.util.FileNameMapper


            throw new BuildException(
                "must not specify both type and classname attribute");
        }

        try {
            FileNameMapper m = getImplementationClass().newInstance();
            final Project p = getProject();
            if (p != null) {
                p.setProjectReference(m);
            }
            m.setFrom(from);
            m.setTo(to);

            return m;
        } catch (BuildException be) {
            throw be;
        } catch (Throwable t) {
View Full Code Here


     * @param files    A list of files to copy.
     * @param dirs     A list of directories to copy.
     */
    protected void scan(File fromDir, File toDir, String[] files,
                        String[] dirs) {
        FileNameMapper mapper = getMapper();
        buildMap(fromDir, toDir, files, mapper, fileCopyMap);

        if (includeEmpty) {
            buildMap(fromDir, toDir, dirs, mapper, dirCopyMap);
        }
View Full Code Here

    /**
     * returns the mapper to use based on nested elements or the
     * flatten attribute.
     */
    private FileNameMapper getMapper() {
        FileNameMapper mapper = null;
        if (mapperElement != null) {
            mapper = mapperElement.getImplementation();
        } else if (flatten) {
            mapper = new FlatFileNameMapper();
        } else {
View Full Code Here

        return cachedColl;
    }

    private Collection<Resource> getCollection() {
        Collection<Resource> collected = new ArrayList<Resource>();
        FileNameMapper m =
            mapper != null ? mapper.getImplementation() : new IdentityMapper();
        for (Resource r : nested) {
            if (enableMultipleMappings) {
                String[] n = m.mapFileName(r.getName());
                if (n != null) {
                    for (int i = 0; i < n.length; i++) {
                        collected.add(new MappedResource(r,
                                                         new MergingMapper(n[i]))
                                      );
View Full Code Here

    protected String[] scanDir(String[] files) {
        ArrayList result = new ArrayList();
        String[] newFiles = files;

        SourceFileScanner scanner = new SourceFileScanner(this);
        FileNameMapper mapper = new GlobPatternMapper();
        mapper.setFrom("*.class");
        mapper.setTo("*__Proxy.java");
        newFiles = scanner.restrict(files, _base, _sourceBase, mapper);

        for (int i = 0; i < newFiles.length; i++) {
            String classname = newFiles[i].replace(File.separatorChar, '.');
            classname = classname.substring(0, classname.lastIndexOf(".class"));
View Full Code Here

            //the rest of the method treats single jar like
            //a nested path with one file

            Path sources = createUnifiedSourcePath();
            //set up our mapping policy
            FileNameMapper destMapper;
            if (hasMapper) {
                destMapper = mapper;
            } else {
                //no mapper? use the identity policy
                destMapper = new IdentityMapper();
            }


            //at this point the paths are set up with lists of files,
            //and the mapper is ready to map from source dirs to dest files
            //now we iterate through every JAR giving source and dest names
            // deal with the paths
            for (Resource r : sources) {
                FileResource fr = ResourceUtils
                    .asFileResource(r.as(FileProvider.class));

                //calculate our destination directory; it is either the destDir
                //attribute, or the base dir of the fileset (for in situ updates)
                File toDir = hasDestDir ? destDir : fr.getBaseDir();

                //determine the destination filename via the mapper
                String[] destFilenames = destMapper.mapFileName(fr.getName());
                if (destFilenames == null || destFilenames.length != 1) {
                    //we only like simple mappers.
                    throw new BuildException(ERROR_BAD_MAP + fr.getFile());
                }
                File destFile = new File(toDir, destFilenames[0]);
View Full Code Here

     * @param dir       the destination directory
     */
    protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
        log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
        ZipFile zf = null;
        FileNameMapper mapper = getMapper();
        if (!srcF.exists()) {
            throw new BuildException("Unable to expand "
                    + srcF
                    + " as the file does not exist",
                    getLocation());
View Full Code Here

    /**
     * get a mapper for a file
     * @return a filenamemapper for a file
     */
    protected FileNameMapper getMapper() {
        FileNameMapper mapper = null;
        if (mapperElement != null) {
            mapper = mapperElement.getImplementation();
        } else {
            mapper = new IdentityMapper();
        }
View Full Code Here

            File dest = destDir != null ? destDir : srcDir;

            int writeCount = 0;

            // build mapper
            final FileNameMapper mapper;
            if (mapperElement==null){
                mapper = new IdentityMapper();
            } else {
                mapper = mapperElement.getImplementation();
            }
View Full Code Here

        Mapper.MapperType mt = new Mapper.MapperType();
        mt.setValue("glob");
        m3.setType(mt);
        m3.setFrom("*.java");
        m3.setTo("*.class");
        FileNameMapper fmm = m1.getImplementation();
        assertTrue("should be glob", fmm instanceof GlobPatternMapper);
        String[] result = fmm.mapFileName("a.java");
        assertEquals("a.java should match", 1, result.length);
        assertEquals("a.class", result[0]);
    }
View Full Code Here

TOP

Related Classes of org.apache.tools.ant.util.FileNameMapper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.