Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <a href="https://github.com/apache/maven/issues/13911">GH-13911</a>.
*
* <p>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.</p>
*/
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.gh13911</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>client</artifactId>
<packaging>jar</packaging>

<name>Maven Integration Test :: GH-13911 :: Client (uses reactor AP)</name>
<description>Uses the annotation processor built from source in the sibling module.
The provided dependency on the processor triggers Maven's reactor ordering.</description>

<dependencies>
<dependency>
<groupId>org.apache.maven.its.gh13911</groupId>
<artifactId>processor</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!--
Explicit annotationProcessorPaths is the recommended modern approach.
The reactor-built processor artifact is resolved from target/classes via the
workspace reader (no install phase required), so the dependency ordering
created by the provided-scope dep above is sufficient.
-->
<annotationProcessorPaths>
<path>
<groupId>org.apache.maven.its.gh13911</groupId>
<artifactId>processor</artifactId>
<version>1.0-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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 {}
41 changes: 41 additions & 0 deletions core-it-suite/src/test/resources/gh-13911-reactor-ap/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.gh13911</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Maven Integration Test :: GH-13911 :: Reactor Annotation Processor</name>
<description>Verifies that an annotation processor built in the same Maven reactor can be used by a sibling
module during its compile phase.</description>

<modules>
<module>processor</module>
<module>client</module>
</modules>

<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.maven.its.gh13911</groupId>
<artifactId>aggregator</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>processor</artifactId>
<packaging>jar</packaging>

<name>Maven Integration Test :: GH-13911 :: Annotation Processor</name>
</project>
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
@@ -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.
* <p>
* 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<? extends TypeElement> 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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.maven.its.gh13911.Gh13911Processor
Loading