import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.repository.indexing.ArtifactRepositoryIndex;
-import org.apache.maven.repository.indexing.DefaultRepositoryIndexSearcher;
import org.apache.maven.repository.indexing.RepositoryIndexException;
import org.apache.maven.repository.indexing.RepositoryIndexSearchException;
+import org.apache.maven.repository.indexing.RepositoryIndexSearcher;
import org.apache.maven.repository.indexing.RepositoryIndexingFactory;
import org.apache.maven.repository.indexing.query.SinglePhraseQuery;
import org.codehaus.classworlds.ClassWorld;
ArtifactRepositoryIndex index =
indexFactory.createArtifactRepositoryIndex( new File( args[0], ".index" ).getAbsolutePath(), repository );
- DefaultRepositoryIndexSearcher searcher = indexFactory.createDefaultRepositoryIndexSearcher( index );
+ RepositoryIndexSearcher searcher = (RepositoryIndexSearcher) embedder.lookup( RepositoryIndexSearcher.ROLE );
try
{
- System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ) ) );
+ System.out.println( searcher.search( new SinglePhraseQuery( args[1], args[2] ), index ) );
}
finally
{
import java.util.zip.ZipEntry;
/**
- * Abstract class for RepositoryIndexers
+ * Abstract class for RepositoryIndexers.
*
* @author Edwin Punzalan
*/
public abstract class AbstractRepositoryIndex
implements RepositoryIndex
{
+ // TODO [!] can this be derived from the repository?
private String indexPath;
private boolean indexOpen;
+ // TODO [!] why is the writer open for the life, but not the reader? why keep them open that length of time anyway? investigate best practices in Lucene
private IndexWriter indexWriter;
protected ArtifactRepository repository;
+ // TODO [!] is this really needed externally?
private Analyzer analyzer;
/**
protected IndexWriter getIndexWriter()
throws IOException
{
+ // TODO [!] why is this allowed to be called before open()?
if ( indexWriter == null )
{
indexWriter = new IndexWriter( indexPath, getAnalyzer(), false );
}
catch ( IOException ie )
{
- throw new RepositoryIndexException( indexPath + "is not a valid directory." );
+ throw new RepositoryIndexException( indexPath + " is not a valid directory." );
}
finally
{
--- /dev/null
+package org.apache.maven.repository.indexing;\r
+\r
+/*\r
+ * Copyright 2005-2006 The Apache Software Foundation.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+import org.apache.maven.artifact.Artifact;\r
+import org.apache.maven.artifact.factory.ArtifactFactory;\r
+import org.apache.maven.model.Dependency;\r
+import org.apache.maven.model.License;\r
+import org.apache.maven.model.Model;\r
+import org.apache.maven.model.Plugin;\r
+import org.apache.maven.model.ReportPlugin;\r
+import org.apache.maven.repository.indexing.query.Query;\r
+import org.apache.maven.repository.indexing.query.SinglePhraseQuery;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.Iterator;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.StringTokenizer;\r
+\r
+/**\r
+ * This class is to be invoked or called by the action class for\r
+ * general and advanced searching. It uses the DefaultRepositoryIndexSearcher\r
+ * to perform the search and constructs the search result objects to be\r
+ * returned to tha webapp action class.\r
+ *\r
+ * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexSearchLayer"\r
+ */\r
+public class DefaultRepositoryIndexSearchLayer\r
+ implements RepositoryIndexSearchLayer\r
+{\r
+ /**\r
+ * @plexus.requirement\r
+ */\r
+ private ArtifactFactory factory;\r
+\r
+ /**\r
+ * @plexus.requirement\r
+ */\r
+ private RepositoryIndexSearcher searcher;\r
+\r
+ public List searchGeneral( String keyword, RepositoryIndex index )\r
+ throws RepositoryIndexSearchException\r
+ {\r
+ List generalSearchResults = new ArrayList();\r
+ for ( int i = 0; i < RepositoryIndex.FIELDS.length; i++ )\r
+ {\r
+ Query qry = new SinglePhraseQuery( RepositoryIndex.FIELDS[i], keyword );\r
+ List results = searchAdvanced( qry, index );\r
+ for ( Iterator iter = results.iterator(); iter.hasNext(); )\r
+ {\r
+ SearchResult result = (SearchResult) iter.next();\r
+ Map map = result.getFieldMatches();\r
+ Set entrySet = map.entrySet();\r
+ for ( Iterator it = entrySet.iterator(); it.hasNext(); )\r
+ {\r
+ Map.Entry entry = (Map.Entry) it.next();\r
+ SearchResult result2 = createSearchResult( result.getArtifact(), map, keyword,\r
+ (String) entry.getKey(), generalSearchResults );\r
+ generalSearchResults.add( result2 );\r
+ }\r
+ }\r
+ }\r
+\r
+ return generalSearchResults;\r
+ }\r
+\r
+ public List searchAdvanced( Query qry, RepositoryIndex index )\r
+ throws RepositoryIndexSearchException\r
+ {\r
+ List searchResults = new ArrayList();\r
+\r
+ List hits = searcher.search( qry, index );\r
+ for ( Iterator it = hits.iterator(); it.hasNext(); )\r
+ {\r
+ RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) it.next();\r
+ SearchResult result = new SearchResult();\r
+ if ( hit.isHashMap() )\r
+ {\r
+ Map map = (Map) hit.getObject();\r
+ result.setArtifact( (Artifact) map.get( RepositoryIndex.ARTIFACT ) );\r
+\r
+ Map fields = new HashMap();\r
+ fields.put( RepositoryIndex.FLD_CLASSES, map.get( RepositoryIndex.FLD_CLASSES ) );\r
+ fields.put( RepositoryIndex.FLD_PACKAGES, map.get( RepositoryIndex.FLD_PACKAGES ) );\r
+ fields.put( RepositoryIndex.FLD_FILES, map.get( RepositoryIndex.FLD_FILES ) );\r
+ fields.put( RepositoryIndex.FLD_PACKAGING, map.get( RepositoryIndex.FLD_PACKAGING ) );\r
+ fields.put( RepositoryIndex.FLD_SHA1, map.get( RepositoryIndex.FLD_SHA1 ) );\r
+ fields.put( RepositoryIndex.FLD_MD5, map.get( RepositoryIndex.FLD_MD5 ) );\r
+\r
+ result.setFieldMatches( fields );\r
+ searchResults.add( result );\r
+ }\r
+ else if ( hit.isModel() )\r
+ {\r
+ Model model = (Model) hit.getObject();\r
+ for ( int i = 0; i < RepositoryIndex.MODEL_FIELDS.length; i++ )\r
+ {\r
+ result = createSearchResult( model, RepositoryIndex.MODEL_FIELDS[i], searchResults );\r
+ searchResults.add( result );\r
+ }\r
+ }\r
+ else if ( hit.isMetadata() )\r
+ {\r
+ //@todo what about metadata objects?\r
+// RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject();\r
+ }\r
+ }\r
+\r
+ return searchResults;\r
+ }\r
+\r
+ /**\r
+ * Method for checking if the artifact already exists in the search result list.\r
+ *\r
+ * @param groupId the group id of the artifact\r
+ * @param artifactId the artifact id of the artifact\r
+ * @param version the version of the artifact\r
+ * @return the int index number of the artifact in the search result\r
+ */\r
+ private int getListIndex( String groupId, String artifactId, String version, List list )\r
+ {\r
+ int index = 0;\r
+ for ( Iterator iter = list.iterator(); iter.hasNext(); )\r
+ {\r
+ SearchResult result = (SearchResult) iter.next();\r
+ Artifact artifact = result.getArtifact();\r
+ if ( artifact.getGroupId().equals( groupId ) && artifact.getArtifactId().equals( artifactId ) &&\r
+ artifact.getVersion().equals( version ) )\r
+ {\r
+ return index;\r
+ }\r
+ index++;\r
+ }\r
+ return -1;\r
+ }\r
+\r
+ /**\r
+ * Method to create the unique artifact id to represent the artifact in the repository\r
+ *\r
+ * @param groupId the artifact groupId\r
+ * @param artifactId the artifact artifactId\r
+ * @param version the artifact version\r
+ * @return the String id to uniquely represent the artifact\r
+ */\r
+ private String getId( String groupId, String artifactId, String version )\r
+ {\r
+ return groupId + ":" + artifactId + ":" + version;\r
+ }\r
+\r
+ /**\r
+ * Method to get the matching values (packages, classes and files) in the\r
+ * given string to be tokenized.\r
+ *\r
+ * @param tokenizeStr the string to be tokenized\r
+ * @param key the map key\r
+ * @param resultMap the map to be populated\r
+ * @param keyword the value to be matched\r
+ * @return the map that contains the matched values\r
+ */\r
+ private Map getArtifactHits( String tokenizeStr, String key, Map resultMap, String keyword )\r
+ {\r
+ List values = new ArrayList();\r
+ StringTokenizer st = new StringTokenizer( tokenizeStr, "\n" );\r
+ while ( st.hasMoreTokens() )\r
+ {\r
+ String str = st.nextToken();\r
+ if ( str.toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )\r
+ {\r
+ values.add( str );\r
+ }\r
+ }\r
+\r
+ if ( !values.isEmpty() )\r
+ {\r
+ resultMap.put( key, values );\r
+ }\r
+\r
+ return resultMap;\r
+ }\r
+\r
+ /**\r
+ * Method to create SearchResult object from a given HashMap. Used for general search results\r
+ *\r
+ * @param artifact the retrieved artifact from the index\r
+ * @param map the HashMap object that contains the values for the search result\r
+ * @param keyword the query term\r
+ * @return the SearchResult object\r
+ */\r
+ private SearchResult createSearchResult( Artifact artifact, Map map, String keyword, String field,\r
+ List generalSearchResults )\r
+ {\r
+ int index = getListIndex( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),\r
+ generalSearchResults );\r
+ SearchResult result;\r
+ Map resultMap;\r
+\r
+ if ( index > -1 )\r
+ {\r
+ result = (SearchResult) generalSearchResults.remove( index );\r
+ resultMap = result.getFieldMatches();\r
+ }\r
+ else\r
+ {\r
+ result = new SearchResult();\r
+ result.setArtifact( artifact );\r
+ resultMap = new HashMap();\r
+ }\r
+\r
+ // the searched field is either the class, package or file field\r
+ if ( field.equals( RepositoryIndex.FLD_CLASSES ) || field.equals( RepositoryIndex.FLD_PACKAGES ) ||\r
+ field.equals( RepositoryIndex.FLD_FILES ) )\r
+ {\r
+ resultMap = getArtifactHits( (String) map.get( field ), field, resultMap, keyword );\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_SHA1 ) ||\r
+ ( field.equals( RepositoryIndex.FLD_MD5 ) || field.equals( RepositoryIndex.FLD_PACKAGING ) ) )\r
+ {\r
+ if ( map.get( field ) != null )\r
+ {\r
+ // the searched field is either the md5, sha1 or packaging field\r
+ if ( ( (String) map.get( field ) ).toLowerCase().equals( keyword.toLowerCase() ) ||\r
+ ( (String) map.get( field ) ).toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )\r
+ {\r
+ resultMap.put( field, map.get( field ) );\r
+ }\r
+ }\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) ||\r
+ field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) || field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) ||\r
+ field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )\r
+ {\r
+ List contents = (List) map.get( field );\r
+ List values = new ArrayList();\r
+ for ( Iterator it = contents.iterator(); it.hasNext(); )\r
+ {\r
+ String str = (String) it.next();\r
+ if ( str.toLowerCase().equals( keyword.toLowerCase() ) )\r
+ {\r
+ values.add( str );\r
+ }\r
+ }\r
+ if ( values.size() > 0 )\r
+ {\r
+ resultMap.put( field, values );\r
+ }\r
+ }\r
+ result.setFieldMatches( resultMap );\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Method to create a SearchResult object from the given model. Used for advanced search results\r
+ *\r
+ * @param model the Model object that contains the values for the search result\r
+ * @param field the field whose value is to be retrieved\r
+ * @return a SearchResult object\r
+ */\r
+ private SearchResult createSearchResult( Model model, String field, List searchResults )\r
+ {\r
+ int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );\r
+ SearchResult result;\r
+ Map map;\r
+\r
+ // the object already exists in the search result list\r
+ if ( index > -1 )\r
+ {\r
+ result = (SearchResult) searchResults.remove( index );\r
+ map = result.getFieldMatches();\r
+ }\r
+ else\r
+ {\r
+ result = new SearchResult();\r
+ result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),\r
+ model.getVersion(), model.getPackaging() ) );\r
+ map = new HashMap();\r
+ }\r
+\r
+ // get the matched value with the query term\r
+ List values = new ArrayList();\r
+ if ( field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )\r
+ {\r
+ values = getLicenseUrls( model );\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) )\r
+ {\r
+ values = getDependencies( model );\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) )\r
+ {\r
+ if ( model.getBuild() != null && model.getBuild().getPlugins() != null )\r
+ {\r
+ values = getBuildPlugins( model );\r
+ }\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) )\r
+ {\r
+ if ( model.getReporting() != null && model.getReporting().getPlugins() != null )\r
+ {\r
+ values = getReportPlugins( model );\r
+ }\r
+ }\r
+ else if ( field.equals( RepositoryIndex.FLD_PACKAGING ) )\r
+ {\r
+ if ( model.getPackaging() != null )\r
+ {\r
+ map.put( RepositoryIndex.FLD_PACKAGING, model.getPackaging() );\r
+ }\r
+ }\r
+\r
+ if ( !values.isEmpty() )\r
+ {\r
+ map.put( field, values );\r
+ }\r
+ result.setFieldMatches( map );\r
+\r
+ return result;\r
+ }\r
+\r
+ /**\r
+ * Method for getting the query term hits or matches in the pom's license urls.\r
+ *\r
+ * @param model the Model object that contains the pom values\r
+ * @return a List of matched license urls\r
+ */\r
+ private List getLicenseUrls( Model model )\r
+ {\r
+ List licenseUrls = new ArrayList();\r
+ List licenseList = model.getLicenses();\r
+ for ( Iterator it = licenseList.iterator(); it.hasNext(); )\r
+ {\r
+ License license = (License) it.next();\r
+ licenseUrls.add( license.getUrl() );\r
+ }\r
+ return licenseUrls;\r
+ }\r
+\r
+ /**\r
+ * Method for getting the hits or matches in the dependencies specified in the pom\r
+ *\r
+ * @param model the Model object that contains the pom values\r
+ * @return a List of matched dependencies\r
+ */\r
+ private List getDependencies( Model model )\r
+ {\r
+ List dependencies = new ArrayList();\r
+ List dependencyList = model.getDependencies();\r
+ for ( Iterator it = dependencyList.iterator(); it.hasNext(); )\r
+ {\r
+ Dependency dep = (Dependency) it.next();\r
+ dependencies.add( getId( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() ) );\r
+ }\r
+\r
+ return dependencies;\r
+ }\r
+\r
+ /**\r
+ * Method for getting the hits or matches in the build plugins specified in the pom\r
+ *\r
+ * @param model the Model object that contains the pom values\r
+ * @return a List of matched build plugins\r
+ */\r
+ private List getBuildPlugins( Model model )\r
+ {\r
+ List values = new ArrayList();\r
+ List plugins = model.getBuild().getPlugins();\r
+ for ( Iterator it = plugins.iterator(); it.hasNext(); )\r
+ {\r
+ Plugin plugin = (Plugin) it.next();\r
+ values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );\r
+ }\r
+\r
+ return values;\r
+ }\r
+\r
+ /**\r
+ * Method for getting the hits or matches in the reporting plugins specified in the pom\r
+ *\r
+ * @param model the Model object that contains the pom values\r
+ * @return a List of matched reporting plugins\r
+ */\r
+ private List getReportPlugins( Model model )\r
+ {\r
+ List values = new ArrayList();\r
+ List plugins = model.getReporting().getPlugins();\r
+ for ( Iterator it = plugins.iterator(); it.hasNext(); )\r
+ {\r
+ ReportPlugin plugin = (ReportPlugin) it.next();\r
+ values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );\r
+ }\r
+\r
+ return values;\r
+ }\r
+\r
+}\r
import org.apache.lucene.search.IndexSearcher;\r
import org.apache.maven.artifact.Artifact;\r
import org.apache.maven.artifact.factory.ArtifactFactory;\r
+import org.apache.maven.artifact.repository.ArtifactRepository;\r
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata;\r
import org.apache.maven.artifact.repository.metadata.Metadata;\r
/**\r
* Implementation Class for searching through the index.\r
*\r
- * @todo this is not a component, but extends ALE, meaning logging will throw an exception! -- should be a component\r
+ * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexSearcher"\r
*/\r
public class DefaultRepositoryIndexSearcher\r
extends AbstractLogEnabled\r
implements RepositoryIndexSearcher\r
{\r
- protected RepositoryIndex index;\r
-\r
- private ArtifactFactory factory;\r
-\r
- private List artifactList;\r
-\r
/**\r
- * Constructor\r
- *\r
- * @param index the index object\r
+ * @plexus.requirement\r
*/\r
- protected DefaultRepositoryIndexSearcher( RepositoryIndex index, ArtifactFactory factory )\r
- {\r
- this.index = index;\r
- this.factory = factory;\r
- }\r
+ private ArtifactFactory factory;\r
\r
- /**\r
- * @see RepositoryIndexSearcher#search(org.apache.maven.repository.indexing.query.Query)\r
- */\r
- public List search( Query query )\r
+ public List search( Query query, RepositoryIndex index )\r
throws RepositoryIndexSearchException\r
{\r
- artifactList = new ArrayList();\r
org.apache.lucene.search.Query luceneQuery;\r
try\r
{\r
- luceneQuery = createLuceneQuery( query );\r
+ luceneQuery = query.createLuceneQuery( index );\r
}\r
catch ( ParseException e )\r
{\r
throw new RepositoryIndexSearchException( "Unable to open index: " + e.getMessage(), e );\r
}\r
\r
- List docs;\r
+ List docs = new ArrayList();\r
try\r
{\r
Hits hits = searcher.search( luceneQuery );\r
- docs = buildList( hits );\r
+ for ( int i = 0; i < hits.length(); i++ )\r
+ {\r
+ Document doc = hits.doc( i );\r
+ docs.add( createSearchedObjectFromIndexDocument( doc, index.getRepository() ) );\r
+ }\r
}\r
catch ( MalformedURLException e )\r
{\r
return docs;\r
}\r
\r
- /**\r
- * Method to create a lucene Query object by converting a prepared Query object\r
- *\r
- * @param query the prepared Query object to be converted into a lucene Query object\r
- * @return a lucene Query object to represent the passed Query object\r
- * @throws ParseException\r
- */\r
- private org.apache.lucene.search.Query createLuceneQuery( Query query )\r
- throws ParseException\r
- {\r
- return query.createLuceneQuery( index );\r
- }\r
-\r
- /**\r
- * Create a list of artifact objects from the result set.\r
- *\r
- * @param hits the search result set\r
- * @return List\r
- */\r
- private List buildList( Hits hits )\r
- throws RepositoryIndexSearchException, IOException\r
- {\r
- for ( int i = 0; i < hits.length(); i++ )\r
- {\r
- Document doc = hits.doc( i );\r
- artifactList.add( createSearchedObjectFromIndexDocument( doc ) );\r
- }\r
-\r
- return artifactList;\r
- }\r
-\r
/**\r
* Method for creating the object to be returned for the search\r
*\r
- * @param doc the index document where the object field values will be retrieved from\r
+ * @param doc the index document where the object field values will be retrieved from\r
+ * @param repository\r
* @return Object\r
*/\r
- protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc )\r
+ protected RepositoryIndexSearchHit createSearchedObjectFromIndexDocument( Document doc,\r
+ ArtifactRepository repository )\r
throws RepositoryIndexSearchException\r
{\r
RepositoryIndexSearchHit searchHit = null;\r
String packaging = doc.get( RepositoryIndex.FLD_PACKAGING );\r
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );\r
\r
- artifact.setFile(\r
- new File( index.getRepository().getBasedir(), index.getRepository().pathOf( artifact ) ) );\r
+ artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );\r
\r
Map map = new HashMap();\r
map.put( RepositoryIndex.ARTIFACT, artifact );\r
Artifact pomArtifact = factory.createProjectArtifact( groupId, artifactId, version );\r
\r
searchHit = new RepositoryIndexSearchHit( false, false, true );\r
- searchHit.setObject( readPom( pomArtifact ) );\r
+ searchHit.setObject( readPom( pomArtifact, repository ) );\r
}\r
// the document is of type metadata\r
else if ( doc.get( RepositoryIndex.FLD_DOCTYPE ).equals( RepositoryIndex.METADATA ) )\r
repoMetadata = new GroupRepositoryMetadata( groupId );\r
}\r
\r
- repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
+ repoMetadata.setMetadata( readMetadata( repoMetadata, repository ) );\r
\r
searchHit = new RepositoryIndexSearchHit( false, true, false );\r
searchHit.setObject( repoMetadata );\r
*\r
* @return RepositoryMetadata\r
*/\r
- private Metadata readMetadata( RepositoryMetadata repoMetadata )\r
+ private Metadata readMetadata( RepositoryMetadata repoMetadata, ArtifactRepository repository )\r
throws RepositoryIndexSearchException\r
{\r
- File file = new File( index.getRepository().getBasedir(),\r
- index.getRepository().pathOfRemoteRepositoryMetadata( repoMetadata ) );\r
+ File file = new File( repository.getBasedir(), repository.pathOfRemoteRepositoryMetadata( repoMetadata ) );\r
\r
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();\r
\r
*\r
* @return RepositoryMetadata\r
*/\r
- private Model readPom( Artifact pomArtifact )\r
+ private Model readPom( Artifact pomArtifact, ArtifactRepository repository )\r
throws RepositoryIndexSearchException\r
{\r
- File file = new File( index.getRepository().getBasedir(), index.getRepository().pathOf( pomArtifact ) );\r
+ File file = new File( repository.getBasedir(), repository.pathOf( pomArtifact ) );\r
\r
MavenXpp3Reader r = new MavenXpp3Reader();\r
\r
/**
* @author Edwin Punzalan
* @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexingFactory"
- * @todo these methods should be replaced by plexus lookups of some kind!
*/
public class DefaultRepositoryIndexingFactory
implements RepositoryIndexingFactory
return new MetadataRepositoryIndex( indexPath, repository );
}
- /*
- * @see RepositoryIndexingFactory#createRepositoryIndexSearchLayer(RepositoryIndex)
- */
- public RepositoryIndexSearchLayer createRepositoryIndexSearchLayer( RepositoryIndex index )
- {
- return new RepositoryIndexSearchLayer( index, artifactFactory );
- }
-
- /**
- * @see RepositoryIndexingFactory#createDefaultRepositoryIndexSearcher(RepositoryIndex)
- */
- public DefaultRepositoryIndexSearcher createDefaultRepositoryIndexSearcher( RepositoryIndex index )
- {
- return new DefaultRepositoryIndexSearcher( index, artifactFactory );
- }
-
}
-package org.apache.maven.repository.indexing;\r
-\r
-/*\r
- * Copyright 2005-2006 The Apache Software Foundation.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-import org.apache.maven.artifact.Artifact;\r
-import org.apache.maven.artifact.factory.ArtifactFactory;\r
-import org.apache.maven.model.Dependency;\r
-import org.apache.maven.model.License;\r
-import org.apache.maven.model.Model;\r
-import org.apache.maven.model.Plugin;\r
-import org.apache.maven.model.ReportPlugin;\r
-import org.apache.maven.repository.indexing.query.Query;\r
-import org.apache.maven.repository.indexing.query.SinglePhraseQuery;\r
-\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
-import java.util.StringTokenizer;\r
-\r
-/**\r
- * <p/>\r
- * This class is to be invoked or called by the action class for\r
- * general and advanced searching. It uses the DefaultRepositoryIndexSearcher\r
- * to perform the search and constructs the search result objects to be\r
- * returned to tha webapp action class.\r
- */\r
-public class RepositoryIndexSearchLayer\r
-{\r
- private RepositoryIndex index;\r
-\r
- private ArtifactFactory factory;\r
-\r
- private List searchResults;\r
-\r
- private List generalSearchResults;\r
-\r
- /**\r
- * Class constructor\r
- *\r
- * @param index\r
- */\r
- public RepositoryIndexSearchLayer( RepositoryIndex index, ArtifactFactory factory )\r
- {\r
- this.index = index;\r
- this.factory = factory;\r
- }\r
-\r
- /**\r
- * Method for searching the keyword in all the fields in the index. "Query everything" search.\r
- * The index fields will be retrieved and query objects will be constructed using the\r
- * optional (OR) CompoundQuery.\r
- *\r
- * @param keyword\r
- * @return\r
- * @throws RepositoryIndexSearchException\r
- */\r
- public List searchGeneral( String keyword )\r
- throws RepositoryIndexSearchException\r
- {\r
- generalSearchResults = new ArrayList();\r
- for ( int i = 0; i < RepositoryIndex.FIELDS.length; i++ )\r
- {\r
- Query qry = new SinglePhraseQuery( RepositoryIndex.FIELDS[i], keyword );\r
- List results = searchAdvanced( qry );\r
- for ( Iterator iter = results.iterator(); iter.hasNext(); )\r
- {\r
- SearchResult result = (SearchResult) iter.next();\r
- Map map = result.getFieldMatches();\r
- Set entrySet = map.entrySet();\r
- for ( Iterator it = entrySet.iterator(); it.hasNext(); )\r
- {\r
- Map.Entry entry = (Map.Entry) it.next();\r
- SearchResult result2 =\r
- createSearchResult( result.getArtifact(), map, keyword, (String) entry.getKey() );\r
- generalSearchResults.add( result2 );\r
- }\r
- }\r
- }\r
-\r
- return generalSearchResults;\r
- }\r
-\r
- /**\r
- * Method for "advanced search" of the index\r
- *\r
- * @param qry the query object that will be used for searching the index\r
- * @return\r
- * @throws RepositoryIndexSearchException\r
- */\r
- public List searchAdvanced( Query qry )\r
- throws RepositoryIndexSearchException\r
- {\r
- RepositoryIndexSearcher searcher = new DefaultRepositoryIndexSearcher( index, factory );\r
- searchResults = new ArrayList();\r
-\r
- List hits = searcher.search( qry );\r
- for ( Iterator it = hits.iterator(); it.hasNext(); )\r
- {\r
- RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) it.next();\r
- SearchResult result = new SearchResult();\r
- if ( hit.isHashMap() )\r
- {\r
- Map map = (Map) hit.getObject();\r
- result.setArtifact( (Artifact) map.get( RepositoryIndex.ARTIFACT ) );\r
-\r
- Map fields = new HashMap();\r
- fields.put( RepositoryIndex.FLD_CLASSES, map.get( RepositoryIndex.FLD_CLASSES ) );\r
- fields.put( RepositoryIndex.FLD_PACKAGES, map.get( RepositoryIndex.FLD_PACKAGES ) );\r
- fields.put( RepositoryIndex.FLD_FILES, map.get( RepositoryIndex.FLD_FILES ) );\r
- fields.put( RepositoryIndex.FLD_PACKAGING, map.get( RepositoryIndex.FLD_PACKAGING ) );\r
- fields.put( RepositoryIndex.FLD_SHA1, map.get( RepositoryIndex.FLD_SHA1 ) );\r
- fields.put( RepositoryIndex.FLD_MD5, map.get( RepositoryIndex.FLD_MD5 ) );\r
-\r
- result.setFieldMatches( fields );\r
- searchResults.add( result );\r
- }\r
- else if ( hit.isModel() )\r
- {\r
- Model model = (Model) hit.getObject();\r
- for ( int i = 0; i < RepositoryIndex.MODEL_FIELDS.length; i++ )\r
- {\r
- result = createSearchResult( model, RepositoryIndex.MODEL_FIELDS[i] );\r
- searchResults.add( result );\r
- }\r
- }\r
- else if ( hit.isMetadata() )\r
- {\r
- //@todo what about metadata objects?\r
-// RepositoryMetadata metadata = (RepositoryMetadata) hit.getObject();\r
- }\r
- }\r
-\r
- return searchResults;\r
- }\r
-\r
- /**\r
- * Method for checking if the artifact already exists in the search result list.\r
- *\r
- * @param groupId the group id of the artifact\r
- * @param artifactId the artifact id of the artifact\r
- * @param version the version of the artifact\r
- * @return the int index number of the artifact in the search result\r
- */\r
- private int getListIndex( String groupId, String artifactId, String version, List list )\r
- {\r
- int index = 0;\r
- for ( Iterator iter = list.iterator(); iter.hasNext(); )\r
- {\r
- SearchResult result = (SearchResult) iter.next();\r
- Artifact artifact = result.getArtifact();\r
- if ( artifact.getGroupId().equals( groupId ) && artifact.getArtifactId().equals( artifactId ) &&\r
- artifact.getVersion().equals( version ) )\r
- {\r
- return index;\r
- }\r
- index++;\r
- }\r
- return -1;\r
- }\r
-\r
- /**\r
- * Method to create the unique artifact id to represent the artifact in the repository\r
- *\r
- * @param groupId the artifact groupId\r
- * @param artifactId the artifact artifactId\r
- * @param version the artifact version\r
- * @return the String id to uniquely represent the artifact\r
- */\r
- private String getId( String groupId, String artifactId, String version )\r
- {\r
- return groupId + ":" + artifactId + ":" + version;\r
- }\r
-\r
- /**\r
- * Method to get the matching values (packages, classes and files) in the\r
- * given string to be tokenized.\r
- *\r
- * @param tokenizeStr the string to be tokenized\r
- * @param key the map key\r
- * @param resultMap the map to be populated\r
- * @param keyword the value to be matched\r
- * @return the map that contains the matched values\r
- */\r
- private Map getArtifactHits( String tokenizeStr, String key, Map resultMap, String keyword )\r
- {\r
- List values = new ArrayList();\r
- StringTokenizer st = new StringTokenizer( tokenizeStr, "\n" );\r
- while ( st.hasMoreTokens() )\r
- {\r
- String str = st.nextToken();\r
- if ( str.toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )\r
- {\r
- values.add( str );\r
- }\r
- }\r
-\r
- if ( !values.isEmpty() )\r
- {\r
- resultMap.put( key, values );\r
- }\r
-\r
- return resultMap;\r
- }\r
-\r
- /**\r
- * Method to create SearchResult object from a given HashMap. Used for general search results\r
- *\r
- * @param artifact the retrieved artifact from the index\r
- * @param map the HashMap object that contains the values for the search result\r
- * @param keyword the query term\r
- * @return the SearchResult object\r
- */\r
- private SearchResult createSearchResult( Artifact artifact, Map map, String keyword, String field )\r
- {\r
- int index = getListIndex( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),\r
- generalSearchResults );\r
- SearchResult result;\r
- Map resultMap;\r
-\r
- if ( index > -1 )\r
- {\r
- result = (SearchResult) generalSearchResults.get( index );\r
- generalSearchResults.remove( index );\r
- resultMap = result.getFieldMatches();\r
- }\r
- else\r
- {\r
- result = new SearchResult();\r
- result.setArtifact( artifact );\r
- resultMap = new HashMap();\r
- }\r
-\r
- // the searched field is either the class, package or file field\r
- if ( field.equals( RepositoryIndex.FLD_CLASSES ) || field.equals( RepositoryIndex.FLD_PACKAGES ) ||\r
- field.equals( RepositoryIndex.FLD_FILES ) )\r
- {\r
- resultMap = getArtifactHits( (String) map.get( field ), field, resultMap, keyword );\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_SHA1 ) ||\r
- ( field.equals( RepositoryIndex.FLD_MD5 ) || field.equals( RepositoryIndex.FLD_PACKAGING ) ) )\r
- {\r
- if ( map.get( field ) != null )\r
- {\r
- // the searched field is either the md5, sha1 or packaging field\r
- if ( ( (String) map.get( field ) ).toLowerCase().equals( keyword.toLowerCase() ) ||\r
- ( (String) map.get( field ) ).toLowerCase().indexOf( keyword.toLowerCase() ) != -1 )\r
- {\r
- resultMap.put( field, map.get( field ) );\r
- }\r
- }\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) ||\r
- field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) || field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) ||\r
- field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )\r
- {\r
- List contents = (List) map.get( field );\r
- List values = new ArrayList();\r
- for ( Iterator it = contents.iterator(); it.hasNext(); )\r
- {\r
- String str = (String) it.next();\r
- if ( str.toLowerCase().equals( keyword.toLowerCase() ) )\r
- {\r
- values.add( str );\r
- }\r
- }\r
- if ( values.size() > 0 )\r
- {\r
- resultMap.put( field, values );\r
- }\r
- }\r
- result.setFieldMatches( resultMap );\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- * Method to create a SearchResult object from the given model. Used for advanced search results\r
- *\r
- * @param model the Model object that contains the values for the search result\r
- * @param field the field whose value is to be retrieved\r
- * @return a SearchResult object\r
- */\r
- private SearchResult createSearchResult( Model model, String field )\r
- {\r
- int index = getListIndex( model.getGroupId(), model.getArtifactId(), model.getVersion(), searchResults );\r
- SearchResult result;\r
- Map map;\r
-\r
- // the object already exists in the search result list\r
- if ( index > -1 )\r
- {\r
- result = (SearchResult) searchResults.get( index );\r
- searchResults.remove( index );\r
- map = result.getFieldMatches();\r
- }\r
- else\r
- {\r
- result = new SearchResult();\r
- result.setArtifact( factory.createBuildArtifact( model.getGroupId(), model.getArtifactId(),\r
- model.getVersion(), model.getPackaging() ) );\r
- map = new HashMap();\r
- }\r
-\r
- // get the matched value with the query term\r
- List values = new ArrayList();\r
- if ( field.equals( RepositoryIndex.FLD_LICENSE_URLS ) )\r
- {\r
- values = getLicenseUrls( model );\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_DEPENDENCIES ) )\r
- {\r
- values = getDependencies( model );\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_PLUGINS_BUILD ) )\r
- {\r
- if ( model.getBuild() != null && model.getBuild().getPlugins() != null )\r
- {\r
- values = getBuildPlugins( model );\r
- }\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_PLUGINS_REPORT ) )\r
- {\r
- if ( model.getReporting() != null && model.getReporting().getPlugins() != null )\r
- {\r
- values = getReportPlugins( model );\r
- }\r
- }\r
- else if ( field.equals( RepositoryIndex.FLD_PACKAGING ) )\r
- {\r
- if ( model.getPackaging() != null )\r
- {\r
- map.put( RepositoryIndex.FLD_PACKAGING, model.getPackaging() );\r
- }\r
- }\r
-\r
- if ( !values.isEmpty() )\r
- {\r
- map.put( field, values );\r
- }\r
- result.setFieldMatches( map );\r
-\r
- return result;\r
- }\r
-\r
- /**\r
- * Method for getting the query term hits or matches in the pom's license urls.\r
- *\r
- * @param model the Model object that contains the pom values\r
- * @return a List of matched license urls\r
- */\r
- private List getLicenseUrls( Model model )\r
- {\r
- List licenseUrls = new ArrayList();\r
- List licenseList = model.getLicenses();\r
- for ( Iterator it = licenseList.iterator(); it.hasNext(); )\r
- {\r
- License license = (License) it.next();\r
- licenseUrls.add( license.getUrl() );\r
- }\r
- return licenseUrls;\r
- }\r
-\r
- /**\r
- * Method for getting the hits or matches in the dependencies specified in the pom\r
- *\r
- * @param model the Model object that contains the pom values\r
- * @return a List of matched dependencies\r
- */\r
- private List getDependencies( Model model )\r
- {\r
- List dependencies = new ArrayList();\r
- List dependencyList = model.getDependencies();\r
- for ( Iterator it = dependencyList.iterator(); it.hasNext(); )\r
- {\r
- Dependency dep = (Dependency) it.next();\r
- dependencies.add( getId( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() ) );\r
- }\r
-\r
- return dependencies;\r
- }\r
-\r
- /**\r
- * Method for getting the hits or matches in the build plugins specified in the pom\r
- *\r
- * @param model the Model object that contains the pom values\r
- * @return a List of matched build plugins\r
- */\r
- private List getBuildPlugins( Model model )\r
- {\r
- List values = new ArrayList();\r
- List plugins = model.getBuild().getPlugins();\r
- for ( Iterator it = plugins.iterator(); it.hasNext(); )\r
- {\r
- Plugin plugin = (Plugin) it.next();\r
- values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );\r
- }\r
-\r
- return values;\r
- }\r
-\r
- /**\r
- * Method for getting the hits or matches in the reporting plugins specified in the pom\r
- *\r
- * @param model the Model object that contains the pom values\r
- * @return a List of matched reporting plugins\r
- */\r
- private List getReportPlugins( Model model )\r
- {\r
- List values = new ArrayList();\r
- List plugins = model.getReporting().getPlugins();\r
- for ( Iterator it = plugins.iterator(); it.hasNext(); )\r
- {\r
- ReportPlugin plugin = (ReportPlugin) it.next();\r
- values.add( getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() ) );\r
- }\r
-\r
- return values;\r
- }\r
-\r
-}\r
+package org.apache.maven.repository.indexing;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.repository.indexing.query.Query;
+
+import java.util.List;
+
+/**
+ * Repository search layer.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ */
+public interface RepositoryIndexSearchLayer
+{
+ /**
+ * The Plexus component role name.
+ */
+ String ROLE = RepositoryIndexSearchLayer.class.getName();
+
+ /**
+ * Method for searching the keyword in all the fields in the index. "Query everything" search.
+ * The index fields will be retrieved and query objects will be constructed using the
+ * optional (OR) CompoundQuery.
+ *
+ * @param keyword
+ * @param index
+ * @return
+ * @throws RepositoryIndexSearchException
+ *
+ */
+ List searchGeneral( String keyword, RepositoryIndex index )
+ throws RepositoryIndexSearchException;
+
+ /**
+ * Method for "advanced search" of the index
+ *
+ * @param qry the query object that will be used for searching the index
+ * @param index
+ * @return
+ * @throws RepositoryIndexSearchException
+ *
+ */
+ List searchAdvanced( Query qry, RepositoryIndex index )
+ throws RepositoryIndexSearchException;
+}
*/
public interface RepositoryIndexSearcher
{
+ /**
+ * Plexus component role name.
+ */
+ String ROLE = RepositoryIndexSearcher.class.getName();
+
/**
* Search the artifact based on the search criteria specified in the query object. Returns a list of
* artifact objects.
*
* @param query The query object that contains the search criteria.
+ * @param index
* @return List
* @throws RepositoryIndexSearchException
*/
- List search( Query query )
+ List search( Query query, RepositoryIndex index )
throws RepositoryIndexSearchException;
}
MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository )
throws RepositoryIndexException;
- /**
- * Method to create an instance of RepositoryIndexSearchLayer
- *
- * @param index the RepositoryIndex object where the query string will be searched
- * @return the RepositoryIndexSearchLayer instance
- */
- RepositoryIndexSearchLayer createRepositoryIndexSearchLayer( RepositoryIndex index );
-
- /**
- * Method to create an instance of DefaultRepositoryIndexSearcher
- *
- * @param index the RepositoryIndex object where the query string will be searched
- * @return the DefaultRepositoryIndexSearcher instance
- */
- DefaultRepositoryIndexSearcher createDefaultRepositoryIndexSearcher( RepositoryIndex index );
}
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearchLayer repoSearchLayer =
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
+
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// search version
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
- List artifacts = repoSearchLayer.searchAdvanced( qry );
+ List artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
// search classes
qry = new SinglePhraseQuery( RepositoryIndex.FLD_CLASSES, "App" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
// search packages
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGES, "groupId" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
// search files
qry = new SinglePhraseQuery( RepositoryIndex.FLD_FILES, "pom.xml" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 3, artifacts.size() );
Iterator iter = artifacts.iterator();
if ( iter.hasNext() )
// search group id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifacts.size() );
iter = artifacts.iterator();
if ( iter.hasNext() )
// search artifact id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); )
{
// search version
qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); )
{
String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); )
{
// search md5 checksum
String md5 = digester.createChecksum( artifact.getFile(), Digester.MD5 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() );
- artifacts = repoSearchLayer.searchAdvanced( qry );
+ artifacts = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifacts.size() );
for ( iter = artifacts.iterator(); iter.hasNext(); )
{
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearchLayer repoSearchLayer =
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
- //RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// Criteria 1: required query
// ex. artifactId=maven-artifact AND groupId=org.apache.maven
rQry.and( qry1 );
rQry.and( qry2 );
- List artifacts = repoSearchLayer.searchAdvanced( rQry );
+ List artifacts = repoSearchLayer.searchAdvanced( rQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
oQry.or( rQry );
oQry.or( qry3 );
- artifacts = repoSearchLayer.searchAdvanced( oQry );
+ artifacts = repoSearchLayer.searchAdvanced( oQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
rQry2.and( rQry );
rQry2.or( oQry5 );
- artifacts = repoSearchLayer.searchAdvanced( rQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( rQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
oQry2.and( rQry2 );
oQry2.and( rQry3 );
- artifacts = repoSearchLayer.searchAdvanced( oQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
rQry4.and( qry8 );
oQry2.and( rQry4 );
- artifacts = repoSearchLayer.searchAdvanced( oQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearchLayer repoSearchLayer =
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
+
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
- // RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
try
{
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "~~~~~" );
- repoSearchLayer.searchAdvanced( qry );
+ repoSearchLayer.searchAdvanced( qry, indexer );
fail( "Must throw an exception on unparseable query." );
}
catch ( RepositoryIndexSearchException re )
}
indexer = factory.createArtifactRepositoryIndex( "target/index/sample", repository );
- repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
try
{
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
- repoSearchLayer.searchAdvanced( qry );
+ repoSearchLayer.searchAdvanced( qry, indexer );
fail( "Must throw an exception on invalid index location." );
}
catch ( RepositoryIndexSearchException re )
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );
+
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
- RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.ARTIFACT + artifact.getId() );
- List artifacts = repoSearcher.search( qry );
+ List artifacts = repoSearcher.search( qry, indexer );
assertEquals( 0, artifacts.size() );
}
createTestIndex();\r
\r
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
+ RepositoryIndexSearchLayer repoSearchLayer =\r
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );\r
+\r
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
- //RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );\r
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );\r
\r
// search last update\r
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_LASTUPDATE, "20051212044643" );\r
- List metadataList = repoSearchLayer.searchAdvanced( qry );\r
+ List metadataList = repoSearchLayer.searchAdvanced( qry, indexer );\r
//assertEquals( 1, metadataList.size() );\r
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )\r
{\r
\r
// search plugin prefix\r
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINPREFIX, "org.apache.maven" );\r
- metadataList = repoSearchLayer.searchAdvanced( qry );\r
+ metadataList = repoSearchLayer.searchAdvanced( qry, indexer );\r
//assertEquals( 1, metadataList.size() );\r
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )\r
{\r
rQry.addQuery( qry1 );\r
rQry.addQuery( qry2 );\r
\r
- metadataList = repoSearchLayer.searchAdvanced( rQry );\r
+ metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );\r
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); )\r
{\r
RepositoryIndexSearchHit hit = (RepositoryIndexSearchHit) iter.next();\r
rQry.addQuery( qry1 );\r
rQry.addQuery( qry2 );\r
\r
- metadataList = repoSearchLayer.searchAdvanced( rQry );\r
+ metadataList = repoSearchLayer.searchAdvanced( rQry, indexer );\r
assertEquals( 0, metadataList.size() );\r
\r
indexer.close();\r
createTestIndex();\r
\r
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
+ RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );\r
+\r
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository );\r
\r
RepositoryMetadata repoMetadata = new GroupRepositoryMetadata( "org.apache.maven" );\r
repoMetadata.setMetadata( readMetadata( repoMetadata ) );\r
indexer.deleteDocument( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );\r
\r
- RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );\r
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, (String) repoMetadata.getKey() );\r
- List metadataList = repoSearcher.search( qry );\r
+ List metadataList = repoSearcher.search( qry, indexer );\r
assertEquals( 0, metadataList.size() );\r
}\r
\r
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearchLayer repoSearchLayer =
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
+
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
- //RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// search version
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "1.0" );
- List artifactList = repoSearchLayer.searchAdvanced( qry );
+ List artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( Iterator iter = artifactList.iterator(); iter.hasNext(); )
{
// search group id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_GROUPID, "org.apache.maven" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() );
Iterator artifacts = artifactList.iterator();
if ( artifacts.hasNext() )
// search artifact id
qry = new SinglePhraseQuery( RepositoryIndex.FLD_ARTIFACTID, "maven-artifact" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
// search version
qry = new SinglePhraseQuery( RepositoryIndex.FLD_VERSION, "2" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
// search packaging
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PACKAGING, "jar" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 3, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
//search license url
qry =
new SinglePhraseQuery( RepositoryIndex.FLD_LICENSE_URLS, "http://www.apache.org/licenses/LICENSE-2.0.txt" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
//search dependencies
qry = new SinglePhraseQuery( RepositoryIndex.FLD_DEPENDENCIES, "org.codehaus.plexus:plexus-utils:1.0.5" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 2, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
//search build plugin
qry =
new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_BUILD, "org.codehaus.modello:modello-maven-plugin:2.0" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
//search reporting plugin
qry = new SinglePhraseQuery( RepositoryIndex.FLD_PLUGINS_REPORT,
"org.apache.maven.plugins:maven-checkstyle-plugin:2.0" );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
String sha1 = digester.createChecksum( artifact.getFile(), Digester.SHA1 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_SHA1, sha1.trim() );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
// search md5 checksum
String md5 = digester.createChecksum( getPomFile( artifact ), Digester.MD5 );
qry = new SinglePhraseQuery( RepositoryIndex.FLD_MD5, md5.trim() );
- artifactList = repoSearchLayer.searchAdvanced( qry );
+ artifactList = repoSearchLayer.searchAdvanced( qry, indexer );
assertEquals( 1, artifactList.size() );
for ( artifacts = artifactList.iterator(); artifacts.hasNext(); )
{
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearchLayer repoSearchLayer =
+ (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );
+
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
- //RepositoryIndexSearcher repoSearchLayer = factory.createDefaultRepositoryIndexSearcher( indexer );
- RepositoryIndexSearchLayer repoSearchLayer = factory.createRepositoryIndexSearchLayer( indexer );
// Criteria 1: required query
// ex. artifactId=maven-artifact AND groupId=org.apache.maven
rQry.and( qry1 );
rQry.and( qry2 );
- List artifacts = repoSearchLayer.searchAdvanced( rQry );
+ List artifacts = repoSearchLayer.searchAdvanced( rQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
oQry.and( rQry );
oQry.or( qry3 );
- artifacts = repoSearchLayer.searchAdvanced( oQry );
+ artifacts = repoSearchLayer.searchAdvanced( oQry, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
rQry2.and( rQry );
rQry2.and( oQry5 );
- artifacts = repoSearchLayer.searchAdvanced( rQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( rQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
oQry2.and( rQry2 );
oQry2.and( rQry3 );
- artifacts = repoSearchLayer.searchAdvanced( oQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
rQry4.and( qry8 );
oQry2.and( rQry4 );
- artifacts = repoSearchLayer.searchAdvanced( oQry2 );
+ artifacts = repoSearchLayer.searchAdvanced( oQry2, indexer );
for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
{
SearchResult result = (SearchResult) iter.next();
createTestIndex();
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ RepositoryIndexSearcher repoSearcher = (RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE );
+
PomRepositoryIndex indexer = factory.createPomRepositoryIndex( indexPath, repository );
+
Model pom = getPom( "org.apache.maven", "maven-artifact", "2.0.1" );
indexer.deleteDocument( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() );
- RepositoryIndexSearcher repoSearcher = factory.createDefaultRepositoryIndexSearcher( indexer );
Query qry = new SinglePhraseQuery( RepositoryIndex.FLD_ID, RepositoryIndex.POM + pom.getId() );
- List artifactList = repoSearcher.search( qry );
+ List artifactList = repoSearcher.search( qry, indexer );
assertEquals( 0, artifactList.size() );
}
{\r
createTestIndex();\r
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );\r
+ RepositoryIndexSearchLayer searchLayer = (RepositoryIndexSearchLayer) lookup( RepositoryIndexSearchLayer.ROLE );\r
+\r
ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );\r
- RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( indexer );\r
\r
- List returnList = searchLayer.searchGeneral( "org.apache.maven" );\r
+ List returnList = searchLayer.searchGeneral( "org.apache.maven", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
//POM license urls\r
- returnList = searchLayer.searchGeneral( "http://www.apache.org/licenses/LICENSE-2.0.txt" );\r
+ returnList = searchLayer.searchGeneral( "http://www.apache.org/licenses/LICENSE-2.0.txt", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
//POM dependency\r
- returnList = searchLayer.searchGeneral( "org.codehaus.plexus:plexus-utils:1.0.5" );\r
+ returnList = searchLayer.searchGeneral( "org.codehaus.plexus:plexus-utils:1.0.5", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
// POM reporting plugin\r
- returnList = searchLayer.searchGeneral( "org.apache.maven.plugins:maven-checkstyle-plugin:2.0" );\r
+ returnList = searchLayer.searchGeneral( "org.apache.maven.plugins:maven-checkstyle-plugin:2.0", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
// POM build plugin\r
- returnList = searchLayer.searchGeneral( "org.codehaus.modello:modello-maven-plugin:2.0" );\r
+ returnList = searchLayer.searchGeneral( "org.codehaus.modello:modello-maven-plugin:2.0", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
//maven-artifact-2.0.1.jar MD5 checksum\r
- returnList = searchLayer.searchGeneral( "F5A934ABBBC70A33136D89A996B9D5C09F652766" );\r
+ returnList = searchLayer.searchGeneral( "F5A934ABBBC70A33136D89A996B9D5C09F652766", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
//maven-artifact-2.0.1.jar SHA1 checksum\r
- returnList = searchLayer.searchGeneral( "AE55D9B5720E11B6CF19FE1E31A42E51" );\r
+ returnList = searchLayer.searchGeneral( "AE55D9B5720E11B6CF19FE1E31A42E51", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
\r
//packaging jar\r
- returnList = searchLayer.searchGeneral( "jar" );\r
+ returnList = searchLayer.searchGeneral( "jar", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
}\r
}\r
\r
- returnList = searchLayer.searchGeneral( "test" );\r
+ returnList = searchLayer.searchGeneral( "test", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
assertEquals( "test", result.getArtifact().getGroupId() );\r
}\r
\r
- returnList = searchLayer.searchGeneral( "test-artifactId" );\r
+ returnList = searchLayer.searchGeneral( "test-artifactId", indexer );\r
for ( Iterator iter = returnList.iterator(); iter.hasNext(); )\r
{\r
SearchResult result = (SearchResult) iter.next();\r
*/\r
private RepositoryIndexingFactory factory;\r
\r
+ /**\r
+ * @plexus.requirement\r
+ */\r
+ private RepositoryIndexSearchLayer searchLayer;\r
+\r
/**\r
* @plexus.requirement\r
*/\r
\r
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );\r
\r
- RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( index );\r
-\r
- searchResult = searchLayer.searchGeneral( searchString );\r
+ searchResult = searchLayer.searchGeneral( searchString, index );\r
\r
return SUCCESS;\r
}\r
*/
private ArtifactRepositoryFactory repositoryFactory;
+ /**
+ * @plexus.requirement
+ */
+ private RepositoryIndexSearchLayer searchLayer;
+
/**
* @plexus.requirement
*/
ArtifactRepositoryIndex index = factory.createArtifactRepositoryIndex( indexPath, repository );
- RepositoryIndexSearchLayer searchLayer = factory.createRepositoryIndexSearchLayer( index );
-
- searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ) );
+ searchResult = searchLayer.searchAdvanced( new SinglePhraseQuery( key, searchTerm ), index );
return SUCCESS;
}