diff options
Diffstat (limited to 'archiva-modules/archiva-base')
7 files changed, 125 insertions, 19 deletions
diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java index ccdb2c493..960adfbd8 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/java/org/apache/archiva/consumers/lucene/NexusIndexerConsumer.java @@ -19,13 +19,7 @@ package org.apache.archiva.consumers.lucene; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Date; -import java.util.List; - +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; @@ -49,6 +43,13 @@ import org.codehaus.plexus.taskqueue.TaskQueueException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; + /** * Consumer for indexing the repository to provide search and IDE integration features. */ @@ -77,14 +78,15 @@ public class NexusIndexerConsumer private List<IndexCreator> allIndexCreators; public NexusIndexerConsumer( ArchivaTaskScheduler<ArtifactIndexingTask> scheduler, - ArchivaConfiguration configuration, FileTypes filetypes, PlexusSisuBridge plexusSisuBridge ) + ArchivaConfiguration configuration, FileTypes filetypes, + PlexusSisuBridge plexusSisuBridge, MavenIndexerUtils mavenIndexerUtils ) throws PlexusSisuBridgeException { this.configuration = configuration; this.filetypes = filetypes; this.scheduler = scheduler; this.nexusIndexer = plexusSisuBridge.lookup( NexusIndexer.class ); - this.allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class ); + this.allIndexCreators = mavenIndexerUtils.getAllIndexCreators(); } public String getDescription() @@ -126,14 +128,14 @@ public class NexusIndexerConsumer public void beginScan( ManagedRepositoryConfiguration repository, Date whenGathered, boolean executeOnEntireRepo ) throws ConsumerException { - if( executeOnEntireRepo ) + if ( executeOnEntireRepo ) { beginScan( repository, whenGathered ); } else { this.repository = repository; - managedRepository = new File( repository.getLocation() ); + managedRepository = new File( repository.getLocation() ); } } @@ -158,7 +160,7 @@ public class NexusIndexerConsumer public void processFile( String path, boolean executeOnEntireRepo ) throws Exception { - if( executeOnEntireRepo ) + if ( executeOnEntireRepo ) { processFile( path ); } @@ -199,7 +201,7 @@ public class NexusIndexerConsumer public void completeScan( boolean executeOnEntireRepo ) { - if( executeOnEntireRepo ) + if ( executeOnEntireRepo ) { completeScan(); } diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml index c9268894a..cf23270e5 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-lucene-consumers/src/main/resources/META-INF/spring-context.xml @@ -32,6 +32,7 @@ <constructor-arg ref="archivaConfiguration"/> <constructor-arg ref="fileTypes"/> <constructor-arg ref="plexusSisuBridge"/> + <constructor-arg ref="mavenIndexerUtils"/> </bean> <bean id="logger" class="org.apache.maven.archiva.common.utils.Slf4JPlexusLogger"> 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 a22b599e9..6cba688d6 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,7 @@ package org.apache.archiva.indexer.search; * under the License. */ +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.indexer.util.SearchUtil; @@ -56,21 +57,23 @@ import java.util.Set; public class NexusRepositorySearch implements RepositorySearch { - private Logger log = LoggerFactory.getLogger( NexusRepositorySearch.class ); + private Logger log = LoggerFactory.getLogger( getClass() ); private NexusIndexer indexer; private ArchivaConfiguration archivaConfig; - private List<? extends IndexCreator> allIndexCreators; + private MavenIndexerUtils mavenIndexerUtils; @Inject - public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig ) + public NexusRepositorySearch( PlexusSisuBridge plexusSisuBridge, ArchivaConfiguration archivaConfig, + MavenIndexerUtils mavenIndexerUtils ) throws PlexusSisuBridgeException { this.indexer = plexusSisuBridge.lookup( NexusIndexer.class ); this.archivaConfig = archivaConfig; - allIndexCreators = plexusSisuBridge.lookupList( IndexCreator.class ); + this.mavenIndexerUtils = mavenIndexerUtils; + } /** @@ -299,9 +302,9 @@ public class NexusRepositorySearch } - protected List<? extends IndexCreator> getAllIndexCreators() + protected List<IndexCreator> getAllIndexCreators() { - return allIndexCreators; + return mavenIndexerUtils.getAllIndexCreators(); } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java index fac51e112..808a19cbd 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/SearchFields.java @@ -199,4 +199,14 @@ public class SearchFields { this.bundleExportService = bundleExportService; } + + @Override + public String toString() + { + return "SearchFields{" + "groupId='" + groupId + '\'' + ", artifactId='" + artifactId + '\'' + ", version='" + + version + '\'' + ", packaging='" + packaging + '\'' + ", className='" + className + '\'' + + ", repositories=" + repositories + ", bundleVersion='" + bundleVersion + '\'' + ", bundleSymbolicName='" + + bundleSymbolicName + '\'' + ", bundleExportPackage='" + bundleExportPackage + '\'' + + ", bundleExportService='" + bundleExportService + '\'' + '}'; + } } diff --git a/archiva-modules/archiva-base/archiva-plexus-bridge/pom.xml b/archiva-modules/archiva-base/archiva-plexus-bridge/pom.xml index 8f4fe3a4d..0da840e23 100644 --- a/archiva-modules/archiva-base/archiva-plexus-bridge/pom.xml +++ b/archiva-modules/archiva-base/archiva-plexus-bridge/pom.xml @@ -49,5 +49,9 @@ <groupId>javax.annotation</groupId> <artifactId>jsr250-api</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven.indexer</groupId> + <artifactId>indexer-core</artifactId> + </dependency> </dependencies> </project> diff --git a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/MavenIndexerUtils.java b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/MavenIndexerUtils.java new file mode 100644 index 000000000..4992dcf02 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/MavenIndexerUtils.java @@ -0,0 +1,80 @@ +package org.apache.archiva.common.plexusbridge; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +import org.apache.maven.index.context.IndexCreator; +import org.apache.maven.index.creator.JarFileContentsIndexCreator; +import org.apache.maven.index.creator.MavenArchetypeArtifactInfoIndexCreator; +import org.apache.maven.index.creator.MavenPluginArtifactInfoIndexCreator; +import org.apache.maven.index.creator.MinimalArtifactInfoIndexCreator; +import org.apache.maven.index.creator.OSGIArtifactIndexCreator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import javax.inject.Inject; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @author Olivier Lamy + * @since 1.4 + */ +@Service("mavenIndexerUtils") +public class MavenIndexerUtils +{ + + private Logger log = LoggerFactory.getLogger( getClass() ); + + private List<? extends IndexCreator> allIndexCreators; + + @Inject + public MavenIndexerUtils( PlexusSisuBridge plexusSisuBridge ) + throws PlexusSisuBridgeException + { + allIndexCreators = new ArrayList( plexusSisuBridge.lookupList( IndexCreator.class ) ); + + if ( allIndexCreators == null || allIndexCreators.isEmpty() ) + { + // olamy when the TCL is not a URLClassLoader lookupList fail ! + // when using tomcat maven plugin so adding a simple hack + log.warn( "using lookList from sisu plexus failed so build indexCreator manually" ); + + allIndexCreators = + Arrays.asList( new OSGIArtifactIndexCreator(), new MavenArchetypeArtifactInfoIndexCreator(), + new MinimalArtifactInfoIndexCreator(), new JarFileContentsIndexCreator(), + new MavenPluginArtifactInfoIndexCreator() ); + + } + + log.debug( "allIndexCreators {}", allIndexCreators ); + } + + public List<? extends IndexCreator> getAllIndexCreators() + { + return allIndexCreators; + } + + public void setAllIndexCreators( List<IndexCreator> allIndexCreators ) + { + this.allIndexCreators = allIndexCreators; + } +} diff --git a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridgeException.java b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridgeException.java index 7b67fdf6a..c963b609f 100644 --- a/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridgeException.java +++ b/archiva-modules/archiva-base/archiva-plexus-bridge/src/main/java/org/apache/archiva/common/plexusbridge/PlexusSisuBridgeException.java @@ -25,6 +25,12 @@ package org.apache.archiva.common.plexusbridge; public class PlexusSisuBridgeException extends Exception { + + public PlexusSisuBridgeException( String message ) + { + super( message ); + } + public PlexusSisuBridgeException( String message, Throwable throwable ) { super( message, throwable ); |