001 package org.apache.maven.project.artifact; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.maven.artifact.Artifact; 023 import org.apache.maven.artifact.DefaultArtifact; 024 import org.apache.maven.artifact.InvalidArtifactRTException; 025 import org.apache.maven.artifact.handler.ArtifactHandler; 026 import org.apache.maven.artifact.metadata.ArtifactMetadata; 027 import org.apache.maven.artifact.repository.ArtifactRepository; 028 import org.apache.maven.artifact.versioning.VersionRange; 029 030 import java.util.Collection; 031 import java.util.Collections; 032 import java.util.List; 033 034 /** 035 *<strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part 036 * of the public API. In particular, this class can be changed or deleted without prior notice. Use 037 * {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} instead. 038 */ 039 @Deprecated 040 public class AttachedArtifact 041 extends DefaultArtifact 042 { 043 044 private final Artifact parent; 045 046 public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler ) 047 { 048 super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type, 049 classifier, artifactHandler, parent.isOptional() ); 050 051 setDependencyTrail( Collections.singletonList( parent.getId() ) ); 052 053 this.parent = parent; 054 055 if ( getId().equals( parent.getId() ) ) 056 { 057 throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), 058 parent.getType(), "An attached artifact must have a different ID" 059 + " than its corresponding main artifact." ); 060 } 061 } 062 063 public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler ) 064 { 065 this( parent, type, null, artifactHandler ); 066 } 067 068 public void setArtifactId( String artifactId ) 069 { 070 throw new UnsupportedOperationException( "Cannot change the artifactId for an attached artifact." 071 + " It is derived from the main artifact." ); 072 } 073 074 public List getAvailableVersions() 075 { 076 return parent.getAvailableVersions(); 077 } 078 079 public void setAvailableVersions( List availableVersions ) 080 { 081 throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact." 082 + " It is derived from the main artifact." ); 083 } 084 085 public String getBaseVersion() 086 { 087 return parent.getBaseVersion(); 088 } 089 090 public void setBaseVersion( String baseVersion ) 091 { 092 throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact." 093 + " It is derived from the main artifact." ); 094 } 095 096 public String getDownloadUrl() 097 { 098 return parent.getDownloadUrl(); 099 } 100 101 public void setDownloadUrl( String downloadUrl ) 102 { 103 throw new UnsupportedOperationException( "Cannot change the download information for an attached artifact." 104 + " It is derived from the main artifact." ); 105 } 106 107 public void setGroupId( String groupId ) 108 { 109 throw new UnsupportedOperationException( "Cannot change the groupId for an attached artifact." 110 + " It is derived from the main artifact." ); 111 } 112 113 public ArtifactRepository getRepository() 114 { 115 return parent.getRepository(); 116 } 117 118 public void setRepository( ArtifactRepository repository ) 119 { 120 throw new UnsupportedOperationException( "Cannot change the repository information for an attached artifact." 121 + " It is derived from the main artifact." ); 122 } 123 124 public String getScope() 125 { 126 return parent.getScope(); 127 } 128 129 public void setScope( String scope ) 130 { 131 throw new UnsupportedOperationException( "Cannot change the scoping information for an attached artifact." 132 + " It is derived from the main artifact." ); 133 } 134 135 public String getVersion() 136 { 137 return parent.getVersion(); 138 } 139 140 public void setVersion( String version ) 141 { 142 throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact." 143 + " It is derived from the main artifact." ); 144 } 145 146 public VersionRange getVersionRange() 147 { 148 return parent.getVersionRange(); 149 } 150 151 public void setVersionRange( VersionRange range ) 152 { 153 throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact." 154 + " It is derived from the main artifact." ); 155 } 156 157 public boolean isRelease() 158 { 159 return parent.isRelease(); 160 } 161 162 public void setRelease( boolean release ) 163 { 164 throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact." 165 + " It is derived from the main artifact." ); 166 } 167 168 public boolean isSnapshot() 169 { 170 return parent.isSnapshot(); 171 } 172 173 public void addMetadata( ArtifactMetadata metadata ) 174 { 175 // ignore. The parent artifact will handle metadata. 176 // we must fail silently here to avoid problems with the artifact transformers. 177 } 178 179 public Collection getMetadataList() 180 { 181 return Collections.EMPTY_LIST; 182 } 183 184 }