forked from mojohaus/versions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
175 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,11 @@ | |
<contributor> | ||
<name>Erik Schepers</name> | ||
</contributor> | ||
<contributor> | ||
<name>Anton Johansson</name> | ||
<email>[email protected]</email> | ||
<timezone>+1</timezone> | ||
</contributor> | ||
</contributors> | ||
|
||
<prerequisites> | ||
|
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,2 @@ | ||
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:set-scm-tag -DnewTag=v1.0 | ||
invoker.buildResult.1=success |
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,13 @@ | ||
<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-set-scm-tag-001</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>set-scm-tag</name> | ||
<scm> | ||
<tag>HEAD</tag> | ||
</scm> | ||
</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,32 @@ | ||
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<scm>\\E\\s*\\Q<tag>\\Ev1\\.0\\Q</tag>\\E\\s*\\Q</scm>\\E" ); | ||
Matcher m = p.matcher( buf.toString() ); | ||
if ( !m.find() ) | ||
{ | ||
System.out.println( "Setting new tag" ); | ||
return false; | ||
} | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:set-scm-tag -DnewTag=v1.0 | ||
invoker.buildResult.1=failure |
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,10 @@ | ||
<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-set-scm-tag-002</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>set-scm-tag</name> | ||
</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,2 @@ | ||
invoker.goals.1=${project.groupId}:${project.artifactId}:${project.version}:set-scm-tag | ||
invoker.buildResult.1=failure |
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,13 @@ | ||
<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-set-scm-tag-003</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>set-scm-tag</name> | ||
<scm> | ||
<tag>HEAD</tag> | ||
</scm> | ||
</project> |
80 changes: 80 additions & 0 deletions
80
src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.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,80 @@ | ||
package org.codehaus.mojo.versions; | ||
|
||
import static org.apache.commons.lang.StringUtils.isBlank; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.xml.stream.XMLStreamException; | ||
|
||
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; | ||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.Scm; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.codehaus.mojo.versions.api.PomHelper; | ||
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; | ||
|
||
/** | ||
* Updates the current project's SCM tag. | ||
* | ||
* @author Anton Johansson | ||
* @since 2.5 | ||
*/ | ||
@Mojo( name = "set-scm-tag", requiresDirectInvocation = true ) | ||
public class SetScmTagMojo | ||
extends AbstractVersionsUpdaterMojo | ||
{ | ||
|
||
/** | ||
* The new SCM tag to set. | ||
* | ||
* @since 2.5 | ||
*/ | ||
@Parameter( property = "newTag" ) | ||
private String newTag; | ||
|
||
/** | ||
* Called when this mojo is executed. | ||
* | ||
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong. | ||
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong. | ||
*/ | ||
@Override | ||
public void execute() | ||
throws MojoExecutionException, MojoFailureException | ||
{ | ||
if ( isBlank(newTag) ) | ||
{ | ||
throw new MojoFailureException("'newTag' cannot be empty"); | ||
} | ||
|
||
super.execute(); | ||
} | ||
|
||
@Override | ||
protected void update(ModifiedPomXMLEventReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException | ||
{ | ||
try | ||
{ | ||
Model model = PomHelper.getRawModel( pom ); | ||
Scm scm = model.getScm(); | ||
if (scm == null) | ||
{ | ||
throw new MojoFailureException( "No <scm> was present" ); | ||
} | ||
getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag ); | ||
|
||
boolean success = PomHelper.setProjectValue(pom, "/project/scm/tag", newTag ); | ||
if ( !success ) | ||
{ | ||
throw new MojoFailureException( "Could not update the SCM tag" ); | ||
} | ||
} | ||
catch ( IOException e ) | ||
{ | ||
throw new MojoExecutionException( e.getMessage(), e ); | ||
} | ||
} | ||
} |
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