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  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.artifact.DefaultArtifact;
27  import org.apache.maven.artifact.InvalidArtifactRTException;
28  import org.apache.maven.artifact.handler.ArtifactHandler;
29  import org.apache.maven.artifact.metadata.ArtifactMetadata;
30  import org.apache.maven.artifact.repository.ArtifactRepository;
31  import org.apache.maven.artifact.versioning.ArtifactVersion;
32  import org.apache.maven.artifact.versioning.VersionRange;
33  
34  /**
35   *<strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
36   * of the public API. In particular, this class can be changed or deleted without prior notice. Use
37   * {@link org.apache.maven.project.MavenProjectHelper#attachArtifact} instead.
38   */
39  @Deprecated
40  public class AttachedArtifact extends DefaultArtifact {
41  
42      private final Artifact parent;
43  
44      public AttachedArtifact(Artifact parent, String type, String classifier, ArtifactHandler artifactHandler) {
45          super(
46                  parent.getGroupId(),
47                  parent.getArtifactId(),
48                  parent.getVersionRange(),
49                  parent.getScope(),
50                  type,
51                  classifier,
52                  artifactHandler,
53                  parent.isOptional());
54  
55          setDependencyTrail(Collections.singletonList(parent.getId()));
56  
57          this.parent = parent;
58  
59          if (getId().equals(parent.getId())) {
60              throw new InvalidArtifactRTException(
61                      parent.getGroupId(),
62                      parent.getArtifactId(),
63                      parent.getVersion(),
64                      parent.getType(),
65                      "An attached artifact must have a different ID" + " than its corresponding main artifact.");
66          }
67      }
68  
69      public AttachedArtifact(Artifact parent, String type, ArtifactHandler artifactHandler) {
70          this(parent, type, null, artifactHandler);
71      }
72  
73      public void setArtifactId(String artifactId) {
74          throw new UnsupportedOperationException(
75                  "Cannot change the artifactId for an attached artifact." + " It is derived from the main artifact.");
76      }
77  
78      public List<ArtifactVersion> getAvailableVersions() {
79          return parent.getAvailableVersions();
80      }
81  
82      public void setAvailableVersions(List<ArtifactVersion> availableVersions) {
83          throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
84                  + " It is derived from the main artifact.");
85      }
86  
87      public String getBaseVersion() {
88          return parent.getBaseVersion();
89      }
90  
91      public void setBaseVersion(String baseVersion) {
92          throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
93                  + " It is derived from the main artifact.");
94      }
95  
96      public String getDownloadUrl() {
97          return parent.getDownloadUrl();
98      }
99  
100     public void setDownloadUrl(String downloadUrl) {
101         throw new UnsupportedOperationException("Cannot change the download information for an attached artifact."
102                 + " It is derived from the main artifact.");
103     }
104 
105     public void setGroupId(String groupId) {
106         throw new UnsupportedOperationException(
107                 "Cannot change the groupId for an attached artifact." + " It is derived from the main artifact.");
108     }
109 
110     public ArtifactRepository getRepository() {
111         return parent.getRepository();
112     }
113 
114     public void setRepository(ArtifactRepository repository) {
115         throw new UnsupportedOperationException("Cannot change the repository information for an attached artifact."
116                 + " It is derived from the main artifact.");
117     }
118 
119     public String getScope() {
120         return parent.getScope();
121     }
122 
123     public void setScope(String scope) {
124         throw new UnsupportedOperationException("Cannot change the scoping information for an attached artifact."
125                 + " It is derived from the main artifact.");
126     }
127 
128     public String getVersion() {
129         return parent.getVersion();
130     }
131 
132     public void setVersion(String version) {
133         throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
134                 + " It is derived from the main artifact.");
135     }
136 
137     public VersionRange getVersionRange() {
138         return parent.getVersionRange();
139     }
140 
141     public void setVersionRange(VersionRange range) {
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 boolean isRelease() {
147         return parent.isRelease();
148     }
149 
150     public void setRelease(boolean release) {
151         throw new UnsupportedOperationException("Cannot change the version information for an attached artifact."
152                 + " It is derived from the main artifact.");
153     }
154 
155     public boolean isSnapshot() {
156         return parent.isSnapshot();
157     }
158 
159     public void addMetadata(ArtifactMetadata metadata) {
160         // ignore. The parent artifact will handle metadata.
161         // we must fail silently here to avoid problems with the artifact transformers.
162     }
163 
164     public Collection<ArtifactMetadata> getMetadataList() {
165         return Collections.emptyList();
166     }
167 }