/** * Returns list of mapped files, that should be transformed. Files can by specified via attributes * (srcFile, srcDir) or resources (FileSet, FileList, DirSet, etc). Mapped file represents input * and output file for transformation. * * @return list of mapped files */ public List<MappedFile> getMappedFiles() { mappedFiles.clear(); // one src file if (getSrcFile() != null) { addMappedFile(getSrcFile()); } if (getSrcDir() != null) { addMappedFile(getSrcDir()); } Iterator element = resources.iterator(); while (element.hasNext()) { ResourceCollection rc = (ResourceCollection) element.next(); if (rc instanceof FileSet && rc.isFilesystemOnly()) { FileSet fs = (FileSet) rc; File fromDir = fs.getDir(getProject()); DirectoryScanner ds; try { ds = fs.getDirectoryScanner(getProject()); } catch (BuildException ex) { log("Could not scan directory " + fromDir, ex, Project.MSG_ERR); continue; } for (String f : ds.getIncludedFiles()) { addMappedFile(new File(fromDir + System.getProperty("file.separator") + f), fromDir); } } else { if (!rc.isFilesystemOnly()) { log("Only filesystem resources are supported", Project.MSG_WARN); continue; } Iterator rcIt = rc.iterator(); while (rcIt.hasNext()) { Resource r = (Resource) rcIt.next(); if (!r.isExists()) { log("Could not find resource " + r.toLongString(), Project.MSG_VERBOSE); continue; } if (r instanceof FileResource) { FileResource fr = (FileResource) r; addMappedFile(fr.getFile(), fr.getBaseDir()); } else { log( "Only file resources are supported (" + r.getClass().getSimpleName() + " found)", Project.MSG_WARN); continue; } } } } return mappedFiles; }
/** * Protected method for simplyfied addinng of mapped files * * @param file file to add * @param baseDir base directory for file */ protected void addMappedFile(File file, File baseDir) { if (file.isFile()) { if (baseDir == null) { baseDir = file.getParentFile(); } MappedFile mappedFile = new MappedFile(); mappedFile.setFrom(file); String filename = file.getName(); String[] names = getMapper().mapFileName(filename); // we don't use original filename if no mapping is available if (names == null || names.length == 0) { return; } File newFile = new File(file.getParent() + System.getProperty("file.separator") + names[0]); if (getDestDir() != null) { try { newFile = new File( newFile .getCanonicalPath() .replace(baseDir.getCanonicalPath(), getDestDir().getCanonicalPath())); } catch (IOException ex) { log("Couldn't map file", ex, Project.MSG_WARN); return; } } mappedFile.setTo(newFile); mappedFiles.add(mappedFile); } else if (file.isDirectory()) { if (baseDir == null) { baseDir = file; } DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(file); ds.scan(); for (String fileName : ds.getIncludedFiles()) { addMappedFile(new File(file + System.getProperty("file.separator") + fileName), baseDir); } } }
/** * Return the list of files from this DirectoryScanner that should be included on the command line * - i.e. only those that are newer than the corresponding target files. */ protected String[] getFiles(File baseDir, DirectoryScanner ds) { SourceFileScanner sfs = new SourceFileScanner(this); return sfs.restrict(ds.getIncludedFiles(), baseDir, destDir, mapper); }
/** * Adds the contents of this class path element to the given class path. * * @param classPath the class path to be extended. * @param output specifies whether this is an output entry or not. */ public void appendClassPathEntriesTo(ClassPath classPath, boolean output) { File baseDir = getProject().getBaseDir(); String[] fileNames; if (isReference()) { // Get the referenced path or file set. Object referencedObject = getCheckedRef(DataType.class, DataType.class.getName()); if (referencedObject instanceof Path) { Path path = (Path) referencedObject; // Get the names of the files in the referenced path. fileNames = path.list(); } else if (referencedObject instanceof AbstractFileSet) { AbstractFileSet fileSet = (AbstractFileSet) referencedObject; // Get the names of the existing input files in the referenced file set. DirectoryScanner scanner = fileSet.getDirectoryScanner(getProject()); baseDir = scanner.getBasedir(); fileNames = scanner.getIncludedFiles(); } else { throw new BuildException( "The refid attribute doesn't point to a <path> element or a <fileset> element"); } } else { // Get the names of the files in this path. fileNames = list(); } if (output) { if (fileNames.length != 1) { throw new BuildException( "The <outjar> element must specify exactly one file or directory [" + fileNames.length + "]"); } } // else // { // if (fileNames.length < 1) // { // throw new BuildException("The <injar> element must specify at least one file or // directory"); // } // } for (int index = 0; index < fileNames.length; index++) { // Create a new class path entry, with the proper file name and // any filters. String fileName = fileNames[index]; File file = new File(fileName); ClassPathEntry entry = new ClassPathEntry(file.isAbsolute() ? file : new File(baseDir, fileName), output); entry.setFilter(ListUtil.commaSeparatedList(filter)); entry.setApkFilter(ListUtil.commaSeparatedList(apkFilter)); entry.setJarFilter(ListUtil.commaSeparatedList(jarFilter)); entry.setAarFilter(ListUtil.commaSeparatedList(aarFilter)); entry.setWarFilter(ListUtil.commaSeparatedList(warFilter)); entry.setEarFilter(ListUtil.commaSeparatedList(earFilter)); entry.setZipFilter(ListUtil.commaSeparatedList(zipFilter)); // Add it to the class path. classPath.add(entry); } }