]> source.dussan.org Git - archiva.git/blob
81f92c96e52ca14e66f3ab476297c91c8d36fb0e
[archiva.git] /
1 package org.apache.maven.repository.manager.web.action;
2
3 /*
4  * Copyright 2005-2006 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 import com.opensymphony.xwork.Action;
20 import org.apache.maven.artifact.repository.ArtifactRepository;
21 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
22 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
23 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
24 import org.apache.maven.repository.indexing.ArtifactRepositoryIndexSearcher;
25 import org.apache.maven.repository.indexing.RepositoryIndexException;
26 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
27 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
28 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
29
30 import java.io.File;
31 import java.net.MalformedURLException;
32 import java.util.List;
33
34 /**
35  * TODO: Description.
36  *
37  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
38  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.PackageSearchAction"
39  */
40 public class PackageSearchAction
41     implements Action
42 {
43     private String packageName;
44
45     private String md5;
46
47     /**
48      * @plexus.requirement
49      */
50     private RepositoryIndexingFactory factory;
51
52     /**
53      * @plexus.requirement
54      */
55     private ArtifactRepositoryFactory repositoryFactory;
56
57     /**
58      * @plexus.requirement role-hint="legacy"
59      */
60     private ArtifactRepositoryLayout layout;
61
62     private List artifacts;
63
64     public String execute()
65         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
66     {
67         String searchTerm;
68         String key;
69         if ( packageName != null && packageName.length() != 0 )
70         {
71             searchTerm = packageName;
72             key = "packages";
73         }
74         else if ( md5 != null && md5.length() != 0 )
75         {
76             searchTerm = md5;
77             key = "md5";
78         }
79         else
80         {
81             return ERROR;
82         }
83
84         // TODO: better config
85         String indexPath = "c:/home/brett/repository/.index";
86
87         // TODO: reduce the amount of lookup?
88         ArtifactRepository repository = repositoryFactory.createArtifactRepository( "repository", new File(
89             indexPath ).toURL().toString(), layout, null, null );
90
91         ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
92
93         ArtifactRepositoryIndexSearcher searcher = factory.createArtifactRepositoryIndexSearcher( index );
94
95         artifacts = searcher.search( new SinglePhraseQuery( key, searchTerm ) );
96
97         return SUCCESS;
98     }
99
100     public void setPackageName( String packageName )
101     {
102         this.packageName = packageName;
103     }
104
105     public void setMd5( String md5 )
106     {
107         this.md5 = md5;
108     }
109
110     public List getArtifacts()
111     {
112         return artifacts;
113     }
114 }