Skip to content

Commit 2c78f43

Browse files
andrzejj0slawekjaranowski
authored andcommitted
Resolves #289: Handle processParent in mojos which support it.
Also: - added failIfNotReplaced to ForceReleasesMojo as a first steps towards converging with UseReleasesMojo - enhanced documentation on UseReleasesMojo#allowRangeMatching - streamlined UseReleasesMojo in order to converge it with ForceReleasesMojo and then fold further with other similar mojos - added unit tests and integration tests - some refactoring
1 parent c50851f commit 2c78f43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+716
-770
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ target
44
.project
55
*.iml
66
.idea
7+
.checkstyle
78
/.factorypath

versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersions.java

+1
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,5 @@ public String toString()
253253
return "ArtifactVersions" + "{artifact=" + artifact + ", versions=" + versions + ", versionComparator="
254254
+ versionComparator + '}';
255255
}
256+
256257
}

versions-common/src/main/java/org/codehaus/mojo/versions/api/ArtifactVersionsCache.java

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public ArtifactVersionsCache( BiFunction<AbstractVersionDetails, Optional<Segmen
5252
* If the information is already present in cache, the cached version is returned. Otherwise,
5353
* the {@code artifactVersions} object is queried and the response is cached.
5454
*
55+
* @param <V> concrete implementation of {@linkplain AbstractVersionDetails}
56+
* @param <R> return type of the cached function
5557
* @param artifactVersions {@linkplain ArtifactVersions} object referring to the given dependency
5658
* @param updateScope update scope
5759
* @return last retrieved update information

versions-common/src/main/java/org/codehaus/mojo/versions/api/PropertyVersions.java

+1
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,5 @@ public int getSegmentCount( ArtifactVersion v )
492492
return result;
493493
}
494494
}
495+
495496
}

versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderNull.java

+2-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121

2222
import java.io.OutputStream;
23-
import java.util.Objects;
2423

2524
/**
2625
* A recorder that ignores updates.
@@ -29,35 +28,20 @@
2928
public class ChangeRecorderNull implements ChangeRecorder
3029
{
3130
/**
32-
* Create a new change recorder that serializes to XML.
33-
*
34-
* @return A new change recorder
31+
* Creates a new instance
3532
*/
36-
37-
public static ChangeRecorder create()
38-
{
39-
return new ChangeRecorderNull();
40-
}
41-
42-
private ChangeRecorderNull()
33+
public ChangeRecorderNull()
4334
{
44-
4535
}
4636

4737
@Override
4838
public final void recordUpdate( final String kind, final String groupId, final String artifactId,
4939
final String oldVersion, final String newVersion )
5040
{
51-
Objects.requireNonNull( kind, "kind" );
52-
Objects.requireNonNull( groupId, "groupId" );
53-
Objects.requireNonNull( artifactId, "artifactId" );
54-
Objects.requireNonNull( oldVersion, "oldVersion" );
55-
Objects.requireNonNull( newVersion, "newVersion" );
5641
}
5742

5843
@Override
5944
public final void serialize( final OutputStream outputStream )
6045
{
61-
6246
}
6347
}

versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java

+4-14
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,24 @@ public class ChangeRecorderXML implements ChangeRecorder
5353
private final Element root;
5454

5555
/**
56-
* Create a new change recorder that serializes to XML.
57-
*
58-
* @return A new change recorder
56+
* Creates a new instance
5957
*/
60-
61-
public static ChangeRecorder create()
58+
public ChangeRecorderXML()
6259
{
6360
try
6461
{
6562
final DocumentBuilderFactory documentBuilders = DocumentBuilderFactory.newInstance();
6663
final DocumentBuilder documentBuilder = documentBuilders.newDocumentBuilder();
67-
final Document document = documentBuilder.newDocument();
68-
final Element root = document.createElementNS( CHANGES_NAMESPACE, "updates" );
64+
document = documentBuilder.newDocument();
65+
root = document.createElementNS( CHANGES_NAMESPACE, "updates" );
6966
document.appendChild( root );
70-
return new ChangeRecorderXML( document, root );
7167
}
7268
catch ( final ParserConfigurationException | DOMException e )
7369
{
7470
throw new IllegalStateException( e );
7571
}
7672
}
7773

78-
private ChangeRecorderXML( final Document document, final Element root )
79-
{
80-
this.document = Objects.requireNonNull( document, "document" );
81-
this.root = Objects.requireNonNull( root, "root" );
82-
}
83-
8474
@Override
8575
public final void recordUpdate( final String kind, final String groupId, final String artifactId,
8676
final String oldVersion, final String newVersion )

versions-common/src/main/java/org/codehaus/mojo/versions/utils/DependencyBuilder.java

+9
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public static DependencyBuilder newBuilder()
144144

145145
/**
146146
* Convenience builder method
147+
* @param groupId groupId of the dependency
148+
* @param artifactId artifactId of the dependency
149+
* @param version version of the dependency
147150
* @return new instance of {@linkplain Dependency}
148151
*/
149152
public static Dependency dependencyWith( String groupId, String artifactId, String version )
@@ -157,6 +160,12 @@ public static Dependency dependencyWith( String groupId, String artifactId, Stri
157160

158161
/**
159162
* Convenience builder method
163+
* @param groupId groupId of the dependency
164+
* @param artifactId artifactId of the dependency
165+
* @param version version of the dependency
166+
* @param type type of the dependency
167+
* @param classifier classifier of the dependency
168+
* @param scope scope of the dependency
160169
* @return new instance of {@linkplain Dependency}
161170
*/
162171
public static Dependency dependencyWith( String groupId, String artifactId, String version, String type,

versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void testChanges() throws Exception
6464

6565
copyResource( "expectedFile.xml", file0 );
6666

67-
final ChangeRecorder recorder = ChangeRecorderXML.create();
67+
final ChangeRecorder recorder = new ChangeRecorderXML();
6868
recorder.recordUpdate( "exampleKind", "org.codehaus", "example0", "0.0.1", "0.0.2" );
6969
recorder.recordUpdate( "exampleKind", "org.codehaus", "example1", "1.0.0", "2.0.0" );
7070

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>dummy-parent2</artifactId>
8+
<version>2.0</version>
9+
</parent>
10+
11+
<artifactId>dummy-with-parent</artifactId>
12+
<version>1.0</version>
13+
<packaging>pom</packaging>
14+
15+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:compare-dependencies
2+
invoker.mavenOpts = -DremotePom=localhost:dummy-with-parent:1.0 -DreportMode=false -DprocessParent=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>dummy-parent2</artifactId>
8+
<version>1.0</version>
9+
</parent>
10+
11+
<artifactId>dummy-with-parent</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
<packaging>pom</packaging>
14+
15+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
2+
assert project.parent.version == '2.0'

versions-maven-plugin/src/it/it-use-latest-versions-009/verify.bsh

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
2+
assert project.parent.version == '3.0'

versions-maven-plugin/src/it/it-use-latest-versions-010/verify.bsh

-62
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
2+
assert project.parent.version == '3.0'

versions-maven-plugin/src/it/it-use-latest-versions-011/verify.bsh

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def project = new XmlSlurper().parse( new File( basedir, 'pom.xml' ) )
2+
assert project.parent.version == '1.0.0'

0 commit comments

Comments
 (0)