/** * Normalize a source location * * @param source the source location to be normalized. * * @return the normalized source location. */ private static File normalizeSource(File source) { if (source != null) { try { source = FILE_UTILS.normalize(source.getAbsolutePath()); } catch (BuildException e) { // relative path } } return source; }
/** * Compares two filenames. * * <p>Unlike java.io.File#equals this method will try to compare * the absolute paths and "normalize" the filenames * before comparing them.</p> * * @param f1 the file whose name is to be compared. * @param f2 the other file whose name is to be compared. * * @return true if the file are for the same file. * * @since Ant 1.5.3 */ public boolean fileNameEquals(File f1, File f2) { return normalize(f1.getAbsolutePath()).getAbsolutePath().equals( normalize(f2.getAbsolutePath()).getAbsolutePath()); }
/** * Are the two File instances pointing to the same object on the * file system? * * @param f1 File * @param f2 File * @return boolean * @throws IOException if file name canonicalization fails * @since Ant 1.8.2 */ public boolean areSame(File f1, File f2) throws IOException { if (f1 == null && f2 == null) { return true; } if (f1 == null || f2 == null) { return false; } File f1Normalized = normalize(f1.getAbsolutePath()); File f2Normalized = normalize(f2.getAbsolutePath()); return f1Normalized.equals(f2Normalized) || f1Normalized.getCanonicalFile().equals(f2Normalized .getCanonicalFile()); }
/** * Look for an executable in a given directory. * * @return null if the executable cannot be found. */ private static File findInDir(String dirName, String commandName) { File dir = FILE_UTILS.normalize(dirName); File executable = null; if (dir.exists()) { executable = new File(dir, addExtension(commandName)); if (!executable.exists()) { executable = null; } } return executable; }
/** * Removes a leading path from a second path. * * <p>This method uses {@link #normalize} under the covers and * does not resolve symbolic links.</p> * * @param leading The leading path, must not be null, must be absolute. * @param path The path to remove from, must not be null, must be absolute. * * @return path's normalized absolute if it doesn't start with * leading; path's path with leading's path removed otherwise. * * @since Ant 1.5 */ public String removeLeadingPath(File leading, File path) { String l = normalize(leading.getAbsolutePath()).getAbsolutePath(); String p = normalize(path.getAbsolutePath()).getAbsolutePath(); if (l.equals(p)) { return ""; } // ensure that l ends with a / // so we never think /foo was a parent directory of /foobar if (!l.endsWith(File.separator)) { l += File.separator; } return (p.startsWith(l)) ? p.substring(l.length()) : p; }
localFile = normalize(localFile.getAbsolutePath()); if (!localFile.exists()) { return false;
/** * Set the base directory for the project, checking that * the given file exists and is a directory. * * @param baseDir The project base directory. * Must not be <code>null</code>. * @exception BuildException if the specified file doesn't exist or * isn't a directory. */ public void setBaseDir(File baseDir) throws BuildException { baseDir = FILE_UTILS.normalize(baseDir.getAbsolutePath()); if (!baseDir.exists()) { throw new BuildException("Basedir " + baseDir.getAbsolutePath() + " does not exist"); } if (!baseDir.isDirectory()) { throw new BuildException("Basedir " + baseDir.getAbsolutePath() + " is not a directory"); } this.baseDir = baseDir; setPropertyInternal(MagicNames.PROJECT_BASEDIR, this.baseDir.getPath()); final String msg = "Project base dir set to: " + this.baseDir; log(msg, MSG_VERBOSE); }
/** * Constructs a file path from a <code>file:</code> URI. * * <p>Will be an absolute path if the given URI is absolute.</p> * * <p>Swallows '%' that are not followed by two characters, * doesn't deal with non-ASCII characters.</p> * * @param uri the URI designating a file in the local filesystem. * @return the local file system path for the file. * @since Ant 1.6 */ public String fromURI(String uri) { synchronized (cacheFromUriLock) { if (uri.equals(cacheFromUriRequest)) { return cacheFromUriResponse; } String path = Locator.fromURI(uri); String ret = isAbsolutePath(path) ? normalize(path).getAbsolutePath() : path; cacheFromUriRequest = uri; cacheFromUriResponse = ret; return ret; } }
String path = normalize(f.getAbsolutePath()).getPath(); String name = f.getName(); boolean isAbsolute = path.charAt(0) == File.separatorChar;
/** * Get the string representation of this Resource. * @return this FileResource formatted as a String. */ @Override public String toString() { if (isReference()) { return getCheckedRef().toString(); } if (file == null) { return "(unbound file resource)"; } String absolutePath = file.getAbsolutePath(); return FILE_UTILS.normalize(absolutePath).getAbsolutePath(); }
return normalize(filename);
/** * From <code>base</code> traverse the filesystem in order to find * a file that matches the given name. * * @param base base File (dir). * @param cs whether to scan case-sensitively. * @return File object that points to the file in question or null. */ public File findFile(File base, final boolean cs) { String[] tokens = tokenizedPath; if (FileUtils.isAbsolutePath(path)) { if (base == null) { String[] s = FILE_UTILS.dissect(path); base = new File(s[0]); tokens = SelectorUtils.tokenizePathAsArray(s[1]); } else { File f = FILE_UTILS.normalize(path); String s = FILE_UTILS.removeLeadingPath(base, f); if (s.equals(f.getAbsolutePath())) { //removing base from path yields no change; path //not child of base return null; } tokens = SelectorUtils.tokenizePathAsArray(s); } } return findFile(base, tokens, cs); }
FileUtils.getFileUtils().normalize(buildFile.getAbsolutePath());
private Resource getFileAttributeResource() { // Paths are relative to the build file they're imported from, // *not* the current directory (same as entity includes). if (file != null) { if (isExistingAbsoluteFile(file)) { return new FileResource(FILE_UTILS.normalize(file)); } File buildFile = new File(getLocation().getFileName()).getAbsoluteFile(); if (buildFile.exists()) { File buildFileParent = new File(buildFile.getParent()); File importedFile = FILE_UTILS.resolveFile(buildFileParent, file); return new FileResource(importedFile); } // maybe this import tasks is inside an imported URL? try { URL buildFileURL = new URL(getLocation().getFileName()); URL importedFile = new URL(buildFileURL, file); return new URLResource(importedFile); } catch (MalformedURLException ex) { log(ex.toString(), Project.MSG_VERBOSE); } throw new BuildException("failed to resolve %s relative to %s", file, getLocation().getFileName()); } return null; }
buildFile = FILE_UTILS.normalize(buildFile.getAbsolutePath()); context.setBuildFile(buildFile); buildFileName = buildFile.toString();
private void includeClasses() throws BuildException { if (classpathFileList == null) { // Initialize the classpath once. if (classpath == null) throw new BuildException("autoinclude set, but classpath attribute not set"); String[] classpathList = classpath.list(); classpathFileList = new File[classpathList.length]; classpathZipList = new ZipFile[classpathList.length]; for (int i = 0; i < classpathList.length; ++i) classpathFileList[i] = fileUtils.normalize(classpathList[i]); } processJarXml(); includeTypeSpecificClasses(); }