]> source.dussan.org Git - archiva.git/blob
f1e7a5707fd2b98797f1ff391da9242014dced1f
[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.RepositoryIndexException;
25 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
26 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
27 import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher;
28 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
29 import org.codehaus.plexus.scheduler.Scheduler;
30 import org.codehaus.plexus.scheduler.configuration.SchedulerConfiguration;
31
32 import java.io.File;
33 import java.net.MalformedURLException;
34 import java.util.List;
35
36 /**
37  * TODO: Description.
38  *
39  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
40  * @plexus.component role="com.opensymphony.xwork.Action" role-hint="org.apache.maven.repository.manager.web.action.PackageSearchAction"
41  */
42 public class PackageSearchAction
43     implements Action
44 {
45     private String packageName;
46
47     private String md5;
48
49     /**
50      * @plexus.requirement
51      */
52     private Scheduler scheduler;
53
54     /**
55      * @plexus.requirement
56      */
57     private RepositoryIndexingFactory factory;
58
59     /**
60      * @plexus.requirement
61      */
62     private ArtifactRepositoryFactory repositoryFactory;
63
64     /**
65      * @plexus.requirement role-hint="legacy"
66      */
67     private ArtifactRepositoryLayout layout;
68
69     private List artifacts;
70
71     public String execute()
72         throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
73     {
74         String searchTerm;
75         String key;
76         if ( packageName != null && packageName.length() != 0 )
77         {
78             searchTerm = packageName;
79             key = "packages";
80         }
81         else if ( md5 != null && md5.length() != 0 )
82         {
83             searchTerm = md5;
84             key = "md5";
85         }
86         else
87         {
88             return ERROR;
89         }
90
91         // TODO: better config
92         String indexPath = "c:/home/brett/repository/.index";
93
94         // TODO: reduce the amount of lookup?
95         ArtifactRepository repository = repositoryFactory.createArtifactRepository( "repository", new File(
96             indexPath ).toURL().toString(), layout, null, null );
97
98         ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
99
100         DefaultRepositoryIndexSearcher searcher = factory.createDefaultRepositoryIndexSearcher( index );
101
102         artifacts = searcher.search( new SinglePhraseQuery( key, searchTerm ) );
103
104         return SUCCESS;
105     }
106
107     public void setPackageName( String packageName )
108     {
109         this.packageName = packageName;
110     }
111
112     public void setMd5( String md5 )
113     {
114         this.md5 = md5;
115     }
116
117     public List getArtifacts()
118     {
119         return artifacts;
120     }
121 }