Skip to content

Commit

Permalink
Removing the patch for mojohaus#134
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Nov 11, 2022
1 parent 6a950e2 commit b5af0f2
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 148 deletions.
29 changes: 29 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,29 @@
<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>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1</version>
</dependency>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.0</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
29 changes: 29 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,29 @@
<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>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
</dependency>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.0</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
29 changes: 29 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,29 @@
<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>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.1.3</version>
</dependency>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>1.1</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
29 changes: 29 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,29 @@
<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>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>2.0</version>
</dependency>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>2.0</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
29 changes: 29 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,29 @@
<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>

<dependencyManagement>
<dependencies>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>3.0</version>
</dependency>

<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-impl</artifactId>
<version>2.2</version>
</dependency>

</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:force-releases
invoker.mavenOpts = -DprocessDependencyManagement=true
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,5 @@
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,2 @@
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:force-releases
invoker.mavenOpts = -DprocessDependencyManagement=true
22 changes: 22 additions & 0 deletions versions-maven-plugin/src/it/it-use-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-force-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,5 @@
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
Expand Up @@ -111,7 +111,6 @@ protected void update( ModifiedPomXMLEventReader pom )

if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() )
{
useReleases( pom, PomHelper.readImportedPOMsFromDependencyManagementSection( pom ) );
useReleases( pom, getProject().getDependencyManagement().getDependencies() );
}
if ( getProject().getDependencies() != null && isProcessingDependencies() )
Expand Down
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 @@ -6,10 +6,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 @@ -44,39 +42,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
Loading

0 comments on commit b5af0f2

Please sign in to comment.