Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRELEASE-985] Override snapshot dependencies from command line #28

Merged
merged 1 commit into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,36 @@ 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 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 +146,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 +681,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,20 +305,25 @@ 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 );

boolean releaseDescriptorResolvedVersionIsSnapshot = releaseDescriptorResolvedVersion == null
|| releaseDescriptorResolvedVersion.contains( Artifact.SNAPSHOT_VERSION );

// 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 ) );
boolean bannedVersion = artifact.isSnapshot()
&& !artifact.getBaseVersion().equals( releaseDescriptor.getProjectOriginalVersion( versionlessKey ) )
&& releaseDescriptorResolvedVersionIsSnapshot;

// If we have a snapshot but allowTimestampedSnapshots is true, accept the artifact if the version
// indicates that it is a timestamped snapshot.
if ( result && releaseDescriptor.isAllowTimestampedSnapshots() )
if ( bannedVersion && releaseDescriptor.isAllowTimestampedSnapshots() )
{
result = artifact.getVersion().indexOf( Artifact.SNAPSHOT_VERSION ) >= 0;
bannedVersion = artifact.getVersion().indexOf( Artifact.SNAPSHOT_VERSION ) >= 0;
}

return result;
return bannedVersion;
}

@Override
Expand Down Expand Up @@ -456,4 +461,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>