Skip to content

Commit

Permalink
hacked up updating of parent pom version in the .new-version poms
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemers committed Feb 1, 2015
1 parent d848f32 commit 3e8c06c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TODO:
* Finalize strategy API
* Add APT for doc/site
* find out if anyone else cares about this.
* filter new versions into MavenProject and model ( potential changes to parent, dependency, and plugin versions)
* filter new versions into MavenProject and model ( dependency, dependency management, plugin, etc)

Other Thoughts
---------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
Expand Down Expand Up @@ -89,6 +91,8 @@ public void afterProjectsRead( MavenSession session )
{
logger.info( "About to change project version in reactor." );

Map<String, String> gavVersionMap = new HashMap<String, String>();

for ( MavenProject mavenProject : session.getAllProjects() )
{
// Lookup this plugin's configuration
Expand Down Expand Up @@ -117,14 +121,47 @@ public void afterProjectsRead( MavenSession session )
logger.info( "Updating project.build.finalName: " + newFinalName );
mavenProject.getBuild().setFinalName( newFinalName );

// write processed new pom out
createNewVersionPom( mavenProject );
gavVersionMap.put( buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), oldVersion ),
newVersion );
logger.info(
"new version added to map: " + buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(),
oldVersion ) + ": " + newVersion );

if ( mavenProject.getParent() != null )
{
logger.info( "My parent is: " + buildGavKey( mavenProject.getParent() ) );
}


}
catch ( ExternalVersionException e )
{
throw new MavenExecutionException( e.getMessage(), e );
}
}

// now we have only updated the versions of the projects, we need to update
// the references between the updated projects

for ( MavenProject mavenProject : session.getAllProjects() )
{
try
{

if ( mavenProject.getParent() != null )
{
logger.info( "looking for parent in map" );

if ( gavVersionMap.containsKey( buildGavKey( mavenProject.getParent() ) ) )
{
// we need to update the parent
logger.info( "WE NEED TO ACT NOW!" );
}
}

// write processed new pom out
createNewVersionPom( mavenProject, gavVersionMap );
}
catch ( XmlPullParserException e )
{
throw new MavenExecutionException( e.getMessage(), e );
Expand All @@ -133,10 +170,28 @@ public void afterProjectsRead( MavenSession session )
{
throw new MavenExecutionException( e.getMessage(), e );
}

}

}

private String buildGavKey( MavenProject mavenProject )
{
return buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), mavenProject.getVersion() );
}

private void createNewVersionPom( MavenProject mavenProject )
private String buildGavKey( MavenProject mavenProject, String oldVersion )
{
return buildGavKey( mavenProject.getGroupId(), mavenProject.getArtifactId(), oldVersion );
}

private String buildGavKey( String groupId, String artifactId, String oldVersion )
{
return new StringBuilder( groupId ).append( ":" ).append( artifactId ).append( ":" ).append(
oldVersion ).toString();
}

private void createNewVersionPom( MavenProject mavenProject, Map<String, String> gavVersionMap )
throws IOException, XmlPullParserException
{
Reader fileReader = null;
Expand All @@ -148,6 +203,18 @@ private void createNewVersionPom( MavenProject mavenProject )
model.setVersion( mavenProject.getVersion() );


// TODO: this needs to be restructured when other references are updated (dependencies, dep-management, plugins, etc)
if ( model.getParent() != null )
{
String key = buildGavKey( model.getParent().getGroupId(), model.getParent().getArtifactId(),
model.getParent().getVersion() );
String newVersionForParent = gavVersionMap.get( key );
if ( newVersionForParent != null )
{
model.getParent().setVersion( newVersionForParent );
}
}

File newPom = new File( mavenProject.getBasedir(), "pom.xml.new-version" );
fileWriter = new FileWriter( newPom );
new MavenXpp3Writer().write( fileWriter, model );
Expand All @@ -158,6 +225,7 @@ private void createNewVersionPom( MavenProject mavenProject )
finally
{
IOUtil.close( fileReader );
IOUtil.close( fileWriter );
}


Expand Down

0 comments on commit 3e8c06c

Please sign in to comment.