Renaming archiva-indexer module to archiva-maven2-indexer
Project: http://git-wip-us.apache.org/repos/asf/archiva/repo Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/07d51cc3 Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/07d51cc3 Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/07d51cc3 Branch: refs/heads/master Commit: 07d51cc35682c68ed29bf55714c9854c22a9347d Parents: e4af2d6 Author: Martin Stockhammer <[email protected]> Authored: Thu Nov 9 17:45:32 2017 +0100 Committer: Martin Stockhammer <[email protected]> Committed: Thu Nov 9 17:45:32 2017 +0100 ---------------------------------------------------------------------- .../archiva-base/archiva-indexer/pom.xml | 249 ----- .../indexer/merger/DefaultIndexMerger.java | 173 ---- .../DefaultMergedRemoteIndexesScheduler.java | 94 -- .../archiva/indexer/merger/IndexMerger.java | 42 - .../indexer/merger/IndexMergerException.java | 32 - .../indexer/merger/IndexMergerRequest.java | 192 ---- .../indexer/merger/MergedRemoteIndexesTask.java | 89 -- .../merger/MergedRemoteIndexesTaskRequest.java | 80 -- .../merger/MergedRemoteIndexesTaskResult.java | 46 - .../indexer/merger/TemporaryGroupIndex.java | 119 --- .../merger/TemporaryGroupIndexCleaner.java | 73 -- .../indexer/search/MavenRepositorySearch.java | 737 --------------- .../search/NoClassifierArtifactInfoFilter.java | 43 - .../apache/archiva/indexer/util/SearchUtil.java | 36 - .../main/resources/META-INF/spring-context.xml | 49 - .../search/AbstractMavenRepositorySearch.java | 303 ------ .../search/MavenRepositorySearchOSGITest.java | 78 -- .../MavenRepositorySearchPaginateTest.java | 105 --- .../search/MavenRepositorySearchTest.java | 937 ------------------- .../archiva-search/1.0/archiva-search-1.0.jar | Bin 2518 -> 0 bytes .../archiva-search/1.0/archiva-search-1.0.pom | 28 - .../archiva-search/1.1/archiva-search-1.1.jar | Bin 2518 -> 0 bytes .../archiva-search/1.1/archiva-search-1.1.pom | 28 - .../1.0/artifactid-numeric-1.0.jar | 0 .../1.0/artifactid-numeric-1.0.pom | 17 - .../1.0/artifactid-numeric123-1.0.jar | 0 .../1.0/artifactid-numeric123-1.0.pom | 17 - .../1.0/classname-search-1.0.jar | Bin 2220 -> 0 bytes .../1.0/classname-search-1.0.pom | 18 - .../1.0/archiva-search-1.0-patch1.jar | Bin 2518 -> 0 bytes .../1.0/archiva-search-1.0-sources.jar | Bin 2518 -> 0 bytes .../archiva-search/1.0/archiva-search-1.0.jar | Bin 2518 -> 0 bytes .../archiva-search/1.0/archiva-search-1.0.pom | 28 - .../archiva-test/1.0/archiva-test-1.0.jar | Bin 2471 -> 0 bytes .../archiva-test/1.0/archiva-test-1.0.pom | 23 - .../archiva-test/2.0/archiva-test-2.0.jar | Bin 2494 -> 0 bytes .../archiva-test/2.0/archiva-test-2.0.pom | 28 - .../archiva-webapp/1.0/archiva-webapp-1.0.pom | 23 - .../archiva-webapp/1.0/archiva-webapp-1.0.war | 0 .../1.0-SNAPSHOT/test-webapp-1.0-SNAPSHOT.war | Bin 4169 -> 0 bytes .../org.apache.felix.bundlerepository-1.6.6.jar | Bin 168279 -> 0 bytes .../org.apache.felix.bundlerepository-1.6.6.pom | 138 --- .../src/test/repo-release/.index/_8.fdt | Bin 86211 -> 0 bytes .../src/test/repo-release/.index/_8.fdx | Bin 114 -> 0 bytes .../src/test/repo-release/.index/_8.fnm | Bin 2157 -> 0 bytes .../src/test/repo-release/.index/_8.nvd | Bin 2330 -> 0 bytes .../src/test/repo-release/.index/_8.nvm | Bin 261 -> 0 bytes .../src/test/repo-release/.index/_8.si | Bin 371 -> 0 bytes .../test/repo-release/.index/_8_Lucene41_0.doc | Bin 21619 -> 0 bytes .../test/repo-release/.index/_8_Lucene41_0.pos | Bin 40037 -> 0 bytes .../test/repo-release/.index/_8_Lucene41_0.tim | Bin 91607 -> 0 bytes .../test/repo-release/.index/_8_Lucene41_0.tip | Bin 1250 -> 0 bytes .../src/test/repo-release/.index/segments.gen | Bin 36 -> 0 bytes .../src/test/repo-release/.index/segments_9 | Bin 102 -> 0 bytes .../src/test/repo-release/.index/timestamp | Bin 8 -> 0 bytes .../src/test/repo-release/.index/write.lock | 0 .../src/test/resources/spring-context.xml | 77 -- .../archiva-base/archiva-maven2-indexer/pom.xml | 249 +++++ .../indexer/merger/DefaultIndexMerger.java | 173 ++++ .../DefaultMergedRemoteIndexesScheduler.java | 94 ++ .../archiva/indexer/merger/IndexMerger.java | 42 + .../indexer/merger/IndexMergerException.java | 32 + .../indexer/merger/IndexMergerRequest.java | 192 ++++ .../indexer/merger/MergedRemoteIndexesTask.java | 89 ++ .../merger/MergedRemoteIndexesTaskRequest.java | 80 ++ .../merger/MergedRemoteIndexesTaskResult.java | 46 + .../indexer/merger/TemporaryGroupIndex.java | 119 +++ .../merger/TemporaryGroupIndexCleaner.java | 73 ++ .../indexer/search/MavenRepositorySearch.java | 737 +++++++++++++++ .../search/NoClassifierArtifactInfoFilter.java | 43 + .../apache/archiva/indexer/util/SearchUtil.java | 36 + .../main/resources/META-INF/spring-context.xml | 49 + .../search/AbstractMavenRepositorySearch.java | 303 ++++++ .../search/MavenRepositorySearchOSGITest.java | 78 ++ .../MavenRepositorySearchPaginateTest.java | 105 +++ .../search/MavenRepositorySearchTest.java | 937 +++++++++++++++++++ .../archiva-search/1.0/archiva-search-1.0.jar | Bin 0 -> 2518 bytes .../archiva-search/1.0/archiva-search-1.0.pom | 28 + .../archiva-search/1.1/archiva-search-1.1.jar | Bin 0 -> 2518 bytes .../archiva-search/1.1/archiva-search-1.1.pom | 28 + .../1.0/artifactid-numeric-1.0.jar | 0 .../1.0/artifactid-numeric-1.0.pom | 17 + .../1.0/artifactid-numeric123-1.0.jar | 0 .../1.0/artifactid-numeric123-1.0.pom | 17 + .../1.0/classname-search-1.0.jar | Bin 0 -> 2220 bytes .../1.0/classname-search-1.0.pom | 18 + .../1.0/archiva-search-1.0-patch1.jar | Bin 0 -> 2518 bytes .../1.0/archiva-search-1.0-sources.jar | Bin 0 -> 2518 bytes .../archiva-search/1.0/archiva-search-1.0.jar | Bin 0 -> 2518 bytes .../archiva-search/1.0/archiva-search-1.0.pom | 28 + .../archiva-test/1.0/archiva-test-1.0.jar | Bin 0 -> 2471 bytes .../archiva-test/1.0/archiva-test-1.0.pom | 23 + .../archiva-test/2.0/archiva-test-2.0.jar | Bin 0 -> 2494 bytes .../archiva-test/2.0/archiva-test-2.0.pom | 28 + .../archiva-webapp/1.0/archiva-webapp-1.0.pom | 23 + .../archiva-webapp/1.0/archiva-webapp-1.0.war | 0 .../1.0-SNAPSHOT/test-webapp-1.0-SNAPSHOT.war | Bin 0 -> 4169 bytes .../org.apache.felix.bundlerepository-1.6.6.jar | Bin 0 -> 168279 bytes .../org.apache.felix.bundlerepository-1.6.6.pom | 138 +++ .../src/test/repo-release/.index/_8.fdt | Bin 0 -> 86211 bytes .../src/test/repo-release/.index/_8.fdx | Bin 0 -> 114 bytes .../src/test/repo-release/.index/_8.fnm | Bin 0 -> 2157 bytes .../src/test/repo-release/.index/_8.nvd | Bin 0 -> 2330 bytes .../src/test/repo-release/.index/_8.nvm | Bin 0 -> 261 bytes .../src/test/repo-release/.index/_8.si | Bin 0 -> 371 bytes .../test/repo-release/.index/_8_Lucene41_0.doc | Bin 0 -> 21619 bytes .../test/repo-release/.index/_8_Lucene41_0.pos | Bin 0 -> 40037 bytes .../test/repo-release/.index/_8_Lucene41_0.tim | Bin 0 -> 91607 bytes .../test/repo-release/.index/_8_Lucene41_0.tip | Bin 0 -> 1250 bytes .../src/test/repo-release/.index/segments.gen | Bin 0 -> 36 bytes .../src/test/repo-release/.index/segments_9 | Bin 0 -> 102 bytes .../src/test/repo-release/.index/timestamp | Bin 0 -> 8 bytes .../src/test/repo-release/.index/write.lock | 0 .../src/test/resources/spring-context.xml | 77 ++ archiva-modules/archiva-base/pom.xml | 2 +- .../src/main/resources/features.xml | 10 +- .../archiva-web/archiva-webapp/pom.xml | 2 +- .../archiva-web/archiva-webdav/pom.xml | 2 +- pom.xml | 2 +- 119 files changed, 3911 insertions(+), 3911 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/pom.xml ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/pom.xml b/archiva-modules/archiva-base/archiva-indexer/pom.xml deleted file mode 100644 index 9634b7c..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/pom.xml +++ /dev/null @@ -1,249 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-base</artifactId> - <version>3.0.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>archiva-indexer</artifactId> - <packaging>bundle</packaging> - <name>Archiva Base :: Indexer</name> - <dependencies> - - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-repository-admin-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-common</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-repository-layer</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context-support</artifactId> - </dependency> - - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-utils</artifactId> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-digest</artifactId> - <exclusions> - <exclusion> - <groupId>org.codehaus.plexus</groupId> - <artifactId>plexus-component-api</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.indexer</groupId> - <artifactId>indexer-reader</artifactId> - </dependency> - <dependency> - <groupId>org.apache.maven.indexer</groupId> - <artifactId>indexer-core</artifactId> - <classifier>shaded-lucene</classifier> - <exclusions> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-queryparser</artifactId> - </exclusion> - <exclusion> - <groupId>org.apache.lucene</groupId> - <artifactId>lucene-analyzers-common</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> - <groupId>org.eclipse.sisu</groupId> - <artifactId>org.eclipse.sisu.plexus</artifactId> - </dependency> - <dependency> - <groupId>com.google.inject</groupId> - <artifactId>guice</artifactId> - <classifier>no_aop</classifier> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-plexus-bridge</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-scheduler-repository</artifactId> - </dependency> - <dependency> - <groupId>javax.inject</groupId> - <artifactId>javax.inject</artifactId> - </dependency> - <dependency> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-mock</artifactId> - <scope>test</scope> - </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> - <groupId>org.apache.archiva</groupId> - <artifactId>archiva-test-utils</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.derby</groupId> - <artifactId>derby</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-keys-memory</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-rbac-cached</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-rbac-memory</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-users-memory</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.archiva.redback</groupId> - <artifactId>redback-common-test-resources</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.wagon</groupId> - <artifactId>wagon-http-lightweight</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.hsqldb</groupId> - <artifactId>hsqldb</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>src/test/maven-search-test-repo*/**</exclude> - <exclude>src/test/repo-release*/**</exclude> - </excludes> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Bundle-SymbolicName>org.apache.archiva.indexer</Bundle-SymbolicName> - <Bundle-Version>${project.version}</Bundle-Version> - <Export-Package> - org.apache.archiva.indexer.*;version=${project.version};-split-package:=merge-first - </Export-Package> - <Import-Package> - javax.annotation, - javax.inject, - com.google.common.io, - org.apache.archiva.admin.model*;version=${project.version}, - org.apache.archiva.common.plexusbridge;version=${project.version}, - org.apache.commons.io;version="[1.4,2)", - org.apache.commons.lang*;version="[2.4,3)", - org.apache.lucene*;version="[3,4)", - org.springframework*;version="[3,4)", - org.apache.maven.index*, - org.apache.archiva.redback.components.scheduler, - org.quartz, - org.apache.archiva.scheduler, - org.slf4j;resolution:=optional - </Import-Package> - </instructions> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <systemPropertyVariables> - <appserver.base>${project.build.directory}/appserver-base</appserver.base> - <plexus.home>${project.build.directory}/appserver-base</plexus.home> - <derby.system.home>${project.build.directory}/appserver-base</derby.system.home> - <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url> - <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name> - <archiva.repositorySessionFactory.id>mock</archiva.repositorySessionFactory.id> - <openjpa.Log>${openjpa.Log}</openjpa.Log> - </systemPropertyVariables> - </configuration> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java deleted file mode 100644 index b4daa8b..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultIndexMerger.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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.archiva.common.utils.FileUtils; -import org.apache.commons.lang.time.StopWatch; -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.apache.maven.index.packer.IndexPacker; -import org.apache.maven.index.packer.IndexPackingRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Collection; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; - -/** - * @author Olivier Lamy - * @since 1.4-M2 - */ -@Service("indexMerger#default") -public class DefaultIndexMerger - implements IndexMerger -{ - - private Logger log = LoggerFactory.getLogger( getClass() ); - - private final NexusIndexer indexer; - - private final IndexPacker indexPacker; - - private final List<IndexCreator> indexCreators; - - private List<TemporaryGroupIndex> temporaryGroupIndexes = new CopyOnWriteArrayList<>(); - - private List<String> runningGroups = new CopyOnWriteArrayList<>(); - - @Inject - public DefaultIndexMerger( NexusIndexer nexusIndexer, IndexPacker indexPacker, List<IndexCreator> indexCreators ) - { - this.indexer = nexusIndexer; - this.indexPacker = indexPacker; - this.indexCreators = indexCreators; - } - - @Override - public IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest ) - throws IndexMergerException - { - String groupId = indexMergerRequest.getGroupId(); - - if ( runningGroups.contains( groupId ) ) - { - log.info( "skip build merge remote indexes for id: '{}' as already running", groupId ); - return null; - } - - runningGroups.add( groupId ); - - StopWatch stopWatch = new StopWatch(); - stopWatch.reset(); - stopWatch.start(); - - Path mergedIndexDirectory = indexMergerRequest.getMergedIndexDirectory(); - - String tempRepoId = mergedIndexDirectory.getFileName().toString(); - - try - { - Path indexLocation = mergedIndexDirectory.resolve( indexMergerRequest.getMergedIndexPath() ); - IndexingContext indexingContext = - indexer.addIndexingContext( tempRepoId, tempRepoId, mergedIndexDirectory.toFile(), indexLocation.toFile(), null, null, - indexCreators ); - - for ( String repoId : indexMergerRequest.getRepositoriesIds() ) - { - IndexingContext idxToMerge = indexer.getIndexingContexts().get( repoId ); - if ( idxToMerge != null ) - { - indexingContext.merge( idxToMerge.getIndexDirectory() ); - } - } - - indexingContext.optimize(); - - if ( indexMergerRequest.isPackIndex() ) - { - IndexPackingRequest request = new IndexPackingRequest( indexingContext, // - indexingContext.acquireIndexSearcher().getIndexReader(), // - indexLocation.toFile() ); - indexPacker.packIndex( request ); - } - - if ( indexMergerRequest.isTemporary() ) - { - temporaryGroupIndexes.add( new TemporaryGroupIndex( mergedIndexDirectory, tempRepoId, groupId, - indexMergerRequest.getMergedIndexTtl() ) ); - } - stopWatch.stop(); - log.info( "merged index for repos {} in {} s", indexMergerRequest.getRepositoriesIds(), - stopWatch.getTime() ); - return indexingContext; - } - catch ( IOException | UnsupportedExistingLuceneIndexException e ) - { - throw new IndexMergerException( e.getMessage(), e ); - } - finally - { - runningGroups.remove( groupId ); - } - } - - @Async - @Override - public void cleanTemporaryGroupIndex( TemporaryGroupIndex temporaryGroupIndex ) - { - if ( temporaryGroupIndex == null ) - { - return; - } - - try - { - IndexingContext indexingContext = indexer.getIndexingContexts().get( temporaryGroupIndex.getIndexId() ); - if ( indexingContext != null ) - { - indexer.removeIndexingContext( indexingContext, true ); - } - Path directory = temporaryGroupIndex.getDirectory(); - if ( directory != null && Files.exists(directory) ) - { - FileUtils.deleteDirectory( directory ); - } - temporaryGroupIndexes.remove( temporaryGroupIndex ); - } - catch ( IOException e ) - { - log.warn( "fail to delete temporary group index {}", temporaryGroupIndex.getIndexId(), e ); - } - } - - @Override - public Collection<TemporaryGroupIndex> getTemporaryGroupIndexes() - { - return this.temporaryGroupIndexes; - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java deleted file mode 100644 index f0fbcbd..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/DefaultMergedRemoteIndexesScheduler.java +++ /dev/null @@ -1,94 +0,0 @@ -package org.apache.archiva.indexer.merger; - -/* - * 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.archiva.admin.model.beans.RepositoryGroup; -import org.apache.archiva.scheduler.MergedRemoteIndexesScheduler; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.scheduling.TaskScheduler; -import org.springframework.scheduling.support.CronTrigger; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import javax.inject.Named; -import java.nio.file.Path; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledFuture; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -@Service( "mergedRemoteIndexesScheduler#default" ) -public class DefaultMergedRemoteIndexesScheduler - implements MergedRemoteIndexesScheduler -{ - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - @Inject - @Named( value = "taskScheduler#mergeRemoteIndexes" ) - private TaskScheduler taskScheduler; - - @Inject - private IndexMerger indexMerger; - - private Map<String, ScheduledFuture> scheduledFutureMap = new ConcurrentHashMap<>(); - - @Override - public void schedule( RepositoryGroup repositoryGroup, Path directory ) - { - if ( StringUtils.isEmpty( repositoryGroup.getCronExpression() ) ) - { - return; - } - CronTrigger cronTrigger = new CronTrigger( repositoryGroup.getCronExpression() ); - - List<String> repositories = repositoryGroup.getRepositories(); - - IndexMergerRequest indexMergerRequest = - new IndexMergerRequest( repositories, true, repositoryGroup.getId(), repositoryGroup.getMergedIndexPath(), - repositoryGroup.getMergedIndexTtl() ).mergedIndexDirectory( directory ); - - MergedRemoteIndexesTaskRequest taskRequest = - new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger ); - - logger.info( "schedule merge remote index for group {} with cron {}", repositoryGroup.getId(), - repositoryGroup.getCronExpression() ); - - ScheduledFuture scheduledFuture = - taskScheduler.schedule( new MergedRemoteIndexesTask( taskRequest ), cronTrigger ); - scheduledFutureMap.put( repositoryGroup.getId(), scheduledFuture ); - } - - @Override - public void unschedule( RepositoryGroup repositoryGroup ) - { - ScheduledFuture scheduledFuture = scheduledFutureMap.remove( repositoryGroup.getId() ); - if ( scheduledFuture != null ) - { - scheduledFuture.cancel( true ); - } - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java deleted file mode 100644 index 756819e..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMerger.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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.IndexingContext; - -import java.util.Collection; - -/** - * @author Olivier Lamy - * @since 1.4-M2 - */ -public interface IndexMerger -{ - /** - * @param indexMergerRequest - * @return a temporary directory with a merge index (directory marked deleteOnExit) - * @throws IndexMergerException - */ - IndexingContext buildMergedIndex( IndexMergerRequest indexMergerRequest ) - throws IndexMergerException; - - void cleanTemporaryGroupIndex( TemporaryGroupIndex temporaryGroupIndex ); - - Collection<TemporaryGroupIndex> getTemporaryGroupIndexes(); -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerException.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerException.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerException.java deleted file mode 100644 index 3930831..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerException.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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. - */ - -/** - * @author Olivier Lamy - * @since 1.4-M2 - */ -public class IndexMergerException - extends Exception -{ - public IndexMergerException( String message, Throwable t ) - { - super( message, t ); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java deleted file mode 100644 index 0b3803f..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/IndexMergerRequest.java +++ /dev/null @@ -1,192 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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 java.nio.file.Path; -import java.util.Collection; - -/** - * @author Olivier Lamy - */ -public class IndexMergerRequest -{ - /** - * repositories Ids to merge content - */ - private Collection<String> repositoriesIds; - - /** - * will generate a downloadable index - */ - private boolean packIndex; - - /** - * original groupId (repositoryGroup id) - */ - private String groupId; - - private String mergedIndexPath = ".indexer"; - - private int mergedIndexTtl; - - private Path mergedIndexDirectory; - - private boolean temporary; - - public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId ) - { - this.repositoriesIds = repositoriesIds; - this.packIndex = packIndex; - this.groupId = groupId; - } - - /** - * @since 1.4-M4 - */ - public IndexMergerRequest( Collection<String> repositoriesIds, boolean packIndex, String groupId, - String mergedIndexPath, int mergedIndexTtl ) - { - this.repositoriesIds = repositoriesIds; - this.packIndex = packIndex; - this.groupId = groupId; - this.mergedIndexPath = mergedIndexPath; - this.mergedIndexTtl = mergedIndexTtl; - } - - public Collection<String> getRepositoriesIds() - { - return repositoriesIds; - } - - public void setRepositoriesIds( Collection<String> repositoriesIds ) - { - this.repositoriesIds = repositoriesIds; - } - - public boolean isPackIndex() - { - return packIndex; - } - - public void setPackIndex( boolean packIndex ) - { - this.packIndex = packIndex; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public String getMergedIndexPath() - { - return mergedIndexPath; - } - - public void setMergedIndexPath( String mergedIndexPath ) - { - this.mergedIndexPath = mergedIndexPath; - } - - public int getMergedIndexTtl() - { - return mergedIndexTtl; - } - - public void setMergedIndexTtl( int mergedIndexTtl ) - { - this.mergedIndexTtl = mergedIndexTtl; - } - - public Path getMergedIndexDirectory() - { - return mergedIndexDirectory; - } - - public void setMergedIndexDirectory( Path mergedIndexDirectory ) - { - this.mergedIndexDirectory = mergedIndexDirectory; - } - - public IndexMergerRequest mergedIndexDirectory( Path mergedIndexDirectory ) - { - this.mergedIndexDirectory = mergedIndexDirectory; - return this; - } - - public boolean isTemporary() - { - return temporary; - } - - public void setTemporary( boolean temporary ) - { - this.temporary = temporary; - } - - - public IndexMergerRequest temporary( boolean temporary ) - { - this.temporary = temporary; - return this; - } - - @Override - public String toString() - { - final StringBuilder sb = new StringBuilder( "IndexMergerRequest{" ); - sb.append( "repositoriesIds=" ).append( repositoriesIds ); - sb.append( ", packIndex=" ).append( packIndex ); - sb.append( ", groupId='" ).append( groupId ).append( '\'' ); - sb.append( ", mergedIndexPath='" ).append( mergedIndexPath ).append( '\'' ); - sb.append( ", mergedIndexTtl=" ).append( mergedIndexTtl ); - sb.append( ", mergedIndexDirectory=" ).append( mergedIndexDirectory ); - sb.append( ", temporary=" ).append( temporary ); - sb.append( '}' ); - return sb.toString(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - IndexMergerRequest that = (IndexMergerRequest) o; - - return groupId.equals( that.groupId ); - } - - @Override - public int hashCode() - { - return groupId.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java deleted file mode 100644 index c67d312..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTask.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.apache.archiva.indexer.merger; - -/* - * 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.IndexingContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class MergedRemoteIndexesTask - implements Runnable -{ - - private Logger logger = LoggerFactory.getLogger( getClass() ); - - private MergedRemoteIndexesTaskRequest mergedRemoteIndexesTaskRequest; - - public MergedRemoteIndexesTask( MergedRemoteIndexesTaskRequest mergedRemoteIndexesTaskRequest ) - { - this.mergedRemoteIndexesTaskRequest = mergedRemoteIndexesTaskRequest; - } - - @Override - public void run() - { - try - { - this.execute(); - } - catch ( IndexMergerException e ) - { - logger.error( e.getMessage(), e ); - } - } - - public MergedRemoteIndexesTaskResult execute() - throws IndexMergerException - { - IndexMerger indexMerger = mergedRemoteIndexesTaskRequest.getIndexMerger(); - - IndexingContext indexingContext = - indexMerger.buildMergedIndex( mergedRemoteIndexesTaskRequest.getIndexMergerRequest() ); - - return new MergedRemoteIndexesTaskResult( indexingContext ); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof MergedRemoteIndexesTask ) ) - { - return false; - } - - MergedRemoteIndexesTask that = (MergedRemoteIndexesTask) o; - - return mergedRemoteIndexesTaskRequest.equals( that.mergedRemoteIndexesTaskRequest ); - } - - @Override - public int hashCode() - { - return mergedRemoteIndexesTaskRequest.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java deleted file mode 100644 index bc0663d..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskRequest.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.apache.archiva.indexer.merger; - -/* - * 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. - */ - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class MergedRemoteIndexesTaskRequest -{ - private IndexMergerRequest indexMergerRequest; - - private IndexMerger indexMerger; - - public MergedRemoteIndexesTaskRequest( IndexMergerRequest indexMergerRequest, IndexMerger indexMerger ) - { - this.indexMergerRequest = indexMergerRequest; - this.indexMerger = indexMerger; - } - - public IndexMergerRequest getIndexMergerRequest() - { - return indexMergerRequest; - } - - public void setIndexMergerRequest( IndexMergerRequest indexMergerRequest ) - { - this.indexMergerRequest = indexMergerRequest; - } - - public IndexMerger getIndexMerger() - { - return indexMerger; - } - - public void setIndexMerger( IndexMerger indexMerger ) - { - this.indexMerger = indexMerger; - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( o == null || getClass() != o.getClass() ) - { - return false; - } - - MergedRemoteIndexesTaskRequest that = (MergedRemoteIndexesTaskRequest) o; - - return indexMergerRequest.equals( that.indexMergerRequest ); - } - - @Override - public int hashCode() - { - return indexMergerRequest.hashCode(); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java deleted file mode 100644 index b75a292..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/MergedRemoteIndexesTaskResult.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.archiva.indexer.merger; - -/* - * 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.IndexingContext; - -/** - * @author Olivier Lamy - * @since 2.0.0 - */ -public class MergedRemoteIndexesTaskResult -{ - private IndexingContext indexingContext; - - public MergedRemoteIndexesTaskResult( IndexingContext indexingContext ) - { - this.indexingContext = indexingContext; - } - - public IndexingContext getIndexingContext() - { - return indexingContext; - } - - public void setIndexingContext( IndexingContext indexingContext ) - { - this.indexingContext = indexingContext; - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java deleted file mode 100644 index d0b576b..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndex.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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 java.io.Serializable; -import java.nio.file.Path; -import java.util.Date; - -/** - * @author Olivier Lamy - */ -public class TemporaryGroupIndex - implements Serializable -{ - private long creationTime = new Date().getTime(); - - private Path directory; - - private String indexId; - - private String groupId; - - private int mergedIndexTtl; - - public TemporaryGroupIndex(Path directory, String indexId, String groupId, int mergedIndexTtl) - { - this.directory = directory; - this.indexId = indexId; - this.groupId = groupId; - this.mergedIndexTtl = mergedIndexTtl; - } - - public long getCreationTime() - { - return creationTime; - } - - public TemporaryGroupIndex setCreationTime( long creationTime ) - { - this.creationTime = creationTime; - return this; - } - - public Path getDirectory() - { - return directory; - } - - public TemporaryGroupIndex setDirectory( Path directory ) - { - this.directory = directory; - return this; - } - - public String getIndexId() - { - return indexId; - } - - public TemporaryGroupIndex setIndexId( String indexId ) - { - this.indexId = indexId; - return this; - } - - public String getGroupId() - { - return groupId; - } - - public void setGroupId( String groupId ) - { - this.groupId = groupId; - } - - public int getMergedIndexTtl() { - return mergedIndexTtl; - } - - public void setMergedIndexTtl(int mergedIndexTtl) { - this.mergedIndexTtl = mergedIndexTtl; - } - - @Override - public int hashCode() - { - return Long.toString( creationTime ).hashCode(); - } - - @Override - public boolean equals( Object o ) - { - if ( this == o ) - { - return true; - } - if ( !( o instanceof TemporaryGroupIndex ) ) - { - return false; - } - return this.creationTime == ( (TemporaryGroupIndex) o ).creationTime; - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java deleted file mode 100644 index dc7f5c0..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/merger/TemporaryGroupIndexCleaner.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.apache.archiva.indexer.merger; -/* - * 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.archiva.common.plexusbridge.PlexusSisuBridge; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; -import org.apache.maven.index.NexusIndexer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import java.util.Date; - -/** - * @author Olivier Lamy - * @since 1.4-M2 - */ -@Service -public class TemporaryGroupIndexCleaner -{ - private Logger log = LoggerFactory.getLogger( getClass() ); - - @Inject - private IndexMerger indexMerger; - - private NexusIndexer indexer; - - @Inject - public TemporaryGroupIndexCleaner( NexusIndexer nexusIndexer ) - throws PlexusSisuBridgeException - { - this.indexer = nexusIndexer; - } - - // 900000 - @Scheduled(fixedDelay = 900000) - public void cleanTemporaryIndex() - { - - indexMerger.getTemporaryGroupIndexes() - .stream() - .forEach( temporaryGroupIndex -> - { - // cleanup files older than the ttl - if ( new Date().getTime() - temporaryGroupIndex.getCreationTime() > - temporaryGroupIndex.getMergedIndexTtl() ) - { - log.info( "cleanTemporaryIndex for groupId {}", temporaryGroupIndex.getGroupId() ); - indexMerger.cleanTemporaryGroupIndex( temporaryGroupIndex ); - - } - } - ); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java deleted file mode 100644 index b6f4984..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/MavenRepositorySearch.java +++ /dev/null @@ -1,737 +0,0 @@ -package org.apache.archiva.indexer.search; - -/* - * 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.archiva.admin.model.RepositoryAdminException; -import org.apache.archiva.admin.model.beans.ManagedRepository; -import org.apache.archiva.admin.model.beans.ProxyConnector; -import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin; -import org.apache.archiva.admin.model.proxyconnector.ProxyConnectorAdmin; -import org.apache.archiva.common.plexusbridge.PlexusSisuBridgeException; -import org.apache.archiva.indexer.util.SearchUtil; -import org.apache.archiva.model.ArchivaArtifactModel; -import org.apache.archiva.model.ArtifactReference; -import org.apache.commons.lang.StringUtils; -import org.apache.maven.index.ArtifactInfo; -import org.apache.maven.index.FlatSearchRequest; -import org.apache.maven.index.FlatSearchResponse; -import org.apache.maven.index.MAVEN; -import org.apache.maven.index.NexusIndexer; -import org.apache.maven.index.OSGI; -import org.apache.maven.index.QueryCreator; -import org.apache.maven.index.SearchType; -import org.apache.maven.index.context.IndexingContext; -import org.apache.maven.index.expr.SearchExpression; -import org.apache.maven.index.expr.SearchTyped; -import org.apache.maven.index.expr.SourcedSearchExpression; -import org.apache.maven.index.expr.UserInputSearchExpression; -import org.apache.maven.index_shaded.lucene.search.BooleanClause; -import org.apache.maven.index_shaded.lucene.search.BooleanClause.Occur; -import org.apache.maven.index_shaded.lucene.search.BooleanQuery; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import javax.inject.Inject; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * RepositorySearch implementation which uses the Maven Indexer for searching. - */ -@Service( "repositorySearch#maven" ) -public class MavenRepositorySearch - implements RepositorySearch -{ - private Logger log = LoggerFactory.getLogger( getClass() ); - - private NexusIndexer indexer; - - private QueryCreator queryCreator; - - private ManagedRepositoryAdmin managedRepositoryAdmin; - - private ProxyConnectorAdmin proxyConnectorAdmin; - - protected MavenRepositorySearch() - { - // for test purpose - } - - @Inject - public MavenRepositorySearch( NexusIndexer nexusIndexer, ManagedRepositoryAdmin managedRepositoryAdmin, - ProxyConnectorAdmin proxyConnectorAdmin, QueryCreator queryCreator ) - throws PlexusSisuBridgeException - { - this.indexer = nexusIndexer; - this.queryCreator = queryCreator; - this.managedRepositoryAdmin = managedRepositoryAdmin; - this.proxyConnectorAdmin = proxyConnectorAdmin; - } - - /** - * @see RepositorySearch#search(String, List, String, SearchResultLimits, List) - */ - @Override - public SearchResults search( String principal, List<String> selectedRepos, String term, SearchResultLimits limits, - List<String> previousSearchTerms ) - throws RepositorySearchException - { - List<String> indexingContextIds = addIndexingContexts( selectedRepos ); - - // since upgrade to nexus 2.0.0, query has changed from g:[QUERIED TERM]* to g:*[QUERIED TERM]* - // resulting to more wildcard searches so we need to increase max clause count - BooleanQuery.setMaxClauseCount( Integer.MAX_VALUE ); - BooleanQuery q = new BooleanQuery(); - - if ( previousSearchTerms == null || previousSearchTerms.isEmpty() ) - { - constructQuery( term, q ); - } - else - { - for ( String previousTerm : previousSearchTerms ) - { - BooleanQuery iQuery = new BooleanQuery(); - constructQuery( previousTerm, iQuery ); - - q.add( iQuery, BooleanClause.Occur.MUST ); - } - - BooleanQuery iQuery = new BooleanQuery(); - constructQuery( term, iQuery ); - q.add( iQuery, BooleanClause.Occur.MUST ); - } - - // we retun only artifacts without classifier in quick search, olamy cannot find a way to say with this field empty - // FIXME cannot find a way currently to setup this in constructQuery !!! - return search( limits, q, indexingContextIds, NoClassifierArtifactInfoFilter.LIST, selectedRepos, true ); - - } - - /** - * @see RepositorySearch#search(String, SearchFields, SearchResultLimits) - */ - @Override - public SearchResults search( String principal, SearchFields searchFields, SearchResultLimits limits ) - throws RepositorySearchException - { - if ( searchFields.getRepositories() == null ) - { - throw new RepositorySearchException( "Repositories cannot be null." ); - } - - List<String> indexingContextIds = addIndexingContexts( searchFields.getRepositories() ); - - // if no index found in the specified ones return an empty search result instead of doing a search on all index - // olamy: IMHO doesn't make sense - if ( !searchFields.getRepositories().isEmpty() && ( indexingContextIds == null - || indexingContextIds.isEmpty() ) ) - { - return new SearchResults(); - } - - BooleanQuery q = new BooleanQuery(); - if ( StringUtils.isNotBlank( searchFields.getGroupId() ) ) - { - q.add( indexer.constructQuery( MAVEN.GROUP_ID, searchFields.isExactSearch() ? new SourcedSearchExpression( - searchFields.getGroupId() ) : new UserInputSearchExpression( searchFields.getGroupId() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getArtifactId() ) ) - { - q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, - searchFields.isExactSearch() - ? new SourcedSearchExpression( searchFields.getArtifactId() ) - : new UserInputSearchExpression( searchFields.getArtifactId() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getVersion() ) ) - { - q.add( indexer.constructQuery( MAVEN.VERSION, searchFields.isExactSearch() ? new SourcedSearchExpression( - searchFields.getVersion() ) : new SourcedSearchExpression( searchFields.getVersion() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getPackaging() ) ) - { - q.add( indexer.constructQuery( MAVEN.PACKAGING, searchFields.isExactSearch() ? new SourcedSearchExpression( - searchFields.getPackaging() ) : new UserInputSearchExpression( searchFields.getPackaging() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getClassName() ) ) - { - q.add( indexer.constructQuery( MAVEN.CLASSNAMES, - new UserInputSearchExpression( searchFields.getClassName() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleSymbolicName() ) ) - { - q.add( indexer.constructQuery( OSGI.SYMBOLIC_NAME, - new UserInputSearchExpression( searchFields.getBundleSymbolicName() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleVersion() ) ) - { - q.add( indexer.constructQuery( OSGI.VERSION, - new UserInputSearchExpression( searchFields.getBundleVersion() ) ), - BooleanClause.Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleExportPackage() ) ) - { - q.add( indexer.constructQuery( OSGI.EXPORT_PACKAGE, - new UserInputSearchExpression( searchFields.getBundleExportPackage() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleExportService() ) ) - { - q.add( indexer.constructQuery( OSGI.EXPORT_SERVICE, - new UserInputSearchExpression( searchFields.getBundleExportService() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) - { - q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, - new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleName() ) ) - { - q.add( indexer.constructQuery( OSGI.NAME, new UserInputSearchExpression( searchFields.getBundleName() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleImportPackage() ) ) - { - q.add( indexer.constructQuery( OSGI.IMPORT_PACKAGE, - new UserInputSearchExpression( searchFields.getBundleImportPackage() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getBundleRequireBundle() ) ) - { - q.add( indexer.constructQuery( OSGI.REQUIRE_BUNDLE, - new UserInputSearchExpression( searchFields.getBundleRequireBundle() ) ), - Occur.MUST ); - } - - if ( StringUtils.isNotBlank( searchFields.getClassifier() ) ) - { - q.add( indexer.constructQuery( MAVEN.CLASSIFIER, searchFields.isExactSearch() ? new SourcedSearchExpression( - searchFields.getClassifier() ) : new UserInputSearchExpression( searchFields.getClassifier() ) ), - Occur.MUST ); - } - else if ( searchFields.isExactSearch() ) - { - //TODO improvement in case of exact search and no classifier we must query for classifier with null value - // currently it's done in DefaultSearchService with some filtering - } - - if ( q.getClauses() == null || q.getClauses().length <= 0 ) - { - throw new RepositorySearchException( "No search fields set." ); - } - System.err.println("CLAUSES "+q.getClauses()); - if (q.getClauses()!=null) { - for (BooleanClause cl : q.getClauses()) { - System.err.println("Clause "+cl); - } - } - - return search( limits, q, indexingContextIds, Collections.<ArtifactInfoFilter>emptyList(), - searchFields.getRepositories(), searchFields.isIncludePomArtifacts() ); - } - - private static class NullSearch - implements SearchTyped, SearchExpression - { - private static final NullSearch INSTANCE = new NullSearch(); - - @Override - public String getStringValue() - { - return "[[NULL_VALUE]]"; - } - - @Override - public SearchType getSearchType() - { - return SearchType.EXACT; - } - } - - private SearchResults search( SearchResultLimits limits, BooleanQuery q, List<String> indexingContextIds, - List<? extends ArtifactInfoFilter> filters, List<String> selectedRepos, - boolean includePoms ) - throws RepositorySearchException - { - - try - { - FlatSearchRequest request = new FlatSearchRequest( q ); - - request.setContexts( getIndexingContexts( indexingContextIds ) ); - if ( limits != null ) - { - // we apply limits only when first page asked - if ( limits.getSelectedPage() == 0 ) - { - request.setCount( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) ); - } - } - - FlatSearchResponse response = indexer.searchFlat( request ); - - if ( response == null || response.getTotalHits() == 0 ) - { - SearchResults results = new SearchResults(); - results.setLimits( limits ); - return results; - } - - return convertToSearchResults( response, limits, filters, selectedRepos, includePoms ); - } - catch ( IOException e ) - { - throw new RepositorySearchException( e.getMessage(), e ); - } - catch ( RepositoryAdminException e ) - { - throw new RepositorySearchException( e.getMessage(), e ); - } - - } - - private List<IndexingContext> getIndexingContexts( List<String> ids ) - { - List<IndexingContext> contexts = new ArrayList<>( ids.size() ); - - for ( String id : ids ) - { - IndexingContext context = indexer.getIndexingContexts().get( id ); - if ( context != null ) - { - contexts.add( context ); - } - else - { - log.warn( "context with id {} not exists", id ); - } - } - - return contexts; - } - - private void constructQuery( String term, BooleanQuery q ) - { - q.add( indexer.constructQuery( MAVEN.GROUP_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); - q.add( indexer.constructQuery( MAVEN.ARTIFACT_ID, new UserInputSearchExpression( term ) ), Occur.SHOULD ); - q.add( indexer.constructQuery( MAVEN.VERSION, new UserInputSearchExpression( term ) ), Occur.SHOULD ); - q.add( indexer.constructQuery( MAVEN.PACKAGING, new UserInputSearchExpression( term ) ), Occur.SHOULD ); - q.add( indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( term ) ), Occur.SHOULD ); - - //Query query = - // new WildcardQuery( new Term( MAVEN.CLASSNAMES.getFieldName(), "*" ) ); - //q.add( query, Occur.MUST_NOT ); - // olamy IMHO we could set this option as at least one must match - //q.setMinimumNumberShouldMatch( 1 ); - } - - - /** - * @param selectedRepos - * @return indexing contextId used - */ - private List<String> addIndexingContexts( List<String> selectedRepos ) - { - Set<String> indexingContextIds = new HashSet<>(); - for ( String repo : selectedRepos ) - { - try - { - ManagedRepository repoConfig = managedRepositoryAdmin.getManagedRepository( repo ); - - if ( repoConfig != null ) - { - - IndexingContext context = managedRepositoryAdmin.createIndexContext( repoConfig ); - if ( context.isSearchable() ) - { - indexingContextIds.addAll( getRemoteIndexingContextIds( repo ) ); - indexingContextIds.add( context.getId() ); - } - else - { - log.warn( "indexingContext with id {} not searchable", repoConfig.getId() ); - } - - } - else - { - log.warn( "Repository '{}' not found in configuration.", repo ); - } - } - catch ( RepositoryAdminException e ) - { - log.warn( "RepositoryAdminException occured while accessing index of repository '{}' : {}", repo, - e.getMessage() ); - continue; - } - catch ( RepositorySearchException e ) - { - log.warn( "RepositorySearchException occured while accessing index of repository '{}' : {}", repo, - e.getMessage() ); - continue; - } - } - - return new ArrayList<>( indexingContextIds ); - } - - - @Override - public Set<String> getRemoteIndexingContextIds( String managedRepoId ) - throws RepositorySearchException - { - Set<String> ids = new HashSet<>(); - - List<ProxyConnector> proxyConnectors = null; - try - { - proxyConnectors = proxyConnectorAdmin.getProxyConnectorAsMap().get( managedRepoId ); - } - catch ( RepositoryAdminException e ) - { - throw new RepositorySearchException( e.getMessage(), e ); - } - - if ( proxyConnectors == null || proxyConnectors.isEmpty() ) - { - return ids; - } - - for ( ProxyConnector proxyConnector : proxyConnectors ) - { - String remoteId = "remote-" + proxyConnector.getTargetRepoId(); - IndexingContext context = indexer.getIndexingContexts().get( remoteId ); - if ( context != null && context.isSearchable() ) - { - ids.add( remoteId ); - } - } - - return ids; - } - - @Override - public Collection<String> getAllGroupIds( String principal, List<String> selectedRepos ) - throws RepositorySearchException - { - List<IndexingContext> indexContexts = getIndexingContexts( selectedRepos ); - - if ( indexContexts == null || indexContexts.isEmpty() ) - { - return Collections.emptyList(); - } - - try - { - Set<String> allGroupIds = new HashSet<>(); - for ( IndexingContext indexingContext : indexContexts ) - { - allGroupIds.addAll( indexingContext.getAllGroups() ); - } - return allGroupIds; - } - catch ( IOException e ) - { - throw new RepositorySearchException( e.getMessage(), e ); - } - - } - - private SearchResults convertToSearchResults( FlatSearchResponse response, SearchResultLimits limits, - List<? extends ArtifactInfoFilter> artifactInfoFilters, - List<String> selectedRepos, boolean includePoms ) - throws RepositoryAdminException - { - SearchResults results = new SearchResults(); - Set<ArtifactInfo> artifactInfos = response.getResults(); - - for ( ArtifactInfo artifactInfo : artifactInfos ) - { - if ( StringUtils.equalsIgnoreCase( "pom", artifactInfo.getFileExtension() ) && !includePoms ) - { - continue; - } - String id = SearchUtil.getHitId( artifactInfo.getGroupId(), // - artifactInfo.getArtifactId(), // - artifactInfo.getClassifier(), // - artifactInfo.getPackaging() ); - Map<String, SearchResultHit> hitsMap = results.getHitsMap(); - - - if ( !applyArtifactInfoFilters( artifactInfo, artifactInfoFilters, hitsMap ) ) - { - continue; - } - - SearchResultHit hit = hitsMap.get( id ); - if ( hit != null ) - { - if ( !hit.getVersions().contains( artifactInfo.getVersion() ) ) - { - hit.addVersion( artifactInfo.getVersion() ); - } - } - else - { - hit = new SearchResultHit(); - hit.setArtifactId( artifactInfo.getArtifactId() ); - hit.setGroupId( artifactInfo.getGroupId() ); - hit.setRepositoryId( artifactInfo.getRepository() ); - hit.addVersion( artifactInfo.getVersion() ); - hit.setBundleExportPackage( artifactInfo.getBundleExportPackage() ); - hit.setBundleExportService( artifactInfo.getBundleExportService() ); - hit.setBundleSymbolicName( artifactInfo.getBundleSymbolicName() ); - hit.setBundleVersion( artifactInfo.getBundleVersion() ); - hit.setBundleDescription( artifactInfo.getBundleDescription() ); - hit.setBundleDocUrl( artifactInfo.getBundleDocUrl() ); - hit.setBundleRequireBundle( artifactInfo.getBundleRequireBundle() ); - hit.setBundleImportPackage( artifactInfo.getBundleImportPackage() ); - hit.setBundleLicense( artifactInfo.getBundleLicense() ); - hit.setBundleName( artifactInfo.getBundleName() ); - hit.setContext( artifactInfo.getContext() ); - hit.setGoals( artifactInfo.getGoals() ); - hit.setPrefix( artifactInfo.getPrefix() ); - hit.setPackaging( artifactInfo.getPackaging() ); - hit.setClassifier( artifactInfo.getClassifier() ); - hit.setFileExtension( artifactInfo.getFileExtension() ); - hit.setUrl( getBaseUrl( artifactInfo, selectedRepos ) ); - } - - results.addHit( id, hit ); - } - - results.setTotalHits( response.getTotalHitsCount() ); - results.setTotalHitsMapSize( results.getHitsMap().values().size() ); - results.setReturnedHitsCount( response.getReturnedHitsCount() ); - results.setLimits( limits ); - - if ( limits == null || limits.getSelectedPage() == SearchResultLimits.ALL_PAGES ) - { - return results; - } - else - { - return paginate( results ); - } - } - - /** - * calculate baseUrl without the context and base Archiva Url - * - * @param artifactInfo - * @return - */ - protected String getBaseUrl( ArtifactInfo artifactInfo, List<String> selectedRepos ) - throws RepositoryAdminException - { - StringBuilder sb = new StringBuilder(); - if ( StringUtils.startsWith( artifactInfo.getContext(), "remote-" ) ) - { - // it's a remote index result we search a managed which proxying this remote and on which - // current user has read karma - String managedRepoId = - getManagedRepoId( StringUtils.substringAfter( artifactInfo.getContext(), "remote-" ), selectedRepos ); - if ( managedRepoId != null ) - { - sb.append( '/' ).append( managedRepoId ); - artifactInfo.setContext( managedRepoId ); - } - } - else - { - sb.append( '/' ).append( artifactInfo.getContext() ); - } - - sb.append( '/' ).append( StringUtils.replaceChars( artifactInfo.getGroupId(), '.', '/' ) ); - sb.append( '/' ).append( artifactInfo.getArtifactId() ); - sb.append( '/' ).append( artifactInfo.getVersion() ); - sb.append( '/' ).append( artifactInfo.getArtifactId() ); - sb.append( '-' ).append( artifactInfo.getVersion() ); - if ( StringUtils.isNotBlank( artifactInfo.getClassifier() ) ) - { - sb.append( '-' ).append( artifactInfo.getClassifier() ); - } - // maven-plugin packaging is a jar - if ( StringUtils.equals( "maven-plugin", artifactInfo.getPackaging() ) ) - { - sb.append( "jar" ); - } - else - { - sb.append( '.' ).append( artifactInfo.getPackaging() ); - } - - return sb.toString(); - } - - /** - * return a managed repo for a remote result - * - * @param remoteRepo - * @param selectedRepos - * @return - * @throws RepositoryAdminException - */ - private String getManagedRepoId( String remoteRepo, List<String> selectedRepos ) - throws RepositoryAdminException - { - Map<String, List<ProxyConnector>> proxyConnectorMap = proxyConnectorAdmin.getProxyConnectorAsMap(); - if ( proxyConnectorMap == null || proxyConnectorMap.isEmpty() ) - { - return null; - } - if ( selectedRepos != null && !selectedRepos.isEmpty() ) - { - for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() ) - { - if ( selectedRepos.contains( entry.getKey() ) ) - { - for ( ProxyConnector proxyConnector : entry.getValue() ) - { - if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) ) - { - return proxyConnector.getSourceRepoId(); - } - } - } - } - } - - // we don't find in search selected repos so return the first one - for ( Map.Entry<String, List<ProxyConnector>> entry : proxyConnectorMap.entrySet() ) - { - - for ( ProxyConnector proxyConnector : entry.getValue() ) - { - if ( StringUtils.equals( remoteRepo, proxyConnector.getTargetRepoId() ) ) - { - return proxyConnector.getSourceRepoId(); - } - } - - } - return null; - } - - private boolean applyArtifactInfoFilters( ArtifactInfo artifactInfo, - List<? extends ArtifactInfoFilter> artifactInfoFilters, - Map<String, SearchResultHit> currentResult ) - { - if ( artifactInfoFilters == null || artifactInfoFilters.isEmpty() ) - { - return true; - } - - ArchivaArtifactModel artifact = new ArchivaArtifactModel(); - artifact.setArtifactId( artifactInfo.getArtifactId() ); - artifact.setClassifier( artifactInfo.getClassifier() ); - artifact.setGroupId( artifactInfo.getGroupId() ); - artifact.setRepositoryId( artifactInfo.getRepository() ); - artifact.setVersion( artifactInfo.getVersion() ); - artifact.setChecksumMD5( artifactInfo.getMd5() ); - artifact.setChecksumSHA1( artifactInfo.getSha1() ); - for ( ArtifactInfoFilter filter : artifactInfoFilters ) - { - if ( !filter.addArtifactInResult( artifact, currentResult ) ) - { - return false; - } - } - return true; - } - - protected SearchResults paginate( SearchResults results ) - { - SearchResultLimits limits = results.getLimits(); - SearchResults paginated = new SearchResults(); - - // ( limits.getPageSize() * ( Math.max( 1, limits.getSelectedPage() ) ) ); - - int fetchCount = limits.getPageSize(); - int offset = ( limits.getSelectedPage() * limits.getPageSize() ); - - if ( fetchCount > results.getTotalHits() ) - { - fetchCount = results.getTotalHits(); - } - - // Goto offset. - if ( offset < results.getTotalHits() ) - { - // only process if the offset is within the hit count. - for ( int i = 0; i < fetchCount; i++ ) - { - // Stop fetching if we are past the total # of available hits. - if ( offset + i >= results.getHits().size() ) - { - break; - } - - SearchResultHit hit = results.getHits().get( ( offset + i ) ); - if ( hit != null ) - { - String id = SearchUtil.getHitId( hit.getGroupId(), hit.getArtifactId(), hit.getClassifier(), - hit.getPackaging() ); - paginated.addHit( id, hit ); - } - else - { - break; - } - } - } - paginated.setTotalHits( results.getTotalHits() ); - paginated.setReturnedHitsCount( paginated.getHits().size() ); - paginated.setTotalHitsMapSize( results.getTotalHitsMapSize() ); - paginated.setLimits( limits ); - - return paginated; - } - - -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java deleted file mode 100644 index f37c874..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/search/NoClassifierArtifactInfoFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.apache.archiva.indexer.search; -/* - * 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.archiva.model.ArchivaArtifactModel; -import org.apache.commons.lang.StringUtils; - -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -/** - * @author Olivier Lamy - */ -public class NoClassifierArtifactInfoFilter - implements ArtifactInfoFilter -{ - public static final NoClassifierArtifactInfoFilter INSTANCE = new NoClassifierArtifactInfoFilter(); - - public static final List<? extends ArtifactInfoFilter> LIST = Arrays.asList( INSTANCE ); - - @Override - public boolean addArtifactInResult( ArchivaArtifactModel artifact, Map<String, SearchResultHit> currentResult ) - { - return StringUtils.isBlank( artifact.getClassifier() ); - } -} http://git-wip-us.apache.org/repos/asf/archiva/blob/07d51cc3/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java ---------------------------------------------------------------------- diff --git a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java b/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java deleted file mode 100644 index 0a0c922..0000000 --- a/archiva-modules/archiva-base/archiva-indexer/src/main/java/org/apache/archiva/indexer/util/SearchUtil.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apache.archiva.indexer.util; - -/* - * 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.commons.lang.StringUtils; - -/** - * SearchUtil - utility class for search. - */ -public class SearchUtil -{ - public static String getHitId( String groupId, String artifactId, String classifier, String packaging ) - { - return ( StringUtils.isBlank( groupId ) ? "" : StringUtils.trim( groupId ) ) + ":" // - + ( StringUtils.isBlank( artifactId ) ? "" : StringUtils.trim( artifactId ) ) + ":" // - + ( StringUtils.isBlank( classifier ) ? "" : StringUtils.trim( classifier ) ) + ":" // - + ( StringUtils.isBlank( packaging ) ? "" : StringUtils.trim( packaging ) ); - } -}
