import java.util.Arrays;
import java.util.Date;
import java.util.List;
-import org.apache.maven.archiva.configuration.FileTypes;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.maven.archiva.consumers.AbstractMonitoredConsumer;
import org.apache.maven.archiva.consumers.ConsumerException;
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.packer.IndexPacker;
public class NexusIndexerConsumer
extends AbstractMonitoredConsumer
private final ArtifactContextProducer artifactContextProducer;
+ private final IndexPacker indexPacker;
+
private ManagedRepositoryConfiguration repository;
private ManagedDefaultRepositoryContent repositoryContent;
private IndexingContext context;
- public NexusIndexerConsumer(NexusIndexer indexer)
+ private File managedRepository;
+
+ public NexusIndexerConsumer(NexusIndexer indexer, IndexPacker indexPacker)
{
this.indexer = indexer;
+ this.indexPacker = indexPacker;
this.artifactContextProducer = new DefaultArtifactContextProducer();
}
throws ConsumerException
{
this.repository = repository;
- File managedRepository = new File(repository.getLocation());
+ managedRepository = new File(repository.getLocation());
File indexDirectory = new File(managedRepository, ".indexer");
repositoryContent = new ManagedDefaultRepositoryContent();
{
try
{
- context = indexer.addIndexingContextForced(repository.getId(), repository.getId(), managedRepository, indexDirectory, "repourl", "updateurl", NexusIndexer.FULL_INDEX);
+ context = indexer.addIndexingContext(repository.getId(), repository.getId(), managedRepository, indexDirectory, null, null, NexusIndexer.FULL_INDEX);
context.setSearchable(repository.isScanned());
}
+ catch (UnsupportedExistingLuceneIndexException e)
+ {
+ log.error("Could not create index at " + indexDirectory.getAbsoluteFile(), e);
+ }
catch (IOException e)
{
- log.error("Could not create FSDirectory for index at " + indexDirectory.getAbsoluteFile(), e);
+ log.error("Could not create index at " + indexDirectory.getAbsoluteFile(), e);
}
}
}
public void completeScan()
{
- /** do nothing **/
+ final File indexLocation = new File(managedRepository, ".index");
+ try
+ {
+ indexPacker.packIndex(context, indexLocation);
+ }
+ catch (IOException e)
+ {
+ log.error("Could not pack index" + indexLocation.getAbsolutePath(), e );
+ }
}
public List<String> getExcludes()
public void processFile(String path)
throws ConsumerException
{
- File artifactFile = new File(path);
-
- try
- {
- repositoryContent.toArtifactReference(path);
- }
- catch (LayoutException e)
- {
- /** do nothing **/
- return;
- }
+ File artifactFile = new File(managedRepository, path);
ArtifactContext artifactContext = artifactContextProducer.getArtifactContext(context, artifactFile);
- try
- {
- indexer.artifactDiscovered(artifactContext, context);
- }
- catch (IOException e)
+ if (artifactContext != null)
{
- throw new ConsumerException(e.getMessage(), e);
+ try
+ {
+ indexer.artifactDiscovered(artifactContext, context);
+ }
+ catch (IOException e)
+ {
+ throw new ConsumerException(e.getMessage(), e);
+ }
}
}
}
import org.apache.maven.archiva.repository.scanner.functors.ConsumerProcessFileClosure;
import org.apache.maven.archiva.repository.scanner.functors.ConsumerWantsFilePredicate;
import org.apache.maven.archiva.repository.scanner.functors.TriggerBeginScanClosure;
+import org.apache.maven.archiva.repository.scanner.functors.TriggerScanCompletedClosure;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
// Nothing known processed this file. It is invalid!
CollectionUtils.forAllDo( selectedInvalidConsumers, closure );
}
+
+ TriggerScanCompletedClosure scanCompletedClosure = new TriggerScanCompletedClosure(repository);
+
+ CollectionUtils.forAllDo(selectedKnownConsumers, scanCompletedClosure);
+ CollectionUtils.forAllDo(selectedKnownConsumers, scanCompletedClosure);
}
finally
{
--- /dev/null
+/*
+ * Copyright 2008 jdumay.
+ *
+ * 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.
+ * under the License.
+ */
+
+package org.apache.maven.archiva.repository.scanner.functors;
+
+import org.apache.commons.collections.Closure;
+import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.maven.archiva.consumers.RepositoryContentConsumer;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TriggerScanCompletedClosure implements Closure
+{
+ private Logger log = LoggerFactory.getLogger( TriggerScanCompletedClosure.class );
+
+ private final ManagedRepositoryConfiguration repository;
+
+ public TriggerScanCompletedClosure(ManagedRepositoryConfiguration repository)
+ {
+ this.repository = repository;
+ }
+
+ public void execute(Object input)
+ {
+ if ( input instanceof RepositoryContentConsumer )
+ {
+ RepositoryContentConsumer consumer = (RepositoryContentConsumer) input;
+ consumer.completeScan();
+ log.info( "Consumer [" + consumer.getId() + "] completed for repository [" + repository.getId() + "]");
+ }
+ }
+}