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.MetadataResolverException;
30 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
31 import org.apache.commons.lang.StringUtils;
32 import org.apache.maven.archiva.database.ArchivaDatabaseException;
33 import org.apache.maven.archiva.database.ObjectNotFoundException;
34 import org.apache.maven.archiva.database.browsing.RepositoryBrowsing;
35 import org.apache.maven.archiva.model.ArchivaProjectModel;
36 import org.apache.maven.archiva.model.CiManagement;
37 import org.apache.maven.archiva.model.Dependency;
38 import org.apache.maven.archiva.model.IssueManagement;
39 import org.apache.maven.archiva.model.License;
40 import org.apache.maven.archiva.model.MailingList;
41 import org.apache.maven.archiva.model.Organization;
42 import org.apache.maven.archiva.model.Scm;
43 import org.apache.maven.archiva.model.VersionedReference;
44 import org.apache.maven.archiva.security.AccessDeniedException;
45 import org.apache.maven.archiva.security.ArchivaSecurityException;
46 import org.apache.maven.archiva.security.PrincipalNotFoundException;
47 import org.apache.maven.archiva.security.UserRepositories;
50 * Browse the repository.
52 * TODO change name to ShowVersionedAction to conform to terminology.
54 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="showArtifactAction" instantiation-strategy="per-lookup"
56 public class ShowArtifactAction
57 extends PlexusActionSupport
58 implements Validateable
60 /* .\ Not Exposed \._____________________________________________ */
63 * @plexus.requirement role-hint="default"
65 private RepositoryBrowsing repoBrowsing;
70 private UserRepositories userRepositories;
75 private MetadataResolver metadataResolver;
77 /* .\ Exposed Output Objects \.__________________________________ */
79 private String groupId;
81 private String artifactId;
83 private String version;
85 private String repositoryId;
88 * The model of this versioned project.
90 private ArchivaProjectModel model;
93 * The list of artifacts that depend on this versioned project.
95 private List<ArchivaProjectModel> dependees;
97 private List<MailingList> mailingLists;
99 private List<Dependency> dependencies;
101 private List<String> snapshotVersions;
104 * Show the versioned project information tab.
105 * TODO: Change name to 'project' - we are showing project versions here, not specific artifact information (though
106 * that is rendered in the download box).
108 public String artifact()
110 // In the future, this should be replaced by the repository grouping mechanism, so that we are only making
111 // simple resource requests here and letting the resolver take care of it
112 ProjectVersionMetadata versionMetadata = null;
113 snapshotVersions = new ArrayList<String>();
114 for ( String repoId : getObservableRepos() )
116 if ( versionMetadata == null )
118 // TODO: though we have a simple mapping now, do we want to support paths like /1.0-20090111.123456-1/
119 // again by mapping it to /1.0-SNAPSHOT/? Currently, the individual versions are not supported as we
120 // are only displaying the project's single version.
122 // we don't want the implementation being that intelligent - so another resolver to do the
123 // "just-in-time" nature of picking up the metadata (if appropriate for the repository type) is used
126 versionMetadata = metadataResolver.getProjectVersion( repoId, groupId, artifactId, version );
128 catch ( MetadataResolverException e )
130 addActionError( "Error occurred resolving metadata for project: " + e.getMessage() );
133 if ( versionMetadata != null )
135 repositoryId = repoId;
137 snapshotVersions.addAll(
138 metadataResolver.getArtifactVersions( repoId, groupId, artifactId, versionMetadata.getId() ) );
139 snapshotVersions.remove( version );
144 if ( versionMetadata == null )
146 addActionError( "Artifact not found" );
150 // TODO: eventually, move to just use the metadata directly, with minimal JSP changes, mostly for Maven specifics
151 model = new ArchivaProjectModel();
152 MavenProjectFacet projectFacet = (MavenProjectFacet) versionMetadata.getFacet( MavenProjectFacet.FACET_ID );
153 model.setGroupId( projectFacet.getGroupId() );
154 model.setArtifactId( projectFacet.getArtifactId() );
155 model.setPackaging( projectFacet.getPackaging() );
156 if ( projectFacet.getParent() != null )
158 VersionedReference parent = new VersionedReference();
159 parent.setGroupId( projectFacet.getParent().getGroupId() );
160 parent.setArtifactId( projectFacet.getParent().getArtifactId() );
161 parent.setVersion( projectFacet.getParent().getVersion() );
162 model.setParentProject( parent );
165 model.setVersion( versionMetadata.getId() );
166 model.setDescription( versionMetadata.getDescription() );
167 model.setName( versionMetadata.getName() );
168 model.setUrl( versionMetadata.getUrl() );
169 if ( versionMetadata.getOrganization() != null )
171 Organization organization = new Organization();
172 organization.setName( versionMetadata.getOrganization().getName() );
173 organization.setUrl( versionMetadata.getOrganization().getUrl() );
174 model.setOrganization( organization );
176 if ( versionMetadata.getCiManagement() != null )
178 CiManagement ci = new CiManagement();
179 ci.setSystem( versionMetadata.getCiManagement().getSystem() );
180 ci.setUrl( versionMetadata.getCiManagement().getUrl() );
181 model.setCiManagement( ci );
183 if ( versionMetadata.getIssueManagement() != null )
185 IssueManagement issueManagement = new IssueManagement();
186 issueManagement.setSystem( versionMetadata.getIssueManagement().getSystem() );
187 issueManagement.setUrl( versionMetadata.getIssueManagement().getUrl() );
188 model.setIssueManagement( issueManagement );
190 if ( versionMetadata.getScm() != null )
193 scm.setConnection( versionMetadata.getScm().getConnection() );
194 scm.setDeveloperConnection( versionMetadata.getScm().getDeveloperConnection() );
195 scm.setUrl( versionMetadata.getScm().getUrl() );
198 if ( versionMetadata.getLicenses() != null )
200 for ( org.apache.archiva.metadata.model.License l : versionMetadata.getLicenses() )
202 License license = new License();
203 license.setName( l.getName() );
204 license.setUrl( l.getUrl() );
205 model.addLicense( license );
213 * Show the artifact information tab.
215 public String dependencies()
216 throws ObjectNotFoundException, ArchivaDatabaseException
218 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
220 this.dependencies = model.getDependencies();
226 * Show the mailing lists information tab.
228 public String mailingLists()
229 throws ObjectNotFoundException, ArchivaDatabaseException
231 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
232 this.mailingLists = model.getMailingLists();
238 * Show the reports tab.
240 public String reports()
241 throws ObjectNotFoundException, ArchivaDatabaseException
243 // TODO: hook up reports on project - this.reports = artifactsDatabase.findArtifactResults( groupId, artifactId,
250 * Show the dependees (other artifacts that depend on this project) tab.
252 public String dependees()
253 throws ObjectNotFoundException, ArchivaDatabaseException
255 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
257 this.dependees = repoBrowsing.getUsedBy( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
263 * Show the dependencies of this versioned project tab.
265 public String dependencyTree()
266 throws ObjectNotFoundException, ArchivaDatabaseException
268 this.model = repoBrowsing.selectVersion( getPrincipal(), getObservableRepos(), groupId, artifactId, version );
273 private List<String> getObservableRepos()
277 return userRepositories.getObservableRepositoryIds( getPrincipal() );
279 catch ( PrincipalNotFoundException e )
281 log.warn( e.getMessage(), e );
283 catch ( AccessDeniedException e )
285 log.warn( e.getMessage(), e );
286 // TODO: pass this onto the screen.
288 catch ( ArchivaSecurityException e )
290 log.warn( e.getMessage(), e );
292 return Collections.emptyList();
296 public void validate()
298 if ( StringUtils.isBlank( groupId ) )
300 addActionError( "You must specify a group ID to browse" );
303 if ( StringUtils.isBlank( artifactId ) )
305 addActionError( "You must specify a artifact ID to browse" );
308 if ( StringUtils.isBlank( version ) )
310 addActionError( "You must specify a version to browse" );
314 public ArchivaProjectModel getModel()
319 public String getGroupId()
324 public void setGroupId( String groupId )
326 this.groupId = groupId;
329 public String getArtifactId()
334 public void setArtifactId( String artifactId )
336 this.artifactId = artifactId;
339 public String getVersion()
344 public void setVersion( String version )
346 this.version = version;
349 public List<MailingList> getMailingLists()
354 public List<Dependency> getDependencies()
359 public List<ArchivaProjectModel> getDependees()
364 public String getRepositoryId()
369 public void setRepositoryId( String repositoryId )
371 this.repositoryId = repositoryId;
374 public List<String> getSnapshotVersions()
376 return snapshotVersions;
379 public void setSnapshotVersions( List<String> snapshotVersions )
381 this.snapshotVersions = snapshotVersions;
384 public MetadataResolver getMetadataResolver()
386 return metadataResolver;