Skip to content

Instantly share code, notes, and snippets.

@headius
Last active March 11, 2016 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save headius/2671350c4f0ad6788c0a to your computer and use it in GitHub Desktop.
Save headius/2671350c4f0ad6788c0a to your computer and use it in GitHub Desktop.
partial patch for MRELEASE-161
Index: src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java
===================================================================
--- src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java (revision 1734625)
+++ src/main/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhase.java (working copy)
@@ -34,7 +34,6 @@
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.shared.release.ReleaseExecutionException;
import org.apache.maven.shared.release.ReleaseFailureException;
import org.apache.maven.shared.release.ReleaseResult;
@@ -117,12 +116,36 @@
return result;
}
+ private static Map<String, Artifact> artifactMapByFullVersionlessId(Set<Artifact> artifacts) {
+ Map<String, Artifact> artifactMap = new HashMap<String, Artifact>();
+
+ for (Artifact artifact : artifacts) {
+ artifactMap.put(fullVersionlessKey(artifact), artifact);
+ }
+
+ return artifactMap;
+ }
+
+ public static String fullVersionlessKey(Artifact artifact) {
+ return fullVersionlessKey(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier());
+ }
+
+ public static String fullVersionlessKey(String groupId, String artifactId, String classifier) {
+ if (groupId == null) {
+ throw new NullPointerException("groupId was null");
+ } else if (artifactId == null) {
+ throw new NullPointerException("artifactId was null");
+ } else {
+ return groupId + ":" + artifactId + classifier == null ? "" : ":" + classifier;
+ }
+ }
+
private void checkProject( MavenProject project, Map<String, String> originalVersions,
ReleaseDescriptor releaseDescriptor )
throws ReleaseFailureException, ReleaseExecutionException
{
@SuppressWarnings( "unchecked" )
- Map<String, Artifact> artifactMap = ArtifactUtils.artifactMapByVersionlessId( project.getArtifacts() );
+ Map<String, Artifact> artifactMap = artifactMapByFullVersionlessId(project.getArtifacts());
if ( project.getParentArtifact() != null )
{
@@ -131,17 +154,10 @@
usedSnapshotDependencies.add( project.getParentArtifact() );
}
}
-
- try
- {
- @SuppressWarnings( "unchecked" )
- Set<Artifact> dependencyArtifacts = project.createArtifacts( artifactFactory, null, null );
- checkDependencies( originalVersions, releaseDescriptor, artifactMap, dependencyArtifacts );
- }
- catch ( InvalidDependencyVersionException e )
- {
- throw new ReleaseExecutionException( "Failed to create dependency artifacts", e );
- }
+
+ @SuppressWarnings( "unchecked" )
+ Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
+ checkDependencies( originalVersions, releaseDescriptor, artifactMap, dependencyArtifacts );
//@todo check dependencyManagement
@SuppressWarnings( "unchecked" )
@@ -292,18 +308,18 @@
}
private static boolean checkArtifact( Artifact artifact, Map<String, String> originalVersions,
- Map<String, Artifact> artifactMapByVersionlessId,
+ Map<String, Artifact> artifactMapByFullVersionlessId,
ReleaseDescriptor releaseDescriptor )
{
- Artifact checkArtifact = getArtifactFromMap( artifact, artifactMapByVersionlessId );
+ Artifact checkArtifact = getArtifactFromMap( artifact, artifactMapByFullVersionlessId );
return checkArtifact( checkArtifact, originalVersions, releaseDescriptor );
}
- private static Artifact getArtifactFromMap( Artifact artifact, Map<String, Artifact> artifactMapByVersionlessId )
+ private static Artifact getArtifactFromMap( Artifact artifact, Map<String, Artifact> artifactMapByFullVersionlessId )
{
- String versionlessId = ArtifactUtils.versionlessKey( artifact );
- Artifact checkArtifact = artifactMapByVersionlessId.get( versionlessId );
+ String versionlessId = fullVersionlessKey( artifact );
+ Artifact checkArtifact = artifactMapByFullVersionlessId.get( versionlessId );
if ( checkArtifact == null )
{
@@ -315,7 +331,7 @@
private static boolean checkArtifact( Artifact artifact, Map<String, String> originalVersions,
ReleaseDescriptor releaseDescriptor )
{
- String versionlessArtifactKey = ArtifactUtils.versionlessKey( artifact.getGroupId(), artifact.getArtifactId() );
+ String versionlessArtifactKey = fullVersionlessKey( artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier() );
// We are only looking at dependencies external to the project - ignore anything found in the reactor as
// it's version will be updated
@@ -437,7 +453,7 @@
while ( iterator.hasNext() )
{
Artifact currentArtifact = iterator.next();
- String versionlessKey = ArtifactUtils.versionlessKey( currentArtifact );
+ String versionlessKey = fullVersionlessKey( currentArtifact );
Map<String, String> versionMap = new HashMap<String, String>();
VersionInfo versionInfo = new DefaultVersionInfo( currentArtifact.getVersion() );
@@ -473,4 +489,4 @@
return resolvedSnapshots;
}
-}
\ No newline at end of file
+}
Index: src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java
===================================================================
--- src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java (revision 1734625)
+++ src/test/java/org/apache/maven/shared/release/phase/CheckDependencySnapshotsPhaseTest.java (working copy)
@@ -667,6 +669,41 @@
assertEquals( "1.0", versionsMap.get( ReleaseDescriptor.RELEASE_KEY ) );
}
+ public void testSnapshotDependenciesWithNativeAssemblySelectDefaults()
+ throws Exception
+ {
+ CheckDependencySnapshotsPhase phase =
+ (CheckDependencySnapshotsPhase) lookup( ReleasePhase.ROLE, "check-dependency-snapshots" );
+
+ ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
+ List<MavenProject> reactorProjects = createDescriptorFromProjects( "external-snapshot-native-dependencies" );
+
+ phase.setPrompter( createMockPrompter( YES, DEFAULT_CHOICE, new VersionPair( "1.0", "1.0" ) ) );
+
+ try
+ {
+ phase.execute( releaseDescriptor, new DefaultReleaseEnvironment(), reactorProjects );
+ }
+ catch ( ReleaseFailureException e )
+ {
+ fail( e.getMessage() );
+ }
+
+ // validate
+// @SuppressWarnings("rawtypes")
+ Map versionsMap = (Map) releaseDescriptor.getResolvedSnapshotDependencies().get( "external:artifactId" );
+
+ assertNotNull( versionsMap );
+ assertEquals( "1.0", versionsMap.get( ReleaseDescriptor.DEVELOPMENT_KEY ) );
+ assertEquals( "1.0", versionsMap.get( ReleaseDescriptor.RELEASE_KEY ) );
+
+ versionsMap = (Map) releaseDescriptor.getResolvedSnapshotDependencies().get( "external:artifactId:classifier" );
+
+ assertNotNull( versionsMap );
+ assertEquals( "1.0", versionsMap.get( ReleaseDescriptor.DEVELOPMENT_KEY ) );
+ assertEquals( "1.0", versionsMap.get( ReleaseDescriptor.RELEASE_KEY ) );
+ }
+
public void testSnapshotDependenciesInsideAndOutsideProject()
throws Exception
{
Index: src/test/resources/projects/check-dependencies/external-snapshot-native-dependencies/pom.xml
===================================================================
--- src/test/resources/projects/check-dependencies/external-snapshot-native-dependencies/pom.xml (revision 0)
+++ src/test/resources/projects/check-dependencies/external-snapshot-native-dependencies/pom.xml (working copy)
@@ -0,0 +1,36 @@
+<!--
+ ~ 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>
+
+ <dependencies>
+ <dependency>
+ <groupId>external</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>external</groupId>
+ <artifactId>artifactId</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <classifier>native</classifier>
+ </dependency>
+ </dependencies>
+</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment