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

AddAnnotationProcessor should compare and update versions using a property #4822

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -85,8 +85,11 @@ public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
artifactId.equals(child.getChildValue("artifactId").orElse(null))) {
if (!version.equals(child.getChildValue("version").orElse(null))) {
String oldVersion = child.getChildValue("version").orElse("");
VersionComparator comparator = Semver.validate(oldVersion, null).getValue();
if (comparator.compare(version, oldVersion) > 0) {
String lookupVersion = oldVersion.startsWith("${") ?
getResolutionResult().getPom().getValue(oldVersion.trim()) :
oldVersion;
VersionComparator comparator = Semver.validate(lookupVersion, null).getValue();
if (comparator.compare(version, lookupVersion) > 0) {
List<Xml.Tag> tags = tg.getChildren();
tags.set(i, child.withChildValue("version", version));
return tg.withContent(tags);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,111 @@ void shouldUpdateProcessorVersionAlreadyPresent() {
)
);
}

@Test
void addAnnotationWithOlderVersionAsMavenProperty() {
rewriteRun(
spec -> spec.recipe(new AddAnnotationProcessor(
"org.projectlombok",
"lombok-mapstruct-binding",
"0.2.0"
)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<version.lombok.mapstruct.binding>0.1.0</version.lombok.mapstruct.binding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${version.lombok.mapstruct.binding}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
""",
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<version.lombok.mapstruct.binding>0.1.0</version.lombok.mapstruct.binding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not what we want, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed better to update the version tag; this was a first quick attempt at getting rid of the comparison failure. Improvement picked up in 7c2fcd2

</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
"""
)
);
}

@Test
void addAnnotationWithSameVersionAsMavenProperty() {
rewriteRun(
spec -> spec.recipe(new AddAnnotationProcessor(
"org.projectlombok",
"lombok-mapstruct-binding",
"0.2.0"
)),
pomXml(
"""
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<properties>
<version.lombok.mapstruct.binding>0.2.0</version.lombok.mapstruct.binding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>${version.lombok.mapstruct.binding}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
"""
)
);
}
}
Loading