| 1 | |
package org.apache.maven.artifact.factory; |
| 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.Artifact; |
| 23 | |
import org.apache.maven.artifact.DefaultArtifact; |
| 24 | |
import org.apache.maven.artifact.handler.ArtifactHandler; |
| 25 | |
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; |
| 26 | |
import org.apache.maven.artifact.versioning.VersionRange; |
| 27 | |
|
| 28 | |
public class DefaultArtifactFactory |
| 29 | |
implements ArtifactFactory |
| 30 | |
{ |
| 31 | |
|
| 32 | |
private ArtifactHandlerManager artifactHandlerManager; |
| 33 | |
|
| 34 | |
public DefaultArtifactFactory() |
| 35 | 0 | { |
| 36 | 0 | } |
| 37 | |
|
| 38 | |
public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) |
| 39 | |
{ |
| 40 | 0 | return createArtifact( groupId, artifactId, version, scope, type, null, null ); |
| 41 | |
} |
| 42 | |
|
| 43 | |
public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, |
| 44 | |
String classifier ) |
| 45 | |
{ |
| 46 | 0 | return createArtifact( groupId, artifactId, version, null, type, classifier, null ); |
| 47 | |
} |
| 48 | |
|
| 49 | |
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 50 | |
String classifier, String scope ) |
| 51 | |
{ |
| 52 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, null ); |
| 53 | |
} |
| 54 | |
|
| 55 | |
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 56 | |
String classifier, String scope, boolean optional ) |
| 57 | |
{ |
| 58 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, null, optional ); |
| 59 | |
} |
| 60 | |
|
| 61 | |
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 62 | |
String classifier, String scope, String inheritedScope ) |
| 63 | |
{ |
| 64 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope ); |
| 65 | |
} |
| 66 | |
|
| 67 | |
public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 68 | |
String classifier, String scope, String inheritedScope, boolean optional ) |
| 69 | |
{ |
| 70 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope, optional ); |
| 71 | |
} |
| 72 | |
|
| 73 | |
public Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging ) |
| 74 | |
{ |
| 75 | 0 | return createArtifact( groupId, artifactId, version, null, packaging, null, null ); |
| 76 | |
} |
| 77 | |
|
| 78 | |
public Artifact createProjectArtifact( String groupId, String artifactId, String version ) |
| 79 | |
{ |
| 80 | 0 | return createProjectArtifact( groupId, artifactId, version, null ); |
| 81 | |
} |
| 82 | |
|
| 83 | |
public Artifact createParentArtifact( String groupId, String artifactId, String version ) |
| 84 | |
{ |
| 85 | 0 | return createProjectArtifact( groupId, artifactId, version ); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ) |
| 89 | |
{ |
| 90 | 0 | return createArtifact( groupId, artifactId, versionRange, "maven-plugin", null, Artifact.SCOPE_RUNTIME, null ); |
| 91 | |
} |
| 92 | |
|
| 93 | |
public Artifact createProjectArtifact( String groupId, String artifactId, String version, String scope ) |
| 94 | |
{ |
| 95 | 0 | return createArtifact( groupId, artifactId, version, scope, "pom" ); |
| 96 | |
} |
| 97 | |
|
| 98 | |
public Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ) |
| 99 | |
{ |
| 100 | 0 | return createArtifact( groupId, artifactId, versionRange, "jar", null, Artifact.SCOPE_RUNTIME, null ); |
| 101 | |
} |
| 102 | |
|
| 103 | |
private Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type, |
| 104 | |
String classifier, String inheritedScope ) |
| 105 | |
{ |
| 106 | 0 | VersionRange versionRange = null; |
| 107 | 0 | if ( version != null ) |
| 108 | |
{ |
| 109 | 0 | versionRange = VersionRange.createFromVersion( version ); |
| 110 | |
} |
| 111 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope ); |
| 112 | |
} |
| 113 | |
|
| 114 | |
private Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 115 | |
String classifier, String scope, String inheritedScope ) |
| 116 | |
{ |
| 117 | 0 | return createArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope, false ); |
| 118 | |
} |
| 119 | |
|
| 120 | |
private Artifact createArtifact( String groupId, String artifactId, VersionRange versionRange, String type, |
| 121 | |
String classifier, String scope, String inheritedScope, boolean optional ) |
| 122 | |
{ |
| 123 | |
|
| 124 | |
|
| 125 | 0 | String desiredScope = Artifact.SCOPE_RUNTIME; |
| 126 | 0 | if ( inheritedScope == null ) |
| 127 | |
{ |
| 128 | 0 | desiredScope = scope; |
| 129 | |
} |
| 130 | 0 | else if ( Artifact.SCOPE_TEST.equals( scope ) || Artifact.SCOPE_PROVIDED.equals( scope ) ) |
| 131 | |
{ |
| 132 | 0 | return null; |
| 133 | |
} |
| 134 | 0 | else if ( Artifact.SCOPE_COMPILE.equals( scope ) && Artifact.SCOPE_COMPILE.equals( inheritedScope ) ) |
| 135 | |
{ |
| 136 | |
|
| 137 | 0 | desiredScope = Artifact.SCOPE_COMPILE; |
| 138 | |
} |
| 139 | |
|
| 140 | 0 | if ( Artifact.SCOPE_TEST.equals( inheritedScope ) ) |
| 141 | |
{ |
| 142 | 0 | desiredScope = Artifact.SCOPE_TEST; |
| 143 | |
} |
| 144 | |
|
| 145 | 0 | if ( Artifact.SCOPE_PROVIDED.equals( inheritedScope ) ) |
| 146 | |
{ |
| 147 | 0 | desiredScope = Artifact.SCOPE_PROVIDED; |
| 148 | |
} |
| 149 | |
|
| 150 | 0 | if ( Artifact.SCOPE_SYSTEM.equals( scope ) ) |
| 151 | |
{ |
| 152 | |
|
| 153 | 0 | desiredScope = Artifact.SCOPE_SYSTEM; |
| 154 | |
} |
| 155 | |
|
| 156 | 0 | ArtifactHandler handler = artifactHandlerManager.getArtifactHandler( type ); |
| 157 | |
|
| 158 | 0 | return new DefaultArtifact( groupId, artifactId, versionRange, desiredScope, type, classifier, handler, |
| 159 | |
optional ); |
| 160 | |
} |
| 161 | |
} |