java.lang.Object
org.matwoess.jsourceprofiler.common.IO
Helper class containing methods related to relative path finding and filesystem operations.
The outputDir is the most important member variable.
It specifies the root directory for all the tool's output files.
No other paths are statically defined.
All subdirectories and file locations can be retrieved by corresponding get methods,
that resolve their file path relative to the outputDir member.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclearDirectoryContents(Path directory) Deletes all files inside a directory.static <T> voidcopyResource(Class<T> resourceClass, String resourceName, Path destination) Extract a copy of a resource file from the project directory or the .jar file.static <T> voidcopyResourceFolder(Class<T> resourceClass, String resourceFolder, Path destination) Recursively extract a copy of a whole resource folder from the project directory or the .jar file.static booleancreateDirectoriesIfNotExists(Path fileOrFolder) Creates all parent directories in the path description to ensure successful creation of a new file in it.static voidcreateLink(Path link, Path target) Creates a symbolic link at a given path pointing to another file path.static PathTo successfully run instrumented versions of source files, an import statement is added to all source files.static PathTo successfully compile instrumented versions of source files, an import statement is added to all source files.static PathReturns theclassesdirectory relative to theoutputDir.static PathReturns the path to the resulting counts file.static PathReturns theinstrumenteddirectory relative to theoutputDir.static PathgetInstrumentedFilePath(Path relativePath) Returns the path where the instrumented version of a Java source file is stored.static PathReturns the path to the parsed project's metadata file.static Pathstatic PathReturns the containing root directory for the generated report.static PathReturns the file path of the main report classes overview.static PathReturns the target path for the symlink pointing to the main report index file.static PathgetReportMethodIndexPath(String className) Returns the path to the report method index of a java class.static PathgetReportResourcePath(String reportResource) Returns the path of a JavaScript or CSS report file relative to the report directory.static PathgetReportSourceFilePath(Path relativePath) Returns the file path of an annotated HTML source file.static PathReturns where the configured FxUI parameters are persisted to inside the output directory.static PathReturns the home directory of the current user.static PathReturns the path of the file for storing the previously opened project directory.static StringConverts aPathobject to a string with all forward slashes as a separator.
-
Field Details
-
outputDir
Represents the output directory for the profiler. The output directory is used for storing instrumented files, compiled classes, and generated reports. By default, the output directory is set to ".profiler" (of the current working directory).
-
-
Constructor Details
-
IO
public IO()
-
-
Method Details
-
getOutputDir
-
getInstrumentDir
Returns theinstrumenteddirectory relative to theoutputDir. -
getClassesDir
Returns theclassesdirectory relative to theoutputDir. -
getInstrumentedFilePath
Returns the path where the instrumented version of a Java source file is stored. The tool will use this method to replicate the original directory structure for instrumented copies.- Parameters:
relativePath- the relative path of the original file to the sources directory. EveryJavaFileinstance knows its relative location to the sources.- Returns:
- the path of an instrumented copy relative to the instrumented directory
-
getAuxiliaryCounterInstrumentPath
To successfully compile instrumented versions of source files, an import statement is added to all source files. A__Counter.classfile is placed in an "auxiliary" package directory to resolve these imports.- Returns:
- where the pre-compiled
__Counter.classclass will be copied to before compilation
-
getAuxiliaryCounterClassPath
To successfully run instrumented versions of source files, an import statement is added to all source files. A__Counter.classfile is placed in an auxiliary package directory to resolve this dependency.- Returns:
- where the pre-compiled
__Counter.classclass will be copied to before running the instrumented code.
-
getMetadataPath
Returns the path to the parsed project's metadata file. This data is used for instrumentation and report generation.- Returns:
metadata.datrelative to theoutputDir
-
getCountsPath
Returns the path to the resulting counts file. This data is written as soon as the instrumented version is run and is used for report generation.- Returns:
counts.datrelative to theoutputDir
-
getReportDir
Returns the containing root directory for the generated report.- Returns:
reportrelative to theoutputDir
-
getReportIndexPath
Returns the file path of the main report classes overview.- Returns:
index.htmlrelative to the report directory
-
getReportResourcePath
Returns the path of a JavaScript or CSS report file relative to the report directory.- Returns:
- the relative path of a source file in the report directory
-
getReportIndexSymLinkPath
Returns the target path for the symlink pointing to the main report index file. On Windows, we create a shortcut instead of a symlink. Therefore, the file extension".lnk"is added.- Returns:
- the pre-defined link path relative to the current directory
-
getReportMethodIndexPath
Returns the path to the report method index of a java class. Every parsed class gets its own one during report generation.- Parameters:
className- the name of a parsed java class- Returns:
- "index_" +
classNamerelative to the report directory
-
getReportSourceFilePath
Returns the file path of an annotated HTML source file. The relative path of the original source file to its sources directory should be passed to the method. This way the package structure is replicated inside thesourcesreport subdirectory. The ".java" suffix is replaced by ".html" to create the new file name.- Parameters:
relativePath- the relative path from aJavaFileclass relative to its sources directory- Returns:
- the location of the annotated report source code file
-
getUserHomeDir
Returns the home directory of the current user.- Returns:
- the home directory of the current user
-
getUIParametersPath
Returns where the configured FxUI parameters are persisted to inside the output directory.- Returns:
parameters.datrelative to theoutputDir
-
lastProjectPath
Returns the path of the file for storing the previously opened project directory. This is read when re-starting the FxUI application and pre-filled as the project to open.- Returns:
lastProjectRootDirectory.txtrelative to the current directory
-
copyResource
Extract a copy of a resource file from the project directory or the .jar file.- Parameters:
resourceClass- the anchor class used to locate the resourceresourceName- the name of the resource file to be extracteddestination- path where the resource is copied to
-
copyResourceFolder
public static <T> void copyResourceFolder(Class<T> resourceClass, String resourceFolder, Path destination) Recursively extract a copy of a whole resource folder from the project directory or the .jar file. Uses a temporary file system to access the contents of the JAR file if needed.- Type Parameters:
T- the type of the resource class- Parameters:
resourceClass- the anchor class used to locate the resourceresourceFolder- the name of the resource folder to be extracteddestination- folder path where the resource is copied to
-
clearDirectoryContents
Deletes all files inside a directory. Used to clean up output files before the next execution. The root directory itself won't be removed to avoid locking errors.- Parameters:
directory- the root directory that should be cleared of contents recursively
-
createDirectoriesIfNotExists
Creates all parent directories in the path description to ensure successful creation of a new file in it.- Parameters:
fileOrFolder- if a file is specified, all the parent directories will be created. If a directory is specified, all parent directories including the given one will be created.- Returns:
- whether the operation was successful
-
createLink
Creates a symbolic link at a given path pointing to another file path. On Linux and macOS this is a soft link, on Windows it is a shortcut. To create the Windows shortcutcreateWindowsShortcut(Path, Path)is used. The link extension must be ".lnk" in this case.- Parameters:
link- the location of the linking file shortcuttarget- what the link should point to
-
normalize
Converts aPathobject to a string with all forward slashes as a separator. Heavily used during report generation.- Parameters:
path- the path to normalize- Returns:
- the string representation of a path with all "\" replaced by "/"
-