From 135f2c19c10f5064882f7e5d23da6324ef540a7e Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 22 Nov 2026 17:31:12 +0100 Subject: [PATCH] Move the missing-warnings ITs to javac unit tests and assert the ECJ failure reason The unit test pins the [module] warning and its column for both javac paths (forced javac and javax.tools), which is what the two ITs asserted. simple-eclipse-compiler-fail only checked that the build failed; it now asserts the syntax error in MyClass.java. --- .../invoker.properties | 19 ------- .../it/missing-warnings-in-process/pom.xml | 49 ------------------ .../src/main/java/com/company/SomeClass.java | 5 -- .../src/main/java/module-info.java | 3 -- .../missing-warnings-in-process/verify.groovy | 24 --------- .../it/missing-warnings/invoker.properties | 19 ------- .../src/main/it/missing-warnings/pom.xml | 50 ------------------- .../src/main/java/com/company/SomeClass.java | 5 -- .../src/main/java/module-info.java | 3 -- .../verify.groovy | 7 ++- .../compiler/javac/JavacCompilerTest.java | 44 ++++++++++++++++ 11 files changed, 49 insertions(+), 179 deletions(-) delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings-in-process/invoker.properties delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings-in-process/pom.xml delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/com/company/SomeClass.java delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/module-info.java delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings-in-process/verify.groovy delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings/invoker.properties delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings/pom.xml delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings/src/main/java/com/company/SomeClass.java delete mode 100644 plexus-compiler-its/src/main/it/missing-warnings/src/main/java/module-info.java rename plexus-compiler-its/src/main/it/{missing-warnings => simple-eclipse-compiler-fail}/verify.groovy (73%) diff --git a/plexus-compiler-its/src/main/it/missing-warnings-in-process/invoker.properties b/plexus-compiler-its/src/main/it/missing-warnings-in-process/invoker.properties deleted file mode 100644 index 9f1353fff..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings-in-process/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -invoker.goals = clean compile -#invoker.buildResult = failure diff --git a/plexus-compiler-its/src/main/it/missing-warnings-in-process/pom.xml b/plexus-compiler-its/src/main/it/missing-warnings-in-process/pom.xml deleted file mode 100644 index 8fe538f1c..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings-in-process/pom.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - 4.0.0 - - org.apache.maven.plugins.compiler.it - missing-warnings-in-process - 1.0-SNAPSHOT - - - - - - org.apache.maven.plugins - maven-compiler-plugin - @maven.compiler.version@ - - true - - - - org.codehaus.plexus - plexus-compiler-api - ${plexus.compiler.version} - - - org.codehaus.plexus - plexus-compiler-manager - ${plexus.compiler.version} - - - org.codehaus.plexus - plexus-compiler-javac - ${plexus.compiler.version} - - - - - - - - - 11 - 11 - UTF-8 - @pom.version@ - - diff --git a/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/com/company/SomeClass.java b/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/com/company/SomeClass.java deleted file mode 100644 index d0901b444..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/com/company/SomeClass.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.company; - -public class SomeClass -{ -} diff --git a/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/module-info.java b/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/module-info.java deleted file mode 100644 index 03364120e..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings-in-process/src/main/java/module-info.java +++ /dev/null @@ -1,3 +0,0 @@ -module testcase { - exports com.company to someOtherModule; -} \ No newline at end of file diff --git a/plexus-compiler-its/src/main/it/missing-warnings-in-process/verify.groovy b/plexus-compiler-its/src/main/it/missing-warnings-in-process/verify.groovy deleted file mode 100644 index 3c5440c3e..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings-in-process/verify.groovy +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -def logFile = new File( basedir, 'build.log' ) -assert logFile.exists() -content = logFile.text.normalize() - -assert content.contains( "module-info.java:[2,32] [module] module not found: someOtherModule") -//assert content.contains( "exports com.company to someOtherModule;" ) diff --git a/plexus-compiler-its/src/main/it/missing-warnings/invoker.properties b/plexus-compiler-its/src/main/it/missing-warnings/invoker.properties deleted file mode 100644 index 9f1353fff..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings/invoker.properties +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -invoker.goals = clean compile -#invoker.buildResult = failure diff --git a/plexus-compiler-its/src/main/it/missing-warnings/pom.xml b/plexus-compiler-its/src/main/it/missing-warnings/pom.xml deleted file mode 100644 index 812007398..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - - 4.0.0 - - org.apache.maven.plugins.compiler.it - missing-warnings - 1.0-SNAPSHOT - - - - - - org.apache.maven.plugins - maven-compiler-plugin - @maven.compiler.version@ - - true - true - - - - org.codehaus.plexus - plexus-compiler-api - ${plexus.compiler.version} - - - org.codehaus.plexus - plexus-compiler-manager - ${plexus.compiler.version} - - - org.codehaus.plexus - plexus-compiler-javac - ${plexus.compiler.version} - - - - - - - - - 11 - 11 - UTF-8 - @pom.version@ - - diff --git a/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/com/company/SomeClass.java b/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/com/company/SomeClass.java deleted file mode 100644 index c0c65494c..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/com/company/SomeClass.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.company; - -public class SomeClass -{ -} diff --git a/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/module-info.java b/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/module-info.java deleted file mode 100644 index 0b7ef2966..000000000 --- a/plexus-compiler-its/src/main/it/missing-warnings/src/main/java/module-info.java +++ /dev/null @@ -1,3 +0,0 @@ -module testcase { - exports com.company to someOtherModule; -} \ No newline at end of file diff --git a/plexus-compiler-its/src/main/it/missing-warnings/verify.groovy b/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/verify.groovy similarity index 73% rename from plexus-compiler-its/src/main/it/missing-warnings/verify.groovy rename to plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/verify.groovy index 14b6054a9..7808cb859 100644 --- a/plexus-compiler-its/src/main/it/missing-warnings/verify.groovy +++ b/plexus-compiler-its/src/main/it/simple-eclipse-compiler-fail/verify.groovy @@ -20,5 +20,8 @@ def logFile = new File( basedir, 'build.log' ) assert logFile.exists() content = logFile.text.normalize() -assert content.contains( "module-info.java:[2,25] [module] module not found: someOtherModule") -//assert content.contains( "exports com.company to someOtherModule;" ) +// the build fails because ECJ rejects the main source, not for some other reason +assert content.contains( "MyClass.java:[23,5] Syntax error" ) +// the failure stops the build before the test sources are compiled +assert !content.contains( "MyTest.java" ) +assert !new File( basedir, "target/classes/MyClass.class" ).exists() diff --git a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java index 6cf437c7b..7bee39fee 100644 --- a/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java +++ b/plexus-compilers/plexus-compiler-javac/src/test/java/org/codehaus/plexus/compiler/javac/JavacCompilerTest.java @@ -256,6 +256,50 @@ void testForkedAndInProcessLintCategoriesAreEqual(@TempDir Path tempDirectory) t // java.util.List - which is a separate parity gap, so only the category is compared here } + /** + * javac reports a module that {@code exports ... to} cannot find only as a {@code [module]} lint warning. Both + * back-ends must surface it, and they report different columns: javac's own output (parsed when + * {@code forceJavacCompilerUse} is set) points at the module name, the diagnostic API at the end of the name. + */ + @ParameterizedTest(name = "forceJavacCompilerUse={0} -> column {1}") + @CsvSource({"true, 25", "false, 32"}) + void testMissingModuleIsReportedAsWarning( + boolean forceJavacCompilerUse, int expectedColumn, @TempDir Path tempDirectory) throws Exception { + Path sourceDirectory = tempDirectory.resolve("src"); + Path moduleInfo = sourceDirectory.resolve("module-info.java"); + Files.createDirectories(sourceDirectory.resolve("com/company")); + Files.write(moduleInfo, Arrays.asList("module testcase {", "\texports com.company to someOtherModule;", "}")); + Files.write( + sourceDirectory.resolve("com/company/SomeClass.java"), + Arrays.asList("package com.company;", "", "public class SomeClass {", "}")); + + File buildDirectory = tempDirectory.resolve("build").toFile(); + Files.createDirectories(buildDirectory.toPath()); + CompilerConfiguration configuration = new CompilerConfiguration(); + configuration.setForceJavacCompilerUse(forceJavacCompilerUse); + configuration.setWorkingDirectory(tempDirectory.toFile()); + configuration.setBuildDirectory(buildDirectory); + configuration.setOutputLocation(new File(buildDirectory, "classes").getAbsolutePath()); + configuration.addSourceLocation(sourceDirectory.toString()); + configuration.setSourceVersion("11"); + configuration.setTargetVersion("11"); + configuration.setShowWarnings(true); + + CompilerResult result = getCompiler().performCompile(configuration); + + assertTrue(result.isSuccess(), "compilation failed: " + result.getCompilerMessages()); + // javac also warns about the missing system modules path; the module warning is the one of interest + List moduleWarnings = result.getCompilerMessages().stream() + .filter(message -> message.getKind() == CompilerMessage.Kind.WARNING) + .filter(message -> message.getMessage().contains("[module] module not found: someOtherModule")) + .collect(Collectors.toList()); + assertEquals(1, moduleWarnings.size(), "expected the module warning in " + result.getCompilerMessages()); + CompilerMessage warning = moduleWarnings.get(0); + assertEquals("module-info.java", getFileName(warning.getFile())); + assertEquals(2, warning.getStartLine()); + assertEquals(expectedColumn, warning.getStartColumn()); + } + private static CompilerMessage onlyWarning(CompilerResult result) { List warnings = result.getCompilerMessages().stream() .filter(message -> message.getKind() == CompilerMessage.Kind.WARNING)