1 package org.apache.maven.repository.manager.web.action;
\r
4 * Copyright 2005-2006 The Apache Software Foundation.
\r
6 * Licensed under the Apache License, Version 2.0 (the "License");
\r
7 * you may not use this file except in compliance with the License.
\r
8 * You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing, software
\r
13 * distributed under the License is distributed on an "AS IS" BASIS,
\r
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
15 * See the License for the specific language governing permissions and
\r
16 * limitations under the License.
\r
19 import com.opensymphony.xwork.Action;
\r
20 import org.apache.maven.artifact.Artifact;
\r
21 import org.apache.maven.artifact.repository.ArtifactRepository;
\r
22 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
\r
23 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
\r
24 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
\r
26 import java.util.ArrayList;
\r
27 import java.util.Collections;
\r
28 import java.util.Iterator;
\r
29 import java.util.List;
\r
30 import java.util.Map;
\r
31 import java.util.TreeMap;
\r
34 * Browse the repository.
\r
36 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.RepositoryBrowseAction"
\r
38 public class RepositoryBrowseAction
\r
42 * @plexus.requirement role-hint="default"
\r
44 private ArtifactDiscoverer discoverer;
\r
47 * @plexus.requirement
\r
49 private ArtifactRepositoryFactory repositoryFactory;
\r
52 * @plexus.requirement role-hint="default"
\r
54 private ArtifactRepositoryLayout layout;
\r
56 private String group;
\r
58 private Map artifactMap;
\r
60 private String folder;
\r
64 public String execute()
\r
66 // TODO! fix hardcoded path
\r
67 String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository";
\r
69 ArtifactRepository repository =
\r
70 repositoryFactory.createArtifactRepository( "discoveryRepo", "file://" + path, layout, null, null );
\r
72 List artifacts = discoverer.discoverArtifacts( repository, null, true );
\r
74 Iterator iterator = artifacts.iterator();
\r
76 artifactMap = new TreeMap();
\r
78 while ( iterator.hasNext() )
\r
80 Artifact artifact = (Artifact) iterator.next();
\r
82 String groupId = artifact.getGroupId();
\r
84 String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion();
\r
88 if ( artifactMap.containsKey( key ) )
\r
90 artifactList = (List) artifactMap.get( key );
\r
94 artifactList = new ArrayList();
\r
97 artifactList.add( artifact );
\r
99 Collections.sort( artifactList );
\r
101 artifactMap.put( key, artifactList );
\r
104 //set the index for folder level to be displayed
\r
112 // TODO! is this method needed?
\r
113 public String doEdit()
\r
117 //set folder to "" if we are at the root directory
\r
126 public Map getArtifactMap()
\r
128 return artifactMap;
\r
131 public String getGroup()
\r
136 public void setGroup( String group )
\r
138 this.group = group;
\r
141 public String getFolder()
\r
146 public void setFolder( String folder )
\r
148 this.folder = folder;
\r
151 public int getIdx()
\r
156 public void setIdx( int index )
\r