/** * Get the file represented by this FileResource, ensuring it is not null. * @return the not-null File. * @throws BuildException if file is null. */ protected File getNotNullFile() { if (getFile() == null) { throw new BuildException("file attribute is null!"); } dieOnCircularReference(); return getFile(); }
/** * Adds a basedir as nested element. * @param r basedir */ public void addConfiguredBaseDir(final FileResource r) { if (isReference()) { throw noChildrenAllowed(); } baseDirs.add(r.getFile()); }
/** * Compare another Object to this FileResource for equality. * @param another the other Object to compare. * @return true if another is a FileResource representing the same file. */ @Override public boolean equals(Object another) { if (this == another) { return true; } if (isReference()) { return getCheckedRef().equals(another); } if (another == null || !(another.getClass().equals(getClass()))) { return false; } FileResource otherfr = (FileResource) another; return getFile() == null ? otherfr.getFile() == null : getFile().equals(otherfr.getFile()) && getName().equals(otherfr.getName()); }
FileResource fr = (FileResource) r; String baseDir = fr.getBaseDir().getAbsolutePath(); String file = fr.getFile().getAbsolutePath(); file = file.substring(baseDir.length(), file.length()); String[] parts = file.split("/");
/** * Returns the list of files corresponding to the resource collection * * @param resources - A list of {@link ResourceCollection} * @return the list of files corresponding to the resource collection * @throws BuildException */ private List<String> getFiles(List<ResourceCollection> resources) throws BuildException { List<String> files= Lists.newArrayList(); for (ResourceCollection rc : resources) { for (Resource o : rc) { if (o instanceof FileResource) { FileResource fr = ((FileResource) o); if (fr.isDirectory()) { throw new BuildException("Directory based FileResources are not supported."); } if (! fr.isExists()) { log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE); } files.add(fr.getFile().getAbsolutePath()); } else { log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE); } } } return files; }
/** * Returns the list of files corresponding to the resource collection * * @param resources - A list of {@link ResourceCollection} * @return the list of files corresponding to the resource collection * @throws BuildException */ private List<String> getFiles(List<ResourceCollection> resources) throws BuildException { List<String> files = Lists.newArrayList(); for (ResourceCollection rc : resources) { for (Resource o : rc) { if (o instanceof FileResource) { FileResource fr = ((FileResource) o); if (fr.isDirectory()) { throw new BuildException("Directory based FileResources are not supported."); } if (!fr.isExists()) { log("'" + fr.toLongString() + "' does not exist", Project.MSG_VERBOSE); } files.add(fr.getFile().getAbsolutePath()); } else { log("Unsupported Resource type: " + o.toString(), Project.MSG_VERBOSE); } } } return files; }
List<String> files = basedirToFilesMap.computeIfAbsent(base, k -> new Vector<>()); if (base == Copy.NULL_FILE_PLACEHOLDER) { files.add(r.getFile().getAbsolutePath()); } else { files.add(r.getName());
/** * Styles all existing resources. * * @param stylesheet style sheet to use * @since Ant 1.7 */ private void processResources(final Resource stylesheet) { for (final Resource r : resources) { if (!r.isExists()) { continue; } File base = baseDir; String name = r.getName(); final FileProvider fp = r.as(FileProvider.class); if (fp != null) { final FileResource f = ResourceUtils.asFileResource(fp); base = f.getBaseDir(); if (base == null) { name = f.getFile().getAbsolutePath(); } } process(base, name, destDir, stylesheet); } }
/** * Create a new resource that matches a relative or absolute path. * If the current instance has a compatible baseDir attribute, it is copied. * @param path relative/absolute path to a resource * @return a new resource of type FileResource * @throws BuildException if desired * @since Ant1.8 */ @Override public Resource getResource(String path) { File newfile = FILE_UTILS.resolveFile(getFile(), path); FileResource fileResource = new FileResource(newfile); if (FILE_UTILS.isLeadingPath(getBaseDir(), newfile)) { fileResource.setBaseDir(getBaseDir()); } return fileResource; }
File file = fileResource.getFile(); String filename = fileResource.getName(); File basedir = fileResource.getBaseDir();
baseDir = getKeyFile(fr.getBaseDir()); if (fr.getBaseDir() == null) { name = fr.getFile().getAbsolutePath();
/** * Get the file represented by this FileResource. * @return the File. */ @Override public File getFile() { if (isReference()) { return getCheckedRef().getFile(); } dieOnCircularReference(); synchronized (this) { if (file == null) { //try to resolve file set via basedir/name property setters: File d = getBaseDir(); String n = super.getName(); if (n != null) { setFile(FILE_UTILS.resolveFile(d, n)); } } } return file; }
base = fr.getBaseDir(); if (base == null) { name = fr.getFile().getAbsolutePath();
/** * Compare this FileResource to another Resource. * @param another the other Resource against which to compare. * @return a negative integer, zero, or a positive integer as this FileResource * is less than, equal to, or greater than the specified Resource. */ @Override public int compareTo(Resource another) { if (isReference()) { return getCheckedRef().compareTo(another); } if (this.equals(another)) { return 0; } FileProvider otherFP = another.as(FileProvider.class); if (otherFP != null) { File f = getFile(); if (f == null) { return -1; } File of = otherFP.getFile(); if (of == null) { return 1; } int compareFiles = f.compareTo(of); return compareFiles != 0 ? compareFiles : getName().compareTo(another.getName()); } return super.compareTo(another); }
public boolean isComposite() { if (resource instanceof FileResource) { final FileResource fileResource = (FileResource) resource; final File file = fileResource.getFile(); return DocumentImplUtils.isZip(file); } return false; }
@SuppressWarnings("unchecked") private List<File> getJarsFromFileSet() { final List<File> jars = new ArrayList<File>(); final Iterator<Resource> iterator = fileSet.iterator(); while(iterator.hasNext()) { jars.add(((FileResource) iterator.next()).getFile()); } return jars; }
/** * Translates an Ant resource collection into the file list format that * the compiler expects. */ private List<SourceFile> findJavaScriptFiles(ResourceCollection rc) { List<SourceFile> files = new ArrayList<>(); Iterator<Resource> iter = rc.iterator(); while (iter.hasNext()) { FileResource fr = (FileResource) iter.next(); // Construct path to file, relative to current working directory. java.nio.file.Path path = Paths.get("").toAbsolutePath().relativize(fr.getFile().toPath()); files.add(SourceFile.fromPath(path, Charset.forName(encoding))); } return files; }
public String getName() { // TODO: reconsider names String result = null; if (resource instanceof FileResource) { final FileResource fileResource = (FileResource) resource; final File file = fileResource.getFile(); result = DocumentImplUtils.toName(file); } else { result = resource.getName(); } return result; }