Class FileUtils
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.FileUtils
-
public class FileUtils extends java.lang.ObjectSome file helper methods.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileUtils.ScanResult<T extends IArtifact>Represents the result of ascan(File, ArtifactModel, long, ScanResult, Class)execution.
-
Constructor Summary
Constructors Modifier Constructor Description privateFileUtils()Prevents external instantiations (utility class).
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static java.util.List<IFileSystemArtifact>copy(IFileSystemArtifact source, IFileSystemArtifact target)Copiessourcetotarget.private static voidcopyOrMove(java.io.File source, java.io.File target, ArtifactModel sourceModel, ArtifactModel targetModel, java.util.List<IFileSystemArtifact> artifacts)Copy or move fromsourcetotargetconsidering each as directories or files.private static java.util.List<IFileSystemArtifact>copyOrMove(IFileSystemArtifact source, IFileSystemArtifact target, boolean move)Copy or move fromsourcetotargetconsidering each as directories or files.(package private) static Set<IFileSystemArtifact>copyOrMove(Path source, IFileSystemArtifact target, boolean move)Copy or move from thesourcepath to thetargetartifact.(package private) static voiddelete(java.io.File file)Deletes the given file and handles the exceptions / return values in the sense of VIL.private static java.io.FiledetermineDestination(Path sourcePath, FileArtifact sourceArtefakt, java.io.File targetFile)Determines the destination of an artefact, which shall be copied/moved from a given source path (e.g.static java.io.FilegetTempDirectory()Returns a File representing the system temporary directory.static booleanisDirectory(java.io.File file)Returns whetherfileis a directory regardless whether it exists or not.static booleanisFile(java.io.File file)Returns whetherfileis a file regardless whether it exists or not.static booleanisFile(java.lang.String path)A heuristic whether the givenpathis a file.(package private) static java.util.List<IFileSystemArtifact>move(IFileSystemArtifact source, IFileSystemArtifact target)Movessourcetotarget.(package private) static voidrename(java.io.File file, java.io.File newFile)Renames the given file and handles the exceptions / return values in the sense of VIL.(package private) static voidrename(java.io.File file, java.lang.String name)Renames the given file and handles the exceptions / return values in the sense of VIL.static <T extends IArtifact>
voidscan(java.io.File location, ArtifactModel model, long timestamp, FileUtils.ScanResult<T> result, java.lang.Class<T> type)Scans the file system for new files.
-
-
-
Method Detail
-
delete
static void delete(java.io.File file) throws VilExceptionDeletes the given file and handles the exceptions / return values in the sense of VIL.- Parameters:
file- the file to be deleted- Throws:
VilException- in case that anything goes seriously wrong
-
rename
static void rename(java.io.File file, java.io.File newFile) throws VilExceptionRenames the given file and handles the exceptions / return values in the sense of VIL.- Parameters:
file- the file to be renamednewFile- the new file name- Throws:
VilException- in case that anything goes seriously wrong
-
rename
static void rename(java.io.File file, java.lang.String name) throws VilExceptionRenames the given file and handles the exceptions / return values in the sense of VIL.- Parameters:
file- the file to be renamedname- the new name- Throws:
VilException- in case that anything goes seriously wrong
-
move
static java.util.List<IFileSystemArtifact> move(IFileSystemArtifact source, IFileSystemArtifact target) throws VilException
Movessourcetotarget.- Parameters:
source- the source file system artifacttarget- the target file system artifact- Returns:
- the created or touched artifacts
- Throws:
VilException- in case of serious (I/O) errors
-
copyOrMove
static Set<IFileSystemArtifact> copyOrMove(Path source, IFileSystemArtifact target, boolean move) throws VilException
Copy or move from thesourcepath to thetargetartifact.- Parameters:
source- the source pathtarget- the target artifactmove- move or copy- Returns:
- the created or touched artifacts
- Throws:
VilException- in case that file system operations or artifact model operations fail
-
copyOrMove
private static java.util.List<IFileSystemArtifact> copyOrMove(IFileSystemArtifact source, IFileSystemArtifact target, boolean move) throws VilException
Copy or move fromsourcetotargetconsidering each as directories or files. This method informs the involved artifact models appropriately.- Parameters:
source- the source to copy fromtarget- the target to copy tomove- move or copy- Returns:
- the created or touched artifacts
- Throws:
VilException- in case that file system operations or artifact model operations fail
-
copyOrMove
private static void copyOrMove(java.io.File source, java.io.File target, ArtifactModel sourceModel, ArtifactModel targetModel, java.util.List<IFileSystemArtifact> artifacts) throws VilExceptionCopy or move fromsourcetotargetconsidering each as directories or files. This method informs the involved artifact models appropriately.- Parameters:
source- the source to copy fromtarget- the target to copy tosourceModel- the source artifact model (may be null for copy, non-null for move operation)targetModel- the target artifact modelartifacts- the created or touched artifacts (may be null then resulting artifacts will not be collected)- Throws:
VilException- in case that file system operations or artifact model operations fail
-
copy
static java.util.List<IFileSystemArtifact> copy(IFileSystemArtifact source, IFileSystemArtifact target) throws VilException
Copiessourcetotarget.- Parameters:
source- the source file system artifacttarget- the target file system artifact- Returns:
- the created or touched artifacts
- Throws:
VilException- in case of serious (I/O) errors
-
isFile
public static boolean isFile(java.lang.String path)
A heuristic whether the givenpathis a file.- Parameters:
path- the path to be considered- Returns:
trueifpathis considered to be a file,falseelse
-
isFile
public static boolean isFile(java.io.File file)
Returns whetherfileis a file regardless whether it exists or not.- Parameters:
file- the file to be considered- Returns:
trueiffileis considered to be a file,falseelse
-
isDirectory
public static boolean isDirectory(java.io.File file)
Returns whetherfileis a directory regardless whether it exists or not.- Parameters:
file- the file to be considered- Returns:
trueiffileis considered to be a directory,falseelse
-
scan
public static <T extends IArtifact> void scan(java.io.File location, ArtifactModel model, long timestamp, FileUtils.ScanResult<T> result, java.lang.Class<T> type)
Scans the file system for new files.- Type Parameters:
T- the actual type of artifacts to be produced- Parameters:
location- the location to scanmodel- the artifact model to generate new artifacts into if neededtimestamp- the timestamp all returned artifacts must be newer (usePathUtils.normalizedTime())result- the resulting artifacts and errors (to be modified as a side effect, may be null)type- the artifact type to be produced (may be null for any restriction)
-
getTempDirectory
public static java.io.File getTempDirectory()
Returns a File representing the system temporary directory.- Returns:
- the system temporary directory.
-
determineDestination
private static java.io.File determineDestination(Path sourcePath, FileArtifact sourceArtefakt, java.io.File targetFile)
Determines the destination of an artefact, which shall be copied/moved from a given source path (e.g. a pattern) to a given target (folder). Considers sub folder structures, will not consider constant parts at the beginning of a pattern. For instance:
Elements of "src/foo/**//bar/*.java" will be copied to "targetFile/**//bar/*.java"
Part of thecopyOrMove(Path, IFileSystemArtifact, boolean)method.- Parameters:
sourcePath- The sourcepath, containing the sourceArtefact (may be a pattern). Must not be null.sourceArtefakt- An artefact inside the given sourcePath. Must not be nulltargetFile- The destination, should be a folder. Must not be null- Returns:
- The destination of the the file to be copied/moved.
-
-