* under the License.
*/
+import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
-import org.apache.archiva.scheduler.ArchivaTaskScheduler;
-import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.ConfigurationNames;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.archiva.consumers.ConsumerException;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.archiva.scheduler.ArchivaTaskScheduler;
+import org.apache.archiva.scheduler.indexing.ArtifactIndexingTask;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import org.codehaus.plexus.taskqueue.TaskQueueException;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
/**
* Consumer for indexing the repository to provide search and IDE integration features.
*/
-@Service("knownRepositoryContentConsumer#index-content")
-@Scope("prototype")
+@Service( "knownRepositoryContentConsumer#index-content" )
+@Scope( "prototype" )
public class NexusIndexerConsumer
extends AbstractMonitoredConsumer
implements KnownRepositoryContentConsumer, RegistryListener
{
- private Logger log = LoggerFactory.getLogger( NexusIndexerConsumer.class );
+ private Logger log = LoggerFactory.getLogger( getClass() );
private ArchivaConfiguration configuration;
private List<? extends IndexCreator> allIndexCreators;
+ @Inject
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
+
public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
ArchivaConfiguration configuration, FileTypes filetypes,
PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils )
try
{
log.info( "Creating indexing context for repo : {}", repository.getId() );
- context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators );
- }
- catch ( IOException e )
- {
- throw new ConsumerException( e.getMessage(), e );
+ context = managedRepositoryAdmin.createIndexContext( repository );
}
- catch ( UnsupportedExistingLuceneIndexException e )
+ catch ( RepositoryAdminException e )
{
throw new ConsumerException( e.getMessage(), e );
}
* under the License.
*/
+import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException;
import org.apache.lucene.search.BooleanQuery;
import org.apache.maven.index.ArtifactContext;
import org.apache.maven.index.ArtifactContextProducer;
-import org.apache.maven.index.DefaultArtifactContextProducer;
import org.apache.maven.index.FlatSearchRequest;
import org.apache.maven.index.FlatSearchResponse;
import org.apache.maven.index.MAVEN;
import org.apache.maven.index.artifact.IllegalArtifactCoordinateException;
import org.apache.maven.index.context.IndexCreator;
import org.apache.maven.index.context.IndexingContext;
-import org.apache.maven.index.context.UnsupportedExistingLuceneIndexException;
import org.apache.maven.index.expr.SourcedSearchExpression;
import org.apache.maven.index.packer.IndexPacker;
import org.apache.maven.index.packer.IndexPackingRequest;
@Inject
private MavenIndexerUtils mavenIndexerUtils;
+ @Inject
+ private ManagedRepositoryAdmin managedRepositoryAdmin;
+
private NexusIndexer nexusIndexer;
private List<? extends IndexCreator> allIndexCreators;
{
log.debug( "Creating indexing context on resource: {}",
indexingTask.getResourceFile().getPath() );
- context = ArtifactIndexingTask.createContext( repository, nexusIndexer, allIndexCreators );
- }
- catch ( IOException e )
- {
- log.error( "Error occurred while creating context: " + e.getMessage() );
- throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(),
- e );
+ context = managedRepositoryAdmin.createIndexContext( repository );
}
- catch ( UnsupportedExistingLuceneIndexException e )
+ catch ( RepositoryAdminException e )
{
log.error( "Error occurred while creating context: " + e.getMessage() );
throw new TaskExecutionException( "Error occurred while creating context: " + e.getMessage(),
+ resourceFile + "]";
}
- /**
- * FIXME remove this static somewhere else !
- * @param repository
- * @param indexer
- * @param indexCreators
- * @return
- * @throws IOException
- * @throws UnsupportedExistingLuceneIndexException
- */
- public static IndexingContext createContext( ManagedRepository repository, NexusIndexer indexer,
- List<? extends IndexCreator> indexCreators )
- throws IOException, UnsupportedExistingLuceneIndexException
- {
- IndexingContext context = indexer.getIndexingContexts().get( repository.getId() );
-
- if ( context != null )
- {
- LoggerFactory.getLogger( ArtifactIndexingTask.class ).debug(
- "skip adding repository with id {} as already exists", repository.getId() );
- return context;
- }
-
-
- String indexDir = repository.getIndexDirectory();
- File managedRepository = new File( repository.getLocation() );
-
- File indexDirectory = null;
- if ( indexDir != null && !"".equals( indexDir ) )
- {
- indexDirectory = new File( repository.getIndexDirectory() );
- }
- else
- {
- indexDirectory = new File( managedRepository, ".indexer" );
- }
-
-
- context = indexer.addIndexingContext( repository.getId(), repository.getId(), managedRepository, indexDirectory,
- managedRepository.toURI().toURL().toExternalForm(),
- indexDirectory.toURI().toURL().toString(), indexCreators );
-
- context.setSearchable( repository.isScanned() );
- return context;
- }
}
import junit.framework.TestCase;
import org.apache.archiva.admin.model.beans.ManagedRepository;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.common.plexusbridge.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils;
@Inject
MavenIndexerUtils mavenIndexerUtils;
+ @Inject
+ ManagedRepositoryAdmin managedRepositoryAdmin;
+
@Before
public void setUp()
throws Exception
indexer = plexusSisuBridge.lookup( NexusIndexer.class );
- ArtifactIndexingTask.createContext( repositoryConfig, indexer, mavenIndexerUtils.getAllIndexCreators() );
+ managedRepositoryAdmin.createIndexContext( repositoryConfig );
}
@After
{
ManagedRepository repository = managedRepositoryAdmin.getManagedRepository( repositoryId );
- IndexingContext context =
- ArtifactIndexingTask.createContext( repository, plexusSisuBridge.lookup( NexusIndexer.class ),
- new ArrayList<IndexCreator>(
- mavenIndexerUtils.getAllIndexCreators( ) ) );
+ IndexingContext context = managedRepositoryAdmin.createIndexContext( repository );
ArtifactIndexingTask task =
new ArtifactIndexingTask( repository, null, ArtifactIndexingTask.Action.FINISH, context );