View Javadoc
1   package org.apache.maven.project.artifact;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.artifact.DefaultArtifact;
24  import org.apache.maven.artifact.InvalidArtifactRTException;
25  import org.apache.maven.artifact.handler.ArtifactHandler;
26  import org.apache.maven.artifact.metadata.ArtifactMetadata;
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.artifact.versioning.ArtifactVersion;
29  import org.apache.maven.artifact.versioning.VersionRange;
30  
31  import java.util.Collection;
32  import java.util.Collections;
33  import java.util.List;
34  
35  /**
36   *<strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
37   * of the public API. In particular, this class can be changed or deleted without prior notice. Use
38   * {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} instead.
39   */
40  @Deprecated
41  public class AttachedArtifact
42      extends DefaultArtifact
43  {
44  
45      private final Artifact parent;
46  
47      public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler )
48      {
49          super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
50                 classifier, artifactHandler, parent.isOptional() );
51  
52          setDependencyTrail( Collections.singletonList( parent.getId() ) );
53  
54          this.parent = parent;
55  
56          if ( getId().equals( parent.getId() ) )
57          {
58              throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(),
59                                                    parent.getType(), "An attached artifact must have a different ID"
60                                                        + " than its corresponding main artifact." );
61          }
62      }
63  
64      public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler )
65      {
66          this( parent, type, null, artifactHandler );
67      }
68  
69      public void setArtifactId( String artifactId )
70      {
71          throw new UnsupportedOperationException( "Cannot change the artifactId for an attached artifact."
72              + " It is derived from the main artifact." );
73      }
74  
75      public List<ArtifactVersion> getAvailableVersions()
76      {
77          return parent.getAvailableVersions();
78      }
79  
80      public void setAvailableVersions( List<ArtifactVersion> availableVersions )
81      {
82          throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
83              + " It is derived from the main artifact." );
84      }
85  
86      public String getBaseVersion()
87      {
88          return parent.getBaseVersion();
89      }
90  
91      public void setBaseVersion( String baseVersion )
92      {
93          throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
94              + " It is derived from the main artifact." );
95      }
96  
97      public String getDownloadUrl()
98      {
99          return parent.getDownloadUrl();
100     }
101 
102     public void setDownloadUrl( String downloadUrl )
103     {
104         throw new UnsupportedOperationException( "Cannot change the download information for an attached artifact."
105             + " It is derived from the main artifact." );
106     }
107 
108     public void setGroupId( String groupId )
109     {
110         throw new UnsupportedOperationException( "Cannot change the groupId for an attached artifact."
111             + " It is derived from the main artifact." );
112     }
113 
114     public ArtifactRepository getRepository()
115     {
116         return parent.getRepository();
117     }
118 
119     public void setRepository( ArtifactRepository repository )
120     {
121         throw new UnsupportedOperationException( "Cannot change the repository information for an attached artifact."
122             + " It is derived from the main artifact." );
123     }
124 
125     public String getScope()
126     {
127         return parent.getScope();
128     }
129 
130     public void setScope( String scope )
131     {
132         throw new UnsupportedOperationException( "Cannot change the scoping information for an attached artifact."
133             + " It is derived from the main artifact." );
134     }
135 
136     public String getVersion()
137     {
138         return parent.getVersion();
139     }
140 
141     public void setVersion( String version )
142     {
143         throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
144             + " It is derived from the main artifact." );
145     }
146 
147     public VersionRange getVersionRange()
148     {
149         return parent.getVersionRange();
150     }
151 
152     public void setVersionRange( VersionRange range )
153     {
154         throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
155             + " It is derived from the main artifact." );
156     }
157 
158     public boolean isRelease()
159     {
160         return parent.isRelease();
161     }
162 
163     public void setRelease( boolean release )
164     {
165         throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
166             + " It is derived from the main artifact." );
167     }
168 
169     public boolean isSnapshot()
170     {
171         return parent.isSnapshot();
172     }
173 
174     public void addMetadata( ArtifactMetadata metadata )
175     {
176         // ignore. The parent artifact will handle metadata.
177         // we must fail silently here to avoid problems with the artifact transformers.
178     }
179 
180     public Collection<ArtifactMetadata> getMetadataList()
181     {
182         return Collections.emptyList();
183     }
184 
185 }