]> source.dussan.org Git - archiva.git/commitdiff
remove this ugly static method
authorOlivier Lamy <olamy@apache.org>
Wed, 2 Nov 2011 22:32:15 +0000 (22:32 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 2 Nov 2011 22:32:15 +0000 (22:32 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1196841 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutor.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/main/java/org/apache/archiva/scheduler/indexing/ArtifactIndexingTask.java
archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/ArchivaIndexingTaskExecutorTest.java
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java

index 7badf11e15f31ccaaaa8a2ccda4e18619e60b2ea..787c42519e1647cb8e803986c5a0d16abd4fcb74 100644 (file)
@@ -19,22 +19,23 @@ package org.apache.archiva.consumers.lucene;
  * 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;
@@ -44,8 +45,8 @@ import org.springframework.context.annotation.Scope;
 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;
@@ -54,13 +55,13 @@ import java.util.List;
 /**
  * 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;
 
@@ -80,6 +81,9 @@ public class NexusIndexerConsumer
 
     private List<? extends IndexCreator> allIndexCreators;
 
+    @Inject
+    private ManagedRepositoryAdmin managedRepositoryAdmin;
+
     public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler,
                                  ArchivaConfiguration configuration, FileTypes filetypes,
                                  PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils )
@@ -116,13 +120,9 @@ public class NexusIndexerConsumer
         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 );
         }
index 3d9a0b199552e25dcf104bcd860d311f59331180..0598987327b77ba0e139ecc008a15e2924db6e23 100644 (file)
@@ -20,7 +20,9 @@ package org.apache.archiva.scheduler.indexing;
  * 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;
@@ -29,7 +31,6 @@ import org.apache.lucene.search.BooleanClause;
 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;
@@ -37,7 +38,6 @@ import org.apache.maven.index.NexusIndexer;
 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;
@@ -78,6 +78,9 @@ public class ArchivaIndexingTaskExecutor
     @Inject
     private MavenIndexerUtils mavenIndexerUtils;
 
+    @Inject
+    private ManagedRepositoryAdmin managedRepositoryAdmin;
+
     private NexusIndexer nexusIndexer;
 
     private List<? extends IndexCreator> allIndexCreators;
@@ -130,15 +133,9 @@ public class ArchivaIndexingTaskExecutor
                     {
                         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(),
index 5ab9efd08df875549b237e5ca90a62c973ce46de..5601053661b979718da4a4c38b4f27828b627dab 100644 (file)
@@ -181,48 +181,4 @@ public class ArtifactIndexingTask
             + 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;
-    }
 }
index e0fbdeb65b3bd2c8490b3489f56c7004ebb55c97..aff511520f2bc553dff24f4e972479e0fd59acbb 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.archiva.scheduler.indexing;
 
 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;
@@ -76,6 +77,9 @@ public class ArchivaIndexingTaskExecutorTest
     @Inject
     MavenIndexerUtils mavenIndexerUtils;
 
+    @Inject
+    ManagedRepositoryAdmin managedRepositoryAdmin;
+
     @Before
     public void setUp()
         throws Exception
@@ -93,7 +97,7 @@ public class ArchivaIndexingTaskExecutorTest
 
         indexer = plexusSisuBridge.lookup( NexusIndexer.class );
 
-        ArtifactIndexingTask.createContext( repositoryConfig, indexer, mavenIndexerUtils.getAllIndexCreators() );
+        managedRepositoryAdmin.createIndexContext( repositoryConfig );
     }
 
     @After
index 6db1e6f29955aead32de4fd2f9aa38ec149c79e4..79cde9868369024987a3463439ae498903aee474 100644 (file)
@@ -175,10 +175,7 @@ public class DefaultRepositoriesService
         {
             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 );