Class ProjectLayout

java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
Direct Known Subclasses:
DefaultProjectLayout, GragleProjectLayout, 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 paths, 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 paths

Paths 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

      public ProjectLayout()
  • 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.
    • 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
    • findFiles

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

      public static List<File> findDirectories(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