-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect processParent setting by introducing new base class
- Loading branch information
Adam Voss
committed
Jul 2, 2018
1 parent
086d126
commit 6b297e5
Showing
13 changed files
with
244 additions
and
307 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
invoker.goals=${project.groupId}:${project.artifactId}:${project.version}:use-next-releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<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>dummy-parent</artifactId> | ||
<version>1.0</version> | ||
</parent> | ||
|
||
<groupId>localhost</groupId> | ||
<artifactId>it-use-next-releases-005</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>Update a parent dependency</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>localhost</groupId> | ||
<artifactId>dummy-impl</artifactId> | ||
<version>1.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<configuration> | ||
<processParent>true</processParent> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import java.io.*; | ||
import java.util.regex.*; | ||
|
||
try | ||
{ | ||
File file = new File( basedir, "pom.xml" ); | ||
|
||
BufferedReader in = new BufferedReader( new InputStreamReader( new FileInputStream( file ), "UTF-8" ) ); | ||
StringBuilder buf = new StringBuilder(); | ||
String line = in.readLine(); | ||
while ( line != null ) | ||
{ | ||
buf.append( line ); | ||
buf.append( " " ); | ||
line = in.readLine(); | ||
} | ||
|
||
Pattern p = Pattern.compile( "\\Q<parent>\\E.*\\Q<version>\\E\\s*2\\.0\\s*\\Q</version>\\E.*\\Q</parent>\\E" ); | ||
Matcher m = p.matcher( buf.toString() ); | ||
if ( !m.find() ) | ||
{ | ||
System.out.println( "Did not update parent to version 2.0" ); | ||
return false; | ||
} | ||
System.out.println( m.group( 0 ) ); | ||
} | ||
catch( Throwable t ) | ||
{ | ||
t.printStackTrace(); | ||
return false; | ||
} | ||
|
||
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/org/codehaus/mojo/versions/ParentUpdatingDependencyUpdateMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package org.codehaus.mojo.versions; | ||
|
||
import org.apache.maven.artifact.Artifact; | ||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; | ||
import org.apache.maven.artifact.versioning.ArtifactVersion; | ||
import org.apache.maven.model.Dependency; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.codehaus.mojo.versions.api.PomHelper; | ||
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public abstract class ParentUpdatingDependencyUpdateMojo extends AbstractVersionsDependencyUpdaterMojo | ||
{ | ||
/** | ||
* @param pom the pom to update. | ||
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong | ||
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way | ||
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming | ||
* @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) | ||
*/ | ||
protected void update( ModifiedPomXMLEventReader pom ) | ||
throws MojoExecutionException, MojoFailureException, XMLStreamException | ||
{ | ||
try | ||
{ | ||
if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) | ||
{ | ||
setVersions( pom, getProject().getDependencyManagement().getDependencies() ); | ||
} | ||
if ( getProject().getDependencies() != null && isProcessingDependencies() ) | ||
{ | ||
setVersions( pom, getProject().getDependencies() ); | ||
} | ||
if ( getProject().getParent() != null && isProcessingParent() ) | ||
{ | ||
final Dependency dependency = new Dependency(); | ||
dependency.setArtifactId(getProject().getParent().getArtifactId()); | ||
dependency.setGroupId(getProject().getParent().getGroupId()); | ||
dependency.setVersion(getProject().getParent().getVersion()); | ||
dependency.setType("pom"); | ||
setVersions( pom, Collections.singleton(dependency)); | ||
} | ||
} | ||
catch ( ArtifactMetadataRetrievalException e ) | ||
{ | ||
throw new MojoExecutionException( e.getMessage(), e ); | ||
} | ||
} | ||
|
||
protected abstract void setVersions(ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies) | ||
throws ArtifactMetadataRetrievalException, XMLStreamException, MojoExecutionException; | ||
|
||
protected void setVersion(ModifiedPomXMLEventReader pom, Dependency dep, String version, Artifact artifact, ArtifactVersion artifactVersion) throws XMLStreamException | ||
{ | ||
final String newVersion = artifactVersion.toString(); | ||
if(getProject().getParent() != null){ | ||
if(artifact.getId().equals(getProject().getParentArtifact().getId()) && isProcessingParent()) | ||
{ | ||
if ( PomHelper.setProjectParentVersion( pom, newVersion.toString() ) ) | ||
{ | ||
getLog().debug( "Made parent change from " + version + " to " + newVersion.toString() ); | ||
} | ||
} | ||
} | ||
|
||
if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, | ||
newVersion, getProject().getModel() ) ) | ||
{ | ||
getLog().info( "Changed " + toString( dep ) + " to version " + newVersion ); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.