From de9115f69fbd117806ee564a40edfffdfe7f28d3 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 9 Nov 2026 11:24:13 +0000 Subject: [PATCH] IT: verify annotation processor in the same reactor can be used by a sibling module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds MavenITgh13911ReactorAnnotationProcessorTest (sequential builder only, as Maven 3.x has no concurrent builder) with a two-module reactor: - processor/ — jar with @Gh13911Generated annotation and processor that writes META-INF/generated-by-gh13911.txt to the class output directory - client/ — jar that declares processor as provided dep and configures it via Companion to apache/maven#13914. Fixes apache/maven#13911 Co-authored-by: Claude Sonnet 4.6 --- ...gh13911ReactorAnnotationProcessorTest.java | 63 +++++++++++++++++ .../gh-13911-reactor-ap/client/pom.xml | 68 +++++++++++++++++++ .../apache/maven/its/gh13911/ClientClass.java | 25 +++++++ .../resources/gh-13911-reactor-ap/pom.xml | 41 +++++++++++ .../gh-13911-reactor-ap/processor/pom.xml | 33 +++++++++ .../maven/its/gh13911/Gh13911Generated.java | 31 +++++++++ .../maven/its/gh13911/Gh13911Processor.java | 64 +++++++++++++++++ .../javax.annotation.processing.Processor | 1 + 8 files changed, 326 insertions(+) create mode 100644 core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13911ReactorAnnotationProcessorTest.java create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/client/pom.xml create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/client/src/main/java/org/apache/maven/its/gh13911/ClientClass.java create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/pom.xml create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/pom.xml create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Generated.java create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Processor.java create mode 100644 core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13911ReactorAnnotationProcessorTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13911ReactorAnnotationProcessorTest.java new file mode 100644 index 000000000..fe7d7a504 --- /dev/null +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITgh13911ReactorAnnotationProcessorTest.java @@ -0,0 +1,63 @@ +/* + * 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. + */ +package org.apache.maven.it; + +import java.io.File; + +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +/** + * Integration test for GH-13911. + * + *

Verifies that an annotation processor (AP) built from source in the same Maven reactor + * can be used by a sibling module during its {@code compile} phase. The POM {@code provided} + * dependency on the AP module gives Maven the ordering information it needs; no special + * reactor-plugin detection (MNG-1088 class) is required.

+ */ +class MavenITgh13911ReactorAnnotationProcessorTest extends AbstractMavenIntegrationTestCase { + + MavenITgh13911ReactorAnnotationProcessorTest() { + // Annotation processors via provided dep ordering works since Maven 3.0 + super("[3.0,)"); + } + + /** + * Verify that Maven correctly orders the AP module before the client module and that the + * annotation processor generates its output file. + * + * @throws Exception in case of failure + */ + @Test + void testReactorAnnotationProcessor() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/gh-13911-reactor-ap"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("client/target"); + verifier.deleteArtifacts("org.apache.maven.its.gh13911"); + verifier.addCliArgument("compile"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + // The annotation processor must have run and written its marker resource + verifier.verifyFilePresent("client/target/classes/META-INF/generated-by-gh13911.txt"); + } +} diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/pom.xml b/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/pom.xml new file mode 100644 index 000000000..a64ca3258 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/pom.xml @@ -0,0 +1,68 @@ + + + + 4.0.0 + + + org.apache.maven.its.gh13911 + aggregator + 1.0-SNAPSHOT + + + client + jar + + Maven Integration Test :: GH-13911 :: Client (uses reactor AP) + Uses the annotation processor built from source in the sibling module. + The provided dependency on the processor triggers Maven's reactor ordering. + + + + org.apache.maven.its.gh13911 + processor + 1.0-SNAPSHOT + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + org.apache.maven.its.gh13911 + processor + 1.0-SNAPSHOT + + + + + + + diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/src/main/java/org/apache/maven/its/gh13911/ClientClass.java b/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/src/main/java/org/apache/maven/its/gh13911/ClientClass.java new file mode 100644 index 000000000..f5e09fe00 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/client/src/main/java/org/apache/maven/its/gh13911/ClientClass.java @@ -0,0 +1,25 @@ +/* + * 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. + */ +package org.apache.maven.its.gh13911; + +/** + * Client class annotated with the reactor-built annotation processor's annotation. + */ +@Gh13911Generated +public class ClientClass {} diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/pom.xml b/core-it-suite/src/test/resources/gh-13911-reactor-ap/pom.xml new file mode 100644 index 000000000..be9a1e1ac --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + org.apache.maven.its.gh13911 + aggregator + 1.0-SNAPSHOT + pom + + Maven Integration Test :: GH-13911 :: Reactor Annotation Processor + Verifies that an annotation processor built in the same Maven reactor can be used by a sibling + module during its compile phase. + + + processor + client + + + + 8 + 8 + + diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/pom.xml b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/pom.xml new file mode 100644 index 000000000..2222738e4 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/pom.xml @@ -0,0 +1,33 @@ + + + + 4.0.0 + + + org.apache.maven.its.gh13911 + aggregator + 1.0-SNAPSHOT + + + processor + jar + + Maven Integration Test :: GH-13911 :: Annotation Processor + diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Generated.java b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Generated.java new file mode 100644 index 000000000..63c5aa368 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Generated.java @@ -0,0 +1,31 @@ +/* + * 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. + */ +package org.apache.maven.its.gh13911; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Marker annotation processed by {@link Gh13911Processor} at compile time. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Gh13911Generated {} diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Processor.java b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Processor.java new file mode 100644 index 000000000..a33a52210 --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/java/org/apache/maven/its/gh13911/Gh13911Processor.java @@ -0,0 +1,64 @@ +/* + * 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. + */ +package org.apache.maven.its.gh13911; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import javax.tools.Diagnostic; +import javax.tools.FileObject; +import javax.tools.StandardLocation; + +import java.io.IOException; +import java.io.Writer; +import java.util.Set; + +/** + * Annotation processor for the GH-13911 integration test. + *

+ * When it finds any type annotated with {@link Gh13911Generated}, it writes a resource file + * {@code META-INF/generated-by-gh13911.txt} to the class output directory. + */ +@SupportedAnnotationTypes("org.apache.maven.its.gh13911.Gh13911Generated") +@SupportedSourceVersion(SourceVersion.RELEASE_8) +public class Gh13911Processor extends AbstractProcessor { + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (annotations.isEmpty() || roundEnv.processingOver()) { + return false; + } + try { + FileObject resource = processingEnv + .getFiler() + .createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/generated-by-gh13911.txt"); + try (Writer writer = resource.openWriter()) { + writer.write("[GH-13911] annotation processor ran successfully\n"); + } + } catch (IOException e) { + processingEnv + .getMessager() + .printMessage(Diagnostic.Kind.ERROR, "[GH-13911] failed to write marker: " + e.getMessage()); + } + return true; + } +} diff --git a/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor new file mode 100644 index 000000000..5efdbd70a --- /dev/null +++ b/core-it-suite/src/test/resources/gh-13911-reactor-ap/processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -0,0 +1 @@ +org.apache.maven.its.gh13911.Gh13911Processor