-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MVERSIONS-146, Added versions:update-property goal
- Loading branch information
Showing
8 changed files
with
295 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
*.ser | ||
*.class | ||
*~ | ||
*.bak | ||
#*.off | ||
*.old | ||
|
||
# eclipse conf file | ||
.settings | ||
.classpath | ||
.project | ||
.manager | ||
.scala_dependencies | ||
|
||
# idea | ||
.idea | ||
*.iws | ||
*.ipr | ||
*.iml | ||
|
||
# building | ||
target | ||
build | ||
null | ||
tmp* | ||
test-output | ||
*.log | ||
serverLog.xml | ||
|
||
# other scm | ||
.svn | ||
.CVS | ||
.hg* |
1 change: 1 addition & 0 deletions
1
mojo/versions-maven-plugin/src/it/it-update-property-001/invoker.properties
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}:update-property -Dproperty=api -DnewVersion=[2.0] |
48 changes: 48 additions & 0 deletions
48
mojo/versions-maven-plugin/src/it/it-update-property-001/pom.xml
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,48 @@ | ||
<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-001</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>update-properties via autolink with one property only</name> | ||
|
||
<properties> | ||
<api>1.0</api> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>localhost</groupId> | ||
<artifactId>dummy-api</artifactId> | ||
<version>${api}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>2.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.3</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>2.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
21 changes: 21 additions & 0 deletions
21
mojo/versions-maven-plugin/src/it/it-update-property-001/verify.bsh
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,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( "<api>2.0</api>" ) < 0 ) | ||
{ | ||
System.err.println( "Version not updated to 2.0" ); | ||
return false; | ||
} | ||
} | ||
catch( Throwable t ) | ||
{ | ||
t.printStackTrace(); | ||
return false; | ||
} | ||
|
||
return true; |
1 change: 1 addition & 0 deletions
1
mojo/versions-maven-plugin/src/it/it-update-property-002/invoker.properties
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}:update-property -Dproperty=api |
48 changes: 48 additions & 0 deletions
48
mojo/versions-maven-plugin/src/it/it-update-property-002/pom.xml
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,48 @@ | ||
<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-001</artifactId> | ||
<version>1.0</version> | ||
<packaging>pom</packaging> | ||
<name>update-properties via autolink with one property only</name> | ||
|
||
<properties> | ||
<api>1.0</api> | ||
</properties> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>localhost</groupId> | ||
<artifactId>dummy-api</artifactId> | ||
<version>${api}</version> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>2.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<version>2.3</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-install-plugin</artifactId> | ||
<version>2.2</version> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-site-plugin</artifactId> | ||
<version>2.0</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
</project> |
21 changes: 21 additions & 0 deletions
21
mojo/versions-maven-plugin/src/it/it-update-property-002/verify.bsh
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,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( "<api>3.0</api>" ) < 0 ) | ||
{ | ||
System.err.println( "Version not updated to 2.0" ); | ||
return false; | ||
} | ||
} | ||
catch( Throwable t ) | ||
{ | ||
t.printStackTrace(); | ||
return false; | ||
} | ||
|
||
return true; |
122 changes: 122 additions & 0 deletions
122
mojo/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.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,122 @@ | ||
package org.codehaus.mojo.versions; | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import javax.xml.stream.XMLStreamException; | ||
|
||
import org.apache.maven.artifact.versioning.ArtifactVersion; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.codehaus.mojo.versions.api.PomHelper; | ||
import org.codehaus.mojo.versions.api.PropertyVersions; | ||
import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; | ||
|
||
/** | ||
* Sets a property to the latest version in a given range of associated artifacts. | ||
* | ||
* @author Eric Pabst | ||
* @goal update-property | ||
* @requiresProject true | ||
* @requiresDirectInvocation true | ||
* @since 1.3 | ||
*/ | ||
public class UpdatePropertyMojo | ||
extends AbstractVersionsUpdaterMojo | ||
{ | ||
|
||
// ------------------------------ FIELDS ------------------------------ | ||
|
||
/** | ||
* A property to update. | ||
* | ||
* @parameter expression="${property}" | ||
* @since 1.3 | ||
*/ | ||
private String property = null; | ||
|
||
/** | ||
* The new version to set the property to (can be a version range to find a version within). | ||
* | ||
* @parameter expression="${newVersion}" | ||
* @since 1.3 | ||
*/ | ||
private String newVersion = null; | ||
|
||
/** | ||
* Whether properties linking versions should be auto-detected or not. | ||
* | ||
* @parameter expression="${autoLinkItems}" defaultValue="true" | ||
* @since 1.0-alpha-2 | ||
*/ | ||
private Boolean autoLinkItems; | ||
|
||
// -------------------------- STATIC METHODS -------------------------- | ||
|
||
// -------------------------- OTHER METHODS -------------------------- | ||
|
||
/** | ||
* @param pom the pom to update. | ||
* @throws MojoExecutionException when things go wrong | ||
* @throws MojoFailureException when things go wrong in a very bad way | ||
* @throws XMLStreamException when things go wrong with XML streaming | ||
* @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) | ||
* @since 1.0-alpha-1 | ||
*/ | ||
protected void update( ModifiedPomXMLEventReader pom ) | ||
throws MojoExecutionException, MojoFailureException, XMLStreamException | ||
{ | ||
Property propertyConfig = new Property(property); | ||
propertyConfig.setVersion(newVersion); | ||
Map propertyVersions = | ||
this.getHelper().getVersionPropertiesMap( getProject(), new Property[]{propertyConfig}, property, "", | ||
!Boolean.FALSE.equals( autoLinkItems ) ); | ||
Iterator i = propertyVersions.entrySet().iterator(); | ||
while ( i.hasNext() ) | ||
{ | ||
Map.Entry/*<Property,PropertyVersions>*/ entry = (Map.Entry/*<Property,PropertyVersions>*/) i.next(); | ||
Property property = (Property) entry.getKey(); | ||
PropertyVersions version = (PropertyVersions) entry.getValue(); | ||
|
||
final String currentVersion = getProject().getProperties().getProperty( property.getName() ); | ||
if ( currentVersion == null ) | ||
{ | ||
continue; | ||
} | ||
|
||
ArtifactVersion winner = | ||
version.getNewestVersion( currentVersion, property, this.allowSnapshots, this.reactorProjects, | ||
this.getHelper() ); | ||
|
||
if ( winner == null || currentVersion.equals( winner.toString() ) ) | ||
{ | ||
getLog().info( "Property ${" + property.getName() + "}: Leaving unchanged as " + currentVersion ); | ||
} | ||
else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), | ||
winner.toString() ) ) | ||
{ | ||
getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner ); | ||
} | ||
|
||
} | ||
} | ||
|
||
} |