Class ProjectLayout

java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
Direct Known Subclasses:
DefaultProjectLayout, GradleProjectLayout, JScriptProjectLayout, MavenProjectLayout, PythonProjectLayout

public abstract class ProjectLayout extends Object
Base abstraction for describing a project's conventional on-disk layout.

A ProjectLayout implementation is responsible for translating build tool conventions and/or build metadata into a set of root-relative path, such as source roots, test roots, documentation roots, and (optionally) module directories.

Implementations are expected to be configured with a project root via projectDir(File) prior to calling any accessors.

Root-relative path

Path returned from this API are typically expressed as root-relative strings using / as a separator. Callers should resolve them against getProjectDir() before accessing the filesystem.

Example

 
 java.io.File projectDir = new java.io.File("C:\\repo");
 ProjectLayout layout = new MavenProjectLayout().projectDir(projectDir);

 java.util.List<String> sources = layout.getSources();
 
 
Since:
0.0.2
Author:
Viktor Tovstyi
  • Constructor Details

    • ProjectLayout

      protected ProjectLayout()
      Creates a project layout instance.
  • Method Details

    • projectDir

      public ProjectLayout projectDir(File projectDir)
      Sets the project root directory used by this layout.
      Parameters:
      projectDir - the project root directory
      Returns:
      this instance for chaining
    • getProjectDir

      public File getProjectDir()
      Returns the configured project root directory.
      Returns:
      the project root directory
    • getModules

      @Nullable public List<String> getModules()
      Returns a list of module directories (or names) within this project or null for non-parent project.
      Returns:
      list of module directories, or null for non-parent projects
    • getRelativePath

      public String getRelativePath(String basePath, File file)
      Computes a root-relative path for a file, based on the provided base path.
      Parameters:
      basePath - absolute path of the base directory
      file - target file
      Returns:
      the path of file relative to basePath
    • getSources

      public abstract Collection<String> getSources()
      Returns the root-relative source directories for production code.
      Returns:
      list of root-relative source directories
    • getDocuments

      public abstract Collection<String> getDocuments()
      Returns the root-relative documentation directories.
      Returns:
      list of root-relative documentation directories
    • getTests

      public abstract Collection<String> getTests()
      Returns the root-relative source directories for test code.
      Returns:
      list of root-relative test source directories
    • getRelativePath

      public static String getRelativePath(File dir, File file)
      Computes the relative path from the specified project directory to the target file. The result is not prefixed with ./.
      Parameters:
      dir - the base project directory
      file - the target file for which to compute the relative path
      Returns:
      the relative path string, or null if the target file is not within the project directory
      See Also:
    • getRelativePath

      public static String getRelativePath(File dir, File file, boolean addSingleDot)
      Computes the relative path from the specified project directory to the target file. Optionally, the result can be prefixed with ./ if addSingleDot is true.

      If the target file is the same as the project directory, returns .. If an absolute path is provided, it must be located within the project directory.

      Parameters:
      dir - the base project directory
      file - the target file for which to compute the relative path
      addSingleDot - if true, prefixes the result with ./ when appropriate
      Returns:
      the relative path string, or null if the target file is not within the project directory
    • listFiles

      public static List<File> listFiles(File dir)
      Recursively lists all files under a directory, excluding known build/tooling directories.
      Parameters:
      dir - directory to traverse
      Returns:
      files found; never null
    • listDirectories

      public static List<File> listDirectories(File projectDir)
      Recursively lists all directories, excluding known build/tooling directories.
      Parameters:
      projectDir - directory to traverse
      Returns:
      directories found; never null
    • getProjectName

      public String getProjectName()
      Returns a human-friendly project name, when available.
      Returns:
      the project name or null if unknown
    • getProjectId

      public String getProjectId()
      Returns a stable project identifier, when available.
      Returns:
      the project identifier or null if unknown
    • getProjectLayoutType

      public String getProjectLayoutType()
      Returns the layout type name (derived from the implementing class name).
      Returns:
      a short layout type name
    • getParentId

      public String getParentId()
      Returns the parent project identifier, when available.
      Returns:
      parent project identifier or null if unknown
    • getExcludeDirs

      public static String[] getExcludeDirs()
      Returns a copy of the exclude directories array to prevent external modification.
      Returns:
      a copy of the exclude directories array
    • isExcludedPath

      public static boolean isExcludedPath(String path)
      Checks whether the specified path exactly matches an excluded directory name.
      Parameters:
      path - path or directory name to check
      Returns:
      true if the path is excluded; false otherwise
    • getTempDir

      public static String getTempDir()
      Returns the system temporary directory path, initializing it if necessary.

      If the temporary directory has not been set, this method retrieves the value of the java.io.tmpdir system property, logs the initialization, and caches the result for future calls.

      Returns:
      the absolute path to the system temporary directory