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