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