Submitted by: Maria Odea Ching Applied patch for indexing metadata and for searching the metadata index git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@369402 13f79535-47bb-0310-9956-ffa450edef68tags/archiva-0.9-alpha-1
@@ -32,7 +32,6 @@ | |||
<dependency> | |||
<groupId>org.apache.maven</groupId> | |||
<artifactId>maven-artifact-manager</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.maven</groupId> | |||
@@ -55,5 +54,9 @@ | |||
<groupId>org.apache.maven.repository</groupId> | |||
<artifactId>maven-repository-utils</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.maven</groupId> | |||
<artifactId>maven-repository-metadata</artifactId> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -28,6 +28,7 @@ import org.apache.maven.repository.indexing.query.CompoundQuery; | |||
import org.apache.maven.repository.indexing.query.CompoundQueryTerm; | |||
import org.apache.maven.repository.indexing.query.Query; | |||
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | |||
import org.apache.maven.repository.indexing.query.RangeQuery; | |||
import org.codehaus.plexus.logging.AbstractLogEnabled; | |||
import java.io.IOException; | |||
@@ -158,6 +159,21 @@ public abstract class AbstractRepositoryIndexSearcher | |||
} | |||
retVal = booleanQuery; | |||
} | |||
else if( query instanceof RangeQuery ) | |||
{ | |||
RangeQuery rq = (RangeQuery) query; | |||
List queries = rq.getQueries(); | |||
Iterator iter = queries.iterator(); | |||
Term begin = null, end = null; | |||
if(queries.size() == 2) | |||
{ | |||
SinglePhraseQuery qry = (SinglePhraseQuery) iter.next(); | |||
begin = new Term( qry.getField(), qry.getValue() ); | |||
qry = ( SinglePhraseQuery ) iter.next(); | |||
end = new Term( qry.getField(), qry.getValue() ); | |||
} | |||
retVal = new org.apache.lucene.search.RangeQuery( begin, end, rq.isInclusive() ); | |||
} | |||
else | |||
{ | |||
SinglePhraseQuery singlePhraseQuery = (SinglePhraseQuery) query; |
@@ -71,4 +71,14 @@ public class DefaultRepositoryIndexingFactory | |||
{ | |||
return new PomRepositoryIndexSearcher( index, artifactFactory ); | |||
} | |||
public MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository) | |||
throws RepositoryIndexException{ | |||
return new MetadataRepositoryIndex(indexPath, repository); | |||
} | |||
public MetadataRepositoryIndexSearcher createMetadataRepositoryIndexSearcher( MetadataRepositoryIndex index ) | |||
{ | |||
return new MetadataRepositoryIndexSearcher( index, artifactFactory ); | |||
} | |||
} |
@@ -0,0 +1,180 @@ | |||
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.lucene.analysis.Analyzer; | |||
import org.apache.lucene.analysis.standard.StandardAnalyzer; | |||
import org.apache.lucene.document.Document; | |||
import org.apache.lucene.document.Field; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; | |||
import org.apache.maven.artifact.repository.metadata.Metadata; | |||
import org.apache.maven.artifact.repository.metadata.Versioning; | |||
import org.apache.maven.artifact.repository.metadata.Plugin; | |||
import java.util.List; | |||
import java.util.Iterator; | |||
import java.io.IOException; | |||
/** | |||
* This class indexes the metadata in the repository. | |||
*/ | |||
public class MetadataRepositoryIndex | |||
extends AbstractRepositoryIndex | |||
{ | |||
private static final String FLD_LASTUPDATE = "lastUpdate"; | |||
private static final String FLD_PLUGINPREFIX = "pluginPrefix"; | |||
private static final String FLD_METADATAPATH = "path"; | |||
private static final String FLD_GROUPID = "groupId"; | |||
private static final String FLD_ARTIFACTID = "artifactId"; | |||
private static final String FLD_VERSION = "version"; | |||
private static final String[] FIELDS = {FLD_METADATAPATH, FLD_PLUGINPREFIX, FLD_LASTUPDATE, | |||
FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION}; | |||
/** | |||
* Constructor | |||
* @param indexPath the path to the index | |||
* @param repository the repository where the metadata to be indexed is located | |||
* @throws RepositoryIndexException | |||
*/ | |||
public MetadataRepositoryIndex( String indexPath, ArtifactRepository repository ) | |||
throws RepositoryIndexException | |||
{ | |||
super( indexPath, repository, FIELDS ); | |||
} | |||
/** | |||
* Get the field names to be used in the index | |||
* @return array of strings | |||
*/ | |||
public String[] getIndexFields() | |||
{ | |||
return FIELDS; | |||
} | |||
/** | |||
* Returns the analyzer used for indexing | |||
* @return Analyzer object | |||
*/ | |||
public Analyzer getAnalyzer() | |||
{ | |||
return new StandardAnalyzer(); | |||
} | |||
/** | |||
* Index the paramater object | |||
* @param obj | |||
* @throws RepositoryIndexException | |||
*/ | |||
public void index( Object obj ) throws RepositoryIndexException | |||
{ | |||
if ( obj instanceof RepositoryMetadata ) | |||
{ | |||
indexMetadata( (RepositoryMetadata) obj ); | |||
} | |||
else | |||
{ | |||
throw new RepositoryIndexException( | |||
"This instance of indexer cannot index instances of " + obj.getClass().getName() ); | |||
} | |||
} | |||
/** | |||
* Index the contents of the specified RepositoryMetadata paramter object | |||
* @param repoMetadata the metadata object to be indexed | |||
* @throws RepositoryIndexException | |||
*/ | |||
private void indexMetadata( RepositoryMetadata repoMetadata ) throws RepositoryIndexException | |||
{ | |||
if ( !isOpen() ) | |||
{ | |||
throw new RepositoryIndexException( "Unable to add artifact index on a closed index" ); | |||
} | |||
//get lastUpdated from Versioning (specified in Metadata object) | |||
//get pluginPrefixes from Plugin (spcified in Metadata object) -----> concatenate/append??? | |||
//get the metadatapath: check where metadata is located, then concatenate the groupId, | |||
// artifactId, version based on its location | |||
Document doc = new Document(); | |||
String path = ""; | |||
if( repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory()) | |||
{ | |||
path = repoMetadata.getGroupId() + "/"; | |||
} | |||
else if(!repoMetadata.storedInGroupDirectory() && !repoMetadata.storedInArtifactVersionDirectory()) | |||
{ | |||
path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/"; | |||
} | |||
else if(!repoMetadata.storedInGroupDirectory() && repoMetadata.storedInArtifactVersionDirectory()) | |||
{ | |||
path = repoMetadata.getGroupId() + "/" + repoMetadata.getArtifactId() + "/" + repoMetadata.getBaseVersion() + "/"; | |||
} | |||
//@todo use localfilename or remotefilename to get the path??? | |||
path = path + repoMetadata.getRemoteFilename(); | |||
doc.add( Field.Text( FLD_METADATAPATH, path) ); | |||
Metadata metadata = repoMetadata.getMetadata(); | |||
Versioning versioning = metadata.getVersioning(); | |||
if( versioning != null ) | |||
{ | |||
doc.add( Field.Text( FLD_LASTUPDATE, versioning.getLastUpdated() ) ); | |||
} | |||
List plugins = metadata.getPlugins(); | |||
String pluginAppended = ""; | |||
for( Iterator iter = plugins.iterator(); iter.hasNext(); ) | |||
{ | |||
Plugin plugin = (Plugin) iter.next(); | |||
if( plugin.getPrefix() != null && !plugin.getPrefix().equals("") ) | |||
{ | |||
pluginAppended = plugin.getPrefix() + " "; | |||
} | |||
} | |||
doc.add( Field.Text( FLD_PLUGINPREFIX, pluginAppended ) ); | |||
doc.add( Field.UnIndexed( FLD_GROUPID, metadata.getGroupId() ) ); | |||
if( metadata.getArtifactId() != null && !metadata.getArtifactId().equals("") ) | |||
{ | |||
doc.add( Field.UnIndexed( FLD_ARTIFACTID, metadata.getArtifactId() ) ); | |||
} | |||
if( metadata.getVersion() != null && !metadata.getVersion().equals("") ) | |||
{ | |||
doc.add( Field.UnIndexed( FLD_VERSION, metadata.getVersion() ) ); | |||
} | |||
try | |||
{ | |||
getIndexWriter().addDocument( doc ); | |||
} | |||
catch ( IOException e ) | |||
{ | |||
throw new RepositoryIndexException( "Error opening index", e ); | |||
} | |||
} | |||
public boolean isKeywordField( String field ){ | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,174 @@ | |||
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.lucene.document.Document; | |||
import org.apache.maven.artifact.factory.ArtifactFactory; | |||
import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; | |||
import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; | |||
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; | |||
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; | |||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; | |||
import org.apache.maven.artifact.Artifact; | |||
import java.net.URL; | |||
import java.io.InputStream; | |||
import java.io.File; | |||
import java.io.InputStreamReader; | |||
import java.util.*; | |||
/** | |||
* This class searches the specified index given the search/query criteria. | |||
* | |||
*/ | |||
public class MetadataRepositoryIndexSearcher | |||
extends AbstractRepositoryIndexSearcher | |||
{ | |||
private ArtifactFactory artifactFactory; | |||
private static final String FLD_METADATAPATH = "path"; | |||
private static final String FLD_GROUPID = "groupId"; | |||
private static final String FLD_ARTIFACTID = "artifactId"; | |||
private static final String FLD_VERSION = "version"; | |||
private static final String GROUP_TYPE = "GROUP"; | |||
private static final String ARTIFACT_TYPE = "ARTIFACT"; | |||
private static final String SNAPSHOT_TYPE = "SNAPSHOT"; | |||
/** | |||
* Constructor | |||
* @param index the index object to be set | |||
* @param factory | |||
*/ | |||
public MetadataRepositoryIndexSearcher( MetadataRepositoryIndex index, ArtifactFactory factory) | |||
{ | |||
super(index); | |||
artifactFactory = factory; | |||
} | |||
/** | |||
* Create object to be returned by the search based on the document | |||
* @param doc | |||
* @return Object | |||
*/ | |||
protected Object createSearchedObjectFromIndexDocument( Document doc ) | |||
{ | |||
List pathParts = new ArrayList(); | |||
StringTokenizer st = new StringTokenizer( doc.get( FLD_METADATAPATH ), "/\\" ); | |||
while ( st.hasMoreTokens() ) | |||
{ | |||
pathParts.add( st.nextToken() ); | |||
} | |||
Collections.reverse( pathParts ); | |||
Iterator it = pathParts.iterator(); | |||
String metadataFile = (String) it.next(); | |||
String tmpDir = (String) it.next(); | |||
String metadataType = ""; | |||
if( tmpDir.equals( doc.get( FLD_GROUPID ) ) ) | |||
{ | |||
metadataType = GROUP_TYPE; | |||
} | |||
else if( tmpDir.equals( doc.get( FLD_ARTIFACTID ) ) ) | |||
{ | |||
metadataType = ARTIFACT_TYPE; | |||
} | |||
else | |||
{ | |||
metadataType = SNAPSHOT_TYPE; | |||
} | |||
RepositoryMetadata repoMetadata = null; | |||
try{ | |||
repoMetadata = getMetadata(doc.get( FLD_GROUPID ), doc.get( FLD_ARTIFACTID ), doc.get( FLD_VERSION ), metadataFile, metadataType ); | |||
} | |||
catch(Exception e) | |||
{ | |||
//@todo | |||
} | |||
return repoMetadata; | |||
} | |||
/** | |||
* Create RepositoryMetadata object. | |||
* | |||
* @param groupId the groupId to be set | |||
* @param artifactId the artifactId to be set | |||
* @param version the version to be set | |||
* @param filename the name of the metadata file | |||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) | |||
* @return RepositoryMetadata | |||
* @throws Exception | |||
*/ | |||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, String metadataType) | |||
throws Exception | |||
{ | |||
RepositoryMetadata repoMetadata = null; | |||
URL url; | |||
InputStream is = null; | |||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | |||
//group metadata | |||
if( metadataType.equals( GROUP_TYPE ) ) | |||
{ | |||
url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new GroupRepositoryMetadata(groupId); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
//artifact metadata | |||
else if( metadataType.equals( ARTIFACT_TYPE ) ) | |||
{ | |||
url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
//snapshot/version metadata | |||
else if( metadataType.equals( SNAPSHOT_TYPE ) ) | |||
{ | |||
url = new File( index.getRepository().getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
return repoMetadata; | |||
} | |||
/** | |||
* Create artifact object. | |||
* @param groupId the groupId of the artifact | |||
* @param artifactId the artifactId of the artifact | |||
* @param version the version of the artifact | |||
* @return Artifact | |||
* @throws Exception | |||
*/ | |||
private Artifact getArtifact( String groupId, String artifactId, String version ) | |||
throws Exception | |||
{ | |||
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" ); | |||
} | |||
} |
@@ -64,4 +64,10 @@ public interface RepositoryIndexingFactory | |||
* @return the PomRepositoryIndexSearcher instance | |||
*/ | |||
PomRepositoryIndexSearcher createPomRepositoryIndexSearcher( PomRepositoryIndex index ); | |||
MetadataRepositoryIndex createMetadataRepositoryIndex( String indexPath, ArtifactRepository repository) | |||
throws RepositoryIndexException; | |||
MetadataRepositoryIndexSearcher createMetadataRepositoryIndexSearcher( MetadataRepositoryIndex index ); | |||
} |
@@ -0,0 +1,52 @@ | |||
package org.apache.maven.repository.indexing.query; | |||
/* | |||
* 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 java.util.List; | |||
import java.util.ArrayList; | |||
/** | |||
* Query object that handles range queries for dates. | |||
* @author Maria Odea Ching | |||
*/ | |||
public class RangeQuery | |||
implements Query | |||
{ | |||
List queries = new ArrayList(); | |||
private boolean inclusive; | |||
public RangeQuery( boolean inclusive) | |||
{ | |||
this.inclusive = inclusive; | |||
} | |||
public void addQuery( Query qry ) | |||
{ | |||
queries.add( qry ); | |||
} | |||
public List getQueries() | |||
{ | |||
return queries; | |||
} | |||
public boolean isInclusive() | |||
{ | |||
return inclusive; | |||
} | |||
} |
@@ -0,0 +1,249 @@ | |||
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.artifact.Artifact; | |||
import org.apache.maven.artifact.factory.ArtifactFactory; | |||
import org.apache.maven.artifact.repository.ArtifactRepository; | |||
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; | |||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; | |||
import org.apache.maven.artifact.repository.metadata.*; | |||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; | |||
import org.apache.maven.repository.indexing.query.Query; | |||
import org.apache.maven.repository.indexing.query.RangeQuery; | |||
import org.apache.maven.repository.indexing.query.SinglePhraseQuery; | |||
import org.codehaus.plexus.PlexusTestCase; | |||
import org.codehaus.plexus.util.FileUtils; | |||
import java.io.File; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.net.URL; | |||
import java.util.Iterator; | |||
import java.util.List; | |||
/** | |||
* This class tests the MetadataRepositoryIndex. | |||
*/ | |||
public class MetadataRepositoryIndexingTest | |||
extends PlexusTestCase | |||
{ | |||
private ArtifactRepository repository; | |||
private String indexPath; | |||
private static final String FLD_LASTUPDATE = "lastUpdate"; | |||
private static final String FLD_PLUGINPREFIX = "pluginPrefix"; | |||
private static final String GROUP_TYPE = "GROUP"; | |||
private static final String ARTIFACT_TYPE = "ARTIFACT"; | |||
private static final String SNAPSHOT_TYPE = "SNAPSHOT"; | |||
private MetadataRepositoryIndex indexer; | |||
private ArtifactFactory artifactFactory; | |||
/** | |||
* Set up. | |||
* @throws Exception | |||
*/ | |||
public void setUp() throws Exception | |||
{ | |||
super.setUp(); | |||
File repositoryDirectory = getTestFile( "src/test/repository" ); | |||
String repoDir = repositoryDirectory.toURL().toString(); | |||
ArtifactRepositoryLayout layout = ( ArtifactRepositoryLayout ) lookup( ArtifactRepositoryLayout.ROLE, "default" ); | |||
ArtifactRepositoryFactory repoFactory = ( ArtifactRepositoryFactory ) lookup( ArtifactRepositoryFactory.ROLE ); | |||
repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null ); | |||
indexPath = "target/index/metadata"; | |||
FileUtils.deleteDirectory( indexPath ); | |||
} | |||
/** | |||
* Tear down. | |||
* @throws Exception | |||
*/ | |||
public void tearDown() throws Exception | |||
{ | |||
repository = null; | |||
super.tearDown(); | |||
} | |||
/** | |||
* Create the test index. | |||
* @throws Exception | |||
*/ | |||
private void createTestIndex() throws Exception | |||
{ | |||
RepositoryIndexingFactory factory = ( RepositoryIndexingFactory ) lookup( RepositoryIndexingFactory.ROLE ); | |||
indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||
RepositoryMetadata repoMetadata = getMetadata( "org.apache.maven", null, null, "maven-metadata.xml", GROUP_TYPE ); | |||
indexer.index( repoMetadata ); | |||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", ARTIFACT_TYPE ); | |||
indexer.index( repoMetadata ); | |||
repoMetadata = getMetadata( "org.apache.maven", "maven-artifact", "2.0.1", "maven-metadata.xml", SNAPSHOT_TYPE ); | |||
indexer.index( repoMetadata ); | |||
indexer.optimize(); | |||
indexer.close(); | |||
} | |||
/** | |||
* Test the ArtifactRepositoryIndexSearcher using a single-phrase search. | |||
* | |||
* @throws Exception | |||
*/ | |||
public void testSearchSingle() | |||
throws Exception | |||
{ | |||
createTestIndex(); | |||
RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE ); | |||
MetadataRepositoryIndex indexer = factory.createMetadataRepositoryIndex( indexPath, repository ); | |||
RepositoryIndexSearcher repoSearcher = factory.createMetadataRepositoryIndexSearcher( indexer ); | |||
// search last update | |||
org.apache.maven.repository.indexing.query.Query qry = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212044643" ); | |||
List metadataList = repoSearcher.search( qry ); | |||
assertEquals( 1, metadataList.size() ); | |||
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | |||
{ | |||
RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); | |||
Metadata metadata = repoMetadata.getMetadata(); | |||
Versioning versioning = metadata.getVersioning(); | |||
assertEquals( "20051212044643", versioning.getLastUpdated() ); | |||
} | |||
// search plugin prefix | |||
qry = new SinglePhraseQuery( FLD_PLUGINPREFIX, "org.apache.maven" ); | |||
metadataList = repoSearcher.search( qry ); | |||
assertEquals( 1, metadataList.size() ); | |||
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | |||
{ | |||
RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); | |||
Metadata metadata = repoMetadata.getMetadata(); | |||
List plugins = metadata.getPlugins(); | |||
for( Iterator it = plugins.iterator(); it.hasNext(); ) | |||
{ | |||
Plugin plugin = (Plugin) it.next(); | |||
assertEquals( "org.apache.maven", plugin.getPrefix() ); | |||
} | |||
} | |||
// search last update using INCLUSIVE Range Query | |||
Query qry1 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212000000" ); | |||
Query qry2 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212235959"); | |||
RangeQuery rQry = new RangeQuery( true ); | |||
rQry.addQuery( qry1 ); | |||
rQry.addQuery( qry2 ); | |||
metadataList = repoSearcher.search( rQry ); | |||
for ( Iterator iter = metadataList.iterator(); iter.hasNext(); ) | |||
{ | |||
RepositoryMetadata repoMetadata = (RepositoryMetadata) iter.next(); | |||
Metadata metadata = repoMetadata.getMetadata(); | |||
Versioning versioning = metadata.getVersioning(); | |||
assertEquals( "20051212044643", versioning.getLastUpdated() ); | |||
} | |||
// search last update using EXCLUSIVE Range Query | |||
qry1 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212000000" ); | |||
qry2 = new SinglePhraseQuery( FLD_LASTUPDATE, "20051212044643"); | |||
rQry = new RangeQuery( false ); | |||
rQry.addQuery( qry1 ); | |||
rQry.addQuery( qry2 ); | |||
metadataList = repoSearcher.search( rQry ); | |||
assertEquals( metadataList.size(), 0 ); | |||
indexer.close(); | |||
} | |||
/** | |||
* Create RepositoryMetadata object. | |||
* | |||
* @param groupId the groupId to be set | |||
* @param artifactId the artifactId to be set | |||
* @param version the version to be set | |||
* @param filename the name of the metadata file | |||
* @param metadataType the type of RepositoryMetadata object to be created (GROUP, ARTIFACT or SNAPSHOT) | |||
* @return RepositoryMetadata | |||
* @throws Exception | |||
*/ | |||
private RepositoryMetadata getMetadata( String groupId, String artifactId, String version, String filename, String metadataType) | |||
throws Exception | |||
{ | |||
RepositoryMetadata repoMetadata = null; | |||
URL url; | |||
InputStream is = null; | |||
MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); | |||
//group metadata | |||
if( metadataType.equals( GROUP_TYPE ) ) | |||
{ | |||
url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new GroupRepositoryMetadata(groupId); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
//artifact metadata | |||
else if( metadataType.equals( ARTIFACT_TYPE ) ) | |||
{ | |||
url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new ArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
//snapshot/version metadata | |||
else if( metadataType.equals( SNAPSHOT_TYPE ) ) | |||
{ | |||
url = new File( repository.getBasedir() + groupId.replace('.', '/') + "/" + artifactId + "/" + version + "/" + filename ).toURL(); | |||
is = url.openStream(); | |||
repoMetadata = new SnapshotArtifactRepositoryMetadata( getArtifact( groupId, artifactId, version ) ); | |||
repoMetadata.setMetadata( metadataReader.read( new InputStreamReader( is ) ) ); | |||
} | |||
return repoMetadata; | |||
} | |||
/** | |||
* Create artifact object. | |||
* @param groupId the groupId of the artifact | |||
* @param artifactId the artifactId of the artifact | |||
* @param version the version of the artifact | |||
* @return Artifact | |||
* @throws Exception | |||
*/ | |||
private Artifact getArtifact( String groupId, String artifactId, String version ) | |||
throws Exception | |||
{ | |||
if ( artifactFactory == null ) | |||
{ | |||
artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); | |||
} | |||
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" ); | |||
} | |||
} |
@@ -0,0 +1,5 @@ | |||
<metadata> | |||
<groupId>org.apache.maven</groupId> | |||
<artifactId>maven-artifact</artifactId> | |||
<version>2.0.1</version> | |||
</metadata> |
@@ -0,0 +1,12 @@ | |||
<metadata> | |||
<groupId>org.apache.maven</groupId> | |||
<artifactId>maven-artifact</artifactId> | |||
<version>2.0.1</version> | |||
<versioning> | |||
<release>2.0.1</release> | |||
<versions> | |||
<version>2.0.1</version> | |||
</versions> | |||
<lastUpdated>20051212044643</lastUpdated> | |||
</versioning> | |||
</metadata> |
@@ -0,0 +1,9 @@ | |||
<metadata> | |||
<groupId>org.apache.maven</groupId> | |||
<plugins> | |||
<plugin> | |||
<prefix>org.apache.maven</prefix> | |||
<artifactId>org.apache.maven-maven-plugin</artifactId> | |||
</plugin> | |||
</plugins> | |||
</metadata> |