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.commons.lang.StringUtils;
34 * Browse the repository.
36 * TODO change name to ShowVersionedAction to conform to terminology.
38 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
40 public class ShowArtifactAction
41 extends AbstractRepositoryBasedAction
42 implements Validateable
44 /* .\ Not Exposed \._____________________________________________ */
49 private MetadataResolver metadataResolver;
51 /* .\ Exposed Output Objects \.__________________________________ */
53 private String groupId;
55 private String artifactId;
57 private String version;
59 private String repositoryId;
62 * The model of this versioned project.
64 private ProjectVersionMetadata model;
67 * The list of artifacts that depend on this versioned project.
69 private List<ProjectVersionReference> dependees;
71 private List<MailingList> mailingLists;
73 private List<Dependency> dependencies;
75 private List<String> snapshotVersions;
78 * Show the versioned project information tab.
79 * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
80 * that is rendered in the download box).
82 public String artifact()
84 // In the future, this should be replaced by the repository grouping mechanism, so that we are only making
85 // simple resource requests here and letting the resolver take care of it
86 ProjectVersionMetadata versionMetadata = null;
87 snapshotVersions = new ArrayList<String>();
88 for ( String repoId : getObservableRepos() )
90 if ( versionMetadata == null )
92 // TODO: though we have a simple mapping now, do we want to support paths like /1.0-20090111.123456-1/
93 // again by mapping it to /1.0-SNAPSHOT/? Currently, the individual versions are not supported as we
94 // are only displaying the project's single version.
96 // we don't want the implementation being that intelligent - so another resolver to do the
97 // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
98 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
99 if ( versionMetadata != null )
101 repositoryId = repoId;
103 snapshotVersions.addAll(
104 metadataResolver.getArtifactVersions( repoId, groupId, artifactId, versionMetadata.getId() ) );
105 snapshotVersions.remove( version );
110 if ( versionMetadata == null )
112 addActionError( "Artifact not found" );
115 model = versionMetadata;
121 * Show the artifact information tab.
123 public String dependencies()
125 ProjectVersionMetadata versionMetadata = null;
126 for ( String repoId : getObservableRepos() )
128 if ( versionMetadata == null )
130 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
134 if ( versionMetadata == null )
136 addActionError( "Artifact not found" );
139 model = versionMetadata;
141 this.dependencies = model.getDependencies();
147 * Show the mailing lists information tab.
149 public String mailingLists()
151 ProjectVersionMetadata versionMetadata = null;
152 for ( String repoId : getObservableRepos() )
154 if ( versionMetadata == null )
156 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
160 if ( versionMetadata == null )
162 addActionError( "Artifact not found" );
165 model = versionMetadata;
167 this.mailingLists = model.getMailingLists();
173 * Show the reports tab.
175 public String reports()
177 // TODO: hook up reports on project
183 * Show the dependees (other artifacts that depend on this project) tab.
185 public String dependees()
187 ProjectVersionMetadata versionMetadata = null;
188 for ( String repoId : getObservableRepos() )
190 if ( versionMetadata == null )
192 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
196 if ( versionMetadata == null )
198 addActionError( "Artifact not found" );
201 model = versionMetadata;
203 List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
204 // TODO: what if we get duplicates across repositories?
205 for ( String repoId : getObservableRepos() )
207 // TODO: what about if we want to see this irrespective of version?
208 references.addAll( metadataResolver.getProjectReferences( repoId, groupId, artifactId, version ) );
211 this.dependees = references;
213 // 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
214 // (especially in the case of pre-population import)
220 * Show the dependencies of this versioned project tab.
222 public String dependencyTree()
224 // temporarily use this as we only need the model for the tag to perform, but we should be resolving the
225 // graph here instead
227 // 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
228 // (especially in the case of pre-population import)
234 public void validate()
236 if ( StringUtils.isBlank( groupId ) )
238 addActionError( "You must specify a group ID to browse" );
241 if ( StringUtils.isBlank( artifactId ) )
243 addActionError( "You must specify a artifact ID to browse" );
246 if ( StringUtils.isBlank( version ) )
248 addActionError( "You must specify a version to browse" );
252 public ProjectVersionMetadata getModel()
257 public String getGroupId()
262 public void setGroupId( String groupId )
264 this.groupId = groupId;
267 public String getArtifactId()
272 public void setArtifactId( String artifactId )
274 this.artifactId = artifactId;
277 public String getVersion()
282 public void setVersion( String version )
284 this.version = version;
287 public List<MailingList> getMailingLists()
292 public List<Dependency> getDependencies()
297 public List<ProjectVersionReference> getDependees()
302 public String getRepositoryId()
307 public void setRepositoryId( String repositoryId )
309 this.repositoryId = repositoryId;
312 public List<String> getSnapshotVersions()
314 return snapshotVersions;
317 public MetadataResolver getMetadataResolver()
319 return metadataResolver;