diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java deleted file mode 100644 index 444be00f7..000000000 --- a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexArtifactConsumer.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.apache.maven.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 org.apache.maven.archiva.common.utils.BaseFile; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.indexer.RepositoryArtifactIndex; -import org.apache.maven.archiva.indexer.RepositoryArtifactIndexFactory; -import org.apache.maven.archiva.indexer.RepositoryIndexException; -import org.apache.maven.archiva.indexer.record.RepositoryIndexRecordFactory; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; - -import java.io.File; - -/** - * IndexArtifactConsumer - * - * @author Joakim Erdfelt - * @version $Id$ - * - * @plexus.component role="org.apache.maven.archiva.common.consumers.Consumer" - * role-hint="index-artifact" - * instantiation-strategy="per-lookup" - */ -public class IndexArtifactConsumer - extends GenericArtifactConsumer -{ - /** - * @plexus.requirement - */ - private RepositoryArtifactIndexFactory indexFactory; - - /** - * @plexus.requirement role-hint="standard" - */ - private RepositoryIndexRecordFactory recordFactory; - - /** - * Configuration store. - * - * @plexus.requirement - */ - private ArchivaConfiguration archivaConfiguration; - - private RepositoryArtifactIndex index; - - public boolean init( ArtifactRepository repository ) - { - Configuration configuration = archivaConfiguration.getConfiguration(); - - File indexPath = new File( configuration.getIndexPath() ); - - index = indexFactory.createStandardIndex( indexPath ); - - return super.init( repository ); - } - - public void processArtifact( Artifact artifact, BaseFile file ) - { - try - { - index.indexArtifact( artifact, recordFactory ); - } - catch ( RepositoryIndexException e ) - { - getLogger().warn( "Unable to index artifact " + artifact, e ); - } - } - - public void processFileProblem( BaseFile path, String message ) - { - - } - - public String getName() - { - return "Index Artifact Consumer"; - } -} diff --git a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java index 4ed012aa2..a1437dffb 100644 --- a/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java +++ b/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/maven/archiva/consumers/lucene/IndexContentConsumer.java @@ -19,17 +19,24 @@ package org.apache.maven.archiva.consumers.lucene; * under the License. */ +import org.apache.commons.io.FileUtils; import org.apache.maven.archiva.configuration.ArchivaConfiguration; import org.apache.maven.archiva.configuration.FileType; import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer; import org.apache.maven.archiva.consumers.ConsumerException; import org.apache.maven.archiva.consumers.RepositoryContentConsumer; +import org.apache.maven.archiva.indexer.RepositoryContentIndex; +import org.apache.maven.archiva.indexer.RepositoryContentIndexFactory; +import org.apache.maven.archiva.indexer.RepositoryIndexException; +import org.apache.maven.archiva.indexer.filecontent.FileContentRecord; import org.apache.maven.archiva.model.ArchivaRepository; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable; import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException; import org.codehaus.plexus.registry.Registry; import org.codehaus.plexus.registry.RegistryListener; +import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -42,9 +49,14 @@ import java.util.List; * @plexus.component role-hint="index-content" * instantiation-strategy="per-lookup" */ -public class IndexContentConsumer extends AbstractMonitoredConsumer +public class IndexContentConsumer + extends AbstractMonitoredConsumer implements RepositoryContentConsumer, RegistryListener, Initializable { + private static final String READ_CONTENT = "read_content"; + + private static final String INDEX_ERROR = "indexing_error"; + /** * @plexus.configuration default-value="index-content" */ @@ -60,10 +72,19 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer */ private ArchivaConfiguration configuration; + /** + * @plexus.requirement + */ + private RepositoryContentIndexFactory indexFactory; + private List propertyNameTriggers = new ArrayList(); private List includes = new ArrayList(); + private RepositoryContentIndex index; + + private File repositoryDir; + public String getId() { return this.id; @@ -89,17 +110,38 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer return this.includes; } - public void beginScan( ArchivaRepository repository ) throws ConsumerException + public void beginScan( ArchivaRepository repository ) + throws ConsumerException { if ( !repository.isManaged() ) { throw new ConsumerException( "Consumer requires managed repository." ); } + + this.repositoryDir = new File( repository.getUrl().getPath() ); + this.index = indexFactory.createFileContentIndex( repository ); } - public void processFile( String path ) throws ConsumerException + public void processFile( String path ) + throws ConsumerException { - + FileContentRecord record = new FileContentRecord(); + try + { + File file = new File( repositoryDir, path ); + record.setFile( file ); + record.setContents( FileUtils.readFileToString( file, null ) ); + + index.modifyRecord( record ); + } + catch ( IOException e ) + { + triggerConsumerError( READ_CONTENT, "Unable to read file contents: " + e.getMessage() ); + } + catch ( RepositoryIndexException e ) + { + triggerConsumerError( INDEX_ERROR, "Unable to index file contents: " + e.getMessage() ); + } } public void completeScan() @@ -124,15 +166,16 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer { includes.clear(); - FileType artifactTypes = - configuration.getConfiguration().getRepositoryScanning().getFileTypeById( "indexable-content" ); + FileType artifactTypes = configuration.getConfiguration().getRepositoryScanning() + .getFileTypeById( "indexable-content" ); if ( artifactTypes != null ) { includes.addAll( artifactTypes.getPatterns() ); } } - public void initialize() throws InitializationException + public void initialize() + throws InitializationException { propertyNameTriggers = new ArrayList(); propertyNameTriggers.add( "repositoryScanning" );