/*
(non-Javadoc)

@see com.github.maven_nar.NarLayout#getBinDirectory(java.io.File,
java.lang.String)
502820
@Override
  public final File
      getBinDirectory(final File baseDir, final String artifactId, final String version, final String aol) {
    final File dir = new File(baseDir, this.fileLayout.getBinDirectory(aol));
    return dir;
  }
1004591
@Override
    public File findFile(RepositoryPointerImpl location) {
        // Assume that instanceIds are good and check fileId only.
        File result = getChild(location.getFileId());
        return isFile(result) ? result : null;
    }
939995
public static boolean tryDeleteFileOrDirectory(File file) {
    try {
      deleteFileOrDirectory(file);
      return true;
    } catch (Exception e) {
      logger.warn("Failed to delete file. file = " + file.getAbsolutePath(), e);
      return false;
    }
  }
166478
public File getFirstExistingDirectory(String param) {
    final List<String> directoryStrings = getStringList(param);
    for (final String dirName : directoryStrings) {
      final File dir = new File(dirName.trim());
      if (dir.isDirectory()) {
        return dir;
      }
    }

    throw new ParameterConversionException(fullString(param), directoryStrings.toString(),
        "No provided path is an existing directory");
  }
86350
@Override
    Resource getResource(final String relativePath) {
        final File resourceFile = new File(classpathEltDir, relativePath);
        return resourceFile.canRead() && resourceFile.isFile() ? newResource(relativePath, resourceFile) : null;
    }
1130151
@Override
    public File getServerLogDirectory() {
        String logLocation = TrConfigurator.getLogLocation();
        if (logLocation != null) {
            return new File(logLocation);
        } else {
            return null;
        }
    }
922843
public static ArrayList<File> getFilesInDirectoryTree(File file, String includeMask) {
		return getContentsInDirectoryTree(file, includeMask, true, false);
	}
841996
public File getJarDirectory() {
        if (jarDirectory == null) {
            this.jarDirectory = new File(jarPath).getAbsoluteFile().getParentFile();
        }
        return jarDirectory;
    }
178104
public static File getProjectDirectory(final File currentDir)
	{
		final String projectPath = PathFinder.getAbsolutePath(currentDir, true);
		final File projectFile = new File(projectPath);
		return projectFile;
	}
921981
static PathFileObject createDirectoryPathFileObject(JavacPathFileManager fileManager,
            final Path path, final Path dir) {
        return new PathFileObject(fileManager, path) {
            @Override
            String inferBinaryName(Iterable<? extends Path> paths) {
                return toBinaryName(dir.relativize(path));
            }
        };
    }
970724
static String getVersionForFile(final File file)  {
        try {
            final PluginMeta pluginMeta = loadMeta(file);
            return pluginMeta.getVersion();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
43282
public static File getFileFromDirectoryInClassPath(String fileName, String classPath) {

		Collection<String> paths = StringSupport.split(classPath, ";:", false);

		for(String singlePath : paths) {
			File dir = new File(singlePath);
			if (dir.isDirectory()) {
				File file = new File(singlePath + '/' + fileName);
				if (file.exists()) {
					return file;
				}
			}
		}
		return null;
	}
930277
public static String directory(String file) {
      if (StringUtils.isNullOrBlank(file)) {
         return StringUtils.EMPTY;
      }
      file = StringUtils.trim(file);
      int separator = indexOfLastSeparator(file);
      int extension = indexOfFileExtension(file);

      if (extension == -1) {
         return addTrailingSlashIfNeeded(file);
      } else if (separator == -1) {
         return StringUtils.EMPTY;
      }

      return directory(file.substring(0, separator + 1));
   }
221130
protected PathResource getFileResource(final Path file, final String path, final Path symlinkBase, String normalizedFile) throws IOException {
        if (this.caseSensitive) {
            if (symlinkBase != null) {
                String relative = symlinkBase.relativize(file.normalize()).toString();
                String fileResolved = file.toRealPath().toString();
                String symlinkBaseResolved = symlinkBase.toRealPath().toString();
                if (!fileResolved.startsWith(symlinkBaseResolved)) {
                    log.tracef("Rejected path resource %s from path resource manager with base %s, as the case did not match actual case of %s", path, base, normalizedFile);
                    return null;
                }
                String compare = fileResolved.substring(symlinkBaseResolved.length());
                if(compare.startsWith(fileSystem.getSeparator())) {
                    compare = compare.substring(fileSystem.getSeparator().length());
                }
                if(relative.startsWith(fileSystem.getSeparator())) {
                    relative = relative.substring(fileSystem.getSeparator().length());
                }
                if (relative.equals(compare)) {
                    log.tracef("Found path resource %s from path resource manager with base %s", path, base);
                    return new PathResource(file, this, path, eTagFunction.generate(file));
                }
                log.tracef("Rejected path resource %s from path resource manager with base %s, as the case did not match actual case of %s", path, base, normalizedFile);
                return null;
            } else if (isFileSameCase(file, normalizedFile)) {
                log.tracef("Found path resource %s from path resource manager with base %s", path, base);
                return new PathResource(file, this, path, eTagFunction.generate(file));
            } else {
                log.tracef("Rejected path resource %s from path resource manager with base %s, as the case did not match actual case of %s", path, base, normalizedFile);
                return null;
            }
        } else {
            log.tracef("Found path resource %s from path resource manager with base %s", path, base);
            return new PathResource(file, this, path, eTagFunction.generate(file));
        }
    }
1145097
@Pure
	public static File getUserHomeDirectory() throws FileNotFoundException {
		final String userHome = System.getProperty("user.home"); //$NON-NLS-1$
		if (userHome != null && !userHome.isEmpty()) {
			final File file = new File(userHome);
			if (file.isDirectory()) {
				return file;
			}
		}
		if (OperatingSystem.ANDROID.isCurrentOS()) {
			return join(File.listRoots()[0], Android.HOME_DIRECTORY);
		}
		throw new FileNotFoundException();
	}
838031
public static Map<String,String> storeDirectoryResourcesAsString( File directory ) throws IOException {

		Map<String,byte[]> map = storeDirectoryResourcesAsBytes( directory );
		Map<String,String> result = new HashMap<>( map.size());
		for( Map.Entry<String,byte[]> entry : map.entrySet())
			result.put( entry.getKey(), new String( entry.getValue(), StandardCharsets.UTF_8 ));

		return result;
	}
726436
@CheckForNull
  public String relativePath(Path dir, Path file) {
    Path baseDir = dir.normalize();
    Path path = file.normalize();
    if (!path.startsWith(baseDir)) {
      return null;
    }
    try {
      Path relativized = baseDir.relativize(path);
      return FilenameUtils.separatorsToUnix(relativized.toString());
    } catch (IllegalArgumentException e) {
      return null;
    }
  }