Skip to content

Commit 4d17907

Browse files
committed
Initial support of multi-releases project by using the <source> element.
Initial support of modular project (JPMS) by using the `<module>` element. Currently support only one or the other, not yet both in same time. Contains fixes for incremental build: * The `package-info.java` source files may produce no output. * Provide an option to rebuild everything as soon as one file changed. The `additions` aspect has been renamed `rebuild-on-add` for clarity and for consistency with `rebuild-on-change` added in the last above point.
1 parent 00b2250 commit 4d17907

17 files changed

+1065
-334
lines changed

src/it/MCOMPILER-192/verify.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ assert logFile.exists()
2222
def content = logFile.getText('UTF-8')
2323

2424
def causedByExpected = content.contains ( 'Caused by: org.apache.maven.plugin.compiler.CompilationFailureException:' )
25-
def twoFilesBeingCompiled = content.contains ( 'Compiling 2 source files' )
25+
def twoFilesBeingCompiled = content.contains ( 'Compiling all files' )
2626
def checkResult = content.contains ( 'BUILD FAILURE' )
2727
def compilationFailure1 = content.contains( '[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:')
2828
def compilationFailure2 = content.contains( ':compile (default-compile) on project blah: Cannot compile')

src/it/mcompiler-21_methodname-change/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ under the License.
3535
<groupId>org.apache.maven.plugins</groupId>
3636
<artifactId>maven-compiler-plugin</artifactId>
3737
<version>@project.version@</version>
38+
<configuration>
39+
<incrementalCompilation>sources,rebuild-on-change</incrementalCompilation>
40+
</configuration>
3841
</plugin>
3942
</plugins>
4043
</pluginManagement>

src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java

Lines changed: 91 additions & 58 deletions
Large diffs are not rendered by default.

src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.maven.plugin.compiler;
2020

21+
import javax.tools.DiagnosticListener;
22+
import javax.tools.JavaFileObject;
2123
import javax.tools.OptionChecker;
2224

2325
import java.io.IOException;
@@ -237,6 +239,21 @@ protected String getDebugFileName() {
237239
return debugFileName;
238240
}
239241

242+
/**
243+
* Creates a new task for compiling the main classes.
244+
*
245+
* @param listener where to send compilation warnings, or {@code null} for the Maven logger
246+
* @throws MojoException if this method identifies an invalid parameter in this <abbr>MOJO</abbr>
247+
* @return the task to execute for compiling the main code using the configuration in this <abbr>MOJO</abbr>
248+
* @throws IOException if an error occurred while creating the output directory or scanning the source directories
249+
*/
250+
@Override
251+
public ToolExecutor createExecutor(DiagnosticListener<? super JavaFileObject> listener) throws IOException {
252+
ToolExecutor executor = super.createExecutor(listener);
253+
addImplicitDependencies(executor.sourceDirectories, executor.dependencies);
254+
return executor;
255+
}
256+
240257
/**
241258
* If compiling a multi-release JAR in the old deprecated way, add the previous versions to the path.
242259
*
@@ -247,10 +264,8 @@ protected String getDebugFileName() {
247264
*
248265
* @deprecated For compatibility with the previous way to build multi-releases JAR file.
249266
*/
250-
@Override
251267
@Deprecated(since = "4.0.0")
252-
final void addImplicitDependencies(
253-
List<SourceDirectory> sourceDirectories, Map<PathType, List<Path>> addTo, boolean hasModuleDeclaration)
268+
private void addImplicitDependencies(List<SourceDirectory> sourceDirectories, Map<PathType, List<Path>> addTo)
254269
throws IOException {
255270
if (SUPPORT_LEGACY && multiReleaseOutput) {
256271
var paths = new TreeMap<Integer, Path>();

src/main/java/org/apache/maven/plugin/compiler/DiagnosticLogger.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ final class DiagnosticLogger implements DiagnosticListener<JavaFileObject> {
8989
*/
9090
@Override
9191
public void report(Diagnostic<? extends JavaFileObject> diagnostic) {
92-
MessageBuilder record = messageBuilderFactory.builder();
9392
String message = diagnostic.getMessage(locale);
93+
if (message == null || message.isBlank()) {
94+
return;
95+
}
96+
MessageBuilder record = messageBuilderFactory.builder();
9497
record.a(message);
9598
Diagnostic.Kind kind = diagnostic.getKind();
9699
String style;
@@ -176,7 +179,7 @@ void logSummary() {
176179
patternForCount = patternForCount(Math.max(numWarnings, numErrors));
177180
}
178181
if ((numWarnings | numErrors) != 0) {
179-
message.strong("Total:").newline();
182+
message.strong("Total:");
180183
}
181184
if (numWarnings != 0) {
182185
writeCount(message, patternForCount, numWarnings, "warning");
@@ -200,10 +203,10 @@ private static String patternForCount(int n) {
200203
* Appends the count of warnings or errors, making them plural if needed.
201204
*/
202205
private static void writeCount(MessageBuilder message, String patternForCount, int count, String name) {
206+
message.newline();
203207
message.format(patternForCount, count, name);
204208
if (count > 1) {
205209
message.append('s');
206210
}
207-
message.newline();
208211
}
209212
}

src/main/java/org/apache/maven/plugin/compiler/ForkedToolSources.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class ForkedToolSources implements StandardJavaFileManager {
6363
* Option for source files. These options are not declared in
6464
* {@link JavaPathType} because they are not about dependencies.
6565
*/
66-
private enum SourcePathType implements PathType {
66+
private enum OtherPathType implements PathType {
6767
/**
6868
* The option for the directory of source files.
6969
*/
@@ -84,7 +84,7 @@ private enum SourcePathType implements PathType {
8484
*/
8585
private final String option;
8686

87-
SourcePathType(String option) {
87+
OtherPathType(String option) {
8888
this.option = option;
8989
}
9090

@@ -411,11 +411,11 @@ public void setLocationFromPaths(Location location, Collection<? extends Path> p
411411
PathType type = JavaPathType.valueOf(location).orElse(null);
412412
if (type == null) {
413413
if (location == StandardLocation.SOURCE_OUTPUT) {
414-
type = SourcePathType.GENERATED_SOURCES;
414+
type = OtherPathType.GENERATED_SOURCES;
415415
} else if (location == StandardLocation.SOURCE_PATH) {
416-
type = SourcePathType.SOURCES;
416+
type = OtherPathType.SOURCES;
417417
} else if (location == StandardLocation.CLASS_OUTPUT) {
418-
type = SourcePathType.OUTPUT;
418+
type = OtherPathType.OUTPUT;
419419
} else {
420420
throw new IllegalArgumentException("Unsupported location: " + location);
421421
}

0 commit comments

Comments
 (0)