1 package org.apache.maven.archiva.web.action;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import java.util.ArrayList;
23 import java.util.List;
25 import com.opensymphony.xwork2.Validateable;
26 import org.apache.archiva.metadata.model.Dependency;
27 import org.apache.archiva.metadata.model.MailingList;
28 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
29 import org.apache.archiva.metadata.model.ProjectVersionReference;
30 import org.apache.archiva.metadata.repository.MetadataResolver;
31 import org.apache.archiva.metadata.repository.MetadataResolverException;
32 import org.apache.commons.lang.StringUtils;
35 * Browse the repository.
37 * TODO change name to ShowVersionedAction to conform to terminology.
39 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
41 public class ShowArtifactAction
42 extends AbstractRepositoryBasedAction
43 implements Validateable
45 /* .\ Not Exposed \._____________________________________________ */
50 private MetadataResolver metadataResolver;
52 /* .\ Exposed Output Objects \.__________________________________ */
54 private String groupId;
56 private String artifactId;
58 private String version;
60 private String repositoryId;
63 * The model of this versioned project.
65 private ProjectVersionMetadata model;
68 * The list of artifacts that depend on this versioned project.
70 private List<ProjectVersionReference> dependees;
72 private List<MailingList> mailingLists;
74 private List<Dependency> dependencies;
76 private List<String> snapshotVersions;
79 * Show the versioned project information tab.
80 * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
81 * that is rendered in the download box).
83 public String artifact()
85 // In the future, this should be replaced by the repository grouping mechanism, so that we are only making
86 // simple resource requests here and letting the resolver take care of it
87 ProjectVersionMetadata versionMetadata = null;
88 snapshotVersions = new ArrayList<String>();
89 for ( String repoId : getObservableRepos() )
91 if ( versionMetadata == null )
93 // TODO: though we have a simple mapping now, do we want to support paths like /1.0-20090111.123456-1/
94 // again by mapping it to /1.0-SNAPSHOT/? Currently, the individual versions are not supported as we
95 // are only displaying the project's single version.
97 // we don't want the implementation being that intelligent - so another resolver to do the
98 // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
101 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
103 catch ( MetadataResolverException e )
105 addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
108 if ( versionMetadata != null )
110 repositoryId = repoId;
112 snapshotVersions.addAll(
113 metadataResolver.getArtifactVersions( repoId, groupId, artifactId, versionMetadata.getId() ) );
114 snapshotVersions.remove( version );
119 if ( versionMetadata == null )
121 addActionError( "Artifact not found" );
124 model = versionMetadata;
130 * Show the artifact information tab.
132 public String dependencies()
134 ProjectVersionMetadata versionMetadata = null;
135 for ( String repoId : getObservableRepos() )
137 if ( versionMetadata == null )
141 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
143 catch ( MetadataResolverException e )
145 addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
151 if ( versionMetadata == null )
153 addActionError( "Artifact not found" );
156 model = versionMetadata;
158 this.dependencies = model.getDependencies();
164 * Show the mailing lists information tab.
166 public String mailingLists()
168 ProjectVersionMetadata versionMetadata = null;
169 for ( String repoId : getObservableRepos() )
171 if ( versionMetadata == null )
175 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
177 catch ( MetadataResolverException e )
179 addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
185 if ( versionMetadata == null )
187 addActionError( "Artifact not found" );
190 model = versionMetadata;
192 this.mailingLists = model.getMailingLists();
198 * Show the reports tab.
200 public String reports()
202 // TODO: hook up reports on project
208 * Show the dependees (other artifacts that depend on this project) tab.
210 public String dependees()
212 ProjectVersionMetadata versionMetadata = null;
213 for ( String repoId : getObservableRepos() )
215 if ( versionMetadata == null )
219 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
221 catch ( MetadataResolverException e )
223 addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
229 if ( versionMetadata == null )
231 addActionError( "Artifact not found" );
234 model = versionMetadata;
236 List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
237 // TODO: what if we get duplicates across repositories?
238 for ( String repoId : getObservableRepos() )
240 // TODO: what about if we want to see this irrespective of version?
241 references.addAll( metadataResolver.getProjectReferences( repoId, groupId, artifactId, version ) );
244 this.dependees = references;
246 // TODO: may need to note on the page that references will be incomplete if the other artifacts are not yet stored in the content repository
247 // (especially in the case of pre-population import)
253 * Show the dependencies of this versioned project tab.
255 public String dependencyTree()
257 // temporarily use this as we only need the model for the tag to perform, but we should be resolving the
258 // graph here instead
260 // TODO: may need to note on the page that tree will be incomplete if the other artifacts are not yet stored in the content repository
261 // (especially in the case of pre-population import)
267 public void validate()
269 if ( StringUtils.isBlank( groupId ) )
271 addActionError( "You must specify a group ID to browse" );
274 if ( StringUtils.isBlank( artifactId ) )
276 addActionError( "You must specify a artifact ID to browse" );
279 if ( StringUtils.isBlank( version ) )
281 addActionError( "You must specify a version to browse" );
285 public ProjectVersionMetadata getModel()
290 public String getGroupId()
295 public void setGroupId( String groupId )
297 this.groupId = groupId;
300 public String getArtifactId()
305 public void setArtifactId( String artifactId )
307 this.artifactId = artifactId;
310 public String getVersion()
315 public void setVersion( String version )
317 this.version = version;
320 public List<MailingList> getMailingLists()
325 public List<Dependency> getDependencies()
330 public List<ProjectVersionReference> getDependees()
335 public String getRepositoryId()
340 public void setRepositoryId( String repositoryId )
342 this.repositoryId = repositoryId;
345 public List<String> getSnapshotVersions()
347 return snapshotVersions;
350 public MetadataResolver getMetadataResolver()
352 return metadataResolver;