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