]> source.dussan.org Git - archiva.git/blob
31ccb4c984153ea312ee6e0357d77e39988cdc5f
[archiva.git] /
1 package org.apache.maven.repository.manager.web.action;\r
2 \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
9 \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
15 \r
16 /**\r
17  * TODO: Description.\r
18  *\r
19  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.RepositoryBrowseAction"\r
20  */\r
21 public class RepositoryBrowseAction\r
22     implements Action\r
23 {\r
24     /**\r
25      * @plexus.requirement role-hint="default"\r
26      */\r
27     private ArtifactDiscoverer discoverer;\r
28 \r
29     /**\r
30      * @plexus.requirement\r
31      */\r
32     private ArtifactRepositoryFactory repositoryFactory;\r
33 \r
34     /**\r
35      * @plexus.requirement role-hint="default"\r
36      */\r
37     private ArtifactRepositoryLayout layout;\r
38 \r
39     private String group;\r
40 \r
41     private TreeMap artifactMap;\r
42 \r
43     private String folder;\r
44 \r
45     private int idx;\r
46 \r
47     public String execute()\r
48         throws Exception\r
49     {\r
50         String path = "E:/jeprox/maven-repository-manager/trunk/maven-repository-discovery/src/test/repository";\r
51 \r
52         ArtifactRepository repository =\r
53             repositoryFactory.createArtifactRepository( "discoveryRepo", "file://" + path, layout, null, null );\r
54 \r
55         List artifacts = discoverer.discoverArtifacts( repository, null, true );\r
56 \r
57         Iterator iterator = artifacts.iterator();\r
58 \r
59         artifactMap = new TreeMap();\r
60 \r
61         String groupId;\r
62 \r
63         while ( iterator.hasNext() )\r
64         {\r
65             Artifact artifact = (Artifact) iterator.next();\r
66 \r
67             groupId = artifact.getGroupId();\r
68 \r
69             String key = groupId.replace( '.', '/' ) + "/" + artifact.getArtifactId() + "/" + artifact.getVersion();\r
70 \r
71             ArrayList artifactList;\r
72 \r
73             if ( artifactMap.containsKey( key ) )\r
74             {\r
75                 artifactList = (ArrayList) artifactMap.get( key );\r
76             }\r
77             else\r
78             {\r
79                 artifactList = new ArrayList();\r
80             }\r
81 \r
82             artifactList.add( artifact );\r
83 \r
84             Collections.sort( artifactList );\r
85 \r
86             artifactMap.put( key, artifactList );\r
87         }\r
88 \r
89         //set the index for folder level to be displayed\r
90         setIdx( 1 );\r
91 \r
92         setFolder( "" );\r
93 \r
94         return SUCCESS;\r
95     }\r
96 \r
97     public String doEdit()\r
98         throws Exception\r
99     {\r
100         setIdx( getIdx() + 1 );\r
101 \r
102         //set folder to "" if we are at the root directory\r
103         if ( getIdx() == 1 )\r
104         {\r
105             setFolder( "" );\r
106         }\r
107 \r
108         return SUCCESS;\r
109     }\r
110 \r
111     public TreeMap getArtifactMap()\r
112     {\r
113         return artifactMap;\r
114     }\r
115 \r
116     public String getGroup()\r
117     {\r
118         return group;\r
119     }\r
120 \r
121     public void setGroup( String group )\r
122     {\r
123         this.group = group;\r
124     }\r
125 \r
126     public String getFolder()\r
127     {\r
128         return folder;\r
129     }\r
130 \r
131     public void setFolder( String folder )\r
132     {\r
133         this.folder = folder;\r
134     }\r
135 \r
136     public int getIdx()\r
137     {\r
138         return idx;\r
139     }\r
140 \r
141     public void setIdx( int index )\r
142     {\r
143         this.idx = index;\r
144     }\r
145 \r
146 }\r