Class AbstractFileProcessor
java.lang.Object
org.machanism.machai.project.ProjectProcessor
org.machanism.machai.gw.processor.AbstractFileProcessor
- Direct Known Subclasses:
AIFileProcessor
Base implementation for processors that traverse a project directory and
perform work on files and folders.
AbstractFileProcessor provides common functionality used by the
Ghostwriter CLI, such as:
- Collecting files under a project directory while excluding common build and tooling folders,
- Supporting optional include matching via
PathMatcherand optional exclusion patterns, and - Delegating per-file work to subclasses via
processFile(ProjectLayout, File).
This class does not perform dependency resolution or builds; it operates on the filesystem only.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final MutableConfiguratorConfiguration source used to initialize providers.private String[]Optional list of path patterns or exact paths to exclude.private longTimeout for module processing worker pool shutdown, in minutes.private booleanWhether module discovery/recursion is disabled for the current run.private FileSpecifies a special scanning path or path pattern.private PathMatcherOptional matcher used to limit module/file processing to a subset.private FileRoot scanning directory for the current documentation run.private intDegree of concurrency for module processing.Fields inherited from class org.machanism.machai.project.ProjectProcessor
MACHAI_TEMP_DIR -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractFileProcessor(File rootDir, Configurator configurator) Creates a new file processor. -
Method Summary
Modifier and TypeMethodDescription(package private) voidaddMatchingFile(List<File> result, PathMatcher matcher, File projectDir, File file) Adds a file to the result when it is eligible for the requested pattern.Returns the configuration source for this processor.String[]Returns the exclude patterns configured for this processor.longReturns the timeout (in minutes) to wait for module processing completion during shutdown.getPath()Returns the scan directory used to derive match semantics.Returns the matcher used to decide whether a file is included.(package private) static PathMatchergetPatternPath(String path) Returns aPathMatcherwhen the provided string is a path pattern.Returns the root directory used as a base for relative paths.static booleanisModuleDir(ProjectLayout projectLayout, File dir) Checks whetherdiris one of the project module directories.booleanReturns whether recursion into modules/subdirectories is disabled.(package private) static booleanisPathPattern(String pattern) Tests whether a scan pattern string is aglob:orregex:matcher.Recursively lists all files under a directory, excluding known build/tooling directories.Finds all files/directories in the provided project folder that match a pattern.protected booleanDetermines whether the specified file should be included for processing based on exclusion rules, path matching patterns, and project structure.(package private) static intComputes the depth of a path for sorting.protected voidprocessFile(ProjectLayout projectLayout, File file) Extracts guidance for a file and, when present, performs provider processing.voidprocessFolder(ProjectLayout projectLayout) Processes a project layout for documentation gathering.(package private) voidprocessModulesMultiThreaded(File projectDir, List<String> modules) Processes all discovered modules concurrently.protected voidprocessParentFiles(ProjectLayout projectLayout) Processes non-module files and directories directly underrootDir.voidprocessProjectDir(ProjectLayout layout, String filePattern) Processes files in a project directory matching a provided pattern or directory.voidscanFolder(File projectDir) Recursively scans project folders, processing documentation inputs for all found modules and files.voidsetExcludes(String[] excludes) Sets exclude patterns or paths.voidsetModuleThreadTimeoutMinutes(long moduleThreadTimeoutMinutes) Sets the module processing shutdown timeout.voidsetNonRecursive(boolean nonRecursive) Sets whether scanning is restricted to the current directory only.voidSets the scan directory that originated the current match operation.voidsetPathMatcher(PathMatcher pathMatcher) Sets the path matcher used to include only matching files.voidsetThreads(int threads) Configures the number of threads to be used for multi-threaded module processing.booleanshouldExcludePath(Path path) Determines whether a relative path should be excluded according toexcludes.(package private) booleanshouldIncludeInListFiles(File projectDir, File file) Determines whether an entry found inlistFiles(File)should be included.(package private) voidshutdownExecutor(ExecutorService executor) Shuts down an ExecutorService safely without throwing from a finally block.Methods inherited from class org.machanism.machai.project.ProjectProcessor
getProjectLayout, processModule
-
Field Details
-
rootDir
Root scanning directory for the current documentation run. -
path
Specifies a special scanning path or path pattern. This should be a relative path with respect to the current processing project. If an absolute path is provided, it must be located within therootDir. -
threads
private int threadsDegree of concurrency for module processing. -
nonRecursive
private boolean nonRecursiveWhether module discovery/recursion is disabled for the current run. -
pathMatcher
Optional matcher used to limit module/file processing to a subset. -
excludes
Optional list of path patterns or exact paths to exclude. -
configurator
Configuration source used to initialize providers. -
moduleThreadTimeoutMinutes
private long moduleThreadTimeoutMinutesTimeout for module processing worker pool shutdown, in minutes.
-
-
Constructor Details
-
AbstractFileProcessor
Creates a new file processor.- Parameters:
rootDir- root directory used as a base for relative pathconfigurator- configuration source used by implementations
-
-
Method Details
-
scanFolder
Recursively scans project folders, processing documentation inputs for all found modules and files.- Overrides:
scanFolderin classProjectProcessor- Parameters:
projectDir- the directory containing the project/module to be scanned- Throws:
IOException- if an error occurs reading files
-
processModulesMultiThreaded
Processes all discovered modules concurrently.- Parameters:
projectDir- the parent project directorymodules- list of module relative paths
-
shutdownExecutor
Shuts down an ExecutorService safely without throwing from a finally block.Sonar java:S1143/java:S1163 - do not throw from finally blocks; preserve the thread interruption status.
- Parameters:
executor- executor to stop (may benull)
-
isModuleDir
Checks whetherdiris one of the project module directories.- Parameters:
projectLayout- layout containing module definitionsdir- directory candidate- Returns:
trueifdiris a module directory, otherwisefalse
-
match
Determines whether the specified file should be included for processing based on exclusion rules, path matching patterns, and project structure.The matching logic proceeds as follows:
- If the
fileisnull, returnsfalse. - If the file's absolute path contains any of the excluded directory names
defined in
ProjectLayout.EXCLUDE_DIRS, returnsfalse. - Computes the relative path from
rootDirtofile. If this isnull, returnsfalse. - Uses
pathMatcherto check if the relative path matches the configured pattern. - If it does not match and
pathis notnull, performs a secondary match that attempts to resolve the scan directory against the file and re-check from the project root.
- Parameters:
file- the file to check for inclusionprojectDir- the project directory of the project- Returns:
trueif the file matches all criteria for processing;falseotherwise
- If the
-
processParentFiles
Processes non-module files and directories directly underrootDir.- Parameters:
projectLayout- project layout- Throws:
IOException- if file reading fails
-
processFile
Extracts guidance for a file and, when present, performs provider processing.- Parameters:
projectLayout- project layoutfile- file to process- Throws:
IOException- if reading the file or provider execution fails
-
listFiles
Recursively lists all files under a directory, excluding known build/tooling directories.- Parameters:
projectDir- directory to traverse- Returns:
- list of files found
- Throws:
IOException- if directory listing fails
-
shouldIncludeInListFiles
Determines whether an entry found inlistFiles(File)should be included.Sonar java:S135 - reduce break/continue statements by isolating filtering.
- Parameters:
projectDir- project directory being traversedfile- candidate entry- Returns:
truewhen the entry should be included
-
shouldExcludePath
Determines whether a relative path should be excluded according toexcludes.- Parameters:
path- project-relative path- Returns:
truewhen excluded
-
addMatchingFile
Adds a file to the result when it is eligible for the requested pattern.- Parameters:
result- collection of matchesmatcher- optional path matcherprojectDir- project rootfile- candidate file
-
isPathPattern
Tests whether a scan pattern string is aglob:orregex:matcher.- Parameters:
pattern- scan directory argument- Returns:
truewhen the pattern uses a path-matcher prefix
-
getPatternPath
Returns aPathMatcherwhen the provided string is a path pattern.- Parameters:
path- pattern candidate- Returns:
- matcher or
nullwhenpathis not a pattern
-
processFolder
Processes a project layout for documentation gathering.- Specified by:
processFolderin classProjectProcessor- Parameters:
projectLayout- layout describing sources, tests, docs, and modules
-
listFiles
Finds all files/directories in the provided project folder that match a pattern.- Parameters:
projectDir- project rootpattern- directory path,glob:matcher, orregex:matcher- Returns:
- matching files/directories
- Throws:
IOException- if directory traversal fails
-
pathDepth
Computes the depth of a path for sorting.- Parameters:
path- input path- Returns:
- number of path segments
-
processProjectDir
Processes files in a project directory matching a provided pattern or directory.- Parameters:
layout- project layoutfilePattern- directory path,glob:, orregex:pattern
-
setThreads
public void setThreads(int threads) Configures the number of threads to be used for multi-threaded module processing.- Parameters:
threads- the number of concurrent threads to use; must be a positive integer- Throws:
IllegalArgumentException- if the specified number of threads is less than or equal to zero
-
setNonRecursive
public void setNonRecursive(boolean nonRecursive) Sets whether scanning is restricted to the current directory only.- Parameters:
nonRecursive-trueto disable module recursion
-
getExcludes
Returns the exclude patterns configured for this processor.- Returns:
- exclude list
-
setExcludes
Sets exclude patterns or paths.Each entry may be:
- a
glob:orregex:matcher expression - an exact relative path (compared using
Strings.CS)
- Parameters:
excludes- exclude list
- a
-
getRootDir
Returns the root directory used as a base for relative paths.- Returns:
- root directory
-
isNonRecursive
public boolean isNonRecursive()Returns whether recursion into modules/subdirectories is disabled.- Returns:
truewhen non-recursive mode is enabled
-
getModuleThreadTimeoutMinutes
public long getModuleThreadTimeoutMinutes()Returns the timeout (in minutes) to wait for module processing completion during shutdown.- Returns:
- shutdown timeout in minutes
-
setModuleThreadTimeoutMinutes
public void setModuleThreadTimeoutMinutes(long moduleThreadTimeoutMinutes) Sets the module processing shutdown timeout.- Parameters:
moduleThreadTimeoutMinutes- timeout in minutes; must be greater than 0- Throws:
IllegalArgumentException- if the timeout is not positive
-
setPath
Sets the scan directory that originated the current match operation.- Parameters:
path- scan directory
-
setPathMatcher
Sets the path matcher used to include only matching files.- Parameters:
pathMatcher- matcher (may benullto disable matching)
-
getPath
Returns the scan directory used to derive match semantics.- Returns:
- scan directory or
null
-
getPathMatcher
Returns the matcher used to decide whether a file is included.- Returns:
- matcher or
nullwhen matching is disabled
-
getConfigurator
Returns the configuration source for this processor.- Returns:
- configurator
-