| 1 | |
package org.apache.maven.artifact; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
import org.apache.maven.artifact.versioning.VersionRange; |
| 23 | |
import org.apache.maven.artifact.handler.ArtifactHandler; |
| 24 | |
|
| 25 | |
import java.util.ArrayList; |
| 26 | |
import java.util.Collection; |
| 27 | |
import java.util.Iterator; |
| 28 | |
import java.util.LinkedHashMap; |
| 29 | |
import java.util.List; |
| 30 | |
import java.util.Map; |
| 31 | |
|
| 32 | |
public final class ArtifactUtils |
| 33 | |
{ |
| 34 | |
|
| 35 | |
private ArtifactUtils() |
| 36 | 0 | { |
| 37 | 0 | } |
| 38 | |
|
| 39 | |
public static boolean isSnapshot( String version ) |
| 40 | |
{ |
| 41 | 0 | return version != null && |
| 42 | |
( version.toUpperCase().endsWith( Artifact.SNAPSHOT_VERSION ) || Artifact.VERSION_FILE_PATTERN.matcher( version ) |
| 43 | |
.matches() ); |
| 44 | |
} |
| 45 | |
|
| 46 | |
public static String versionlessKey( Artifact artifact ) |
| 47 | |
{ |
| 48 | 0 | return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); |
| 49 | |
} |
| 50 | |
|
| 51 | |
public static String versionlessKey( String groupId, String artifactId ) |
| 52 | |
{ |
| 53 | 0 | if ( groupId == null ) |
| 54 | |
{ |
| 55 | 0 | throw new NullPointerException( "groupId was null" ); |
| 56 | |
} |
| 57 | 0 | if ( artifactId == null ) |
| 58 | |
{ |
| 59 | 0 | throw new NullPointerException( "artifactId was null" ); |
| 60 | |
} |
| 61 | 0 | return groupId + ":" + artifactId; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public static String artifactId( String groupId, String artifactId, String type, String version ) |
| 65 | |
{ |
| 66 | 0 | return artifactId( groupId, artifactId, type, null, version ); |
| 67 | |
} |
| 68 | |
|
| 69 | |
public static String artifactId( String groupId, String artifactId, String type, String classifier, |
| 70 | |
String baseVersion ) |
| 71 | |
{ |
| 72 | 0 | return groupId + ":" + artifactId + ":" + type + ( classifier != null ? ":" + classifier : "" ) + ":" + |
| 73 | |
baseVersion; |
| 74 | |
} |
| 75 | |
|
| 76 | |
public static Map artifactMapByVersionlessId( Collection artifacts ) |
| 77 | |
{ |
| 78 | 0 | Map artifactMap = new LinkedHashMap(); |
| 79 | |
|
| 80 | 0 | if ( artifacts != null ) |
| 81 | |
{ |
| 82 | 0 | for ( Iterator it = artifacts.iterator(); it.hasNext(); ) |
| 83 | |
{ |
| 84 | 0 | Artifact artifact = (Artifact) it.next(); |
| 85 | |
|
| 86 | 0 | artifactMap.put( versionlessKey( artifact ), artifact ); |
| 87 | 0 | } |
| 88 | |
} |
| 89 | |
|
| 90 | 0 | return artifactMap; |
| 91 | |
} |
| 92 | |
|
| 93 | |
public static Map artifactMapByArtifactId( Collection artifacts ) |
| 94 | |
{ |
| 95 | 0 | Map artifactMap = new LinkedHashMap(); |
| 96 | |
|
| 97 | 0 | if ( artifacts != null ) |
| 98 | |
{ |
| 99 | 0 | for ( Iterator it = artifacts.iterator(); it.hasNext(); ) |
| 100 | |
{ |
| 101 | 0 | Artifact artifact = (Artifact) it.next(); |
| 102 | |
|
| 103 | 0 | artifactMap.put( artifact.getId(), artifact ); |
| 104 | 0 | } |
| 105 | |
} |
| 106 | |
|
| 107 | 0 | return artifactMap; |
| 108 | |
} |
| 109 | |
|
| 110 | |
public static Artifact copyArtifact( Artifact artifact ) |
| 111 | |
{ |
| 112 | 0 | VersionRange range = artifact.getVersionRange(); |
| 113 | 0 | DefaultArtifact clone = new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), range.cloneOf(), |
| 114 | |
artifact.getScope(), artifact.getType(), artifact.getClassifier(), |
| 115 | |
artifact.getArtifactHandler(), artifact.isOptional() ); |
| 116 | 0 | clone.setRelease( artifact.isRelease() ); |
| 117 | 0 | clone.setResolvedVersion( artifact.getVersion() ); |
| 118 | 0 | clone.setResolved( artifact.isResolved() ); |
| 119 | 0 | clone.setFile( artifact.getFile() ); |
| 120 | |
|
| 121 | 0 | clone.setAvailableVersions( copyList( artifact.getAvailableVersions() ) ); |
| 122 | 0 | clone.setBaseVersion( artifact.getBaseVersion() ); |
| 123 | 0 | clone.setDependencyFilter( artifact.getDependencyFilter() ); |
| 124 | 0 | clone.setDependencyTrail( copyList( artifact.getDependencyTrail() ) ); |
| 125 | 0 | clone.setDownloadUrl( artifact.getDownloadUrl() ); |
| 126 | 0 | clone.setRepository( artifact.getRepository() ); |
| 127 | |
|
| 128 | 0 | return clone; |
| 129 | |
} |
| 130 | |
|
| 131 | |
private static List copyList( List original ) |
| 132 | |
{ |
| 133 | 0 | List copy = null; |
| 134 | |
|
| 135 | 0 | if ( original != null ) |
| 136 | |
{ |
| 137 | 0 | copy = new ArrayList(); |
| 138 | |
|
| 139 | 0 | if ( !original.isEmpty() ) |
| 140 | |
{ |
| 141 | 0 | copy.addAll( original ); |
| 142 | |
} |
| 143 | |
} |
| 144 | |
|
| 145 | 0 | return copy; |
| 146 | |
} |
| 147 | |
|
| 148 | |
} |