1 package org.apache.maven.project.artifact; 2 3 18 19 import org.apache.maven.artifact.Artifact; 20 import org.apache.maven.artifact.DefaultArtifact; 21 import org.apache.maven.artifact.InvalidArtifactRTException; 22 import org.apache.maven.artifact.handler.ArtifactHandler; 23 import org.apache.maven.artifact.metadata.ArtifactMetadata; 24 import org.apache.maven.artifact.repository.ArtifactRepository; 25 import org.apache.maven.artifact.versioning.VersionRange; 26 27 import java.util.Collection ; 28 import java.util.Collections ; 29 import java.util.List ; 30 31 public class AttachedArtifact 32 extends DefaultArtifact 33 { 34 35 private final Artifact parent; 36 37 public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler ) 38 { 39 super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, 40 classifier, artifactHandler, parent.isOptional() ); 41 42 setDependencyTrail( Collections.singletonList( parent.getId() ) ); 43 44 this.parent = parent; 45 46 if ( getId().equals( parent.getId() ) ) 47 { 48 throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), parent.getType(), "An attached artifact must have a different ID than its corresponding main artifact." ); 49 } 50 } 51 52 public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler ) 53 { 54 this( parent, type, null, artifactHandler ); 55 } 56 57 public void setArtifactId( String artifactId ) 58 { 59 throw new UnsupportedOperationException ( "Cannot change the artifactId for an attached artifact. It is derived from the main artifact." ); 60 } 61 62 public List getAvailableVersions() 63 { 64 return parent.getAvailableVersions(); 65 } 66 67 public void setAvailableVersions( List availableVersions ) 68 { 69 throw new UnsupportedOperationException ( "Cannot change the version information for an attached artifact. It is derived from the main artifact." ); 70 } 71 72 public String getBaseVersion() 73 { 74 return parent.getBaseVersion(); 75 } 76 77 public void setBaseVersion( String baseVersion ) 78 { 79 throw new UnsupportedOperationException ( "Cannot change the version information for an attached artifact. It is derived from the main artifact." ); 80 } 81 82 public String getDownloadUrl() 83 { 84 return parent.getDownloadUrl(); 85 } 86 87 public void setDownloadUrl( String downloadUrl ) 88 { 89 throw new UnsupportedOperationException ( "Cannot change the download information for an attached artifact. It is derived from the main artifact." ); 90 } 91 92 public void setGroupId( String groupId ) 93 { 94 throw new UnsupportedOperationException ( "Cannot change the groupId on attached artifacts. It is derived from the main artifact." ); 95 } 96 97 public ArtifactRepository getRepository() 98 { 99 return parent.getRepository(); 100 } 101 102 public void setRepository( ArtifactRepository repository ) 103 { 104 throw new UnsupportedOperationException ( "Cannot change the repository information for an attached artifact. It is derived from the main artifact." ); 105 } 106 107 public String getScope() 108 { 109 return parent.getScope(); 110 } 111 112 public void setScope( String scope ) 113 { 114 throw new UnsupportedOperationException ( "Cannot change the scoping information for an attached artifact. It is derived from the main artifact." ); 115 } 116 117 public String getVersion() 118 { 119 return parent.getVersion(); 120 } 121 122 public void setVersion( String version ) 123 { 124 throw new UnsupportedOperationException ( "Cannot change the version information for an attached artifact. It is derived from the main artifact." ); 125 } 126 127 public VersionRange getVersionRange() 128 { 129 return parent.getVersionRange(); 130 } 131 132 public void setVersionRange( VersionRange range ) 133 { 134 throw new UnsupportedOperationException ( "Cannot change the version information for an attached artifact. It is derived from the main artifact." ); 135 } 136 137 public boolean isRelease() 138 { 139 return parent.isRelease(); 140 } 141 142 public void setRelease( boolean release ) 143 { 144 throw new UnsupportedOperationException ( "Cannot change the version information for an attached artifact. It is derived from the main artifact." ); 145 } 146 147 public boolean isSnapshot() 148 { 149 return parent.isSnapshot(); 150 } 151 152 public void addMetadata( ArtifactMetadata metadata ) 153 { 154 } 157 158 public Collection getMetadataList() 159 { 160 return Collections.EMPTY_LIST; 161 } 162 163 } 164 | Popular Tags |