in src/main/java/org/apache/maven/plugin/compiler/ToolExecutor.java [202:264]
protected ToolExecutor(final AbstractCompilerMojo mojo, DiagnosticListener<? super JavaFileObject> listener)
throws IOException {
logger = mojo.logger;
if (listener == null) {
listener =
new DiagnosticLogger(logger, mojo.messageBuilderFactory, LOCALE, mojo.project.getRootDirectory());
}
this.listener = listener;
encoding = mojo.charset();
incrementalBuildConfig = mojo.incrementalCompilationConfiguration();
outputDirectory = Files.createDirectories(mojo.getOutputDirectory());
sourceDirectories = mojo.getSourceDirectories(outputDirectory);
dependencies = new LinkedHashMap<>();
/*
* Get the source files and whether they include or are assumed to include `module-info.java`.
* Note that we perform this step after processing compiler arguments, because this block may
* skip the build if there is no source code to compile. We want arguments to be verified first
* in order to warn about possible configuration problems.
*/
if (incrementalBuildConfig.contains(IncrementalBuild.Aspect.MODULES)) {
boolean hasNoFileMatchers = mojo.hasNoFileMatchers();
for (SourceDirectory root : sourceDirectories) {
if (root.moduleName == null) {
throw new CompilationFailureException("The <incrementalCompilation> value can be \"modules\" "
+ "only if all source directories are Java modules.");
}
hasNoFileMatchers &= root.includes.isEmpty() && root.excludes.isEmpty();
}
if (!hasNoFileMatchers) {
throw new CompilationFailureException("Include and exclude filters cannot be specified "
+ "when <incrementalCompilation> is set to \"modules\".");
}
hasModuleDeclaration = true;
sourceFiles = List.of();
} else {
// The order of the two next lines matter for initialization of `SourceDirectory.moduleInfo`.
sourceFiles = new PathFilter(mojo).walkSourceFiles(sourceDirectories);
hasModuleDeclaration = mojo.hasModuleDeclaration(sourceDirectories);
if (sourceFiles.isEmpty()) {
generatedSourceDirectories = Set.of();
dependencyResolution = null;
return;
}
}
generatedSourceDirectories = mojo.addGeneratedSourceDirectory();
/*
* Get the dependencies. If the module-path contains any automatic (filename-based)
* dependency and the MOJO is compiling the main code, then a warning will be logged.
*
* NOTE: this code assumes that the map and the list values are modifiable.
* This code performs a deep copies for safety. They are unnecessary copies when
* the implementation is `org.apache.maven.impl.DefaultDependencyResolverResult`,
* but we assume for now that it is not worth an optimization. The copies also
* protect `dependencyResolution` from changes in `dependencies`.
*/
dependencyResolution = mojo.resolveDependencies(hasModuleDeclaration);
if (dependencyResolution != null) {
dependencies.putAll(dependencyResolution.getDispatchedPaths());
dependencies.entrySet().forEach((e) -> e.setValue(new ArrayList<>(e.getValue())));
}
mojo.resolveProcessorPathEntries(dependencies);
}