Class Utils
- java.lang.Object
-
- org.siouan.frontendgradleplugin.core.Utils
-
public final class Utils extends java.lang.ObjectThis class provides utilities for the whole plugin.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcopyFileTree(java.nio.file.Path sourcePath, java.nio.file.Path targetPath)Copies a file at the given path, recursively if it is a directory.static voiddeleteFileTree(java.nio.file.Path rootPath, boolean deleteRootEnabled)Deletes a file or a directory at the given path.static java.util.Optional<java.lang.String>getExtension(java.lang.String fileName)Gets the extension of a file.static java.util.Optional<java.nio.file.Path>getNodeExecutablePath(java.nio.file.Path nodeInstallDirectory, java.lang.String osName)Gets the path of the Node executable.static java.util.Optional<java.nio.file.Path>getNpmExecutablePath(java.nio.file.Path nodeInstallDirectory, java.lang.String osName)Gets the path of the NPM executable.static java.lang.StringgetSystemJvmArch()Gets the current JVM architecture.static java.lang.StringgetSystemOsName()Gets the current O/S name.static java.util.Optional<java.nio.file.Path>getYarnExecutablePath(java.nio.file.Path yarnInstallDirectory, java.lang.String osName)Gets the path of Yarn executable.static booleanis64BitsArch(java.lang.String jreArch)Tells whether the given JRE architecture is a 64 bits one.static booleanisGzipExtension(java.lang.String extension)Tells whether a file name extension is related to a GZIP file.static booleanisLinuxOs(java.lang.String osName)Tells whether the given OS name matches a Linux OS.static booleanisMacOs(java.lang.String osName)Tells whether the given OS name matches a Mac OS.static booleanisWindowsOs(java.lang.String osName)Tells whether the given OS name matches a Windows OS.static voidmoveFileTree(java.nio.file.Path sourcePath, java.nio.file.Path targetPath)Moves all files/directories from a source directory into a destination directory.static java.lang.StringremoveExtension(java.lang.String filename)Removes the extension of a filename.static booleansetFileExecutable(java.nio.file.Path path, java.lang.String osName)Marks the file as executable.static booleansetFileExecutable(java.nio.file.Path path, java.util.Set<java.nio.file.attribute.PosixFilePermission> originalPermissions, java.lang.String osName)Marks the file as executable.static java.lang.StringtoHexadecimalString(byte[] buffer)Converts a binary buffer into an hexadecimal string, with a lower case.
-
-
-
Method Detail
-
deleteFileTree
public static void deleteFileTree(java.nio.file.Path rootPath, boolean deleteRootEnabled) throws java.io.IOExceptionDeletes a file or a directory at the given path. If the root path is a directory, its content is deleted recursively before the directory itself.- Parameters:
rootPath- Root path.deleteRootEnabled- Whether the file at the root path itself must also be deleted.- Throws:
java.io.IOException- If an I/O error occurs.
-
copyFileTree
public static void copyFileTree(java.nio.file.Path sourcePath, java.nio.file.Path targetPath) throws java.io.IOExceptionCopies a file at the given path, recursively if it is a directory. File attributes and symlinks are preserved.- Parameters:
sourcePath- Source path.targetPath- Target Path.- Throws:
java.io.IOException- If an I/O error occurs.
-
moveFileTree
public static void moveFileTree(java.nio.file.Path sourcePath, java.nio.file.Path targetPath) throws java.io.IOExceptionMoves all files/directories from a source directory into a destination directory. The destination directory is created, and therefore must not exist before this method is called. All directories/files in the source path are copied first, preserving file attributes and symlinks. Finally the source path is deleted. Such method ensures any file tree can be moved from a volume to another.- Parameters:
sourcePath- Source path.targetPath- Target path.- Throws:
java.io.IOException- If an I/O error occurs.java.lang.IllegalArgumentException- If either the source directory or the destination directory is not an existing directory.
-
getExtension
public static java.util.Optional<java.lang.String> getExtension(java.lang.String fileName)
Gets the extension of a file.- Parameters:
fileName- File name.- Returns:
- Extension.
-
getNodeExecutablePath
public static java.util.Optional<java.nio.file.Path> getNodeExecutablePath(java.nio.file.Path nodeInstallDirectory, java.lang.String osName)Gets the path of the Node executable.- Parameters:
nodeInstallDirectory- Node install directory.osName- O/S name.- Returns:
- The path, may be
nullif it was not found. - See Also:
getSystemOsName()
-
getNpmExecutablePath
public static java.util.Optional<java.nio.file.Path> getNpmExecutablePath(java.nio.file.Path nodeInstallDirectory, java.lang.String osName)Gets the path of the NPM executable.- Parameters:
nodeInstallDirectory- Node install directory.osName- O/S name.- Returns:
- The path, may be
nullif it was not found. - See Also:
getSystemOsName()
-
getSystemJvmArch
public static java.lang.String getSystemJvmArch()
Gets the current JVM architecture.- Returns:
- String describing the JVM architecture.
-
getSystemOsName
public static java.lang.String getSystemOsName()
Gets the current O/S name.- Returns:
- String describing the O/S.
-
getYarnExecutablePath
public static java.util.Optional<java.nio.file.Path> getYarnExecutablePath(java.nio.file.Path yarnInstallDirectory, java.lang.String osName)Gets the path of Yarn executable.- Parameters:
yarnInstallDirectory- Yarn install directory.osName- O/S name.- Returns:
- The path, may be
nullif it was not found. - See Also:
getSystemOsName()
-
is64BitsArch
public static boolean is64BitsArch(java.lang.String jreArch)
Tells whether the given JRE architecture is a 64 bits one.- Parameters:
jreArch- JRE architecture.- Returns:
trueif the architecture is a 64 bits.- See Also:
getSystemJvmArch()
-
isGzipExtension
public static boolean isGzipExtension(java.lang.String extension)
Tells whether a file name extension is related to a GZIP file.- Parameters:
extension- Extension- Returns:
trueif the extension is related to a GZIP file.
-
isLinuxOs
public static boolean isLinuxOs(java.lang.String osName)
Tells whether the given OS name matches a Linux OS.- Parameters:
osName- OS name.- Returns:
trueif the OS name matches a Linux OS.- See Also:
getSystemOsName()
-
isMacOs
public static boolean isMacOs(java.lang.String osName)
Tells whether the given OS name matches a Mac OS.- Parameters:
osName- OS name.- Returns:
trueif the OS name matches a Mac OS.- See Also:
getSystemOsName()
-
isWindowsOs
public static boolean isWindowsOs(java.lang.String osName)
Tells whether the given OS name matches a Windows OS.- Parameters:
osName- OS name.- Returns:
trueif the OS name matches a Windows OS.- See Also:
getSystemOsName()
-
removeExtension
public static java.lang.String removeExtension(java.lang.String filename)
Removes the extension of a filename. In case of a compressed TAR archive, the method removes the whole extension (e.g. '.tar.gz').- Parameters:
filename- Filename.- Returns:
- The filename without the extension.
-
setFileExecutable
public static boolean setFileExecutable(java.nio.file.Path path, java.lang.String osName) throws java.io.IOExceptionMarks the file as executable. This method does nothing under Windows.- Parameters:
path- Path.osName- OS name.- Returns:
trueif the file permissions were touched, i.e. under a Non-Windows O/S, the file exists and has not the executable permission yet.- Throws:
java.io.IOException- If an I/O error occurs.
-
setFileExecutable
public static boolean setFileExecutable(java.nio.file.Path path, java.util.Set<java.nio.file.attribute.PosixFilePermission> originalPermissions, java.lang.String osName) throws java.io.IOExceptionMarks the file as executable. This method does nothing under Windows. This method allows to restore a file's permissions by providing the original permissions, in case they cannot be retrieved.- Parameters:
path- Path.originalPermissions- Original file permissions.osName- OS name.- Returns:
trueif the file permissions were touched, i.e. under a Non-Windows O/S, the file exists and has not the executable permission yet.- Throws:
java.io.IOException- If an I/O error occurs.
-
toHexadecimalString
public static java.lang.String toHexadecimalString(byte[] buffer)
Converts a binary buffer into an hexadecimal string, with a lower case.- Parameters:
buffer- Buffer.- Returns:
- Hexadecimal string.
-
-