Skip to content
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 @@ -381,33 +381,7 @@ private boolean isVersionBelow(String currentVersion, String minVersion) {
if (currentVersion == null || minVersion == null) {
return false;
}

// Remove any qualifiers like -SNAPSHOT, -alpha, etc. for comparison
String cleanCurrent = currentVersion.split("-")[0];
String cleanMin = minVersion.split("-")[0];

try {
String[] currentParts = cleanCurrent.split("\\.");
String[] minParts = cleanMin.split("\\.");

int maxLength = Math.max(currentParts.length, minParts.length);

for (int i = 0; i < maxLength; i++) {
int currentPart = i < currentParts.length ? Integer.parseInt(currentParts[i]) : 0;
int minPart = i < minParts.length ? Integer.parseInt(minParts[i]) : 0;

if (currentPart < minPart) {
return true;
} else if (currentPart > minPart) {
return false;
}
}

return false; // Versions are equal
} catch (NumberFormatException e) {
// Fallback to string comparison if parsing fails
return currentVersion.compareTo(minVersion) < 0;
}
return getSession().parseVersion(currentVersion).compareTo(getSession().parseVersion(minVersion)) < 0;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,46 @@ void shouldNotModifyPluginWhenVersionAlreadySufficient() throws Exception {
// POM might still be marked as modified due to other plugin management additions
}

@Test
@DisplayName("should upgrade milestone version below release minimum")
void shouldUpgradeMilestoneVersionBelowRelease() throws Exception {
String pomXml = """
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
</plugins>
</build>
</project>
""";

Document document = saxBuilder.build(new StringReader(pomXml));
Map<Path, Document> pomMap = Map.of(Paths.get("pom.xml"), document);

UpgradeContext context = createMockContext();
UpgradeResult result = strategy.apply(context, pomMap);

assertTrue(result.success(), "Plugin upgrade should succeed");
assertTrue(result.modifiedCount() > 0, "Should have upgraded 3.0.0-M1 to 3.0.0");

Element root = document.getRootElement();
Namespace namespace = root.getNamespace();
Element build = root.getChild("build", namespace);
Element plugins = build.getChild("plugins", namespace);
Element plugin = plugins.getChild("plugin", namespace);
String version = plugin.getChildText("version", namespace);
assertEquals("3.0.0", version, "3.0.0-M1 should be upgraded to 3.0.0");
}

@Test
@DisplayName("should upgrade plugin in pluginManagement")
void shouldUpgradePluginInPluginManagement() throws Exception {
Expand Down
Loading