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

Issue 134 removing the no longer needed patch + adding integration tests #814

Merged
merged 1 commit into from
Nov 19, 2022
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 @@ -29,7 +29,6 @@
import java.io.Reader;
import java.io.StringReader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -62,7 +61,6 @@
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.RegexUtils;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
Expand Down Expand Up @@ -1689,77 +1687,4 @@ public static String getGAV( Model model )
{
return getGroupId( model ) + ":" + getArtifactId( model ) + ":" + getVersion( model );
}

/**
* Reads imported POMs from the dependency management section.
*
* @param pom POM
* @return a non-null list of {@link Dependency} for each imported POM
* @throws XMLStreamException XML stream exception
* @see <a href="https://github.com/mojohaus/versions-maven-plugin/issues/134">bug #134</a>
* @since 2.4
*/
public static List<Dependency> readImportedPOMsFromDependencyManagementSection( ModifiedPomXMLEventReader pom )
throws XMLStreamException
{
List<Dependency> importedPOMs = new ArrayList<>();
Stack<String> stack = new Stack<>();

String groupIdElement = "groupId";
String artifactIdElement = "artifactId";
String versionElement = "version";
String typeElement = "type";
String scopeElement = "scope";
Set<String> recognizedElements =
new HashSet<>( Arrays.asList( groupIdElement, artifactIdElement, versionElement, typeElement,
scopeElement ) );
Map<String, String> depData = new HashMap<>();

pom.rewind();

String depMgmtDependencyPath = "/project/dependencyManagement/dependencies/dependency";

while ( pom.hasNext() )
{
XMLEvent event = pom.nextEvent();

if ( event.isStartElement() )
{
final String elementName = event.asStartElement().getName().getLocalPart();
String parent = "";
if ( !stack.isEmpty() )
{
parent = stack.peek();
}
String currentPath = parent + "/" + elementName;
stack.push( currentPath );

if ( currentPath.startsWith( depMgmtDependencyPath ) && recognizedElements.contains( elementName ) )
{
final String elementText = pom.getElementText().trim();
depData.put( elementName, elementText );
stack.pop();
}
}
if ( event.isEndElement() )
{
String path = stack.pop();
if ( depMgmtDependencyPath.equals( path ) )
{
if ( "pom".equals( depData.get( typeElement ) ) && "import".equals( depData.get( scopeElement ) ) )
{
importedPOMs.add( DependencyBuilder.newBuilder()
.withGroupId( depData.get( groupIdElement ) )
.withArtifactId( depData.get( artifactIdElement ) )
.withVersion( depData.get( versionElement ) )
.withType( depData.get( typeElement ) )
.withScope( depData.get( scopeElement ) )
.build() );
}
depData.clear();
}
}
}
return importedPOMs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
import java.io.File;
import java.io.StringReader;
import java.net.URL;
import java.util.List;
import java.util.Map;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.plugin.logging.SystemStreamLog;
Expand Down Expand Up @@ -64,39 +62,6 @@ public static void setUpClass()
INPUT_FACTORY.setProperty( P_PRESERVE_LOCATION, Boolean.TRUE );
}

/**
* Tests if imported POMs are properly read from dependency management section. Such logic is required to resolve
* <a href="https://github.com/mojohaus/versions-maven-plugin/issues/134">bug #134</a>
*
* @throws Exception if the test fails.
*/
@Test
public void testImportedPOMsRetrievedFromDependencyManagement()
throws Exception
{
URL url = getClass().getResource( "PomHelperTest.dependencyManagementBOMs.pom.xml" );
assert url != null;
File file = new File( url.getPath() );
StringBuilder input = PomHelper.readXmlFile( file );

XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
inputFactory.setProperty( P_PRESERVE_LOCATION, Boolean.TRUE );

ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory, file.getAbsolutePath() );

List<Dependency> dependencies = PomHelper.readImportedPOMsFromDependencyManagementSection( pom );

assertNotNull( dependencies );
assertEquals( 1, dependencies.size() );

Dependency dependency = dependencies.get( 0 );
assertEquals( "org.group1", dependency.getGroupId() );
assertEquals( "artifact-pom", dependency.getArtifactId() );
assertEquals( "1.0-SNAPSHOT", dependency.getVersion() );
assertEquals( "import", dependency.getScope() );
assertEquals( "pom", dependency.getType() );
}

/**
* Tests what happens when changing a long property substitution pattern, e.g.
* <a href="http://jira.codehaus.org/browse/MVERSIONS-44">MVERSIONS-44</a>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<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>dummy-api</artifactId>
<version>3.4.0-20090311.051742-1</version>
<packaging>jar</packaging>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.3</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>3.1.5-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down
26 changes: 26 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom-pom-2.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<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>dummy-bom-pom</artifactId>
<version>2.0</version>
<packaging>pom</packaging>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
12 changes: 12 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0-SNAPSHOT.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-bom2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

</project>
12 changes: 12 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom2-1.0.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-bom2</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

</project>
12 changes: 12 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom2-1.1.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-bom2</artifactId>
<version>1.1.0</version>
<packaging>pom</packaging>

</project>
12 changes: 12 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom2-2.0.0.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-bom2</artifactId>
<version>2.0.0</version>
<packaging>pom</packaging>

</project>
12 changes: 12 additions & 0 deletions versions-maven-plugin/src/it-repo/dummy-bom2-3.0.0-SNAPSHOT.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>dummy-bom2</artifactId>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:force-releases
22 changes: 22 additions & 0 deletions versions-maven-plugin/src/it/it-force-releases-issue-134/pom.xml
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-use-releases-issue-134-001</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Check if boms are upated from snapshots</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-bom2</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )

assert project.dependencyManagement.dependencies.'*'.size() == 1
assert project.dependencyManagement.dependencies.dependency.version == '1.0.0'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:unlock-snapshots
22 changes: 22 additions & 0 deletions versions-maven-plugin/src/it/it-unlock-snapshots-issue-134/pom.xml
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-use-releases-issue-134</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Check if boms are upated</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>3.4.0-20090311.051742-1</version>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )

assert project.dependencyManagement.dependencies.'*'.size() == 1
assert project.dependencyManagement.dependencies.dependency.version == '3.4.0-SNAPSHOT'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:use-dep-version
invoker.mavenOpts = -DdepVersion=2.0.0 -Dincludes=localhost:dummy-bom2
Loading