Skip to content

Commit

Permalink
Improve speed of versions:resolve-ranges in case parents contain many…
Browse files Browse the repository at this point in the history
… version properties - fix #1121
  • Loading branch information
m-schutte-ohra-nl authored Aug 27, 2024
1 parent 5b0aa16 commit 9dc5e0d
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>localhost</groupId>
<artifactId>it-resolve-ranges-issue-1121-parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<dummy.api.version>1.1.1</dummy.api.version>
</properties>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>${dummy.api.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=-X ${project.groupId}:${project.artifactId}:${project.version}:resolve-ranges
19 changes: 19 additions & 0 deletions versions-maven-plugin/src/it/it-resolve-ranges-issue-1121/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>localhost</groupId>
<artifactId>it-resolve-ranges-issue-1121-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>it-resolve-ranges-issues-1121</artifactId>
<packaging>pom</packaging>
<name>resolve-ranges IT issue 1121</name>

<description>Test that resolve-ranges recognizes a property that overrides a property in its parent that is used as a version itself</description>

<properties>
<dummy.api.version>[1,3.0)</dummy.api.version>
</properties>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.io.*;
import org.codehaus.plexus.util.FileUtils;

try
{
File file = new File( basedir, "pom.xml" );
String buf = FileUtils.fileRead( file, "UTF-8" );

if ( buf.indexOf( "<dummy.api.version>2.1</dummy.api.version>" ) < 0 )
{
System.err.println( "Version of dummy-api not resolved" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -277,6 +279,11 @@ private void resolveRanges(ModifiedPomXMLEventReader pom, Collection<Dependency>
private void resolvePropertyRanges(ModifiedPomXMLEventReader pom)
throws XMLStreamException, MojoExecutionException {

if (includeProperties == null) {
Properties originalProperties = getProject().getOriginalModel().getProperties();
includeProperties =
originalProperties.stringPropertyNames().stream().collect(Collectors.joining(","));
}
Map<Property, PropertyVersions> propertyVersions = this.getHelper()
.getVersionPropertiesMap(VersionsHelper.VersionPropertiesMapRequest.builder()
.withMavenProject(getProject())
Expand Down

0 comments on commit 9dc5e0d

Please sign in to comment.