From ebac483742bb6d795da1959553d9f097bb688363 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 13 Sep 2011 21:10:05 +0000 Subject: [PATCH] more cleanup of direct use of archiva-configuration git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1170352 13f79535-47bb-0310-9956-ffa450edef68 --- .../archiva-base/archiva-indexer/pom.xml | 13 ++++++++++- .../indexer/search/NexusRepositorySearch.java | 23 +++++++++++-------- .../resources/META-INF/spring-context.xml | 9 +------- .../search/AbstractNexusRepositorySearch.java | 6 ++++- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml index addd28285..2c61d74f6 100644 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ b/archiva-modules/archiva-base/archiva-indexer/pom.xml @@ -28,9 +28,10 @@ archiva-indexer Archiva Base :: Indexer + org.apache.archiva - archiva-configuration + archiva-repository-admin-api org.apache.lucene @@ -82,6 +83,16 @@ javax.inject javax.inject + + org.apache.archiva + archiva-configuration + test + + + org.apache.archiva + archiva-repository-admin-default + test + org.slf4j slf4j-simple diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java index 1ff81bfbb..9734179d6 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NexusRepositorySearch.java @@ -19,6 +19,9 @@ package org.apache.archiva.indexer.search; * under the License. */ +import org.apache.archiva.admin.model.RepositoryAdminException; +import org.apache.archiva.admin.model.managed.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; @@ -26,9 +29,6 @@ import org.apache.archiva.indexer.util.SearchUtil; import org.apache.commons.lang.StringUtils; import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; -import org.apache.maven.archiva.configuration.ArchivaConfiguration; -import org.apache.maven.archiva.configuration.Configuration; -import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.maven.index.ArtifactInfo; import org.apache.maven.index.FlatSearchRequest; import org.apache.maven.index.FlatSearchResponse; @@ -62,17 +62,17 @@ public class NexusRepositorySearch private NexusIndexer indexer; - private ArchivaConfiguration archivaConfig; + private ManagedRepositoryAdmin managedRepositoryAdmin; private MavenIndexerUtils mavenIndexerUtils; @Inject - public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig, + public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ManagedRepositoryAdmin managedRepositoryAdmin, MavenIndexerUtils mavenIndexerUtils ) throws PlexusSisuBridgeException { this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); - this.archivaConfig = archivaConfig; + this.managedRepositoryAdmin = managedRepositoryAdmin; this.mavenIndexerUtils = mavenIndexerUtils; } @@ -283,16 +283,15 @@ public class NexusRepositorySearch { try { - Configuration config = archivaConfig.getConfiguration(); - ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repo ); + ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repo ); if ( repoConfig != null ) { - String indexDir = repoConfig.getIndexDir(); + String indexDir = repoConfig.getIndexDirectory(); File indexDirectory = null; if ( indexDir != null && !"".equals( indexDir ) ) { - indexDirectory = new File( repoConfig.getIndexDir() ); + indexDirectory = new File( repoConfig.getIndexDirectory() ); } else { @@ -338,6 +337,10 @@ public class NexusRepositorySearch { log.warn( "IO error occured while accessing index of repository '" + repo + "' : " + e.getMessage() ); continue; + } catch ( RepositoryAdminException e ) + { + log.warn( "RepositoryAdminException occured while accessing index of repository '" + repo + "' : " + e.getMessage() ); + continue; } } return indexingContextIds; diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml index 9775f6e53..7530b546c 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/resources/META-INF/spring-context.xml @@ -31,15 +31,8 @@ - org.sonatype.nexus.index.DefaultNexusIndexer - - + \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java index 0a1b56795..435414c54 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/AbstractNexusRepositorySearch.java @@ -20,6 +20,7 @@ package org.apache.archiva.indexer.search; */ import junit.framework.TestCase; +import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin; import org.apache.archiva.common.plexusbridge.MavenIndexerUtils; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.commons.io.FileUtils; @@ -94,7 +95,10 @@ public abstract class AbstractNexusRepositorySearch archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock(); - search = new NexusRepositorySearch( plexusSisuBridge, archivaConfig, mavenIndexerUtils ); + DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin = new DefaultManagedRepositoryAdmin(); + defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfig ); + + search = new NexusRepositorySearch( plexusSisuBridge, defaultManagedRepositoryAdmin, mavenIndexerUtils ); nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); -- 2.39.5