Package org.apache.tools.ant.util

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


        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"));
View Full Code Here


    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"));
View Full Code Here

                    if (slash > -1) {
                        path = path.substring(slash + 1);
                    }
                    dest = new File(destination, path);
                } else {
                    FileNameMapper mapper = mapperElement.getImplementation();
                    String[] d = mapper.mapFileName(source.toString());
                    if (d == null) {
                        log("skipping " + r + " - mapper can't handle it",
                            Project.MSG_WARN);
                        continue;
                    } else if (d.length == 0) {
View Full Code Here

        if (srcDir.equals(destDir) && extension == null && mapper == null) {
            throw new BuildException("The ext attribute or a mapper must be set if"
                                     + " src and dest dirs are the same.");
        }

        FileNameMapper m = null;
        if (mapper == null) {
            if (extension == null) {
                m = new IdentityMapper();
            } else {
                m = new ExtMapper();
            }
        } else {
            m = mapper.getImplementation();
        }

        scanner = getDirectoryScanner(srcDir);
        files = scanner.getIncludedFiles();
        SourceFileScanner sfs = new SourceFileScanner(this);
        files = sfs.restrict(files, srcDir, destDir, m);
        int count = files.length;
        if (count == 0) {
            return;
        }
        String message = "Converting " + count + " file"
            + (count != 1 ? "s" : "") + " from ";
        log(message + srcDir + " to " + destDir);
        for (int i = 0; i < files.length; i++) {
            convert(files[i], m.mapFileName(files[i])[0]);
        }
    }
View Full Code Here

            StringBuffer rslt = new StringBuffer();

            ResourceCollection resources = isPreserveDuplicates() ? (ResourceCollection) path : new Union(path);
            List ret = new ArrayList();
            FileNameMapper mapperImpl = mapper == null ? new IdentityMapper() : mapper.getImplementation();
            for (Resource r : resources) {
                String[] mapped = mapperImpl.mapFileName(String.valueOf(r));
                for (int m = 0; mapped != null && m < mapped.length; ++m) {
                    ret.add(mapped[m]);
                }
            }
            boolean first = true;
View Full Code Here

    private void expandStream(String name, InputStream stream, File dir)
        throws IOException {
        ArchiveInputStream is = null;
        try {
            FileNameMapper mapper = getMapper();
            log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
            is = factory.getArchiveStream(new BufferedInputStream(stream),
                                          getEncoding());
            boolean empty = true;
            ArchiveEntry ent = null;
View Full Code Here

        CacheManager cacheMgr = getIvyInstance().getCacheManager(cache);
        for (int i = 0; i < confs.length; i++) {
            File reportFile = cacheMgr.getConfigurationResolveReportInCache(resolveId, confs[i]);
            xslt.setIncludes(reportFile.getName());

            FileNameMapper reportMapper = new GlobPatternMapper();
            reportMapper.setFrom(reportFile.getName());
            reportMapper.setTo(IvyPatternHelper.substitute(outputpattern, organisation, module,
                "", "", "", ext, confs[i]));
            mapper.add(reportMapper);
        }
        xslt.setStyle(style);
View Full Code Here

                log("Skipping " + inF + " it is a directory.",
                    Project.MSG_VERBOSE);
                return;
            }

            FileNameMapper mapper;
            if (mapperElement != null) {
                mapper = mapperElement.getImplementation();
            } else {
                mapper = new StyleMapper();
            }

            String[] outFileName = mapper.mapFileName(xmlFile);
            if (outFileName == null || outFileName.length == 0) {
                log("Skipping " + inFile + " it cannot get mapped to output.",
                    Project.MSG_VERBOSE);
                return;
            } else if (outFileName == null || outFileName.length > 1) {
View Full Code Here

      CacheManager cacheMgr = getIvyInstance().getCacheManager(cache);
        for (int i = 0; i < confs.length; i++) {
          File reportFile = cacheMgr.getConfigurationResolveReportInCache(_resolveId, confs[i]);
          xslt.setIncludes(reportFile.getName());
         
          FileNameMapper reportMapper = new GlobPatternMapper();
      reportMapper.setFrom(reportFile.getName());
          reportMapper.setTo(IvyPatternHelper.substitute(_outputpattern, organisation, module, "", "", "", ext, confs[i]));
          mapper.add(reportMapper);
        }
        xslt.setStyle(style);
       
        XSLTProcess.Param param = xslt.createParam();
View Full Code Here

    // overridden in order to take advantage of ZipFile
    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

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.