KickJava   Java API By Example, From Geeks To Geeks.

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


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.handler.ArtifactHandler;
21 import org.apache.maven.artifact.metadata.ArtifactMetadata;
22 import org.apache.maven.artifact.repository.ArtifactRepository;
23 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
24 import org.apache.maven.artifact.versioning.ArtifactVersion;
25 import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
26 import org.apache.maven.artifact.versioning.VersionRange;
27 import org.apache.maven.project.MavenProject;
28
29 import java.io.File JavaDoc;
30 import java.util.Collection JavaDoc;
31 import java.util.List JavaDoc;
32
33 /**
34  * Wraps an active project instance to be able to receive updates from its artifact without affecting the original
35  * attributes of this artifact.
36  *
37  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
38  * @version $Id: ActiveProjectArtifact.java 354544 2005-12-06 20:50:41Z jdcasey $
39  * @todo I think this exposes a design flaw in that the immutable and mutable parts of an artifact are in one class and
40  * should be split. ie scope, file, etc depend on the context of use, whereas everything else is immutable.
41  */

42 public class ActiveProjectArtifact
43     implements Artifact
44 {
45     private final Artifact artifact;
46
47     private final MavenProject project;
48
49     public ActiveProjectArtifact( MavenProject project, Artifact artifact )
50     {
51         this.artifact = artifact;
52         this.project = project;
53
54         artifact.setFile( project.getArtifact().getFile() );
55         artifact.setResolved( true );
56     }
57
58     public File JavaDoc getFile()
59     {
60         // we need to get the latest file for the project, not the artifact that was created at one point in time
61
return project.getArtifact().getFile();
62     }
63
64     public String JavaDoc getGroupId()
65     {
66         return artifact.getGroupId();
67     }
68
69     public String JavaDoc getArtifactId()
70     {
71         return artifact.getArtifactId();
72     }
73
74     public String JavaDoc getVersion()
75     {
76         return artifact.getVersion();
77     }
78
79     public void setVersion( String JavaDoc version )
80     {
81         artifact.setVersion( version );
82     }
83
84     public String JavaDoc getScope()
85     {
86         return artifact.getScope();
87     }
88
89     public String JavaDoc getType()
90     {
91         return artifact.getType();
92     }
93
94     public String JavaDoc getClassifier()
95     {
96         return artifact.getClassifier();
97     }
98
99     public boolean hasClassifier()
100     {
101         return artifact.hasClassifier();
102     }
103
104     public void setFile( File JavaDoc destination )
105     {
106         artifact.setFile( destination );
107         project.getArtifact().setFile( destination );
108     }
109
110     public String JavaDoc getBaseVersion()
111     {
112         return artifact.getBaseVersion();
113     }
114
115     public void setBaseVersion( String JavaDoc baseVersion )
116     {
117         artifact.setBaseVersion( baseVersion );
118     }
119
120     public String JavaDoc getId()
121     {
122         return artifact.getId();
123     }
124
125     public String JavaDoc getDependencyConflictId()
126     {
127         return artifact.getDependencyConflictId();
128     }
129
130     public void addMetadata( ArtifactMetadata metadata )
131     {
132         artifact.addMetadata( metadata );
133     }
134
135     public Collection JavaDoc getMetadataList()
136     {
137         return artifact.getMetadataList();
138     }
139
140     public void setRepository( ArtifactRepository remoteRepository )
141     {
142         artifact.setRepository( remoteRepository );
143     }
144
145     public ArtifactRepository getRepository()
146     {
147         return artifact.getRepository();
148     }
149
150     public void updateVersion( String JavaDoc version, ArtifactRepository localRepository )
151     {
152         artifact.updateVersion( version, localRepository );
153     }
154
155     public String JavaDoc getDownloadUrl()
156     {
157         return artifact.getDownloadUrl();
158     }
159
160     public void setDownloadUrl( String JavaDoc downloadUrl )
161     {
162         artifact.setDownloadUrl( downloadUrl );
163     }
164
165     public ArtifactFilter getDependencyFilter()
166     {
167         return artifact.getDependencyFilter();
168     }
169
170     public void setDependencyFilter( ArtifactFilter artifactFilter )
171     {
172         artifact.setDependencyFilter( artifactFilter );
173     }
174
175     public ArtifactHandler getArtifactHandler()
176     {
177         return artifact.getArtifactHandler();
178     }
179
180     public List JavaDoc getDependencyTrail()
181     {
182         return artifact.getDependencyTrail();
183     }
184
185     public void setDependencyTrail( List JavaDoc dependencyTrail )
186     {
187         artifact.setDependencyTrail( dependencyTrail );
188     }
189
190     public void setScope( String JavaDoc scope )
191     {
192         artifact.setScope( scope );
193     }
194
195     public VersionRange getVersionRange()
196     {
197         return artifact.getVersionRange();
198     }
199
200     public void setVersionRange( VersionRange newRange )
201     {
202         artifact.setVersionRange( newRange );
203     }
204
205     public void selectVersion( String JavaDoc version )
206     {
207         artifact.selectVersion( version );
208     }
209
210     public void setGroupId( String JavaDoc groupId )
211     {
212         artifact.setGroupId( groupId );
213     }
214
215     public void setArtifactId( String JavaDoc artifactId )
216     {
217         artifact.setArtifactId( artifactId );
218     }
219
220     public boolean isSnapshot()
221     {
222         return artifact.isSnapshot();
223     }
224
225     public int compareTo( Object JavaDoc o )
226     {
227         return artifact.compareTo( o );
228     }
229
230     public void setResolved( boolean resolved )
231     {
232         artifact.setResolved( resolved );
233     }
234
235     public boolean isResolved()
236     {
237         return artifact.isResolved();
238     }
239
240     public void setResolvedVersion( String JavaDoc version )
241     {
242         artifact.setResolvedVersion( version );
243     }
244
245     public void setArtifactHandler( ArtifactHandler handler )
246     {
247         artifact.setArtifactHandler( handler );
248     }
249
250     public String JavaDoc toString()
251     {
252         return "active project artifact:\n\tartifact = " + artifact + ";\n\tproject: " + project;
253     }
254
255     public boolean isRelease()
256     {
257         return artifact.isRelease();
258     }
259
260     public void setRelease( boolean release )
261     {
262         artifact.setRelease( release );
263     }
264
265     public List JavaDoc getAvailableVersions()
266     {
267         return artifact.getAvailableVersions();
268     }
269
270     public void setAvailableVersions( List JavaDoc versions )
271     {
272         artifact.setAvailableVersions( versions );
273     }
274
275     public boolean isOptional()
276     {
277         return artifact.isOptional();
278     }
279
280     public ArtifactVersion getSelectedVersion()
281         throws OverConstrainedVersionException
282     {
283         return artifact.getSelectedVersion();
284     }
285
286     public boolean isSelectedVersionKnown()
287         throws OverConstrainedVersionException
288     {
289         return artifact.isSelectedVersionKnown();
290     }
291
292     public void setOptional( boolean optional )
293     {
294         artifact.setOptional( optional );
295     }
296 }
297
Popular Tags