java.lang.Object
org.matwoess.jsourceprofiler.common.IO

public class IO extends Object
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 Details

    • outputDir

      public static Path 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

      public static Path getOutputDir()
    • getInstrumentDir

      public static Path getInstrumentDir()
      Returns the instrumented directory relative to the outputDir.
    • getClassesDir

      public static Path getClassesDir()
      Returns the classes directory relative to the outputDir.
    • getInstrumentedFilePath

      public static Path getInstrumentedFilePath(Path relativePath)
      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. Every JavaFile instance knows its relative location to the sources.
      Returns:
      the path of an instrumented copy relative to the instrumented directory
    • getAuxiliaryCounterInstrumentPath

      public static Path getAuxiliaryCounterInstrumentPath()
      To successfully compile instrumented versions of source files, an import statement is added to all source files. A __Counter.class file is placed in an "auxiliary" package directory to resolve these imports.
      Returns:
      where the pre-compiled __Counter.class class will be copied to before compilation
    • getAuxiliaryCounterClassPath

      public static Path getAuxiliaryCounterClassPath()
      To successfully run instrumented versions of source files, an import statement is added to all source files. A __Counter.class file is placed in an auxiliary package directory to resolve this dependency.
      Returns:
      where the pre-compiled __Counter.class class will be copied to before running the instrumented code.
    • getMetadataPath

      public static Path getMetadataPath()
      Returns the path to the parsed project's metadata file. This data is used for instrumentation and report generation.
      Returns:
      metadata.dat relative to the outputDir
    • getCountsPath

      public static Path 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.dat relative to the outputDir
    • getReportDir

      public static Path getReportDir()
      Returns the containing root directory for the generated report.
      Returns:
      report relative to the outputDir
    • getReportIndexPath

      public static Path getReportIndexPath()
      Returns the file path of the main report classes overview.
      Returns:
      index.html relative to the report directory
    • getReportResourcePath

      public static Path getReportResourcePath(String reportResource)
      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

      public static Path 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

      public static Path getReportMethodIndexPath(String className)
      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_" + className relative to the report directory
    • getReportSourceFilePath

      public static Path getReportSourceFilePath(Path relativePath)
      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 the sources report subdirectory. The ".java" suffix is replaced by ".html" to create the new file name.
      Parameters:
      relativePath - the relative path from a JavaFile class relative to its sources directory
      Returns:
      the location of the annotated report source code file
    • getUserHomeDir

      public static Path getUserHomeDir()
      Returns the home directory of the current user.
      Returns:
      the home directory of the current user
    • getUIParametersPath

      public static Path getUIParametersPath()
      Returns where the configured FxUI parameters are persisted to inside the output directory.
      Returns:
      parameters.dat relative to the outputDir
    • lastProjectPath

      public static Path 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.txt relative to the current directory
    • copyResource

      public static <T> void copyResource(Class<T> resourceClass, String resourceName, Path destination)
      Extract a copy of a resource file from the project directory or the .jar file.
      Parameters:
      resourceClass - the anchor class used to locate the resource
      resourceName - the name of the resource file to be extracted
      destination - 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 resource
      resourceFolder - the name of the resource folder to be extracted
      destination - folder path where the resource is copied to
    • clearDirectoryContents

      public static void clearDirectoryContents(Path directory)
      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

      public static boolean createDirectoriesIfNotExists(Path fileOrFolder)
      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

      public static void createLink(Path link, Path target)
      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 shortcut createWindowsShortcut(Path, Path) is used. The link extension must be ".lnk" in this case.
      Parameters:
      link - the location of the linking file shortcut
      target - what the link should point to
    • normalize

      public static String normalize(Path path)
      Converts a Path object 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 "/"