1 package org.apache.maven.repository.manager.web.action;
\r
3 import com.opensymphony.xwork.Action;
\r
4 import org.apache.maven.artifact.Artifact;
\r
5 import org.apache.maven.artifact.repository.ArtifactRepository;
\r
6 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
\r
7 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
\r
8 import org.apache.maven.repository.discovery.ArtifactDiscoverer;
\r
10 import java.util.ArrayList;
\r
11 import java.util.Collections;
\r
12 import java.util.Iterator;
\r
13 import java.util.List;
\r
14 import java.util.TreeMap;
\r
17 * TODO: Description.
\r
19 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.RepositoryBrowseAction"
\r
21 public class RepositoryBrowseAction
\r
25 * @plexus.requirement role-hint="default"
\r
27 private ArtifactDiscoverer discoverer;
\r
30 * @plexus.requirement
\r
32 private ArtifactRepositoryFactory repositoryFactory;
\r
35 * @plexus.requirement role-hint="default"
\r
37 private ArtifactRepositoryLayout layout;
\r
39 private String group;
\r
41 private TreeMap artifactMap;
\r
43 private String folder;
\r
47 public String execute()
\r
50 String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository";
\r
52 ArtifactRepository repository =
\r
53 repositoryFactory.createArtifactRepository( "discoveryRepo", "file://" + path, layout, null, null );
\r
55 List artifacts = discoverer.discoverArtifacts( repository, null, true );
\r
57 Iterator iterator = artifacts.iterator();
\r
59 artifactMap = new TreeMap();
\r
63 while ( iterator.hasNext() )
\r
65 Artifact artifact = (Artifact) iterator.next();
\r
67 groupId = artifact.getGroupId();
\r
69 String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion();
\r
71 ArrayList artifactList;
\r
73 if ( artifactMap.containsKey( key ) )
\r
75 artifactList = (ArrayList) artifactMap.get( key );
\r
79 artifactList = new ArrayList();
\r
82 artifactList.add( artifact );
\r
84 Collections.sort( artifactList );
\r
86 artifactMap.put( key, artifactList );
\r
89 //set the index for folder level to be displayed
\r
97 public String doEdit()
\r
100 setIdx( getIdx() + 1 );
\r
102 //set folder to "" if we are at the root directory
\r
103 if ( getIdx() == 1 )
\r
111 public TreeMap getArtifactMap()
\r
113 return artifactMap;
\r
116 public String getGroup()
\r
121 public void setGroup( String group )
\r
123 this.group = group;
\r
126 public String getFolder()
\r
131 public void setFolder( String folder )
\r
133 this.folder = folder;
\r
136 public int getIdx()
\r
141 public void setIdx( int index )
\r