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
This commit is contained in:
Olivier Lamy 2011-09-13 21:10:05 +00:00
parent d1fe90fe66
commit ebac483742
4 changed files with 31 additions and 20 deletions

View File

@ -28,9 +28,10 @@
<artifactId>archiva-indexer</artifactId> <artifactId>archiva-indexer</artifactId>
<name>Archiva Base :: Indexer</name> <name>Archiva Base :: Indexer</name>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.apache.archiva</groupId> <groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId> <artifactId>archiva-repository-admin-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.lucene</groupId> <groupId>org.apache.lucene</groupId>
@ -82,6 +83,16 @@
<groupId>javax.inject</groupId> <groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId> <artifactId>javax.inject</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-admin-default</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>

View File

@ -19,6 +19,9 @@ package org.apache.archiva.indexer.search;
* under the License. * 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.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; 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.commons.lang.StringUtils;
import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery; 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.ArtifactInfo;
import org.apache.maven.index.FlatSearchRequest; import org.apache.maven.index.FlatSearchRequest;
import org.apache.maven.index.FlatSearchResponse; import org.apache.maven.index.FlatSearchResponse;
@ -62,17 +62,17 @@ public class NexusRepositorySearch
private NexusIndexer indexer; private NexusIndexer indexer;
private ArchivaConfiguration archivaConfig; private ManagedRepositoryAdmin managedRepositoryAdmin;
private MavenIndexerUtils mavenIndexerUtils; private MavenIndexerUtils mavenIndexerUtils;
@Inject @Inject
public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig, public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ManagedRepositoryAdmin managedRepositoryAdmin,
MavenIndexerUtils mavenIndexerUtils ) MavenIndexerUtils mavenIndexerUtils )
throws PlexusSisuBridgeException throws PlexusSisuBridgeException
{ {
this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.indexer = plexusSisuBridge.lookup( NexusIndexer.class );
this.archivaConfig = archivaConfig; this.managedRepositoryAdmin = managedRepositoryAdmin;
this.mavenIndexerUtils = mavenIndexerUtils; this.mavenIndexerUtils = mavenIndexerUtils;
} }
@ -283,16 +283,15 @@ public class NexusRepositorySearch
{ {
try try
{ {
Configuration config = archivaConfig.getConfiguration(); ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repo );
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repo );
if ( repoConfig != null ) if ( repoConfig != null )
{ {
String indexDir = repoConfig.getIndexDir(); String indexDir = repoConfig.getIndexDirectory();
File indexDirectory = null; File indexDirectory = null;
if ( indexDir != null && !"".equals( indexDir ) ) if ( indexDir != null && !"".equals( indexDir ) )
{ {
indexDirectory = new File( repoConfig.getIndexDir() ); indexDirectory = new File( repoConfig.getIndexDirectory() );
} }
else else
{ {
@ -338,6 +337,10 @@ public class NexusRepositorySearch
{ {
log.warn( "IO error occured while accessing index of repository '" + repo + "' : " + e.getMessage() ); log.warn( "IO error occured while accessing index of repository '" + repo + "' : " + e.getMessage() );
continue; continue;
} catch ( RepositoryAdminException e )
{
log.warn( "RepositoryAdminException occured while accessing index of repository '" + repo + "' : " + e.getMessage() );
continue;
} }
} }
return indexingContextIds; return indexingContextIds;

View File

@ -31,15 +31,8 @@
<context:annotation-config/> <context:annotation-config/>
<context:component-scan base-package="org.apache.archiva.indexer.search"/> <context:component-scan base-package="org.apache.archiva.indexer.search"/>
<!--
<bean id="nexusSearch" class="org.apache.archiva.indexer.search.NexusRepositorySearch">
<constructor-arg ref="nexusIndexer"/>
<constructor-arg ref="archivaConfiguration#default"/>
</bean>
-->
<bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger"> <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger">
<constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg> <constructor-arg type="java.lang.Class"><value>org.sonatype.nexus.index.DefaultNexusIndexer</value></constructor-arg>
</bean> </bean>
<!-- <bean id="indexingContextMap" class="org.apache.archiva.indexer.IndexingContextMap"/> -->
</beans> </beans>

View File

@ -20,6 +20,7 @@ package org.apache.archiva.indexer.search;
*/ */
import junit.framework.TestCase; 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.MavenIndexerUtils;
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge; import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
@ -94,7 +95,10 @@ public abstract class AbstractNexusRepositorySearch
archivaConfig = (ArchivaConfiguration) archivaConfigControl.getMock(); 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 ); nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class );