Package com.diffplug.gradle
Class FileMisc
java.lang.Object
com.diffplug.gradle.FileMisc
Miscellaneous utilties for copying files around.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertMacApp(File file) Ensures that the given file ends with ".app" on macOS, does nothing on all others.static StringPrefixes `file://` to the file's absolute path.static voidDeletes the given file or directory if it exists, then creates a fresh directory in its place.static voidConcats the first files and writes them to the last file.static booleancontainsExecutablePermission(Set<PosixFilePermission> permissions) Returns true if any of the bits contain the executable permission.static voidCopies from src to dst and performs a simple copy-replace templating operation along the way.static voidDeletes all empty folders (recursively).static booleanReturns true if the given directory exists, and waits up to 500ms for the directory to exist.static voidDownloads the url to the destination file (with support for redirects).static voidFlattens a single directory (moves its children to be its peers, then deletes the given directory.static voidforceDelete(File f) CallsFileUtils.forceDelete(File)and throws an exception if it fails.static booleanReturns true iff the given directory has a file with the given name.static booleanReturns true iff the given directory has a file with the given name containing the given content.static booleanhasTokenFile(File tokenFile) Returns true iff the given directory has a file with the given name.static booleanhasTokenFile(File tokenFile, String content) Returns true iff the given directory has a file with the given name containing the given content.Lists the children of the given file in a safe way (File.listFiles()can return null).static StringmacApp()Returns ".app" on macOS, and empty string on all others.static StringReturns "Contents/Eclipse/" on macOS, and empty string on all others.static voidCallsFile.mkdirs()and throws an exception if it fails.static voidmodifyFile(File file, Function<String, String> modifier) Modifies the given file in place.static StringThrows an exception if the given input property contains whitespace.parseListFile(Project project, List<Object> inputs) static StringQuotes the absolute path of the given file iff it contains whitespace.static StringQuotes the given input string iff it contains whitespace.Returns the contents of a file with the given name, if it exists.static StringtoOctalFileMode(Set<PosixFilePermission> permissions) Converts a set ofPosixFilePermissionto chmod-style octal file mode.static inttoOctalFileModeInt(Set<PosixFilePermission> permissions) Converts a set ofPosixFilePermissionto chmod-style octal file mode.static StringtoUnixNewline(String input) Enforces unix newlines on the given string.static voidwriteToken(File dir, String name) Writes an empty file with the given name in the given directory.static voidwriteToken(File dir, String name, String value) Writes a file with the given name, to the given directory, containing the given value.static voidwriteTokenFile(File tokenFile, String value) Writes a token file containing the given value.
-
Field Details
-
PROTOCOL
The `file://` protocol.
-
-
Constructor Details
-
FileMisc
public FileMisc()
-
-
Method Details
-
download
Downloads the url to the destination file (with support for redirects).- Throws:
IOException
-
list
Lists the children of the given file in a safe way (File.listFiles()can return null). -
mkdirs
CallsFile.mkdirs()and throws an exception if it fails. -
forceDelete
CallsFileUtils.forceDelete(File)and throws an exception if it fails. If the file doesn't exist at all, that's fine. -
dirExists
Returns true if the given directory exists, and waits up to 500ms for the directory to exist. -
toUnixNewline
Enforces unix newlines on the given string. -
quote
Quotes the given input string iff it contains whitespace. -
quote
Quotes the absolute path of the given file iff it contains whitespace. -
noQuote
Throws an exception if the given input property contains whitespace. -
writeToken
Writes a file with the given name, to the given directory, containing the given value.- Throws:
IOException
-
writeTokenFile
Writes a token file containing the given value.- Throws:
IOException
-
readToken
Returns the contents of a file with the given name, if it exists.- Throws:
IOException
-
writeToken
Writes an empty file with the given name in the given directory.- Throws:
IOException
-
hasToken
Returns true iff the given directory has a file with the given name.- Throws:
IOException
-
hasToken
Returns true iff the given directory has a file with the given name containing the given content.- Throws:
IOException
-
hasTokenFile
Returns true iff the given directory has a file with the given name.- Throws:
IOException
-
hasTokenFile
Returns true iff the given directory has a file with the given name containing the given content.- Throws:
IOException
-
copyFile
Copies from src to dst and performs a simple copy-replace templating operation along the way. ```java copyFile(src, dst, "%username%", "lskywalker" "%firstname%", "Luke", "%lastname%", "Skywalker"); ```- Throws:
IOException
-
modifyFile
Modifies the given file in place.- Throws:
IOException
-
cleanDir
Deletes the given file or directory if it exists, then creates a fresh directory in its place.- Throws:
IOException
-
flatten
Flattens a single directory (moves its children to be its peers, then deletes the given directory. ``` before: root/ toFlatten/ child1 child2 flatten("root/toFlatten") after: root/ child1 child2 ```- Throws:
IOException
-
concat
Concats the first files and writes them to the last file.- Throws:
IOException
-
deleteEmptyFolders
Deletes all empty folders (recursively).- Throws:
IOException
-
parseListFile
-
toOctalFileModeInt
Converts a set ofPosixFilePermissionto chmod-style octal file mode. -
toOctalFileMode
Converts a set ofPosixFilePermissionto chmod-style octal file mode. -
containsExecutablePermission
Returns true if any of the bits contain the executable permission. -
asUrl
Prefixes `file://` to the file's absolute path. -
macApp
Returns ".app" on macOS, and empty string on all others. -
macContentsEclipse
Returns "Contents/Eclipse/" on macOS, and empty string on all others. -
assertMacApp
Ensures that the given file ends with ".app" on macOS, does nothing on all others.
-