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

Enforce the version of the annotation processor for now #118

Merged
merged 2 commits into from
Jan 24, 2024
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 @@ -15,6 +15,7 @@
import org.openrewrite.config.CompositeRecipe;
import org.openrewrite.config.Environment;
import org.openrewrite.config.YamlResourceLoader;
import org.openrewrite.maven.UpgradeDependencyVersion;
import org.openrewrite.maven.ChangePropertyValue;
import org.openrewrite.test.RecipeSpec;

Expand Down Expand Up @@ -51,8 +52,8 @@ public static RecipeSpec recipe(RecipeSpec spec, Path recipeFile, String quarkus
}

private static Recipe updateQuarkus(String quarkusVersion) {
return new CompositeRecipe(List.of(new ChangePropertyValue("quarkus.version", quarkusVersion, null, null),
new ChangePropertyValue("quarkus.platform.version", quarkusVersion, null, null)));
return new CompositeRecipe(List.of(new UpgradeDependencyVersion("io.quarkus.platform", "quarkus-bom", quarkusVersion, null, null, null),
new UpgradeDependencyVersion("io.quarkus", "quarkus-bom", quarkusVersion, null, null, null)));
}

private static Recipe recipeFromResource(String yamlResource, String... activeRecipes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.nio.file.Path;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
Expand All @@ -15,7 +14,7 @@ public class CoreUpdate37Test implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
CoreTestUtil.recipe(spec, Path.of("quarkus-updates", "core", "3.7.alpha1.yaml"), "3.7.0")
CoreTestUtil.recipe(spec, Path.of("quarkus-updates", "core", "3.7.alpha1.yaml"), "3.7.0.CR1")
.parser(JavaParser.fromJavaVersion().logCompilationWarningsAndErrors(true))
.typeValidationOptions(TypeValidation.none());
}
Expand Down Expand Up @@ -429,7 +428,7 @@ void testJpaModelgenNewDependencyManagedByQuarkusBom() {
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>3.6.4</version>
<version>3.7.0.CR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -446,6 +445,7 @@ void testJpaModelgenNewDependencyManagedByQuarkusBom() {
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.4.1.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down Expand Up @@ -701,7 +701,7 @@ void testJpaModelgenOldJpaModelgenAnnotationProcessorAlreadyPresent() {
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>3.6.4</version>
<version>3.7.0.CR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -718,6 +718,7 @@ void testJpaModelgenOldJpaModelgenAnnotationProcessorAlreadyPresent() {
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.4.1.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand Down Expand Up @@ -786,7 +787,92 @@ void testJpaModelgenOldJpaModelgenAnnotationProcessorAlreadyPresentWithOutdatedV
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>3.6.4</version>
<version>3.7.0.CR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.4.1.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
"""));
}

@Test
void testSyncVersion() {
//language=xml
rewriteRun(pomXml("""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>io.quarkus.bot</groupId>
<artifactId>release</artifactId>
<version>999-SNAPSHOT</version>
<properties>
<quarkus.version>3.6.4</quarkus.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.2.13.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>io.quarkus.bot</groupId>
<artifactId>release</artifactId>
<version>999-SNAPSHOT</version>
<properties>
<quarkus.version>3.7.0.CR1</quarkus.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>${quarkus.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -803,6 +889,7 @@ void testJpaModelgenOldJpaModelgenAnnotationProcessorAlreadyPresentWithOutdatedV
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>6.4.1.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
Expand All @@ -814,7 +901,6 @@ void testJpaModelgenOldJpaModelgenAnnotationProcessorAlreadyPresentWithOutdatedV
}

@Test
@Disabled("Pending the release of 3.7.0")
void testResteasyClientRenaming() {
//language=xml
rewriteRun(pomXml("""
Expand Down Expand Up @@ -868,7 +954,7 @@ void testResteasyClientRenaming() {
<artifactId>release</artifactId>
<version>999-SNAPSHOT</version>
<properties>
<quarkus.version>3.7.0</quarkus.version>
<quarkus.version>3.7.0.CR1</quarkus.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import java.nio.file.Path;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import org.openrewrite.Option;
import org.openrewrite.Recipe;
import org.openrewrite.TreeVisitor;
import org.openrewrite.internal.lang.Nullable;
import org.openrewrite.maven.MavenVisitor;
import org.openrewrite.maven.tree.MavenResolutionResult;
import org.openrewrite.maven.tree.ResolvedManagedDependency;
import org.openrewrite.xml.tree.Xml;

import lombok.EqualsAndHashCode;
Expand All @@ -25,6 +28,10 @@ public class AddMavenCompilerAnnotationProcessor extends Recipe {
@Option(displayName = "Annotation processor artifactId", description = "The artifactId of the annotation processor.", example = "hibernate-jpamodelgen", required = true)
String artifactId;

@Option(displayName = "Enforce managed version", description = "If the new annotation processor has a managed version, this flag can be used to explicitly set the version on the annotation processor with the version of the managed dependency. The default for this flag is `false`.", required = false)
@Nullable
Boolean enforceManagedVersion;

@Override
public String getDisplayName() {
return "Add an annotation processor to the Maven Compiler plugin configuration";
Expand All @@ -48,6 +55,13 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
String annotationProcessorPath = "<groupId>" + groupId + "</groupId>\n<artifactId>" + artifactId
+ "</artifactId>";

if (Boolean.TRUE.equals(enforceManagedVersion)) {
String managedVersion = getManagedVersion(groupId, artifactId);
if (managedVersion != null) {
annotationProcessorPath += "<version>" + managedVersion + "</version>";
}
}

if (configuration.isPresent()) {
Optional<Xml.Tag> annotationProcessorPathsWrapper = configuration.get()
.getChild("annotationProcessorPaths");
Expand Down Expand Up @@ -79,6 +93,17 @@ public Xml visitTag(Xml.Tag tag, ExecutionContext ctx) {
}
return mavenCompilerPluginTag;
}

private String getManagedVersion(String groupId, String artifactId) {
MavenResolutionResult result = getResolutionResult();
for (ResolvedManagedDependency managedDependency : result.getPom().getDependencyManagement()) {
if (groupId.equals(managedDependency.getGroupId())
&& artifactId.equals(managedDependency.getArtifactId())) {
return managedDependency.getVersion();
}
}
return null;
}
};
}
}
Loading