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.Collections;
24 import java.util.List;
26 import com.opensymphony.xwork2.Validateable;
27 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
28 import org.apache.archiva.metadata.repository.MetadataResolver;
29 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
30 import org.apache.commons.lang.StringUtils;
31 import org.apache.maven.archiva.database.ArchivaDatabaseException;
32 import org.apache.maven.archiva.database.ObjectNotFoundException;
33 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
34 import org.apache.maven.archiva.model.ArchivaProjectModel;
35 import org.apache.maven.archiva.model.CiManagement;
36 import org.apache.maven.archiva.model.Dependency;
37 import org.apache.maven.archiva.model.IssueManagement;
38 import org.apache.maven.archiva.model.License;
39 import org.apache.maven.archiva.model.MailingList;
40 import org.apache.maven.archiva.model.Organization;
41 import org.apache.maven.archiva.model.Scm;
42 import org.apache.maven.archiva.model.VersionedReference;
43 import org.apache.maven.archiva.security.AccessDeniedException;
44 import org.apache.maven.archiva.security.ArchivaSecurityException;
45 import org.apache.maven.archiva.security.PrincipalNotFoundException;
46 import org.apache.maven.archiva.security.UserRepositories;
49 * Browse the repository.
51 * TODO change name to ShowVersionedAction to conform to terminology.
53 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
55 public class ShowArtifactAction
56 extends PlexusActionSupport
57 implements Validateable
59 /* .\ Not Exposed \._____________________________________________ */
62 * @plexus.requirement role-hint="default"
64 private RepositoryBrowsing repoBrowsing;
69 private UserRepositories userRepositories;
74 private MetadataResolver metadataResolver;
76 /* .\ Exposed Output Objects \.__________________________________ */
78 private String groupId;
80 private String artifactId;
82 private String version;
84 private String repositoryId;
87 * The model of this versioned project.
89 private ArchivaProjectModel model;
92 * The list of artifacts that depend on this versioned project.
94 private List<ArchivaProjectModel> dependees;
96 private List<MailingList> mailingLists;
98 private List<Dependency> dependencies;
100 private List<String> snapshotVersions;
103 * Show the versioned project information tab.
104 * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
105 * that is rendered in the download box).
107 public String artifact()
109 // In the future, this should be replaced by the repository grouping mechanism, so that we are only making
110 // simple resource requests here and letting the resolver take care of it
111 ProjectVersionMetadata versionMetadata = null;
112 snapshotVersions = new ArrayList<String>();
113 for ( String repoId : getObservableRepos() )
115 if ( versionMetadata == null )
117 // TODO: though we have a simple mapping now, do we want to support paths like /1.0-20090111.123456-1/
118 // again by mapping it to /1.0-SNAPSHOT/? Currently, the individual versions are not supported as we
119 // are only displaying the project's single version.
121 // we don't want the implementation being that intelligent - so another resolver to do the
122 // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
123 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
124 if ( versionMetadata != null )
126 repositoryId = repoId;
128 snapshotVersions.addAll(
129 metadataResolver.getArtifactVersions( repoId, groupId, artifactId, versionMetadata.getId() ) );
130 snapshotVersions.remove( version );
135 if ( versionMetadata == null )
137 addActionError( "Artifact not found" );
141 // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
142 model = new ArchivaProjectModel();
143 MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
144 model.setGroupId( projectFacet.getGroupId() );
145 model.setArtifactId( projectFacet.getArtifactId() );
146 model.setPackaging( projectFacet.getPackaging() );
147 if ( projectFacet.getParent() != null )
149 VersionedReference parent = new VersionedReference();
150 parent.setGroupId( projectFacet.getParent().getGroupId() );
151 parent.setArtifactId( projectFacet.getParent().getArtifactId() );
152 parent.setVersion( projectFacet.getParent().getVersion() );
153 model.setParentProject( parent );
156 model.setVersion( versionMetadata.getId() );
157 model.setDescription( versionMetadata.getDescription() );
158 model.setName( versionMetadata.getName() );
159 model.setUrl( versionMetadata.getUrl() );
160 if ( versionMetadata.getOrganization() != null )
162 Organization organization = new Organization();
163 organization.setName( versionMetadata.getOrganization().getName() );
164 organization.setUrl( versionMetadata.getOrganization().getUrl() );
165 model.setOrganization( organization );
167 if ( versionMetadata.getCiManagement() != null )
169 CiManagement ci = new CiManagement();
170 ci.setSystem( versionMetadata.getCiManagement().getSystem() );
171 ci.setUrl( versionMetadata.getCiManagement().getUrl() );
172 model.setCiManagement( ci );
174 if ( versionMetadata.getIssueManagement() != null )
176 IssueManagement issueManagement = new IssueManagement();
177 issueManagement.setSystem( versionMetadata.getIssueManagement().getSystem() );
178 issueManagement.setUrl( versionMetadata.getIssueManagement().getUrl() );
179 model.setIssueManagement( issueManagement );
181 if ( versionMetadata.getScm() != null )
184 scm.setConnection( versionMetadata.getScm().getConnection() );
185 scm.setDeveloperConnection( versionMetadata.getScm().getDeveloperConnection() );
186 scm.setUrl( versionMetadata.getScm().getUrl() );
189 if ( versionMetadata.getLicenses() != null )
191 for ( org.apache.archiva.metadata.model.License l : versionMetadata.getLicenses() )
193 License license = new License();
194 license.setName( l.getName() );
195 license.setUrl( l.getUrl() );
196 model.addLicense( license );
204 * Show the artifact information tab.
206 public String dependencies()
207 throws ObjectNotFoundException, ArchivaDatabaseException
209 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
211 this.dependencies = model.getDependencies();
217 * Show the mailing lists information tab.
219 public String mailingLists()
220 throws ObjectNotFoundException, ArchivaDatabaseException
222 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
223 this.mailingLists = model.getMailingLists();
229 * Show the reports tab.
231 public String reports()
232 throws ObjectNotFoundException, ArchivaDatabaseException
234 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
241 * Show the dependees (other artifacts that depend on this project) tab.
243 public String dependees()
244 throws ObjectNotFoundException, ArchivaDatabaseException
246 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
248 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
254 * Show the dependencies of this versioned project tab.
256 public String dependencyTree()
257 throws ObjectNotFoundException, ArchivaDatabaseException
259 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
264 private List<String> getObservableRepos()
268 return userRepositories.getObservableRepositoryIds( getPrincipal() );
270 catch ( PrincipalNotFoundException e )
272 log.warn( e.getMessage(), e );
274 catch ( AccessDeniedException e )
276 log.warn( e.getMessage(), e );
277 // TODO: pass this onto the screen.
279 catch ( ArchivaSecurityException e )
281 log.warn( e.getMessage(), e );
283 return Collections.emptyList();
287 public void validate()
289 if ( StringUtils.isBlank( groupId ) )
291 addActionError( "You must specify a group ID to browse" );
294 if ( StringUtils.isBlank( artifactId ) )
296 addActionError( "You must specify a artifact ID to browse" );
299 if ( StringUtils.isBlank( version ) )
301 addActionError( "You must specify a version to browse" );
305 public ArchivaProjectModel getModel()
310 public String getGroupId()
315 public void setGroupId( String groupId )
317 this.groupId = groupId;
320 public String getArtifactId()
325 public void setArtifactId( String artifactId )
327 this.artifactId = artifactId;
330 public String getVersion()
335 public void setVersion( String version )
337 this.version = version;
340 public List<MailingList> getMailingLists()
345 public List<Dependency> getDependencies()
350 public List<ArchivaProjectModel> getDependees()
355 public String getRepositoryId()
360 public void setRepositoryId( String repositoryId )
362 this.repositoryId = repositoryId;
365 public List<String> getSnapshotVersions()
367 return snapshotVersions;
370 public void setSnapshotVersions( List<String> snapshotVersions )
372 this.snapshotVersions = snapshotVersions;
375 public MetadataResolver getMetadataResolver()
377 return metadataResolver;