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.ActionSupport;
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.configuration.Configuration;
24 import org.apache.maven.repository.configuration.ConfigurationStore;
25 import org.apache.maven.repository.configuration.ConfigurationStoreException;
26 import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
27 import org.apache.maven.repository.indexing.RepositoryIndexException;
28 import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
29 import org.apache.maven.repository.indexing.RepositoryIndexSearchLayer;
30 import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
33 import java.net.MalformedURLException;
34 import java.util.List;
38 * Searches for searchString in all indexed fields.
40 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="quickSearchAction" instantiation-strategy="per-lookup"
42 public class QuickSearchAction
53 private List searchResult;
58 private RepositoryIndexingFactory factory;
63 private RepositoryIndexSearchLayer searchLayer;
68 private ArtifactRepositoryFactory repositoryFactory;
71 * @plexus.requirement role="org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
73 private Map repositoryLayouts;
78 private ConfigurationStore configurationStore;
80 public String execute()
81 throws MalformedURLException, RepositoryIndexException, RepositoryIndexSearchException,
82 ConfigurationStoreException
84 // TODO: give action message if indexing is in progress
86 // TODO: return zero results if index doesn't yet exist
88 assert q != null && q.length() != 0;
90 Configuration configuration = configurationStore.getConfigurationFromStore();
91 File indexPath = new File( configuration.getIndexPath() );
93 ArtifactRepository repository = getDefaultRepository( configuration );
95 ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
97 searchResult = searchLayer.searchGeneral( q, index );
102 private ArtifactRepository getDefaultRepository( Configuration configuration )
103 throws MalformedURLException
105 // TODO: [!] repository should only have been instantiated once
106 File repositoryDirectory = new File( configuration.getRepositoryDirectory() );
107 String repoDir = repositoryDirectory.toURI().toURL().toString();
109 ArtifactRepositoryLayout layout =
110 (ArtifactRepositoryLayout) repositoryLayouts.get( configuration.getRepositoryLayout() );
111 return repositoryFactory.createArtifactRepository( "test", repoDir, layout, null, null );
114 public String doInput()
124 public void setQ( String q )
129 public List getSearchResult()