mirror of https://github.com/apache/archiva.git
Correcting index-content Consumer.
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/branches/archiva-jpox-database-refactor@525974 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e192fbc08f
commit
10cd2d962a
|
@ -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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
|
||||||
* @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";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -19,17 +19,24 @@ package org.apache.maven.archiva.consumers.lucene;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
|
||||||
import org.apache.maven.archiva.configuration.FileType;
|
import org.apache.maven.archiva.configuration.FileType;
|
||||||
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
|
||||||
import org.apache.maven.archiva.consumers.ConsumerException;
|
import org.apache.maven.archiva.consumers.ConsumerException;
|
||||||
import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
|
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.apache.maven.archiva.model.ArchivaRepository;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
|
||||||
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
|
||||||
import org.codehaus.plexus.registry.Registry;
|
import org.codehaus.plexus.registry.Registry;
|
||||||
import org.codehaus.plexus.registry.RegistryListener;
|
import org.codehaus.plexus.registry.RegistryListener;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -42,9 +49,14 @@ import java.util.List;
|
||||||
* @plexus.component role-hint="index-content"
|
* @plexus.component role-hint="index-content"
|
||||||
* instantiation-strategy="per-lookup"
|
* instantiation-strategy="per-lookup"
|
||||||
*/
|
*/
|
||||||
public class IndexContentConsumer extends AbstractMonitoredConsumer
|
public class IndexContentConsumer
|
||||||
|
extends AbstractMonitoredConsumer
|
||||||
implements RepositoryContentConsumer, RegistryListener, Initializable
|
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"
|
* @plexus.configuration default-value="index-content"
|
||||||
*/
|
*/
|
||||||
|
@ -60,10 +72,19 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer
|
||||||
*/
|
*/
|
||||||
private ArchivaConfiguration configuration;
|
private ArchivaConfiguration configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @plexus.requirement
|
||||||
|
*/
|
||||||
|
private RepositoryContentIndexFactory indexFactory;
|
||||||
|
|
||||||
private List propertyNameTriggers = new ArrayList();
|
private List propertyNameTriggers = new ArrayList();
|
||||||
|
|
||||||
private List includes = new ArrayList();
|
private List includes = new ArrayList();
|
||||||
|
|
||||||
|
private RepositoryContentIndex index;
|
||||||
|
|
||||||
|
private File repositoryDir;
|
||||||
|
|
||||||
public String getId()
|
public String getId()
|
||||||
{
|
{
|
||||||
return this.id;
|
return this.id;
|
||||||
|
@ -89,17 +110,38 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer
|
||||||
return this.includes;
|
return this.includes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void beginScan( ArchivaRepository repository ) throws ConsumerException
|
public void beginScan( ArchivaRepository repository )
|
||||||
|
throws ConsumerException
|
||||||
{
|
{
|
||||||
if ( !repository.isManaged() )
|
if ( !repository.isManaged() )
|
||||||
{
|
{
|
||||||
throw new ConsumerException( "Consumer requires managed repository." );
|
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()
|
public void completeScan()
|
||||||
|
@ -124,15 +166,16 @@ public class IndexContentConsumer extends AbstractMonitoredConsumer
|
||||||
{
|
{
|
||||||
includes.clear();
|
includes.clear();
|
||||||
|
|
||||||
FileType artifactTypes =
|
FileType artifactTypes = configuration.getConfiguration().getRepositoryScanning()
|
||||||
configuration.getConfiguration().getRepositoryScanning().getFileTypeById( "indexable-content" );
|
.getFileTypeById( "indexable-content" );
|
||||||
if ( artifactTypes != null )
|
if ( artifactTypes != null )
|
||||||
{
|
{
|
||||||
includes.addAll( artifactTypes.getPatterns() );
|
includes.addAll( artifactTypes.getPatterns() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize() throws InitializationException
|
public void initialize()
|
||||||
|
throws InitializationException
|
||||||
{
|
{
|
||||||
propertyNameTriggers = new ArrayList();
|
propertyNameTriggers = new ArrayList();
|
||||||
propertyNameTriggers.add( "repositoryScanning" );
|
propertyNameTriggers.add( "repositoryScanning" );
|
||||||
|
|
Loading…
Reference in New Issue