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

Improve speed of versions:resolve-ranges in case parents contain many version properties #1122

Merged
merged 2 commits into from
Aug 27, 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
@@ -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>
Copy link
Member

Choose a reason for hiding this comment

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

I prefer groovy than bsh ... but it is also ok

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