KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > project > artifact > AttachedArtifact


1 package org.apache.maven.project.artifact;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.artifact.Artifact;
20 import org.apache.maven.artifact.DefaultArtifact;
21 import org.apache.maven.artifact.InvalidArtifactRTException;
22 import org.apache.maven.artifact.handler.ArtifactHandler;
23 import org.apache.maven.artifact.metadata.ArtifactMetadata;
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.versioning.VersionRange;
26
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.List JavaDoc;
30
31 public class AttachedArtifact
32     extends DefaultArtifact
33 {
34
35     private final Artifact parent;
36
37     public AttachedArtifact( Artifact parent, String JavaDoc type, String JavaDoc classifier, ArtifactHandler artifactHandler )
38     {
39         super( parent.getGroupId(), parent.getArtifactId(), parent.getVersionRange(), parent.getScope(), type,
40                classifier, artifactHandler, parent.isOptional() );
41         
42         setDependencyTrail( Collections.singletonList( parent.getId() ) );
43         
44         this.parent = parent;
45         
46         if ( getId().equals( parent.getId() ) )
47         {
48             throw new InvalidArtifactRTException( parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), parent.getType(), "An attached artifact must have a different ID than its corresponding main artifact." );
49         }
50     }
51
52     public AttachedArtifact( Artifact parent, String JavaDoc type, ArtifactHandler artifactHandler )
53     {
54         this( parent, type, null, artifactHandler );
55     }
56     
57     public void setArtifactId( String JavaDoc artifactId )
58     {
59         throw new UnsupportedOperationException JavaDoc( "Cannot change the artifactId for an attached artifact. It is derived from the main artifact." );
60     }
61
62     public List JavaDoc getAvailableVersions()
63     {
64         return parent.getAvailableVersions();
65     }
66     
67     public void setAvailableVersions( List JavaDoc availableVersions )
68     {
69         throw new UnsupportedOperationException JavaDoc( "Cannot change the version information for an attached artifact. It is derived from the main artifact." );
70     }
71
72     public String JavaDoc getBaseVersion()
73     {
74         return parent.getBaseVersion();
75     }
76     
77     public void setBaseVersion( String JavaDoc baseVersion )
78     {
79         throw new UnsupportedOperationException JavaDoc( "Cannot change the version information for an attached artifact. It is derived from the main artifact." );
80     }
81
82     public String JavaDoc getDownloadUrl()
83     {
84         return parent.getDownloadUrl();
85     }
86     
87     public void setDownloadUrl( String JavaDoc downloadUrl )
88     {
89         throw new UnsupportedOperationException JavaDoc( "Cannot change the download information for an attached artifact. It is derived from the main artifact." );
90     }
91
92     public void setGroupId( String JavaDoc groupId )
93     {
94         throw new UnsupportedOperationException JavaDoc( "Cannot change the groupId on attached artifacts. It is derived from the main artifact." );
95     }
96
97     public ArtifactRepository getRepository()
98     {
99         return parent.getRepository();
100     }
101     
102     public void setRepository( ArtifactRepository repository )
103     {
104         throw new UnsupportedOperationException JavaDoc( "Cannot change the repository information for an attached artifact. It is derived from the main artifact." );
105     }
106
107     public String JavaDoc getScope()
108     {
109         return parent.getScope();
110     }
111     
112     public void setScope( String JavaDoc scope )
113     {
114         throw new UnsupportedOperationException JavaDoc( "Cannot change the scoping information for an attached artifact. It is derived from the main artifact." );
115     }
116
117     public String JavaDoc getVersion()
118     {
119         return parent.getVersion();
120     }
121     
122     public void setVersion( String JavaDoc version )
123     {
124         throw new UnsupportedOperationException JavaDoc( "Cannot change the version information for an attached artifact. It is derived from the main artifact." );
125     }
126
127     public VersionRange getVersionRange()
128     {
129         return parent.getVersionRange();
130     }
131     
132     public void setVersionRange( VersionRange range )
133     {
134         throw new UnsupportedOperationException JavaDoc( "Cannot change the version information for an attached artifact. It is derived from the main artifact." );
135     }
136
137     public boolean isRelease()
138     {
139         return parent.isRelease();
140     }
141     
142     public void setRelease( boolean release )
143     {
144         throw new UnsupportedOperationException JavaDoc( "Cannot change the version information for an attached artifact. It is derived from the main artifact." );
145     }
146
147     public boolean isSnapshot()
148     {
149         return parent.isSnapshot();
150     }
151     
152     public void addMetadata( ArtifactMetadata metadata )
153     {
154         // ignore. The parent artifact will handle metadata.
155
// we must fail silently here to avoid problems with the artifact transformers.
156
}
157
158     public Collection JavaDoc getMetadataList()
159     {
160         return Collections.EMPTY_LIST;
161     }
162
163 }
164
Popular Tags