public interface ProjectFilesystem
Modifier and Type | Method and Description |
---|---|
ProjectFilesystemView |
asView() |
Sha1HashCode |
computeSha1(Path pathRelativeToProjectRootOrJustAbsolute) |
String |
computeSha256(Path pathRelativeToProjectRoot) |
void |
copy(Path source,
Path target,
CopySourceMode sourceMode) |
void |
copyFile(Path source,
Path target) |
void |
copyFolder(Path source,
Path target) |
void |
copyToOutputStream(Path pathRelativeToProjectRoot,
OutputStream out)
Copies a file to an output stream.
|
void |
copyToPath(InputStream inputStream,
Path pathRelativeToProjectRoot,
CopyOption... options) |
ProjectFilesystem |
createBuckOutProjectFilesystem() |
Path |
createNewFile(Path pathRelativeToProjectRoot)
Creates a new file relative to the project root.
|
void |
createParentDirs(Path pathRelativeToProjectRoot) |
void |
createParentDirs(String pathRelativeToProjectRoot)
// @deprecated Prefer operating on
Path s directly, replaced by createParentDirs(java.nio.file.Path) . |
void |
createSymLink(Path symLink,
Path realFile,
boolean force) |
default void |
createSymLink(PathWrapper symLink,
Path realFile,
boolean force) |
Path |
createTempFile(Path directory,
String prefix,
String suffix,
FileAttribute<?>... attrs)
Prefer
createTempFile(String, String, FileAttribute[]) so that temporary files are
guaranteed to be created under buck-out . |
Path |
createTempFile(String prefix,
String suffix,
FileAttribute<?>... attrs)
Returns a relative path whose parent directory is guaranteed to exist.
|
void |
deleteFileAtPath(Path pathRelativeToProjectRoot)
Deletes a file specified by its path relative to the project root.
|
boolean |
deleteFileAtPathIfExists(Path pathRelativeToProjectRoot)
Deletes a file specified by its path relative to the project root.
|
void |
deleteRecursivelyIfExists(Path pathRelativeToProjectRoot)
Recursively delete everything under the specified path.
|
default boolean |
exists(ForwardRelativePath pathRelativeToProjectRoot,
LinkOption... options) |
boolean |
exists(Path pathRelativeToProjectRoot,
LinkOption... options) |
default boolean |
exists(RelPath pathRelativeToProjectRoot,
LinkOption... options) |
com.google.common.collect.ImmutableSet<PathMatcher> |
getBlacklistedPaths() |
BuckPaths |
getBuckPaths() |
com.google.common.collect.ImmutableMap<String,? extends Object> |
getDelegateDetails() |
com.google.common.collect.ImmutableCollection<Path> |
getDirectoryContents(Path pathToUse)
Deprecated.
|
long |
getFileAttributesForZipEntry(Path path)
getFileAttributesForZipEntry is similar to getPosixFileMode, but returns a number adjusted for
use in zip files.
|
long |
getFileSize(Path pathRelativeToProjectRoot) |
com.google.common.collect.ImmutableSet<Path> |
getFilesUnderPath(Path pathRelativeToProjectRoot)
Deprecated.
|
com.google.common.collect.ImmutableSet<Path> |
getFilesUnderPath(Path pathRelativeToProjectRoot,
java.util.function.Predicate<Path> predicate)
Deprecated.
|
com.google.common.collect.ImmutableSet<Path> |
getFilesUnderPath(Path pathRelativeToProjectRoot,
java.util.function.Predicate<Path> predicate,
EnumSet<FileVisitOption> visitOptions)
Deprecated.
|
default FileSystem |
getFileSystem() |
com.google.common.collect.ImmutableSet<PathMatcher> |
getIgnorePaths() |
InputStream |
getInputStreamForRelativePath(Path path)
// @deprecated Prefer operation on
Path s directly, replaced by Files.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...) . |
Manifest |
getJarManifest(Path path) |
FileTime |
getLastModifiedTime(Path pathRelativeToProjectRoot) |
com.google.common.collect.ImmutableSortedSet<Path> |
getMtimeSortedMatchingDirectoryContents(Path pathRelativeToProjectRoot,
String globPattern)
Returns the files inside
pathRelativeToProjectRoot which match globPattern ,
ordered in descending last modified time order. |
Path |
getPath(String first,
String... rest)
Converts a path string (or sequence of strings) to a Path with the same VFS as this instance.
|
Path |
getPathForRelativeExistingPath(Path pathRelativeToProjectRoot)
As
getPathForRelativePath(java.nio.file.Path) , but with the added twist that the
existence of the path is checked before returning. |
Path |
getPathForRelativePath(Path pathRelativeToProjectRoot) |
Path |
getPathForRelativePath(String pathRelativeToProjectRoot) |
Optional<Path> |
getPathRelativeToProjectRoot(Path path) |
long |
getPosixFileMode(Path path)
getPosixFileMode returns a number corresponding to stat()'s ST_MODE, for use when constructing
tar archives.
|
Set<PosixFilePermission> |
getPosixFilePermissions(Path path)
Returns the set of POSIX file permissions, or the empty set if the underlying file system does
not support POSIX file attributes.
|
AbsPath |
getRootPath() |
boolean |
isDirectory(Path child,
LinkOption... linkOptions)
Allows
Files.isDirectory(java.nio.file.Path, java.nio.file.LinkOption...) to be faked in tests. |
default boolean |
isDirectory(PathWrapper path,
LinkOption... linkOptions) |
boolean |
isExecutable(Path child)
Allows
Files.isExecutable(java.nio.file.Path) to be faked in tests. |
boolean |
isFile(Path pathRelativeToProjectRoot,
LinkOption... options)
Checks whether there is a normal file at the specified path.
|
default boolean |
isFile(PathWrapper pathRelativeToProjectRoot,
LinkOption... options) |
boolean |
isHidden(Path pathRelativeToProjectRoot) |
boolean |
isIgnored(RelPath path)
Deprecated.
|
boolean |
isSymLink(Path path)
Returns true if the file under
path exists and is a symbolic link, false otherwise. |
void |
mergeChildren(Path source,
Path target,
CopyOption... options)
Moves the children of
source into target , merging the two directories. |
void |
mkdirs(Path pathRelativeToProjectRoot)
Resolves the relative path against the project root and then calls
Files.createDirectories(java.nio.file.Path, java.nio.file.attribute.FileAttribute[]) |
void |
move(Path source,
Path target,
CopyOption... options) |
InputStream |
newFileInputStream(Path pathRelativeToProjectRoot) |
default InputStream |
newFileInputStream(PathWrapper pathRelativeToProjectRoot) |
OutputStream |
newFileOutputStream(Path pathRelativeToProjectRoot,
boolean append,
FileAttribute<?>... attrs) |
OutputStream |
newFileOutputStream(Path pathRelativeToProjectRoot,
FileAttribute<?>... attrs) |
OutputStream |
newUnbufferedFileOutputStream(Path pathRelativeToProjectRoot,
boolean append,
FileAttribute<?>... attrs) |
<A extends BasicFileAttributes> |
readAttributes(Path pathRelativeToProjectRoot,
Class<A> type,
LinkOption... options) |
Optional<String> |
readFileIfItExists(Path pathRelativeToProjectRoot) |
Optional<String> |
readFirstLine(Path pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path.
|
Optional<String> |
readFirstLine(String pathRelativeToProjectRoot)
Attempts to read the first line of the file specified by the relative path.
|
Optional<String> |
readFirstLineFromFile(Path file)
Attempts to read the first line of the specified file.
|
List<String> |
readLines(Path pathRelativeToProjectRoot) |
Properties |
readPropertiesFile(Path propertiesFile) |
Path |
readSymLink(Path path)
Returns the target of the specified symbolic link.
|
default RelPath |
relativize(AbsPath path) |
RelPath |
relativize(Path path)
Construct a relative path between the project root and a given path.
|
default Path |
resolve(ForwardRelativePath path) |
Path |
resolve(Path path) |
default AbsPath |
resolve(RelPath path) |
Path |
resolve(String path) |
Path |
setLastModifiedTime(Path pathRelativeToProjectRoot,
FileTime time)
Sets the last modified time for the given path.
|
void |
touch(Path fileToTouch) |
void |
walkFileTree(Path root,
FileVisitor<Path> fileVisitor)
Deprecated.
|
void |
walkFileTree(Path root,
Set<FileVisitOption> options,
FileVisitor<Path> fileVisitor)
Deprecated.
|
void |
walkRelativeFileTree(Path pathRelativeToProjectRoot,
EnumSet<FileVisitOption> visitOptions,
FileVisitor<Path> fileVisitor,
boolean skipIgnored)
Deprecated.
|
void |
walkRelativeFileTree(Path pathRelativeToProjectRoot,
FileVisitor<Path> fileVisitor)
Deprecated.
|
void |
walkRelativeFileTree(Path pathRelativeToProjectRoot,
FileVisitor<Path> fileVisitor,
boolean skipIgnored)
Deprecated.
|
void |
writeBytesToPath(byte[] bytes,
Path pathRelativeToProjectRoot,
FileAttribute<?>... attrs) |
void |
writeContentsToPath(String contents,
Path pathRelativeToProjectRoot,
FileAttribute<?>... attrs) |
void |
writeLinesToPath(Iterable<String> lines,
Path pathRelativeToProjectRoot,
FileAttribute<?>... attrs)
Writes each line in
lines with a trailing newline to a file at the specified path. |
ProjectFilesystemView asView()
AbsPath getRootPath()
default FileSystem getFileSystem()
ProjectFilesystem createBuckOutProjectFilesystem()
com.google.common.collect.ImmutableMap<String,? extends Object> getDelegateDetails()
String
, int
, or boolean
.Path resolve(Path path)
path
resolved against getRootPath()
to an absolute path.default Path resolve(ForwardRelativePath path)
path
resolved against getRootPath()
to an absolute path.default AbsPath resolve(RelPath path)
path
resolved against getRootPath()
to an absolute path.RelPath relativize(Path path)
com.google.common.collect.ImmutableSet<PathMatcher> getBlacklistedPaths()
PathMatcher
objects ignored by isIgnored(RelPath)
com.google.common.collect.ImmutableSet<PathMatcher> getIgnorePaths()
ImmutableSet
of PathMatcher
objects to have buck ignore.Optional<Path> getPathRelativeToProjectRoot(Path path)
path
- Absolute path or path relative to the project root.path
is relative, it is returned. If it is absolute and is inside the
project root, it is relativized to the project root and returned. Otherwise an absent value
is returned.Path getPathForRelativeExistingPath(Path pathRelativeToProjectRoot)
getPathForRelativePath(java.nio.file.Path)
, but with the added twist that the
existence of the path is checked before returning.boolean exists(Path pathRelativeToProjectRoot, LinkOption... options)
default boolean exists(ForwardRelativePath pathRelativeToProjectRoot, LinkOption... options)
default boolean exists(RelPath pathRelativeToProjectRoot, LinkOption... options)
long getFileSize(Path pathRelativeToProjectRoot) throws IOException
IOException
boolean deleteFileAtPathIfExists(Path pathRelativeToProjectRoot) throws IOException
Ignores the failure if the file does not exist.
pathRelativeToProjectRoot
- path to the filetrue
if the file was deleted, false
if it did not existIOException
void deleteFileAtPath(Path pathRelativeToProjectRoot) throws IOException
pathRelativeToProjectRoot
- path to the fileIOException
Properties readPropertiesFile(Path propertiesFile) throws IOException
IOException
boolean isFile(Path pathRelativeToProjectRoot, LinkOption... options)
default boolean isFile(PathWrapper pathRelativeToProjectRoot, LinkOption... options)
boolean isHidden(Path pathRelativeToProjectRoot) throws IOException
IOException
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor) throws IOException
walkFileTree(Path, FileVisitor)
except this takes in a path relative to the
project root.
This is deprecated. Please use ProjectFilesystemView.walkRelativeFileTree(Path,
EnumSet, FileVisitor)
instead.
IOException
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, FileVisitor<Path> fileVisitor, boolean skipIgnored) throws IOException
walkFileTree(Path, FileVisitor)
except this takes in a path relative to the
project root.
This is deprecated. Please use ProjectFilesystemView.walkRelativeFileTree(Path,
EnumSet, FileVisitor)
instead.
IOException
@Deprecated void walkRelativeFileTree(Path pathRelativeToProjectRoot, EnumSet<FileVisitOption> visitOptions, FileVisitor<Path> fileVisitor, boolean skipIgnored) throws IOException
This is deprecated. Please use ProjectFilesystemView.walkRelativeFileTree(Path,
EnumSet, FileVisitor)
instead.
IOException
@Deprecated void walkFileTree(Path root, FileVisitor<Path> fileVisitor) throws IOException
Files.walkFileTree(java.nio.file.Path, java.util.Set<java.nio.file.FileVisitOption>, int, java.nio.file.FileVisitor<? super java.nio.file.Path>)
to be faked in tests.
Use ProjectFilesystemView.walkFileTree(Path, Set, FileVisitor)
instead.
IOException
@Deprecated void walkFileTree(Path root, Set<FileVisitOption> options, FileVisitor<Path> fileVisitor) throws IOException
IOException
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot) throws IOException
IOException
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate) throws IOException
ProjectFilesystemView.getFilesUnderPath(Path, com.google.common.base.Predicate,
EnumSet)
insteadIOException
@Deprecated com.google.common.collect.ImmutableSet<Path> getFilesUnderPath(Path pathRelativeToProjectRoot, java.util.function.Predicate<Path> predicate, EnumSet<FileVisitOption> visitOptions) throws IOException
ProjectFilesystemView.getFilesUnderPath(Path, com.google.common.base.Predicate,
EnumSet)
insteadIOException
boolean isDirectory(Path child, LinkOption... linkOptions)
Files.isDirectory(java.nio.file.Path, java.nio.file.LinkOption...)
to be faked in tests.default boolean isDirectory(PathWrapper path, LinkOption... linkOptions)
boolean isExecutable(Path child)
Files.isExecutable(java.nio.file.Path)
to be faked in tests.@Deprecated com.google.common.collect.ImmutableCollection<Path> getDirectoryContents(Path pathToUse) throws IOException
ProjectFilesystemView.getDirectoryContents(Path)
insteadIOException
com.google.common.collect.ImmutableSortedSet<Path> getMtimeSortedMatchingDirectoryContents(Path pathRelativeToProjectRoot, String globPattern) throws IOException
pathRelativeToProjectRoot
which match globPattern
,
ordered in descending last modified time order. This will not obey the results of isIgnored(RelPath)
.IOException
FileTime getLastModifiedTime(Path pathRelativeToProjectRoot) throws IOException
IOException
Path setLastModifiedTime(Path pathRelativeToProjectRoot, FileTime time) throws IOException
IOException
void deleteRecursivelyIfExists(Path pathRelativeToProjectRoot) throws IOException
IOException
void mkdirs(Path pathRelativeToProjectRoot) throws IOException
Files.createDirectories(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
IOException
Path createNewFile(Path pathRelativeToProjectRoot) throws IOException
IOException
void createParentDirs(String pathRelativeToProjectRoot) throws IOException
Path
s directly, replaced by createParentDirs(java.nio.file.Path)
.IOException
void createParentDirs(Path pathRelativeToProjectRoot) throws IOException
pathRelativeToProjectRoot
- Must identify a file, not a directory. (Unfortunately, we have
no way to assert this because the path is not expected to exist yet.)IOException
void writeLinesToPath(Iterable<String> lines, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
lines
with a trailing newline to a file at the specified path.
The parent path of pathRelativeToProjectRoot
must exist.
IOException
void writeContentsToPath(String contents, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
IOException
void writeBytesToPath(byte[] bytes, Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
IOException
OutputStream newFileOutputStream(Path pathRelativeToProjectRoot, FileAttribute<?>... attrs) throws IOException
IOException
OutputStream newFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs) throws IOException
IOException
OutputStream newUnbufferedFileOutputStream(Path pathRelativeToProjectRoot, boolean append, FileAttribute<?>... attrs) throws IOException
IOException
<A extends BasicFileAttributes> A readAttributes(Path pathRelativeToProjectRoot, Class<A> type, LinkOption... options) throws IOException
IOException
InputStream newFileInputStream(Path pathRelativeToProjectRoot) throws IOException
IOException
default InputStream newFileInputStream(PathWrapper pathRelativeToProjectRoot) throws IOException
IOException
void copyToPath(InputStream inputStream, Path pathRelativeToProjectRoot, CopyOption... options) throws IOException
inputStream
- Source of the bytes. This method does not close this stream.IOException
void copyToOutputStream(Path pathRelativeToProjectRoot, OutputStream out) throws IOException
IOException
Optional<String> readFirstLine(String pathRelativeToProjectRoot)
Optional.empty()
is
returned. Otherwise, an Optional
with the first line of the file will be returned.
// @deprecated PRefero operation on Path
s directly, replaced by readFirstLine(java.nio.file.Path)
Optional<String> readFirstLine(Path pathRelativeToProjectRoot)
Optional.empty()
is
returned. Otherwise, an Optional
with the first line of the file will be returned.Optional<String> readFirstLineFromFile(Path file)
Optional.empty()
is returned. Otherwise, an
Optional
with the first line of the file will be returned.List<String> readLines(Path pathRelativeToProjectRoot) throws IOException
IOException
InputStream getInputStreamForRelativePath(Path path) throws IOException
Path
s directly, replaced by Files.newInputStream(java.nio.file.Path, java.nio.file.OpenOption...)
.IOException
Sha1HashCode computeSha1(Path pathRelativeToProjectRootOrJustAbsolute) throws IOException
IOException
String computeSha256(Path pathRelativeToProjectRoot) throws IOException
IOException
void copy(Path source, Path target, CopySourceMode sourceMode) throws IOException
IOException
void move(Path source, Path target, CopyOption... options) throws IOException
IOException
void mergeChildren(Path source, Path target, CopyOption... options) throws IOException
source
into target
, merging the two directories.IOException
void copyFolder(Path source, Path target) throws IOException
IOException
void copyFile(Path source, Path target) throws IOException
IOException
void createSymLink(Path symLink, Path realFile, boolean force) throws IOException
IOException
default void createSymLink(PathWrapper symLink, Path realFile, boolean force) throws IOException
IOException
Set<PosixFilePermission> getPosixFilePermissions(Path path) throws IOException
IOException
boolean isSymLink(Path path)
path
exists and is a symbolic link, false otherwise.Path readSymLink(Path path) throws IOException
IOException
Manifest getJarManifest(Path path) throws IOException
IOException
long getPosixFileMode(Path path) throws IOException
IOException
long getFileAttributesForZipEntry(Path path) throws IOException
IOException
BuckPaths getBuckPaths()
@Deprecated boolean isIgnored(RelPath path)
ProjectFilesystemView.isIgnored(Path)
insteadpath
- the path to check.Path createTempFile(String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
buck-out
, so it is safe to write to.IOException
Path createTempFile(Path directory, String prefix, String suffix, FileAttribute<?>... attrs) throws IOException
createTempFile(String, String, FileAttribute[])
so that temporary files are
guaranteed to be created under buck-out
. This method will be deprecated once t12079608
is resolved.IOException
void touch(Path fileToTouch) throws IOException
IOException
Path getPath(String first, String... rest)
FileSystem.getPath(String, String...)