/** * Set the file distribution directory. * * @param filePath file path. */ public void setDistributionDirectory(File filePath) { final ConsoleProperties properties = getConsoleComponent(ConsoleProperties.class); Directory directory; try { directory = new Directory(filePath); properties.setAndSaveDistributionDirectory(directory); } catch (Exception e) { LOGGER.error("Error occurred during setting distribution directory to {} : {}", filePath, e.getMessage()); throw processException(e.getMessage(), e); } }
private StringBuilder addUserDir(StringBuilder jvmArguments) { jvmArguments.append(" -Duser.dir=" + baseDirectory.getFile().getPath() + " "); return jvmArguments; }
throws IOException { if (!getFile().exists()) { throw new DirectoryException( "Source directory '" + getFile() + "' does not exist"); target.create(); target.deleteContents(); final File[] files = listContents(s_matchAllFilesFilter, true, false); final StreamCopier streamCopier = new StreamCopier(4096, false); final File source = getFile(file); final File destination = target.getFile(file);
/** * Delete the contents of the directory. * * <p>Does nothing if the directory does not exist.</p> * * @throws DirectoryException If a file could not be deleted. The * contents of the directory are left in an indeterminate state. * @see #delete */ public void deleteContents() throws DirectoryException { // We rely on the order of the listContents result: more deeply // nested files are later in the list. final File[] deleteList = listContents(s_matchAllFilesFilter, true, true); for (int i = deleteList.length - 1; i >= 0; --i) { if (deleteList[i].equals(getFile())) { continue; } if (!deleteList[i].delete()) { throw new DirectoryException( "Could not delete '" + deleteList[i] + "'"); } } }
/** * Convert the supplied {@code file}, to a path relative to this directory. * The file need not exist. * * <p> * If {@code file} is relative, this directory is considered its base. * </p> * * @param file * The file to search for. * @param mustBeChild * If {@code true} and {@code path} belongs to another file system; * is absolute with a different base path; or is a relative path * outside of the directory ({@code ../somewhere/else}), then * {@code null} will be returned. * @return A path relative to this directory, or {@code null}. */ public File relativeFile(final File file, final boolean mustBeChild) { final File f; if (file.isAbsolute()) { f = file; } else if (!mustBeChild) { return file; } else { f = getFile(file); } return relativePath(getFile(), f, mustBeChild); }
/** * Constructor. * * @param directory * Script working directory. May be relative (to the CWD). * @param file * The script file. May be relative (to {@code directory}). * If absolute, it needn't be below the root directory. */ public ScriptLocation(final Directory directory, final File file) { m_directory = directory; // Try to shorten the name. final File relativeFile = directory.relativeFile(file, false); if (relativeFile != null) { m_shortFile = relativeFile; } else { m_shortFile = file; } if (file.isAbsolute()) { m_absoluteFile = file; } else { m_absoluteFile = directory.getFile(file); } }
public Directory getDirectory() throws FileStoreException { try { synchronized (m_incomingDirectory) { if (m_incomingDirectory.getFile().exists()) { m_incomingDirectory.copyTo(m_currentDirectory, m_incremental); } m_incremental = true; } return m_currentDirectory; } catch (IOException e) { UncheckedInterruptedException.ioException(e); throw new FileStoreException("Could not create file store directory", e); } }
@Override public int hashCode() { return m_directory.hashCode() ^ m_fileFilterPattern.pattern().hashCode(); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (o == null || getClass() != o.getClass()) { return false; } final CacheParametersImplementation other = (CacheParametersImplementation)o; return m_directory.equals(other.m_directory) && m_fileFilterPattern.pattern().equals( other.m_fileFilterPattern.pattern()); }
/** * Equivalent to <code>listContents(filter, false, false)</code>. * * @param filter * Filter that controls the files that are returned. * @return The list of files. Files are relative to the directory, not * absolute. More deeply nested files are later in the list. The list * is empty if the directory does not exist. * @see #listContents(FileFilter, boolean, boolean) */ public File[] listContents(final FileFilter filter) { return listContents(filter, false, false); }
/** * Rebase a whole path by calling {@link #rebaseFile} on each of its * elements and joining the result. * * @param path * The path. * @return The result. */ public List<File> rebasePath(final String path) { final String[] elements = path.split(File.pathSeparator); final List<File> result = new ArrayList<File>(elements.length); for (final String e : elements) { if (!e.isEmpty()) { result.add(rebaseFromCWD(new File(e))); } } return result; }
public void handle(ClearCacheMessage message) throws CommunicationException { m_logger.info("Clearing file store"); try { synchronized (m_incomingDirectory) { m_incomingDirectory.deleteContents(); m_incremental = false; } } catch (Directory.DirectoryException e) { m_logger.error(e.getMessage()); throw new CommunicationException(e.getMessage(), e); } } });
public void handle(DistributeFileMessage message) throws CommunicationException { try { synchronized (m_incomingDirectory) { m_incomingDirectory.create(); createReadmeFile(); final FileContents fileContents = message.getFileContents(); m_logger.info("Updating file store: {}", fileContents); fileContents.create(m_incomingDirectory); } } catch (FileContents.FileContentsException e) { m_logger.error(e.getMessage()); throw new CommunicationException(e.getMessage(), e); } catch (Directory.DirectoryException e) { m_logger.error(e.getMessage()); throw new CommunicationException(e.getMessage(), e); } } });
new File(cacheParameters.getDirectory().getFile(), PRIVATE_DIRECTORY_NAME); privateDirectory.mkdir(); cacheParameters.getDirectory().listContents( new FixedPatternFileFilter(scanTime, cacheParameters.getFileFilterPattern()),
/** * Hash code. * * @return The hash code. */ @Override public int hashCode() { return getDirectory().hashCode() ^ getFile().hashCode(); }
/** * Equality. * * @param other Object to compare. * @return {@code true} if and only if we're equal to {@code other}. */ @Override public boolean equals(final Object other) { if (this == other) { return true; } if (other == null || other.getClass() != ScriptLocation.class) { return false; } final ScriptLocation otherScriptLocation = (ScriptLocation)other; return getDirectory().equals(otherScriptLocation.getDirectory()) && getFile().equals(otherScriptLocation.getFile()); } }
private StringBuilder addCurrentAgentPath(StringBuilder jvmArguments) { return jvmArguments.append(" -Dngrinder.exec.path=").append(baseDirectory.getFile()).append(" "); }
public PropertyBuilder createPropertyBuilder(String hostString) throws DirectoryException { Directory directory = new Directory(new File(".")); GrinderProperties property = new GrinderProperties(); return new PropertyBuilder(property, directory, true, GRINDER_SECURITY_LEVEL_NORMAL, hostString, NetworkUtils.getLocalHostName()); } }
cacheParameters.getDirectory().getFile(), cacheParameters.getDirectory().listContents( new FixedPatternFileFilter(agents.getEarliestAgentTime(), cacheParameters.getFileFilterPattern())),
protected StringBuilder addNativeLibraryPath(StringBuilder jvmArguments) { return jvmArguments.append(" -Djna.library.path=").append(new File(baseDirectory.getFile(), "/lib")) .append(" "); }