You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by oc...@apache.org on 2009/01/22 10:23:02 UTC
svn commit: r736595 - in
/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src:
main/java/org/apache/archiva/ main/java/org/apache/archiva/consumers/
main/java/org/apache/archiva/consumers/l...
Author: oching
Date: Thu Jan 22 01:23:01 2009
New Revision: 736595
URL: http://svn.apache.org/viewvc?rev=736595&view=rev
Log:
[MRM-749]
o re-packaged NexusIndexerConsumer and index discovered artifact using Nexus' IndexerEngine
o added test for NexusIndexerConsumer
Added:
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java
Removed:
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/NexusIndexerConsumer.java
Modified:
archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
Added: archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
URL: http://svn.apache.org/viewvc/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java?rev=736595&view=auto
==============================================================================
--- archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java (added)
+++ archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java Thu Jan 22 01:23:01 2009
@@ -0,0 +1,168 @@
+package org.apache.archiva.consumers.lucene;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
+import org.apache.maven.archiva.consumers.ConsumerException;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonatype.nexus.index.ArtifactContext;
+import org.sonatype.nexus.index.ArtifactContextProducer;
+import org.sonatype.nexus.index.DefaultArtifactContextProducer;
+import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.context.IndexingContext;
+import org.sonatype.nexus.index.context.UnsupportedExistingLuceneIndexException;
+import org.sonatype.nexus.index.creator.IndexerEngine;
+import org.sonatype.nexus.index.packer.IndexPacker;
+
+/**
+ * Consumer for indexing the repository to provide search and IDE integration features.
+ */
+public class NexusIndexerConsumer
+ extends AbstractMonitoredConsumer
+ implements KnownRepositoryContentConsumer
+{
+ private static final Logger log = LoggerFactory.getLogger( NexusIndexerConsumer.class );
+
+ private final NexusIndexer indexer;
+
+ private final ArtifactContextProducer artifactContextProducer;
+
+ private final IndexPacker indexPacker;
+
+ private ManagedRepositoryConfiguration repository;
+
+ private ManagedDefaultRepositoryContent repositoryContent;
+
+ private IndexingContext context;
+
+ private File managedRepository;
+
+ private IndexerEngine indexerEngine;
+
+ public NexusIndexerConsumer( NexusIndexer indexer, IndexPacker indexPacker, IndexerEngine indexerEngine )
+ {
+ this.indexer = indexer;
+ this.indexPacker = indexPacker;
+ this.indexerEngine = indexerEngine;
+ this.artifactContextProducer = new DefaultArtifactContextProducer();
+ }
+
+ public String getDescription()
+ {
+ return "Indexes the repository to provide search and IDE integration features";
+ }
+
+ public String getId()
+ {
+ return "index-content";
+ }
+
+ public boolean isPermanent()
+ {
+ return false;
+ }
+
+ public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered )
+ throws ConsumerException
+ {
+ this.repository = repository;
+ managedRepository = new File( repository.getLocation() );
+ File indexDirectory = new File( managedRepository, ".indexer" );
+
+ repositoryContent = new ManagedDefaultRepositoryContent();
+ repositoryContent.setRepository( repository );
+
+ synchronized ( indexer )
+ {
+ try
+ {
+ context =
+ indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository,
+ indexDirectory, null, null, NexusIndexer.FULL_INDEX );
+ context.setSearchable( repository.isScanned() );
+
+ indexerEngine.beginIndexing( context );
+ }
+ catch ( UnsupportedExistingLuceneIndexException e )
+ {
+ log.error( "Could not create index at " + indexDirectory.getAbsoluteFile(), e );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Could not create index at " + indexDirectory.getAbsoluteFile(), e );
+ }
+ }
+ }
+
+ public void processFile( String path )
+ throws ConsumerException
+ {
+ File artifactFile = new File( managedRepository, path );
+
+ ArtifactContext artifactContext = artifactContextProducer.getArtifactContext( context, artifactFile );
+ if ( artifactContext != null )
+ {
+ try
+ {
+ indexer.artifactDiscovered( artifactContext, context );
+
+ indexerEngine.index( context, artifactContext );
+ }
+ catch ( IOException e )
+ {
+ throw new ConsumerException( e.getMessage(), e );
+ }
+ }
+ }
+
+ public void completeScan()
+ {
+ final File indexLocation = new File( managedRepository, ".index" );
+ try
+ {
+ indexPacker.packIndex( context, indexLocation );
+ indexerEngine.endIndexing( context );
+ }
+ catch ( IOException e )
+ {
+ log.error( "Could not pack index" + indexLocation.getAbsolutePath(), e );
+ }
+ }
+
+ public List<String> getExcludes()
+ {
+ return new ArrayList<String>();
+ }
+
+ public List<String> getIncludes()
+ {
+ return Arrays.asList( "**/*" );
+ }
+}
Modified: archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml?rev=736595&r1=736594&r2=736595&view=diff
==============================================================================
--- archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml (original)
+++ archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml Thu Jan 22 01:23:01 2009
@@ -3,8 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
- <bean id="indexerConsumer" class="org.apache.maven.archiva.consumers.lucene.NexusIndexerConsumer">
+ <bean id="indexerConsumer" class="org.apache.archiva.consumers.lucene.NexusIndexerConsumer">
<constructor-arg ref="nexusIndexer"/>
<constructor-arg ref="indexPacker"/>
+ <constructor-arg ref="indexerEngine"/>
</bean>
</beans>
\ No newline at end of file
Added: archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java
URL: http://svn.apache.org/viewvc/archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java?rev=736595&view=auto
==============================================================================
--- archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java (added)
+++ archiva/branches/archiva-nexus-indexer/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/test/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumerTest.java Thu Jan 22 01:23:01 2009
@@ -0,0 +1,140 @@
+package org.apache.archiva.consumers.lucene;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.io.File;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.BooleanClause.Occur;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.sonatype.nexus.index.ArtifactInfo;
+import org.sonatype.nexus.index.FlatSearchRequest;
+import org.sonatype.nexus.index.FlatSearchResponse;
+import org.sonatype.nexus.index.NexusIndexer;
+import org.sonatype.nexus.index.creator.IndexerEngine;
+import org.sonatype.nexus.index.packer.IndexPacker;
+
+public class NexusIndexerConsumerTest
+ extends PlexusInSpringTestCase
+{
+ private KnownRepositoryContentConsumer nexusIndexerConsumer;
+
+ private ManagedRepositoryConfiguration repositoryConfig;
+
+ private NexusIndexer nexusIndexer;
+
+ private IndexPacker indexPacker;
+
+ private IndexerEngine indexerEngine;
+
+ @Override
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ nexusIndexer = ( NexusIndexer ) lookup( NexusIndexer.class );
+
+ indexPacker = ( IndexPacker ) lookup( IndexPacker.class );
+
+ indexerEngine = ( IndexerEngine ) lookup( IndexerEngine.class );
+
+ nexusIndexerConsumer = new NexusIndexerConsumer( nexusIndexer, indexPacker, indexerEngine );
+
+ repositoryConfig = new ManagedRepositoryConfiguration();
+ repositoryConfig.setId( "test-repo" );
+ repositoryConfig.setLocation( getBasedir() + "/target/test-classes/test-repo" );
+ repositoryConfig.setLayout( "default" );
+ repositoryConfig.setName( "Test Repository" );
+ repositoryConfig.setScanned( true );
+ repositoryConfig.setSnapshots( false );
+ repositoryConfig.setReleases( true );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ // delete created index in the repository
+ File indexDir = new File( repositoryConfig.getLocation(), ".indexer" );
+ FileUtils.deleteDirectory( indexDir );
+ assertFalse( indexDir.exists() );
+
+ indexDir = new File( repositoryConfig.getLocation(), ".index" );
+ FileUtils.deleteDirectory( indexDir );
+ assertFalse( indexDir.exists() );
+
+ super.tearDown();
+ }
+
+ public void testIndexerIndexArtifact()
+ throws Exception
+ {
+ // begin scan
+ Date now = Calendar.getInstance().getTime();
+ nexusIndexerConsumer.beginScan( repositoryConfig, now );
+
+ // process file
+ nexusIndexerConsumer.processFile( "org/apache/archiva/archiva-index-methods-jar-test/1.0/archiva-index-methods-jar-test-1.0.jar" );
+
+ // end scan
+ nexusIndexerConsumer.completeScan();
+
+ // search!
+ BooleanQuery q = new BooleanQuery();
+ q.add( nexusIndexer.constructQuery( ArtifactInfo.GROUP_ID, "org.apache.archiva" ), Occur.SHOULD );
+ q.add( nexusIndexer.constructQuery( ArtifactInfo.ARTIFACT_ID, "archiva-index-methods-jar-test" ), Occur.SHOULD );
+
+ FlatSearchRequest request = new FlatSearchRequest( q );
+ FlatSearchResponse response = nexusIndexer.searchFlat( request );
+
+ assertTrue( new File( repositoryConfig.getLocation(), ".indexer" ).exists() );
+ assertTrue( new File( repositoryConfig.getLocation(), ".index" ).exists() );
+ assertEquals( 1, response.getTotalHits() );
+
+ Set<ArtifactInfo> results = response.getResults();
+
+ ArtifactInfo artifactInfo = (ArtifactInfo) results.iterator().next();
+ assertEquals( "org.apache.archiva", artifactInfo.groupId );
+ assertEquals( "archiva-index-methods-jar-test", artifactInfo.artifactId );
+ assertEquals( "test-repo", artifactInfo.repository );
+ }
+
+ /*public void testIndexerIndexPom()
+ throws Exception
+ {
+ // begin scan
+ Date now = Calendar.getInstance().getTime();
+ nexusIndexerConsumer.beginScan( repositoryConfig, now );
+
+ // process file
+ //nexusIndexerConsumer.processFile( )
+
+ // end scan
+
+ // search!
+ }*/
+}