1 package org.apache.maven.repository.manager.web.action;
4 * Copyright 2005-2006 The Apache Software Foundation.
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.repository.indexing.ArtifactRepositoryIndex;
23 import org.apache.maven.repository.indexing.RepositoryIndex;
24 import org.apache.maven.repository.indexing.RepositoryIndexException;
25 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
26 import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
27 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
28 import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
29 import org.apache.maven.repository.manager.web.job.Configuration;
32 import java.net.MalformedURLException;
33 import java.util.List;
36 * Search by package name.
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"
41 public class PackageSearchAction
44 private String packageName;
48 private List searchResult;
53 private RepositoryIndexingFactory factory;
58 private ArtifactRepositoryFactory repositoryFactory;
63 private RepositoryIndexSearchLayer searchLayer;
68 private Configuration configuration;
70 public String execute()
71 throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException
75 if ( packageName != null && packageName.length() != 0 )
77 searchTerm = packageName;
78 key = RepositoryIndex.FLD_PACKAGES;
80 else if ( md5 != null && md5.length() != 0 )
90 // TODO: better config [!]
91 String indexPath = configuration.getIndexDirectory();
93 // TODO: reduce the amount of lookup?
94 File repositoryDirectory = new File( configuration.getRepositoryDirectory() );
95 String repoDir = repositoryDirectory.toURL().toString();
97 ArtifactRepository repository =
98 repositoryFactory.createArtifactRepository( "repository", repoDir, configuration.getLayout(), null, null );
100 ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
102 searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ), index );
107 public void setPackageName( String packageName )
109 this.packageName = packageName;
112 public void setMd5( String md5 )
117 public List getSearchResult()