Class ProjectLayout
java.lang.Object
org.machanism.machai.project.layout.ProjectLayout
- Direct Known Subclasses:
DefaultProjectLayout,GragleProjectLayout,JScriptProjectLayout,MavenProjectLayout,PythonProjectLayout
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindDirectories(File projectDir) Recursively lists all directories, excluding known build/tooling directories.Recursively lists all files under a directory, excluding known build/tooling directories.abstract Collection<String> Returns the root-relative documentation directories.static String[]Returns a copy of the exclude directories array to prevent external modification.Returns a list of module directories (or names) within this project or null for non-parent project.Returns the parent project identifier, when available.Returns the configured project root directory.Returns a stable project identifier, when available.Returns the layout type name (derived from the implementing class name).Returns a human-friendly project name, when available.static StringgetRelativePath(File dir, File file) Computes the relative path from the specified project directory to the target file.static StringgetRelativePath(File dir, File file, boolean addSingleDot) Computes the relative path from the specified project directory to the target file.getRelativePath(String basePath, File file) Computes a root-relative path for a file, based on the provided base path.abstract Collection<String> Returns the root-relative source directories for production code.abstract Collection<String> getTests()Returns the root-relative source directories for test code.projectDir(File projectDir) Sets the project root directory used by this layout.
-
Constructor Details
-
ProjectLayout
public ProjectLayout()
-
-
Method Details
-
projectDir
Sets the project root directory used by this layout.- Parameters:
projectDir- the project root directory- Returns:
- this instance for chaining
-
getProjectDir
Returns the configured project root directory.- Returns:
- the project root directory
-
getModules
Returns a list of module directories (or names) within this project or null for non-parent project. -
getRelativePath
Computes a root-relative path for a file, based on the provided base path.- Parameters:
basePath- absolute path of the base directoryfile- target file- Returns:
- the path of
filerelative tobasePath
-
getSources
Returns the root-relative source directories for production code.- Returns:
- list of root-relative source directories
-
getDocuments
Returns the root-relative documentation directories.- Returns:
- list of root-relative documentation directories
-
getTests
Returns the root-relative source directories for test code.- Returns:
- list of root-relative test source directories
-
getRelativePath
Computes the relative path from the specified project directory to the target file. The result is not prefixed with./.- Parameters:
dir- the base project directoryfile- the target file for which to compute the relative path- Returns:
- the relative path string, or
nullif the target file is not within the project directory - See Also:
-
getRelativePath
Computes the relative path from the specified project directory to the target file. Optionally, the result can be prefixed with./ifaddSingleDotistrue.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 directoryfile- the target file for which to compute the relative pathaddSingleDot- iftrue, prefixes the result with./when appropriate- Returns:
- the relative path string, or
nullif the target file is not within the project directory
-
findFiles
Recursively lists all files under a directory, excluding known build/tooling directories.- Parameters:
projectDir- directory to traverse- Returns:
- files found; never
null
-
findDirectories
Recursively lists all directories, excluding known build/tooling directories.- Parameters:
projectDir- directory to traverse- Returns:
- directories found; never
null
-
getProjectName
Returns a human-friendly project name, when available.- Returns:
- the project name or
nullif unknown
-
getProjectId
Returns a stable project identifier, when available.- Returns:
- the project identifier or
nullif unknown
-
getProjectLayoutType
Returns the layout type name (derived from the implementing class name).- Returns:
- a short layout type name
-
getParentId
Returns the parent project identifier, when available.- Returns:
- parent project identifier or
nullif unknown
-
getExcludeDirs
Returns a copy of the exclude directories array to prevent external modification.- Returns:
- a copy of the exclude directories array
-