From 57bf8e097a0fc854f9a7ac6d5ed021dfa9460b5e Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 21 Jul 2006 07:43:54 +0000 Subject: [PATCH] rewrote browse to match white site git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@424215 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexing/ArtifactRepositoryIndex.java | 89 ++++- maven-repository-webapp/pom.xml | 4 + .../manager/web/action/BaseAction.java | 88 ----- .../manager/web/action/BrowseAction.java | 316 ++++++++++++++++++ .../web/action/RepositoryBrowseAction.java | 147 -------- .../manager/web/action/SearchAction.java | 8 +- .../web/action/ShowArtifactAction.java | 153 +++++++++ .../web/utils/ConfigurationManager.java | 220 ------------ .../src/main/resources/xwork.xml | 22 +- .../src/main/webapp/WEB-INF/jsp/browse.jsp | 123 +++---- .../webapp/WEB-INF/jsp/browseArtifact.jsp | 66 ++++ .../main/webapp/WEB-INF/jsp/browseGroup.jsp | 86 +++++ .../webapp/WEB-INF/jsp/decorators/default.jsp | 8 +- .../main/webapp/WEB-INF/jsp/generalError.jsp | 33 ++ .../src/main/webapp/WEB-INF/jsp/results.jsp | 2 +- .../main/webapp/WEB-INF/jsp/showArtifact.jsp | 254 ++++++++++++++ .../src/main/webapp/css/site.css | 2 +- .../src/main/webapp/images/collapsed.gif | Bin 0 -> 53 bytes .../src/main/webapp/images/expanded.gif | Bin 0 -> 52 bytes pom.xml | 18 +- 20 files changed, 1080 insertions(+), 559 deletions(-) delete mode 100644 maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java create mode 100644 maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java delete mode 100644 maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/RepositoryBrowseAction.java create mode 100644 maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java delete mode 100644 maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java create mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp create mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp create mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp create mode 100644 maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp create mode 100644 maven-repository-webapp/src/main/webapp/images/collapsed.gif create mode 100644 maven-repository-webapp/src/main/webapp/images/expanded.gif diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java index c86908109..6e3a08527 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java @@ -18,9 +18,11 @@ package org.apache.maven.repository.indexing; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; +import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.Term; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.repository.digest.Digester; import org.apache.maven.repository.digest.DigesterException; @@ -29,8 +31,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipException; import java.util.zip.ZipFile; @@ -74,7 +78,7 @@ public class ArtifactRepositoryIndex { deleteDocuments( getTermList( artifactList ) ); } - catch( IOException e ) + catch ( IOException e ) { throw new RepositoryIndexException( "Failed to delete an index document", e ); } @@ -254,4 +258,87 @@ public class ArtifactRepositoryIndex files.append( name ).append( "\n" ); } } + + public List enumerateGroupIds() + throws IOException + { + IndexReader indexReader = IndexReader.open( getIndexPath() ); + + Set groups = new HashSet(); + + try + { + for ( int i = 0; i < indexReader.numDocs(); i ++ ) + { + Document doc = indexReader.document( i ); + groups.add( doc.getField( FLD_GROUPID ).stringValue() ); + } + } + finally + { + indexReader.close(); + } + + List sortedGroups = new ArrayList( groups ); + Collections.sort( sortedGroups ); + return sortedGroups; + } + + public List getArtifacts( String groupId ) + throws IOException + { + IndexReader indexReader = IndexReader.open( getIndexPath() ); + + Set artifactIds = new HashSet(); + + try + { + for ( int i = 0; i < indexReader.numDocs(); i ++ ) + { + Document doc = indexReader.document( i ); + if ( doc.getField( FLD_GROUPID ).stringValue().equals( groupId ) ) + { + artifactIds.add( doc.getField( FLD_ARTIFACTID ).stringValue() ); + } + } + } + finally + { + indexReader.close(); + } + + List sortedArtifactIds = new ArrayList( artifactIds ); + Collections.sort( sortedArtifactIds ); + return sortedArtifactIds; + } + + public List getVersions( String groupId, String artifactId ) + throws IOException + { + IndexReader indexReader = IndexReader.open( getIndexPath() ); + + Set versions = new HashSet(); + + try + { + for ( int i = 0; i < indexReader.numDocs(); i ++ ) + { + Document doc = indexReader.document( i ); + if ( doc.getField( FLD_GROUPID ).stringValue().equals( groupId ) && + doc.getField( FLD_ARTIFACTID ).stringValue().equals( artifactId ) ) + { + // DefaultArtifactVersion is used for correct ordering + versions.add( new DefaultArtifactVersion( doc.getField( FLD_VERSION ).stringValue() ) ); + } + } + } + finally + { + indexReader.close(); + } + + List sortedVersions = new ArrayList( versions ); + Collections.sort( sortedVersions ); + return sortedVersions; + } } diff --git a/maven-repository-webapp/pom.xml b/maven-repository-webapp/pom.xml index 7d6d2433a..518f6a4ed 100644 --- a/maven-repository-webapp/pom.xml +++ b/maven-repository-webapp/pom.xml @@ -95,6 +95,10 @@ provided + + org.apache.maven + maven-project + maven-repository-webapp diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java deleted file mode 100644 index 26b0bf863..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BaseAction.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import com.opensymphony.webwork.interceptor.ParameterAware; -import com.opensymphony.xwork.ActionSupport; -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.ConfigurationStore; -import org.apache.maven.repository.manager.web.utils.ConfigurationManager; - -import java.util.HashMap; -import java.util.Map; - -/** - * This is the Action class of index.jsp, which is the initial page of the web application. - * It invokes the DiscovererScheduler to set the DiscoverJob in the scheduler. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="baseAction" - * @todo don't like this as a base and as a forwarding action! - */ -public class BaseAction - extends ActionSupport - implements ParameterAware -{ - - /** - * @plexus.requirement - */ - private ConfigurationStore configurationStore; - - private Map parameters; - - public Map getParameters() - { - return parameters; - } - - public void setParameters( Map parameters ) - { - this.parameters = parameters; - } - - /** - * Method that executes the action - * - * @return a String that specifies if the action executed was a success or a failure - */ - public String execute() - { - try - { - Configuration config = configurationStore.getConfigurationFromStore(); - Map parameters = new HashMap(); - parameters.put( ConfigurationManager.INDEXPATH, config.getIndexPath() ); - parameters.put( ConfigurationManager.MIN_INDEXPATH, config.getMinimalIndexPath() ); - parameters.put( ConfigurationManager.DISCOVERY_BLACKLIST_PATTERNS, config.getDiscoveryBlackListPatterns() ); - parameters.put( ConfigurationManager.DISCOVER_SNAPSHOTS, Boolean.valueOf( config.isDiscoverSnapshots() ) ); - parameters.put( ConfigurationManager.DISCOVERY_CRON_EXPRESSION, config.getIndexerCronExpression() ); - this.parameters = parameters; - - //Configuration configuration = new Configuration(); // TODO! -// execution.executeDiscovererIfIndexDoesNotExist( new File( config.getIndexPath() ) ); - } - catch ( Exception e ) - { - // TODO: better exception handling! - e.printStackTrace(); - return ERROR; - } - - return SUCCESS; - } - -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java new file mode 100644 index 000000000..c894a2dab --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/BrowseAction.java @@ -0,0 +1,316 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.opensymphony.xwork.ActionSupport; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.apache.maven.repository.indexing.ArtifactRepositoryIndex; +import org.apache.maven.repository.indexing.RepositoryIndexException; +import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer; +import org.apache.maven.repository.indexing.RepositoryIndexingFactory; +import org.codehaus.plexus.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; +import java.util.TreeMap; + +/** + * Browse the repository. + * + * @todo the tree part probably belongs in a browsing component, along with the methods currently in the indexer + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="browseAction" + */ +public class BrowseAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private RepositoryIndexingFactory factory; + + /** + * @plexus.requirement + */ + private RepositoryIndexSearchLayer searchLayer; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private List groups; + + private String groupId; + + private static final String GROUP_SEPARATOR = "/"; + + private List artifactIds; + + private String artifactId; + + private List versions; + + public String browse() + throws ConfigurationStoreException, RepositoryIndexException, IOException + { + ArtifactRepositoryIndex index = getIndex(); + + if ( !index.indexExists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + GroupTreeNode rootNode = buildGroupTree( index ); + + this.groups = collateGroups( rootNode ); + + return SUCCESS; + } + + public String browseGroup() + throws ConfigurationStoreException, RepositoryIndexException, IOException + { + ArtifactRepositoryIndex index = getIndex(); + + if ( !index.indexExists() ) + { + addActionError( "The repository is not yet indexed. Please wait, and then try again." ); + return ERROR; + } + + GroupTreeNode rootNode = buildGroupTree( index ); + + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + StringTokenizer tok = new StringTokenizer( groupId, GROUP_SEPARATOR ); + while ( tok.hasMoreTokens() ) + { + String part = tok.nextToken(); + + if ( !rootNode.getChildren().containsKey( part ) ) + { + // TODO: i18n + addActionError( "The group specified was not found" ); + return ERROR; + } + else + { + rootNode = (GroupTreeNode) rootNode.getChildren().get( part ); + } + } + + this.groups = collateGroups( rootNode ); + + this.artifactIds = index.getArtifacts( groupId.replaceAll( GROUP_SEPARATOR, "." ) ); + + return SUCCESS; + } + + public String browseArtifact() + throws ConfigurationStoreException, RepositoryIndexException, IOException + { + ArtifactRepositoryIndex index = getIndex(); + + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( artifactId ) ) + { + // TODO: i18n + addActionError( "You must specify a artifact ID to browse" ); + return ERROR; + } + + versions = index.getVersions( groupId.replaceAll( GROUP_SEPARATOR, "." ), artifactId ); + + if ( versions.isEmpty() ) + { + // TODO: i18n + addActionError( "Could not find any artifacts with the given group and artifact ID" ); + return ERROR; + } + + return SUCCESS; + } + + private GroupTreeNode buildGroupTree( ArtifactRepositoryIndex index ) + throws IOException + { + // TODO: give action message if indexing is in progress + + // TODO: this will be inefficient over a very large number of artifacts, should be cached + + List groups = index.enumerateGroupIds(); + + GroupTreeNode rootNode = new GroupTreeNode(); + + // build a tree structure + for ( Iterator i = groups.iterator(); i.hasNext(); ) + { + String groupId = (String) i.next(); + + StringTokenizer tok = new StringTokenizer( groupId, "." ); + + GroupTreeNode node = rootNode; + + while ( tok.hasMoreTokens() ) + { + String part = tok.nextToken(); + + if ( !node.getChildren().containsKey( part ) ) + { + GroupTreeNode newNode = new GroupTreeNode( part, node ); + node.addChild( newNode ); + node = newNode; + } + else + { + node = (GroupTreeNode) node.getChildren().get( part ); + } + } + } + return rootNode; + } + + private List collateGroups( GroupTreeNode rootNode ) + { + List groups = new ArrayList(); + for ( Iterator i = rootNode.getChildren().values().iterator(); i.hasNext(); ) + { + GroupTreeNode node = (GroupTreeNode) i.next(); + + while ( node.getChildren().size() == 1 ) + { + node = (GroupTreeNode) node.getChildren().values().iterator().next(); + } + + groups.add( node.getFullName() ); + } + return groups; + } + + private ArtifactRepositoryIndex getIndex() + throws ConfigurationStoreException, RepositoryIndexException + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + File indexPath = new File( configuration.getIndexPath() ); + + ArtifactRepository repository = repositoryFactory.createRepository( configuration ); + + return factory.createArtifactRepositoryIndex( indexPath, repository ); + } + + public List getGroups() + { + return groups; + } + + public List getArtifactIds() + { + return artifactIds; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public List getVersions() + { + return versions; + } + + private static class GroupTreeNode + { + private final String name; + + private final String fullName; + + private final Map children = new TreeMap(); + + GroupTreeNode() + { + name = null; + fullName = null; + } + + GroupTreeNode( String name, GroupTreeNode parent ) + { + this.name = name; + this.fullName = parent.fullName != null ? parent.fullName + GROUP_SEPARATOR + name : name; + } + + public String getName() + { + return name; + } + + public String getFullName() + { + return fullName; + } + + public Map getChildren() + { + return children; + } + + public void addChild( GroupTreeNode newNode ) + { + children.put( newNode.name, newNode ); + } + } +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/RepositoryBrowseAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/RepositoryBrowseAction.java deleted file mode 100644 index 5b5031b72..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/RepositoryBrowseAction.java +++ /dev/null @@ -1,147 +0,0 @@ -package org.apache.maven.repository.manager.web.action; - -/* - * Copyright 2005-2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import com.opensymphony.xwork.Action; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; -import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; -import org.apache.maven.repository.discovery.ArtifactDiscoverer; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Browse the repository. - * - * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.RepositoryBrowseAction" - */ -public class RepositoryBrowseAction - implements Action -{ - /** - * @plexus.requirement role-hint="default" - */ - private ArtifactDiscoverer discoverer; - - /** - * @plexus.requirement - */ - private ArtifactRepositoryFactory repositoryFactory; - - /** - * @plexus.requirement role-hint="default" - */ - private ArtifactRepositoryLayout layout; - - private String group; - - private Map artifactMap; - - private String folder; - - private int idx; - - public String execute() - { - // TODO! fix hardcoded path - String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository"; - - ArtifactRepository repository = - repositoryFactory.createArtifactRepository( "discoveryRepo", "file://" + path, layout, null, null ); - - List artifacts = discoverer.discoverArtifacts( repository, null, true ); - - Iterator iterator = artifacts.iterator(); - - artifactMap = new TreeMap(); - - while ( iterator.hasNext() ) - { - Artifact artifact = (Artifact) iterator.next(); - - String groupId = artifact.getGroupId(); - - String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion(); - - List artifactList; - - if ( artifactMap.containsKey( key ) ) - { - artifactList = (List) artifactMap.get( key ); - } - else - { - artifactList = new ArrayList(); - } - - artifactList.add( artifact ); - - Collections.sort( artifactList ); - - artifactMap.put( key, artifactList ); - } - - //set the index for folder level to be displayed - idx = 1; - - folder = ""; - - return SUCCESS; - } - - public Map getArtifactMap() - { - return artifactMap; - } - - public String getGroup() - { - return group; - } - - public void setGroup( String group ) - { - this.group = group; - } - - public String getFolder() - { - return folder; - } - - public void setFolder( String folder ) - { - this.folder = folder; - } - - public int getIdx() - { - return idx; - } - - public void setIdx( int index ) - { - this.idx = index; - } - -} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java index 9862142d1..395ecb51f 100644 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/SearchAction.java @@ -32,10 +32,9 @@ import org.apache.maven.repository.indexing.query.SinglePhraseQuery; import java.io.File; import java.net.MalformedURLException; import java.util.List; -import java.util.Map; /** - * Searches for searchString in all indexed fields. + * Search all indexed fields by the given criteria. * * @plexus.component role="com.opensymphony.xwork.Action" role-hint="searchAction" */ @@ -72,11 +71,6 @@ public class SearchAction */ private ConfiguredRepositoryFactory repositoryFactory; - /** - * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout" - */ - private Map repositoryLayouts; - /** * @plexus.requirement */ diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java new file mode 100644 index 000000000..745c575de --- /dev/null +++ b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/action/ShowArtifactAction.java @@ -0,0 +1,153 @@ +package org.apache.maven.repository.manager.web.action; + +/* + * Copyright 2005-2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import com.opensymphony.xwork.ActionSupport; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.repository.configuration.Configuration; +import org.apache.maven.repository.configuration.ConfigurationStore; +import org.apache.maven.repository.configuration.ConfigurationStoreException; +import org.apache.maven.repository.configuration.ConfiguredRepositoryFactory; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; + +/** + * Browse the repository. + * + * @plexus.component role="com.opensymphony.xwork.Action" role-hint="showArtifactAction" + */ +public class ShowArtifactAction + extends ActionSupport +{ + /** + * @plexus.requirement + */ + private ArtifactFactory artifactFactory; + + /** + * @plexus.requirement + */ + private ConfiguredRepositoryFactory repositoryFactory; + + /** + * @plexus.requirement + */ + private MavenProjectBuilder projectBuilder; + + /** + * @plexus.requirement + */ + private ConfigurationStore configurationStore; + + private String groupId; + + private String artifactId; + + private String version; + + private Model model; + + public String execute() + throws ConfigurationStoreException, IOException, XmlPullParserException, ProjectBuildingException + { + Configuration configuration = configurationStore.getConfigurationFromStore(); + ArtifactRepository repository = repositoryFactory.createRepository( configuration ); + + if ( StringUtils.isEmpty( groupId ) ) + { + // TODO: i18n + addActionError( "You must specify a group ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( artifactId ) ) + { + // TODO: i18n + addActionError( "You must specify a artifact ID to browse" ); + return ERROR; + } + + if ( StringUtils.isEmpty( version ) ) + { + // TODO: i18n + addActionError( "You must specify a version to browse" ); + return ERROR; + } + + Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version ); + // TODO: is this going to be problematic because repository is remote format, but being used as local? + // TODO: should it try to use the repo manager as a remote repo, proxying out? + // TODO: maybe we can decouple the assembly parts of the project builder from the repository handling + MavenProject project = projectBuilder.buildFromRepository( artifact, Collections.EMPTY_LIST, repository ); + + if ( !new File( repository.getBasedir(), repository.pathOf( artifact ) ).exists() ) + { + // TODO: i18n + addActionError( "The given artifact was not found in the repository" ); + return ERROR; + } + + model = project.getModel(); + + return SUCCESS; + } + + public Model getModel() + { + return model; + } + + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String artifactId ) + { + this.artifactId = artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } +} diff --git a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java b/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java deleted file mode 100644 index f055590a2..000000000 --- a/maven-repository-webapp/src/main/java/org/apache/maven/repository/manager/web/utils/ConfigurationManager.java +++ /dev/null @@ -1,220 +0,0 @@ -package org.apache.maven.repository.manager.web.utils; - -/* - * Copyright 2006 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import org.apache.maven.repository.configuration.Configuration; -import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Reader; -import org.apache.maven.repository.configuration.io.xpp3.ConfigurationXpp3Writer; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.net.URL; -import java.util.Iterator; -import java.util.Map; - -/** - * This class updates/sets the configuration values in the mrm-admin-config.xml file used - * for discovery and indexing. - * - * @plexus.component role="org.apache.maven.repository.manager.web.utils.ConfigurationManager" - */ -public class ConfigurationManager -{ - public static final String WEB_XML_FILE = "web.xml"; - - public static final String INDEX_CONFIG_FILE = "mrm-admin-config.xml"; - - public static final String DISCOVER_SNAPSHOTS = "discoverSnapshots"; - - public static final String DISCOVERY_CRON_EXPRESSION = "discoveryCronExpression"; - - public static final String INDEXPATH = "indexPath"; - - public static final String MIN_INDEXPATH = "minimalIndexPath"; - - public static final String REPOSITORY_LAYOUT = "repositoryLayout"; - - public static final String REPOSITORY_DIRECTORY = "repositoryDirectory"; - - public static final String DISCOVERY_BLACKLIST_PATTERNS = "discoveryBlacklistPatterns"; - - private Configuration config; - - private File plexusDescriptor; - - /** - * Method for updating the configuration in mrm-admin-config.xml - * - * @param map contains the fields and the values to be updated in the configuration - */ - public void updateConfiguration( Map map ) - throws IOException - { - File file = getConfigFile(); - - try - { - config = readXmlDocument( file ); - } - catch ( XmlPullParserException de ) - { - // TODO! - de.printStackTrace(); - } - - for ( Iterator iter = map.entrySet().iterator(); iter.hasNext(); ) - { - Map.Entry entry = (Map.Entry) iter.next(); - String name = (String) entry.getKey(); - String value = (String) entry.getValue(); - - if ( name.equals( DISCOVERY_CRON_EXPRESSION ) ) - { - config.setIndexerCronExpression( value ); - } - if ( name.equals( REPOSITORY_LAYOUT ) ) - { - config.setRepositoryLayout( value ); - } - if ( name.equals( DISCOVER_SNAPSHOTS ) ) - { - config.setDiscoverSnapshots( Boolean.valueOf( value ).booleanValue() ); - } - if ( name.equals( REPOSITORY_DIRECTORY ) ) - { - config.setRepositoryDirectory( value ); - } - if ( name.equals( INDEXPATH ) ) - { - config.setIndexPath( value ); - } - if ( name.equals( MIN_INDEXPATH ) ) - { - config.setMinimalIndexPath( value ); - } - if ( name.equals( DISCOVERY_BLACKLIST_PATTERNS ) ) - { - config.setDiscoveryBlackListPatterns( value ); - } - } - - writeXmlDocument( getConfigFile() ); - } - - /** - * Method that gets the properties set in the mrm-admin-config.xml for the configuration fields - * used in the schedule, indexing and discovery - * - * @return a Map that contains the elements in the properties of the configuration object - */ - public Configuration getConfiguration() - throws IOException - { - File file = getConfigFile(); - config = new Configuration(); - - if ( file != null ) - { - if ( !file.exists() ) - { - writeXmlDocument( getConfigFile() ); - } - else - { - try - { - config = readXmlDocument( file ); - } - catch ( XmlPullParserException xe ) - { - // TODO: fix error handling! - xe.printStackTrace(); - } - } - } - - return config; - } - - /** - * Method that reads the xml file and returns a Configuration object - * - * @param file the xml file to be read - * @return a Document object that represents the contents of the xml file - * @throws FileNotFoundException - * @throws IOException - * @throws XmlPullParserException - */ - protected Configuration readXmlDocument( File file ) - throws IOException, XmlPullParserException - { - ConfigurationXpp3Reader configReader = new ConfigurationXpp3Reader(); - Reader reader = new FileReader( file ); - Configuration config = configReader.read( reader ); - - return config; - } - - /** - * Method for writing the configuration into the xml file - * - * @param file the file where the document will be written to - */ - protected void writeXmlDocument( File file ) - throws IOException - { - Writer writer = new FileWriter( file ); - ConfigurationXpp3Writer configWriter = new ConfigurationXpp3Writer(); - configWriter.write( writer, config ); - } - - /** - * Method that returns the mrm-admin-config.xml file - * - * @return a File that references the plexus.xml - */ - protected File getConfigFile() - { - URL indexConfigXml = getClass().getClassLoader().getResource( "../" + INDEX_CONFIG_FILE ); - - if ( indexConfigXml != null ) - { - plexusDescriptor = new File( indexConfigXml.getFile() ); - } - else - { - URL xmlPath = getClass().getClassLoader().getResource( "../" + WEB_XML_FILE ); - if ( xmlPath != null ) - { - String path = xmlPath.getFile(); - int lastIndex = path.lastIndexOf( '/' ); - path = path.substring( 0, lastIndex + 1 ); - path = path + INDEX_CONFIG_FILE; - plexusDescriptor = new File( path ); - } - } - - return plexusDescriptor; - } - -} diff --git a/maven-repository-webapp/src/main/resources/xwork.xml b/maven-repository-webapp/src/main/resources/xwork.xml index b6de147ae..b13de36b5 100644 --- a/maven-repository-webapp/src/main/resources/xwork.xml +++ b/maven-repository-webapp/src/main/resources/xwork.xml @@ -39,6 +39,7 @@ /admin/configure.action + /WEB-INF/jsp/generalError.jsp @@ -61,6 +62,22 @@ /WEB-INF/jsp/findArtifact.jsp + + /WEB-INF/jsp/browse.jsp + + + + /WEB-INF/jsp/browseGroup.jsp + + + + /WEB-INF/jsp/browseArtifact.jsp + + + + /WEB-INF/jsp/showArtifact.jsp + + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp index a07fe5948..da6c69ecc 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browse.jsp @@ -14,96 +14,61 @@ ~ limitations under the License. --%> -<%@ taglib uri="webwork" prefix="ww" %> +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - Repository Browser + Browse Repository + -

">basedir / - - - - - - - - - - - - - "> / - - -

-
- - - - - - <% +

Browse Repository

+
+
+

Groups

+ +
- int ctr = 1; + <%-- TODO: later, when supported in metadata +
+

Category

+ + + + + + + +
+ Java +
+ Ruby +
+
+

Labels

- %> - - - <% - - -if (ctr == ((Integer)pageContext.getAttribute("in")).intValue()) { - - %> - - -/""> - / -
-
- <% - } - ctr++; - %> -
- - + + --%> +
- - - - - - - - - - - - - - - - - - - - - - - - - -
Group ID
Artifact ID
Version
Derivatives
Parent
-
-
-
diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp new file mode 100644 index 000000000..f7ba822ee --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseArtifact.jsp @@ -0,0 +1,66 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +

Browse Repository

+ +
+
+

+ + + + + + + + + + + + + ${part} / + + ${artifactId} +

+ +

Versions

+ +
+
+ + + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp new file mode 100644 index 000000000..afa88ab89 --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/browseGroup.jsp @@ -0,0 +1,86 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +

Browse Repository

+ +
+
+

+ + + + + + + + + + + + ${part} + + + + + + ${part} / + + + +

+ + + +

Group / Artifact

+ +
+ + + +

Artifacts

+ +
+
+
+ + + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp index 6ce38467e..c3fdd86e1 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/decorators/default.jsp @@ -75,11 +75,9 @@ Find Artifact - <%-- TODO -
  • - Browse -
  • - --%> +
  • + Browse +
  • Manage
      diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp new file mode 100644 index 000000000..bef5023c3 --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/generalError.jsp @@ -0,0 +1,33 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Error Occurred + + + + + +

      Error Occurred

      + + + + + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp index 9b3e76d84..a27d95500 100644 --- a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/results.jsp @@ -41,7 +41,7 @@ --%> - + diff --git a/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp new file mode 100644 index 000000000..3c7df97ac --- /dev/null +++ b/maven-repository-webapp/src/main/webapp/WEB-INF/jsp/showArtifact.jsp @@ -0,0 +1,254 @@ +<%-- + ~ Copyright 2005-2006 The Apache Software Foundation. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --%> + +<%@ taglib prefix="ww" uri="/webwork" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> + + + + Browse Repository + + + + + +<%-- TODO: image by type +jar +--%> + +<%-- TODO: download link + +--%> + + +

      + + + ${model.artifactId} + + + ${model.name} + + +

      + +
      +
      +

      + Info + <%-- TODO: perhaps using ajax? + Dependencies + Depended On + Mailing Lists + Developers + POM + --%> +

      +
      + +
      +

      + + + + + + + + + + + + + ${part} / + + + + + + ${model.artifactId} / + ${model.version} + + +

      + +

      ${mode.description}

      + + + + + + + + + + + + + + + <%-- TODO: derivatives + + + + + --%> + + + + + + + <%-- TODO: deployment timestamp + + + + + --%> + +
      Group ID${model.groupId}
      Artifact ID${model.artifactId}
      Version${model.version}
      Derivatives + Source + | + Javadoc +
      Parent + ${model.parent.groupId} ${model.parent.artifactId} ${model.parent.version} + + + + + + (View) +
      Deployment Date + 15 Jan 2006, 20:38:00 +1000 +
      + + + +

      Other Details

      + + + + + + + + + + + + + + + + + + + + + + + + + + + +
      Organisation + + + ${model.organization.name} + + + ${model.organization.name} + + +
      License + + + ${license.name} + + + ${license.name} + + +
      Issue Tracker + + + ${model.issueManagement.system} + + + ${model.issueManagement.system} + + +
      Continuous Integration + + + ${model.ciManagement.system} + + + ${model.ciManagement.system} + + +
      +
      + + +

      SCM

      + + + + + + + + + + + + + + + + + + + +
      Connection + ${model.scm.connection} +
      Dev. Connection + ${model.scm.developerConnection} +
      Viewer + ${model.scm.url} +
      +
      + +
      +
      + + + diff --git a/maven-repository-webapp/src/main/webapp/css/site.css b/maven-repository-webapp/src/main/webapp/css/site.css index 6c4e271c6..45622fd69 100644 --- a/maven-repository-webapp/src/main/webapp/css/site.css +++ b/maven-repository-webapp/src/main/webapp/css/site.css @@ -30,7 +30,7 @@ padding: 1em; } -#tabs b { +#tabs strong { border: 1px solid black; padding-left: 1em; padding-right: 1em; diff --git a/maven-repository-webapp/src/main/webapp/images/collapsed.gif b/maven-repository-webapp/src/main/webapp/images/collapsed.gif new file mode 100644 index 0000000000000000000000000000000000000000..6e710840640c1bfd9dd76ce7fef56f1004092508 GIT binary patch literal 53 ycmZ?wbhEHbWM^P!XkdT>#h)yUTnvm1Iv_qshJlI4r7uBZ*YkPFU8d4p4Aua}2?(?R literal 0 HcmV?d00001 diff --git a/maven-repository-webapp/src/main/webapp/images/expanded.gif b/maven-repository-webapp/src/main/webapp/images/expanded.gif new file mode 100644 index 0000000000000000000000000000000000000000..0fef3d89e0df1f8bc49a0cd827f2607c7d7fd2f0 GIT binary patch literal 52 xcmZ?wbhEHbWM^P!XkdT>#h)yUTnvm1Iv_qshJlH@g}+fUi&t{amUB!D)&R0C2fzRT literal 0 HcmV?d00001 diff --git a/pom.xml b/pom.xml index 72155aed2..00413f834 100644 --- a/pom.xml +++ b/pom.xml @@ -152,27 +152,32 @@ org.apache.maven maven-repository-metadata - 2.0.2 + ${maven.version} org.apache.maven maven-model - 2.0.2 + ${maven.version} org.apache.maven maven-artifact - 2.0.2 + ${maven.version} org.apache.maven maven-artifact-manager - 2.0.2 + ${maven.version} + + + org.apache.maven + maven-project + ${maven.version} org.apache.maven maven-model-converter - 2.0.2 + ${maven.version} org.apache.maven.wagon @@ -364,4 +369,7 @@ http://snapshots.repository.codehaus.org + + 2.0.4 + -- 2.39.5