Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add micronaut-inject exclusion to non-core annotation processors. #94

Merged
merged 2 commits into from
Jul 21, 2023
Merged
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
Expand Up @@ -25,11 +25,13 @@
import org.openrewrite.internal.lang.NonNull;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.maven.MavenVisitor;
import org.openrewrite.semver.DependencyMatcher;
import org.openrewrite.xml.AddOrUpdateChild;
import org.openrewrite.xml.ChangeTagValueVisitor;
import org.openrewrite.xml.tree.Xml;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -90,8 +92,11 @@ public String getDescription() {

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {

return new MavenVisitor<ExecutionContext>() {

final DependencyMatcher depMatcher = Objects.requireNonNull(DependencyMatcher.build(ChangeAnnotationProcessorPath.this.oldGroupId + ":" + ChangeAnnotationProcessorPath.this.oldArtifactId).getValue());

@Override
public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
Xml.Tag plugin = (Xml.Tag) super.visitTag(tag, ctx);
Expand Down Expand Up @@ -151,8 +156,8 @@ private void maybeAddExclusionsToPath(@NonNull Xml.Tag path, @NonNull List<Strin
}

private boolean isPathMatch(Xml.Tag path) {
return oldGroupId.equals(path.getChildValue("groupId").orElse(null)) &&
oldArtifactId.equals(path.getChildValue("artifactId").orElse(null));
return this.depMatcher.matches(path.getChildValue("groupId").orElse(""),
path.getChildValue("artifactId").orElse(""));
}

private Xml.Tag changeChildTagValue(Xml.Tag tag, String childTagName, String newValue, ExecutionContext ctx) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/META-INF/rewrite/micronaut3-to-4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,9 @@ recipeList:
- org.openrewrite.java.micronaut.ChangeAnnotationProcessorPath:
oldGroupId: io.micronaut
oldArtifactId: micronaut-graal
newVersion: micronaut.core.version
newVersion: micronaut.core.version
- org.openrewrite.java.micronaut.ChangeAnnotationProcessorPath:
oldGroupId: io.micronaut.*
oldArtifactId: micronaut-*
exclusions:
- io.micronaut:micronaut-inject
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ void updateCoreMavenAnnotationProcessors() {
}

@Test
void updateCoreMavenAnnotationProcessorsAndDontModifyModuleProcessors() {
void updateCoreMavenAnnotationProcessorsAndAddExclusionToModuleProcessors() {
rewriteRun(
//language=xml
pomXml("""
Expand Down Expand Up @@ -318,6 +318,12 @@ void updateCoreMavenAnnotationProcessorsAndDontModifyModuleProcessors() {
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>${micronaut.data.version}</version>
<exclusions>
<exclusion>
<groupId>io.micronaut</groupId>
<artifactId>micronaut-inject</artifactId>
</exclusion>
</exclusions>
</path>
<path>
<groupId>io.micronaut</groupId>
Expand Down