Enum PathStrategy

java.lang.Object
java.lang.Enum<PathStrategy>
io.github.ascopes.jct.workspaces.PathStrategy
All Implemented Interfaces:
Serializable, Comparable<PathStrategy>

public enum PathStrategy extends Enum<PathStrategy>
Strategy to use for creating new test directories.

This is used to define whether to use a totally isolated in-memory file system, or whether to use temporary directories on the default file system.

Since:
0.0.1
Author:
Ashley Scopes
  • Enum Constant Details

    • RAM_DIRECTORIES

      public static final PathStrategy RAM_DIRECTORIES
      Use RAM-based directories for any created directories.

      This is faster as everything remains in-memory. It also prevents the risk of resources not being tidied up correctly if the JVM is suddenly shut down. Test directories are also kept isolated from other tests that may be running in parallel, and isolated from the host operating system.

      If any annotation processors rely on being run in the default file system rather than using the NIO path API or filers directly, then they will not be compatible with reading files from this implementation of test directory. In this situation, users should opt to use TEMP_DIRECTORIES instead.

      Some non-Javac compiler implementations (such as ECJ) may also have some difficulties dealing with these paths.

    • TEMP_DIRECTORIES

      public static final PathStrategy TEMP_DIRECTORIES
      Use OS-level temporary directories for any created directories.

      This will write files to the OS temporary directory. These files will be deleted once the owning workspace is closed, but may be missed if the JVM is forcefully terminated or crashes.

      There are fewer guarantees of speed and isolation compared to using RAM_DIRECTORIES. However, you do gain the ability to set a breakpoint and inspect the contents of the directory in a file explorer.

      Since the temporary directories are usually created on the default file system, they are compatible with any annotation processors or compiler implementations that expect to be run on the default file system only.

      Some restrictions regarding file naming may be present depending on the platform that is in use, such as file name lengths on Windows. See your system documentation for more details.

  • Method Details

    • values

      public static PathStrategy[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static PathStrategy valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • newInstance

      Create a new instance of the test directory type with the given name.

      Note that calling this directly will return an object that you will have to manually manage the lifetime for. Failing to do so will result in resources being leaked.

      Users should not call this method by default unless they know what they are doing. As a result of this constraint, this method is not part of the public API and may be subject to change without notice.

      Parameters:
      name - the name to use.
      Returns:
      the new test directory.
    • defaultStrategy

      public static PathStrategy defaultStrategy()
      Determine the default strategy to fall back onto.

      This will be RAM_DIRECTORIES by default, but this may be subject to change between minor versions without notice, so do not rely on this if you are testing code that may be sensitive to the type of file system being used.

      Returns:
      the path strategy to use by default.