Skip to content

Commit

Permalink
Fixed mojohaus#308
Browse files Browse the repository at this point in the history
 o Use raw model to update versions in dependency management.
  • Loading branch information
Markus Muelleder (MML) committed Sep 25, 2018
1 parent 0b2dc90 commit 32a4e1d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/it/it-use-dep-version-issue-308/invoker.properties
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 -DdepVersion=3.0 -Dincludes=localhost:dummy-api

20 changes: 20 additions & 0 deletions src/it/it-use-dep-version-issue-308/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<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-dep-version-issue-308</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Set dependency to the specified version</name>

<dependencies>
<dependency>
<groupId>localhost</groupId>
<artifactId>dummy-api</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions src/it/it-use-dep-version-issue-308/verify.bsh
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( "<version>3.0</version>" ) < 0 )
{
System.err.println( "Version of dummy-api not bumped to 3.0" );
return false;
}
}
catch( Throwable t )
{
t.printStackTrace();
return false;
}

return true;
11 changes: 10 additions & 1 deletion src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.codehaus.mojo.versions;

import java.io.IOException;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
Expand Down Expand Up @@ -27,6 +29,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -77,7 +80,11 @@ protected void update( ModifiedPomXMLEventReader pom )
{
if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() )
{
useDepVersion( pom, getProject().getDependencyManagement().getDependencies() );
DependencyManagement dependencyManagement = PomHelper.getRawModel( getProject() ).getDependencyManagement();
if ( dependencyManagement != null )
{
useDepVersion( pom, dependencyManagement.getDependencies() );
}
}

if ( getProject().getDependencies() != null && isProcessingDependencies() )
Expand All @@ -88,6 +95,8 @@ protected void update( ModifiedPomXMLEventReader pom )
catch ( ArtifactMetadataRetrievalException e )
{
throw new MojoExecutionException( e.getMessage(), e );
} catch (IOException e) {
throw new MojoExecutionException( e.getMessage(), e );
}
}

Expand Down

0 comments on commit 32a4e1d

Please sign in to comment.