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.VersionRange;
29  
30  import java.util.Collection;
31  import java.util.Collections;
32  import java.util.List;
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
41      extends DefaultArtifact
42  {
43  
44      private final Artifact parent;
45  
46      public AttachedArtifact( Artifact parent, String type, String classifier, ArtifactHandler artifactHandler )
47      {
48          super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
49                 classifier, artifactHandler, parent.isOptional() );
50  
51          setDependencyTrail( Collections.singletonList( parent.getId() ) );
52  
53          this.parent = parent;
54  
55          if ( getId().equals( parent.getId() ) )
56          {
57              throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(),
58                                                    parent.getType(), "An attached artifact must have a different ID"
59                                                        + " than its corresponding main artifact." );
60          }
61      }
62  
63      public AttachedArtifact( Artifact parent, String type, ArtifactHandler artifactHandler )
64      {
65          this( parent, type, null, artifactHandler );
66      }
67  
68      public void setArtifactId( String artifactId )
69      {
70          throw new UnsupportedOperationException( "Cannot change the artifactId for an attached artifact."
71              + " It is derived from the main artifact." );
72      }
73  
74      public List getAvailableVersions()
75      {
76          return parent.getAvailableVersions();
77      }
78  
79      public void setAvailableVersions( List availableVersions )
80      {
81          throw new UnsupportedOperationException( "Cannot change the version information for an attached artifact."
82              + " It is derived from the main artifact." );
83      }
84  
85      public String getBaseVersion()
86      {
87          return parent.getBaseVersion();
88      }
89  
90      public void setBaseVersion( String baseVersion )
91      {
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      {
98          return parent.getDownloadUrl();
99      }
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 }