Skip to content

Commit b14af60

Browse files
andrzejj0slawekjaranowski
authored andcommitted
Fixing #670: allowSnapshots was disabled in PR #665; usePluginRepositories was incorrectly enabled
1 parent e3beb05 commit b14af60

File tree

7 files changed

+91
-3
lines changed

7 files changed

+91
-3
lines changed

src/it-repo/dummy-parent4-70.pom

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
<groupId>localhost</groupId>
6+
<artifactId>dummy-parent4</artifactId>
7+
<version>70</version>
8+
<packaging>pom</packaging>
9+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
<groupId>localhost</groupId>
6+
<artifactId>dummy-parent4</artifactId>
7+
<version>71-SNAPSHOT</version>
8+
<packaging>pom</packaging>
9+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:update-parent -DparentVersion=71-SNAPSHOT -DallowSnapshots
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>localhost</groupId>
7+
<artifactId>dummy-parent4</artifactId>
8+
<version>70</version>
9+
</parent>
10+
11+
<groupId>localhsot</groupId>
12+
<artifactId>issue-670</artifactId>
13+
<version>0.31-SNAPSHOT</version>
14+
<packaging>pom</packaging>
15+
16+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pom = new File( basedir, "pom.xml" ).text
2+
3+
assert pom =~ /<version>71-SNAPSHOT<\/version>/

src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,13 @@ protected void update( ModifiedPomXMLEventReader pom )
134134
ArtifactVersion artifactVersion;
135135
try
136136
{
137-
artifactVersion = findLatestVersion( artifact, versionRange, false, true,
138-
allowDowngrade );
137+
artifactVersion = findLatestVersion( artifact, versionRange, null, false, allowDowngrade );
139138
}
140139
catch ( ArtifactMetadataRetrievalException e )
141140
{
142141
throw new MojoExecutionException( e.getMessage(), e );
143142
}
144143

145-
146144
if ( !shouldApplyUpdate( artifact, currentVersion, artifactVersion, forceUpdate ) )
147145
{
148146
return;

src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java

+52
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ private static ArtifactMetadataSource mockArtifactMetaDataSource() throws Artifa
126126
new DefaultArtifactVersion( "1.0.0" ),
127127
new DefaultArtifactVersion( "0.9.0" ) );
128128
}
129+
else if ( "issue-670-artifact".equals( artifact.getArtifactId() ) )
130+
{
131+
return Arrays.asList( new DefaultArtifactVersion( "0.0.1-1" ),
132+
new DefaultArtifactVersion( "0.0.1-1-impl-SNAPSHOT" ) );
133+
}
129134
else if ( "unknown-artifact".equals( artifact.getArtifactId() ) )
130135
{
131136
return Collections.emptyList();
@@ -236,4 +241,51 @@ public void testParentDowngradeForbiddenWithRange()
236241
}
237242
assertThat( changeRecorder.getChanges(), is( empty() ) );
238243
}
244+
245+
@Test
246+
public void testAllowSnapshots()
247+
throws MojoExecutionException, XMLStreamException, MojoFailureException
248+
{
249+
mojo.allowSnapshots = true;
250+
mojo.getProject().setParent( new MavenProject()
251+
{{
252+
setGroupId( "default-group" );
253+
setArtifactId( "issue-670-artifact" );
254+
setVersion( "0.0.1-1" );
255+
}} );
256+
257+
try ( MockedStatic<PomHelper> pomHelper = mockStatic( PomHelper.class ) )
258+
{
259+
pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
260+
.thenReturn( true );
261+
mojo.update( null );
262+
}
263+
assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
264+
"issue-670-artifact", "0.0.1-1",
265+
"0.0.1-1-impl-SNAPSHOT" ) ) );
266+
}
267+
268+
@Test
269+
public void testAllowSnapshotsWithParentVersion()
270+
throws MojoExecutionException, XMLStreamException, MojoFailureException
271+
{
272+
mojo.allowSnapshots = true;
273+
mojo.parentVersion = "0.0.1-1-impl-SNAPSHOT";
274+
mojo.getProject().setParent( new MavenProject()
275+
{{
276+
setGroupId( "default-group" );
277+
setArtifactId( "issue-670-artifact" );
278+
setVersion( "0.0.1-1" );
279+
}} );
280+
281+
try ( MockedStatic<PomHelper> pomHelper = mockStatic( PomHelper.class ) )
282+
{
283+
pomHelper.when( () -> PomHelper.setProjectParentVersion( any(), any() ) )
284+
.thenReturn( true );
285+
mojo.update( null );
286+
}
287+
assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group",
288+
"issue-670-artifact", "0.0.1-1",
289+
"0.0.1-1-impl-SNAPSHOT" ) ) );
290+
}
239291
}

0 commit comments

Comments
 (0)