Skip to content

Commit

Permalink
MRELEASE-985 Override snapshot dependencies from command line
Browse files Browse the repository at this point in the history
 - Copy properties to the correct release descriptor in DefaultReleaseManager.
 - Do not fail the build if the property is resolved from the comand-line (in CheckDependencySnapshotsPhase).

See https://issues.apache.org/jira/browse/MRELEASE-985
  • Loading branch information
ptahchiev committed May 8, 2019
1 parent a36864f commit 5c80a60
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,42 @@ private void prepare( ReleasePrepareRequest prepareRequest, ReleaseResult result

// Create a config containing values from the session properties (ie command line properties with cli).
ReleaseUtils.copyPropertiesToReleaseDescriptor( prepareRequest.getUserProperties(),
new ReleaseDescriptorBuilder()
{
public ReleaseDescriptorBuilder addDevelopmentVersion( String key,
String value )
{
builder.addDevelopmentVersion( key, value );
return this;
}

public ReleaseDescriptorBuilder addReleaseVersion( String key,
String value )
{
builder.addReleaseVersion( key, value );
return this;
};
} );
new ReleaseDescriptorBuilder()
{
public ReleaseDescriptorBuilder addDevelopmentVersion( String key,
String value )
{
builder.addDevelopmentVersion( key, value );
return this;
}

public ReleaseDescriptorBuilder addReleaseVersion( String key,
String value )
{
builder.addReleaseVersion( key, value );
return this;
}

public ReleaseDescriptorBuilder addDependencyOriginalVersion( String dependencyKey, String version )
{
builder.addDependencyOriginalVersion( dependencyKey, version );
return this;
}

public ReleaseDescriptorBuilder addDependencyReleaseVersion( String dependencyKey,
String version )
{
builder.addDependencyReleaseVersion( dependencyKey, version );
return this;
}

public ReleaseDescriptorBuilder addDependencyDevelopmentVersion( String dependencyKey,
String version )
{
builder.addDependencyDevelopmentVersion( dependencyKey, version );
return this;
}
} );

BuilderReleaseDescriptor config;
if ( BooleanUtils.isNotFalse( prepareRequest.getResume() ) )
Expand All @@ -132,7 +152,7 @@ public ReleaseDescriptorBuilder addReleaseVersion( String key,
}
else
{
config = ReleaseUtils.buildReleaseDescriptor( prepareRequest.getReleaseDescriptorBuilder() );
config = ReleaseUtils.buildReleaseDescriptor( builder );
}

Strategy releaseStrategy = getStrategy( config.getReleaseStrategyId() );
Expand Down Expand Up @@ -667,4 +687,4 @@ private void captureException( ReleaseResult result, ReleaseManagerListener list

result.setResultCode( ReleaseResult.ERROR );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,14 @@ private static Artifact getArtifactFromMap( Artifact artifact, Map<String, Artif
private static boolean checkArtifact( Artifact artifact, ReleaseDescriptor releaseDescriptor )
{
String versionlessKey = ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
String releaseDescriptorResolvedVersion = releaseDescriptor.getDependencyReleaseVersion( versionlessKey );

// We are only looking at dependencies external to the project - ignore anything found in the reactor as
// it's version will be updated
boolean result = artifact.isSnapshot()
&& !artifact.getBaseVersion().equals( releaseDescriptor.getProjectOriginalVersion( versionlessKey ) );
&& !artifact.getBaseVersion().equals( releaseDescriptor.getProjectOriginalVersion( versionlessKey ) )
&& ( releaseDescriptorResolvedVersion == null
|| releaseDescriptorResolvedVersion.contains( Artifact.SNAPSHOT_VERSION ) );

// If we have a snapshot but allowTimestampedSnapshots is true, accept the artifact if the version
// indicates that it is a timestamped snapshot.
Expand Down Expand Up @@ -456,4 +459,4 @@ private void processSnapshot( Set<Artifact> snapshotSet, ReleaseDescriptor relea
releaseDescriptor.addDependencyDevelopmentVersion( versionlessKey, result );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -108,6 +110,35 @@ public void testNoSnapshotRangeDependencies()
assertTrue( true );
}

// MRELEASE-985
@Test
public void testSnapshotDependenciesInProjectAndResolveFromCommandLine() throws Exception {
List<MavenProject> reactorProjects = createDescriptorFromProjects( "internal-snapshot-dependencies-no-reactor" );
ReleaseDescriptorBuilder builder = createReleaseDescriptorBuilder( reactorProjects );
builder.addDependencyReleaseVersion("groupId:test", "1.0");
builder.addDependencyDevelopmentVersion("groupId:test", "1.1");

try
{
phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects );
assertTrue( true );
}
catch ( ReleaseFailureException e )
{
fail( "There should be no failed execution" );
}

try
{
phase.simulate( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects );
assertTrue( true );
}
catch ( ReleaseFailureException e )
{
fail( "There should be no failed execution" );
}
}

@Test
public void testSnapshotDependenciesInProjectOnly()
throws Exception
Expand Down Expand Up @@ -498,10 +529,10 @@ public void testSnapshotDependenciesOutsideProjectOnlyInteractiveWithSnapshotsRe
new VersionPair( "1.0", "1.0" ) ) );

phase.execute( ReleaseUtils.buildReleaseDescriptor( builder ), new DefaultReleaseEnvironment(), reactorProjects );

// validate
ReleaseDescriptor descriptor = ReleaseUtils.buildReleaseDescriptor( builder );

assertEquals( "1.0", descriptor.getDependencyReleaseVersion( "external:artifactId" ) );
assertEquals( "1.1-SNAPSHOT", descriptor.getDependencyDevelopmentVersion( "external:artifactId" ) );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
~ Copyright 2005-2006 The Apache Software Foundation.
~
~ Licensed 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.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>groupId</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

0 comments on commit 5c80a60

Please sign in to comment.