Repository: maven-indexer Updated Branches: refs/heads/master a5039e593 -> 9c907aa64
upgrade some plugins fix parent pom for samples Signed-off-by: olivier lamy <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/maven-indexer/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-indexer/commit/9c907aa6 Tree: http://git-wip-us.apache.org/repos/asf/maven-indexer/tree/9c907aa6 Diff: http://git-wip-us.apache.org/repos/asf/maven-indexer/diff/9c907aa6 Branch: refs/heads/master Commit: 9c907aa641aa2314fc9a80a4bbf11dbe0f099d01 Parents: a5039e5 Author: olivier lamy <[email protected]> Authored: Tue Mar 1 16:18:27 2016 +1100 Committer: olivier lamy <[email protected]> Committed: Tue Mar 1 16:18:27 2016 +1100 ---------------------------------------------------------------------- indexer-cli/pom.xml | 1 - indexer-examples/indexer-examples-basic/pom.xml | 4 +- .../indexer/examples/BasicUsageExample.java | 60 ++++--- .../indexer-examples-spring/pom.xml | 6 +- .../examples/indexing/IndexerConfiguration.java | 14 +- .../indexing/RepositoryIndexManager.java | 20 +-- .../examples/indexing/RepositoryIndexer.java | 164 +++++++++---------- .../indexing/RepositoryIndexerFactory.java | 42 ++--- .../examples/indexing/SearchRequest.java | 4 +- .../examples/indexing/SearchResults.java | 5 +- .../services/ArtifactIndexingService.java | 31 ++-- .../impl/ArtifactIndexingServiceImpl.java | 64 +++----- indexer-examples/pom.xml | 3 +- pom.xml | 34 +++- 14 files changed, 214 insertions(+), 238 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-cli/pom.xml ---------------------------------------------------------------------- diff --git a/indexer-cli/pom.xml b/indexer-cli/pom.xml index bd1f9a2..be41097 100644 --- a/indexer-cli/pom.xml +++ b/indexer-cli/pom.xml @@ -41,7 +41,6 @@ under the License. <dependency> <groupId>org.apache.maven.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>${project.version}</version> </dependency> <!-- Plexus (as compile since it has to end up in CLI) --> http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-basic/pom.xml ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-basic/pom.xml b/indexer-examples/indexer-examples-basic/pom.xml index 32491d1..3d2d782 100644 --- a/indexer-examples/indexer-examples-basic/pom.xml +++ b/indexer-examples/indexer-examples-basic/pom.xml @@ -22,9 +22,8 @@ under the License. <parent> <groupId>org.apache.maven.indexer</groupId> - <artifactId>maven-indexer</artifactId> + <artifactId>maven-indexer-examples</artifactId> <version>6.0-SNAPSHOT</version> - <relativePath>../..</relativePath> </parent> <artifactId>indexer-examples-basic</artifactId> @@ -60,7 +59,6 @@ under the License. <dependency> <groupId>org.apache.maven.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>6.0-SNAPSHOT</version> <scope>compile</scope> </dependency> http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/indexer/examples/BasicUsageExample.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/indexer/examples/BasicUsageExample.java b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/indexer/examples/BasicUsageExample.java index 476ee0b..b1a63bc 100644 --- a/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/indexer/examples/BasicUsageExample.java +++ b/indexer-examples/indexer-examples-basic/src/main/java/org/apache/maven/indexer/examples/BasicUsageExample.java @@ -19,14 +19,6 @@ package org.apache.maven.indexer.examples; * 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 java.util.Map; - import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.MultiFields; @@ -74,6 +66,14 @@ import org.eclipse.aether.util.version.GenericVersionScheme; import org.eclipse.aether.version.InvalidVersionSpecificationException; import org.eclipse.aether.version.Version; +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 java.util.Map; + public class BasicUsageExample { public static void main( String[] args ) @@ -105,7 +105,7 @@ public class BasicUsageExample // google is your friend! final DefaultContainerConfiguration config = new DefaultContainerConfiguration(); config.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); - this.plexusContainer = new DefaultPlexusContainer(config); + this.plexusContainer = new DefaultPlexusContainer( config ); // lookup the indexer components from plexus this.indexer = plexusContainer.lookup( Indexer.class ); @@ -131,7 +131,7 @@ public class BasicUsageExample // Create context for central repository index centralContext = indexer.createIndexingContext( "central-context", "central", centralLocalCache, centralIndexDir, - "http://repo1.maven.org/maven2", null, true, true, indexers ); + "http://repo1.maven.org/maven2", null, true, true, indexers ); // Update the index (incremental update will happen if this is not 1st run and files are not deleted) // This whole block below should not be executed on every app start, but rather controlled by some configuration @@ -175,8 +175,9 @@ public class BasicUsageExample } else { - System.out.println( "Incremental update happened, change covered " + centralContextCurrentTimestamp - + " - " + updateResult.getTimestamp() + " period." ); + System.out.println( + "Incremental update happened, change covered " + centralContextCurrentTimestamp + " - " + + updateResult.getTimestamp() + " period." ); } System.out.println(); @@ -198,15 +199,15 @@ public class BasicUsageExample try { final IndexReader ir = searcher.getIndexReader(); - Bits liveDocs = MultiFields.getLiveDocs(ir); + Bits liveDocs = MultiFields.getLiveDocs( ir ); for ( int i = 0; i < ir.maxDoc(); i++ ) { if ( liveDocs == null || liveDocs.get( i ) ) { final Document doc = ir.document( i ); final ArtifactInfo ai = IndexUtils.constructArtifactInfo( doc, centralContext ); - System.out.println( ai.getGroupId() + ":" + ai.getArtifactId() + ":" + ai.getVersion() + ":" + ai.getClassifier() - + " (sha1=" + ai.getSha1() + ")" ); + System.out.println( ai.getGroupId() + ":" + ai.getArtifactId() + ":" + ai.getVersion() + ":" + + ai.getClassifier() + " (sha1=" + ai.getSha1() + ")" ); } } } @@ -238,7 +239,7 @@ public class BasicUsageExample // we want main artifacts only (no classifier) // Note: this below is unfinished API, needs fixing query.add( indexer.constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( Field.NOT_PRESENT ) ), - Occur.MUST_NOT ); + Occur.MUST_NOT ); // construct the filter to express "V greater than" final ArtifactInfoFilter versionFilter = new ArtifactInfoFilter() @@ -259,7 +260,8 @@ public class BasicUsageExample } }; - System.out.println( "Searching for all GAVs with G=org.sonatype.nexus and nexus-api and having V greater than 1.5.0" ); + System.out.println( + "Searching for all GAVs with G=org.sonatype.nexus and nexus-api and having V greater than 1.5.0" ); final IteratorSearchRequest request = new IteratorSearchRequest( query, Collections.singletonList( centralContext ), versionFilter ); final IteratorSearchResponse response = indexer.searchIterator( request ); @@ -271,7 +273,8 @@ public class BasicUsageExample // Case: // Use index // Searching for some artifact - Query gidQ = indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.maven.indexer" ) ); + Query gidQ = + indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.maven.indexer" ) ); Query aidQ = indexer.constructQuery( MAVEN.ARTIFACT_ID, new SourcedSearchExpression( "indexer-artifact" ) ); BooleanQuery bq = new BooleanQuery(); @@ -291,25 +294,29 @@ public class BasicUsageExample // doing sha1 search searchAndDump( indexer, "SHA1 7ab67e6b20e5332a7fb4fdf2f019aec4275846c2", indexer.constructQuery( MAVEN.SHA1, - new SourcedSearchExpression( "7ab67e6b20e5332a7fb4fdf2f019aec4275846c2" ) ) ); + new SourcedSearchExpression( + "7ab67e6b20e5332a7fb4fdf2f019aec4275846c2" ) ) ); searchAndDump( indexer, "SHA1 7ab67e6b20 (partial hash)", - indexer.constructQuery( MAVEN.SHA1, new UserInputSearchExpression( "7ab67e6b20" ) ) ); + indexer.constructQuery( MAVEN.SHA1, new UserInputSearchExpression( "7ab67e6b20" ) ) ); // doing classname search (incomplete classname) searchAndDump( indexer, "classname DefaultNexusIndexer (note: Central does not publish classes in the index)", - indexer.constructQuery( MAVEN.CLASSNAMES, new UserInputSearchExpression( "DefaultNexusIndexer" ) ) ); + indexer.constructQuery( MAVEN.CLASSNAMES, + new UserInputSearchExpression( "DefaultNexusIndexer" ) ) ); // doing search for all "canonical" maven plugins latest versions bq = new BooleanQuery(); bq.add( indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( "maven-plugin" ) ), Occur.MUST ); bq.add( indexer.constructQuery( MAVEN.GROUP_ID, new SourcedSearchExpression( "org.apache.maven.plugins" ) ), - Occur.MUST ); + Occur.MUST ); searchGroupedAndDump( indexer, "all \"canonical\" maven plugins", bq, new GAGrouping() ); // doing search for all archetypes latest versions - searchGroupedAndDump( indexer, "all maven archetypes (latest versions)", - indexer.constructQuery( MAVEN.PACKAGING, new SourcedSearchExpression( "maven-archetype" ) ), new GAGrouping() ); + searchGroupedAndDump( indexer, "all maven archetypes (latest versions)", + indexer.constructQuery( MAVEN.PACKAGING, + new SourcedSearchExpression( "maven-archetype" ) ), + new GAGrouping() ); // close cleanly indexer.closeIndexingContext( centralContext, false ); @@ -344,8 +351,9 @@ public class BasicUsageExample ArtifactInfo ai = entry.getValue().getArtifactInfos().iterator().next(); System.out.println( "* Entry " + ai ); System.out.println( " Latest version: " + ai.getVersion() ); - System.out.println( StringUtils.isBlank( ai.getDescription() ) ? "No description in plugin's POM." - : StringUtils.abbreviate( ai.getDescription(), 60 ) ); + System.out.println( StringUtils.isBlank( ai.getDescription() ) + ? "No description in plugin's POM." + : StringUtils.abbreviate( ai.getDescription(), 60 ) ); System.out.println(); } http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/pom.xml ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/pom.xml b/indexer-examples/indexer-examples-spring/pom.xml index f56555e..4186cbe 100644 --- a/indexer-examples/indexer-examples-spring/pom.xml +++ b/indexer-examples/indexer-examples-spring/pom.xml @@ -25,9 +25,8 @@ under the License. <parent> <groupId>org.apache.maven.indexer</groupId> - <artifactId>maven-indexer</artifactId> + <artifactId>maven-indexer-examples</artifactId> <version>6.0-SNAPSHOT</version> - <relativePath>../..</relativePath> </parent> <artifactId>indexer-examples-spring</artifactId> @@ -81,7 +80,6 @@ under the License. <dependency> <groupId>org.apache.maven.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>6.0-SNAPSHOT</version> <scope>compile</scope> </dependency> @@ -96,7 +94,7 @@ under the License. <dependency> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-http-lightweight</artifactId> - <version>2.3</version> + <version>2.10</version> <scope>compile</scope> </dependency> http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/IndexerConfiguration.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/IndexerConfiguration.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/IndexerConfiguration.java index 10229be..814cd40 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/IndexerConfiguration.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/IndexerConfiguration.java @@ -19,6 +19,10 @@ package org.apache.maven.indexer.examples.indexing; * under the License. */ +import org.apache.maven.index.Indexer; +import org.apache.maven.index.Scanner; +import org.apache.maven.index.context.IndexCreator; + import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; @@ -26,10 +30,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.apache.maven.index.Indexer; -import org.apache.maven.index.Scanner; -import org.apache.maven.index.context.IndexCreator; - /** * A simple configuration holder class. * This class contains the mapped indexers. @@ -49,9 +49,7 @@ public class IndexerConfiguration @Inject - public IndexerConfiguration( Indexer indexer, - Scanner scanner, - Map<String, IndexCreator> indexers ) + public IndexerConfiguration( Indexer indexer, Scanner scanner, Map<String, IndexCreator> indexers ) { this.indexer = indexer; this.scanner = scanner; @@ -63,7 +61,7 @@ public class IndexerConfiguration List<IndexCreator> indexersAsList = new ArrayList<>(); for ( Map.Entry entry : indexers.entrySet() ) { - indexersAsList.add( ( IndexCreator ) entry.getValue() ); + indexersAsList.add( (IndexCreator) entry.getValue() ); } return indexersAsList; http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexManager.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexManager.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexManager.java index 536b859..b8627c9 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexManager.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexManager.java @@ -19,16 +19,16 @@ package org.apache.maven.indexer.examples.indexing; * under the License. */ +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + import javax.annotation.PreDestroy; import javax.inject.Singleton; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - /** * This class represents a mapping between repositoryId-s and their respective indexes. * @@ -39,7 +39,7 @@ import org.springframework.stereotype.Component; public class RepositoryIndexManager { - private static final Logger logger = LoggerFactory.getLogger( RepositoryIndexManager.class ); + private static final Logger LOGGER = LoggerFactory.getLogger( RepositoryIndexManager.class ); /** * K: repositoryId @@ -50,6 +50,7 @@ public class RepositoryIndexManager public RepositoryIndexManager() { + // no op } /** @@ -67,15 +68,15 @@ public class RepositoryIndexManager { final RepositoryIndexer repositoryIndexer = indexes.get( repositoryId ); - logger.debug( "Closing indexer for " + repositoryIndexer.getRepositoryId() + "..." ); + LOGGER.debug( "Closing indexer for " + repositoryIndexer.getRepositoryId() + "..." ); repositoryIndexer.close(); - logger.debug( "Closed indexer for " + repositoryIndexer.getRepositoryId() + "." ); + LOGGER.debug( "Closed indexer for " + repositoryIndexer.getRepositoryId() + "." ); } catch ( IOException e ) { - logger.error( e.getMessage(), e ); + LOGGER.error( e.getMessage(), e ); } } } @@ -95,8 +96,7 @@ public class RepositoryIndexManager return indexes.get( repositoryId ); } - public RepositoryIndexer addRepositoryIndex( String repositoryId, - RepositoryIndexer value ) + public RepositoryIndexer addRepositoryIndex( String repositoryId, RepositoryIndexer value ) { return indexes.put( repositoryId, value ); } http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexer.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexer.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexer.java index 11a4eb4..a205288 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexer.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexer.java @@ -19,25 +19,35 @@ package org.apache.maven.indexer.examples.indexing; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - import org.apache.lucene.analysis.core.WhitespaceAnalyzer; import org.apache.lucene.queryparser.classic.MultiFieldQueryParser; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.Version; -import org.apache.maven.index.*; +import org.apache.maven.index.ArtifactContext; +import org.apache.maven.index.ArtifactInfo; +import org.apache.maven.index.ArtifactScanningListener; +import org.apache.maven.index.FlatSearchRequest; +import org.apache.maven.index.FlatSearchResponse; +import org.apache.maven.index.Indexer; +import org.apache.maven.index.MAVEN; +import org.apache.maven.index.Scanner; +import org.apache.maven.index.ScanningRequest; +import org.apache.maven.index.ScanningResult; import org.apache.maven.index.context.IndexCreator; import org.apache.maven.index.context.IndexingContext; import org.apache.maven.index.expr.SourcedSearchExpression; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; + import static java.util.Arrays.asList; import static org.apache.lucene.search.BooleanClause.Occur.MUST; @@ -49,7 +59,7 @@ import static org.apache.lucene.search.BooleanClause.Occur.MUST; public class RepositoryIndexer { - private static final Logger logger = LoggerFactory.getLogger( RepositoryIndexer.class ); + private static final Logger LOGGER = LoggerFactory.getLogger( RepositoryIndexer.class ); private static final Version luceneVersion = Version.LUCENE_48; @@ -74,30 +84,30 @@ public class RepositoryIndexer public RepositoryIndexer() { + // no op } public void close() - throws IOException + throws IOException { indexer.closeIndexingContext( indexingContext, false ); } public void close( boolean deleteFiles ) - throws IOException + throws IOException { indexingContext.close( deleteFiles ); } public void delete( final Collection<ArtifactInfo> artifacts ) - throws IOException + throws IOException { final List<ArtifactContext> delete = new ArrayList<ArtifactContext>(); for ( final ArtifactInfo artifact : artifacts ) { - logger.debug( "Deleting artifact: {}; ctx id: {}; idx dir: {}", - new String[]{ artifact.toString(), - indexingContext.getId(), - indexingContext.getIndexDirectory().toString() } ); + LOGGER.debug( "Deleting artifact: {}; ctx id: {}; idx dir: {}", + new String[]{ artifact.toString(), indexingContext.getId(), + indexingContext.getIndexDirectory().toString() } ); delete.add( new ArtifactContext( null, null, null, artifact, null ) ); } @@ -105,12 +115,9 @@ public class RepositoryIndexer getIndexer().deleteArtifactsFromIndex( delete, indexingContext ); } - public Set<ArtifactInfo> search( final String groupId, - final String artifactId, - final String version, - final String packaging, - final String classifier ) - throws IOException + public Set<ArtifactInfo> search( final String groupId, final String artifactId, final String version, + final String packaging, final String classifier ) + throws IOException { final BooleanQuery query = new BooleanQuery(); @@ -142,24 +149,24 @@ public class RepositoryIndexer if ( classifier != null ) { - query.add( getIndexer().constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( classifier ) ), MUST ); + query.add( getIndexer().constructQuery( MAVEN.CLASSIFIER, new SourcedSearchExpression( classifier ) ), + MUST ); } - logger.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", - new String[]{ query.toString(), - indexingContext.getId(), - indexingContext.getIndexDirectory().toString() } ); + LOGGER.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", + new String[]{ query.toString(), indexingContext.getId(), + indexingContext.getIndexDirectory().toString() } ); final FlatSearchResponse response = getIndexer().searchFlat( new FlatSearchRequest( query, indexingContext ) ); - logger.info( "Hit count: {}", response.getReturnedHitsCount() ); + LOGGER.info( "Hit count: {}", response.getReturnedHitsCount() ); final Set<ArtifactInfo> results = response.getResults(); - if ( logger.isDebugEnabled() ) + if ( LOGGER.isDebugEnabled() ) { for ( final ArtifactInfo result : results ) { - logger.debug( "Found artifact: {}", result.toString() ); + LOGGER.debug( "Found artifact: {}", result.toString() ); } } @@ -167,25 +174,24 @@ public class RepositoryIndexer } public Set<ArtifactInfo> search( final String queryText ) - throws ParseException, IOException + throws ParseException, IOException { final Query query = new MultiFieldQueryParser( luceneVersion, luceneFields, luceneAnalyzer ).parse( queryText ); - logger.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", - new String[]{ query.toString(), - indexingContext.getId(), - indexingContext.getIndexDirectory().toString() } ); + LOGGER.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", + new String[]{ query.toString(), indexingContext.getId(), + indexingContext.getIndexDirectory().toString() } ); final FlatSearchResponse response = getIndexer().searchFlat( new FlatSearchRequest( query, indexingContext ) ); final Set<ArtifactInfo> results = response.getResults(); - if ( logger.isDebugEnabled() ) + if ( LOGGER.isDebugEnabled() ) { - logger.debug( "Hit count: {}", response.getReturnedHitsCount() ); + LOGGER.debug( "Hit count: {}", response.getReturnedHitsCount() ); for ( final ArtifactInfo result : results ) { - logger.debug( "Found artifact: {}; uinfo: {}", result.toString(), result.getUinfo() ); + LOGGER.debug( "Found artifact: {}; uinfo: {}", result.toString(), result.getUinfo() ); } } @@ -193,26 +199,25 @@ public class RepositoryIndexer } public Set<ArtifactInfo> searchBySHA1( final String checksum ) - throws IOException + throws IOException { final BooleanQuery query = new BooleanQuery(); query.add( getIndexer().constructQuery( MAVEN.SHA1, new SourcedSearchExpression( checksum ) ), MUST ); - logger.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", - new String[]{ query.toString(), - indexingContext.getId(), - indexingContext.getIndexDirectory().toString() } ); + LOGGER.debug( "Executing search query: {}; ctx id: {}; idx dir: {}", + new String[]{ query.toString(), indexingContext.getId(), + indexingContext.getIndexDirectory().toString() } ); final FlatSearchResponse response = getIndexer().searchFlat( new FlatSearchRequest( query, indexingContext ) ); - logger.info( "Hit count: {}", response.getReturnedHitsCount() ); + LOGGER.info( "Hit count: {}", response.getReturnedHitsCount() ); final Set<ArtifactInfo> results = response.getResults(); - if ( logger.isDebugEnabled() ) + if ( LOGGER.isDebugEnabled() ) { for ( final ArtifactInfo result : results ) { - logger.debug( "Found artifact: {}", result.toString() ); + LOGGER.debug( "Found artifact: {}", result.toString() ); } } @@ -221,58 +226,43 @@ public class RepositoryIndexer public int index( final File startingPath ) { - final ScanningResult scan = getScanner().scan( new ScanningRequest( indexingContext, - new ReindexArtifactScanningListener(), - startingPath == null ? "." : - startingPath.getPath() ) ); + final ScanningResult scan = getScanner().scan( + new ScanningRequest( indexingContext, new ReindexArtifactScanningListener(), + startingPath == null ? "." : startingPath.getPath() ) ); return scan.getTotalFiles(); } - public void addArtifactToIndex( final File artifactFile, - final ArtifactInfo artifactInfo ) - throws IOException + public void addArtifactToIndex( final File artifactFile, final ArtifactInfo artifactInfo ) + throws IOException { getIndexer().addArtifactsToIndex( asList( new ArtifactContext( null, artifactFile, null, artifactInfo, null ) ), indexingContext ); } - public void addArtifactToIndex( String repository, - File artifactFile, - String groupId, - String artifactId, - String version, - String extension, - String classifier ) - throws IOException + public void addArtifactToIndex( String repository, File artifactFile, String groupId, String artifactId, + String version, String extension, String classifier ) + throws IOException { - ArtifactInfo artifactInfo = new ArtifactInfo( repository, - groupId, - artifactId, - version, - classifier, - extension ); + ArtifactInfo artifactInfo = new ArtifactInfo( repository, groupId, artifactId, version, classifier, extension ); if ( extension != null ) { artifactInfo.setFieldValue( MAVEN.EXTENSION, extension ); } - logger.debug( "Adding artifact: {}; repo: {}; type: {}", new String[]{ artifactInfo.getUinfo(), - repository, - extension } ); + LOGGER.debug( "Adding artifact: {}; repo: {}; type: {}", + new String[]{ artifactInfo.getUinfo(), repository, extension } ); - getIndexer().addArtifactsToIndex( asList( new ArtifactContext( null, - artifactFile, - null, - artifactInfo, - artifactInfo.calculateGav() ) ), - indexingContext ); + getIndexer().addArtifactsToIndex( + asList( new ArtifactContext( null, artifactFile, null, artifactInfo, artifactInfo.calculateGav() ) ), + indexingContext ); } private class ReindexArtifactScanningListener - implements ArtifactScanningListener + implements ArtifactScanningListener { int totalFiles = 0; + private IndexingContext context; @Override @@ -282,20 +272,17 @@ public class RepositoryIndexer } @Override - public void scanningFinished( final IndexingContext context, - final ScanningResult result ) + public void scanningFinished( final IndexingContext context, final ScanningResult result ) { result.setTotalFiles( totalFiles ); - logger.debug( "Scanning finished; total files: {}; has exception: {}", - result.getTotalFiles(), + LOGGER.debug( "Scanning finished; total files: {}; has exception: {}", result.getTotalFiles(), result.hasExceptions() ); } @Override - public void artifactError( final ArtifactContext ac, - final Exception ex ) + public void artifactError( final ArtifactContext ac, final Exception ex ) { - logger.error( "Artifact error!", ex ); + LOGGER.error( "Artifact error!", ex ); } @Override @@ -303,17 +290,16 @@ public class RepositoryIndexer { try { - logger.debug( "Adding artifact gav: {}; ctx id: {}; idx dir: {}", - new String[]{ ac.getGav().toString(), - context.getId(), - context.getIndexDirectory().toString() } ); + LOGGER.debug( "Adding artifact gav: {}; ctx id: {}; idx dir: {}", + new String[]{ ac.getGav().toString(), context.getId(), + context.getIndexDirectory().toString() } ); getIndexer().addArtifactsToIndex( asList( ac ), context ); totalFiles++; } catch ( IOException ex ) { - logger.error( "Artifact index error", ex ); + LOGGER.error( "Artifact index error", ex ); } } } http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexerFactory.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexerFactory.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexerFactory.java index b935372..c74777b 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexerFactory.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/RepositoryIndexerFactory.java @@ -19,12 +19,6 @@ package org.apache.maven.indexer.examples.indexing; * under the License. */ -import javax.inject.Inject; -import javax.inject.Singleton; -import java.io.File; -import java.io.IOException; -import java.util.Map; - import org.apache.maven.index.Indexer; import org.apache.maven.index.Scanner; import org.apache.maven.index.context.IndexCreator; @@ -32,6 +26,12 @@ import org.apache.maven.index.context.IndexingContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; +import javax.inject.Singleton; +import java.io.File; +import java.io.IOException; +import java.util.Map; + /** * A factory for pre-configured RepositoryIndexers. * @@ -41,8 +41,6 @@ import org.slf4j.LoggerFactory; public class RepositoryIndexerFactory { - private static final Logger logger = LoggerFactory.getLogger( RepositoryIndexerFactory.class ); - private IndexerConfiguration indexerConfiguration; @@ -52,10 +50,8 @@ public class RepositoryIndexerFactory this.indexerConfiguration = indexerConfiguration; } - public RepositoryIndexer createRepositoryIndexer( String repositoryId, - File repositoryBasedir, - File indexDir ) - throws IOException + public RepositoryIndexer createRepositoryIndexer( String repositoryId, File repositoryBasedir, File indexDir ) + throws IOException { RepositoryIndexer repositoryIndexer = new RepositoryIndexer(); repositoryIndexer.setRepositoryId( repositoryId ); @@ -68,22 +64,16 @@ public class RepositoryIndexerFactory return repositoryIndexer; } - private IndexingContext createIndexingContext( String repositoryId, - File repositoryBasedir, - File indexDir ) - throws IOException + private IndexingContext createIndexingContext( String repositoryId, File repositoryBasedir, File indexDir ) + throws IOException { - return getIndexer().createIndexingContext( repositoryId + "/ctx", - repositoryId, - repositoryBasedir, - indexDir, - null, - null, - true, // if context should be searched in non-targeted mode. + return getIndexer().createIndexingContext( repositoryId + "/ctx", repositoryId, repositoryBasedir, indexDir, + null, null, true, + // if context should be searched in non-targeted mode. true, // if indexDirectory is known to contain (or should contain) - // valid Maven Indexer lucene index, and no checks needed to be - // performed, or, if we want to "stomp" over existing index - // (unsafe to do!). + // valid Maven Indexer lucene index, and no checks needed to be + // performed, or, if we want to "stomp" over existing index + // (unsafe to do!). indexerConfiguration.getIndexersAsList() ); } http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchRequest.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchRequest.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchRequest.java index 131eb3c..31fd0a6 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchRequest.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchRequest.java @@ -34,10 +34,10 @@ public class SearchRequest public SearchRequest() { + // no op } - public SearchRequest( String repository, - String query ) + public SearchRequest( String repository, String query ) { this.repository = repository; this.query = query; http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchResults.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchResults.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchResults.java index 073e737..2e2f1af 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchResults.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/indexing/SearchResults.java @@ -19,12 +19,12 @@ package org.apache.maven.indexer.examples.indexing; * under the License. */ +import org.apache.maven.index.ArtifactInfo; + import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; -import org.apache.maven.index.ArtifactInfo; - /** * This is a convenience class for holding search results mapped by repository. * @@ -42,6 +42,7 @@ public class SearchResults public SearchResults() { + // no op } public Map<String, Collection<ArtifactInfo>> getResults() http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/ArtifactIndexingService.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/ArtifactIndexingService.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/ArtifactIndexingService.java index 0a720b4..5358cca 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/ArtifactIndexingService.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/ArtifactIndexingService.java @@ -19,13 +19,13 @@ package org.apache.maven.indexer.examples.services; * under the License. */ -import java.io.File; -import java.io.IOException; - import org.apache.lucene.queryparser.classic.ParseException; import org.apache.maven.indexer.examples.indexing.SearchRequest; import org.apache.maven.indexer.examples.indexing.SearchResults; +import java.io.File; +import java.io.IOException; + /** * A simple indexing and search service. * @@ -34,27 +34,18 @@ import org.apache.maven.indexer.examples.indexing.SearchResults; public interface ArtifactIndexingService { - void addToIndex( String repositoryId, - File artifactFile, - String groupId, - String artifactId, - String version, - String extension, - String classifier ) - throws IOException; - - void deleteFromIndex( String repositoryId, - String groupId, - String artifactId, - String version, - String extension, + void addToIndex( String repositoryId, File artifactFile, String groupId, String artifactId, String version, + String extension, String classifier ) + throws IOException; + + void deleteFromIndex( String repositoryId, String groupId, String artifactId, String version, String extension, String classifier ) - throws IOException; + throws IOException; SearchResults search( SearchRequest searchRequest ) - throws IOException, ParseException; + throws IOException, ParseException; boolean contains( SearchRequest searchRequest ) - throws IOException, ParseException; + throws IOException, ParseException; } http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/impl/ArtifactIndexingServiceImpl.java ---------------------------------------------------------------------- diff --git a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/impl/ArtifactIndexingServiceImpl.java b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/impl/ArtifactIndexingServiceImpl.java index 8f74cf5..5b2caf1 100644 --- a/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/impl/ArtifactIndexingServiceImpl.java +++ b/indexer-examples/indexer-examples-spring/src/main/java/org/apache/maven/indexer/examples/services/impl/ArtifactIndexingServiceImpl.java @@ -19,10 +19,6 @@ package org.apache.maven.indexer.examples.services.impl; * under the License. */ -import java.io.File; -import java.io.IOException; -import java.util.*; - import org.apache.lucene.queryparser.classic.ParseException; import org.apache.maven.index.ArtifactInfo; import org.apache.maven.indexer.examples.indexing.RepositoryIndexManager; @@ -35,12 +31,20 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; + /** * @author mtodorov */ @Component public class ArtifactIndexingServiceImpl - implements ArtifactIndexingService + implements ArtifactIndexingService { private static final Logger logger = LoggerFactory.getLogger( ArtifactIndexingServiceImpl.class ); @@ -50,14 +54,9 @@ public class ArtifactIndexingServiceImpl @Override - public void addToIndex( String repositoryId, - File artifactFile, - String groupId, - String artifactId, - String version, - String extension, - String classifier ) - throws IOException + public void addToIndex( String repositoryId, File artifactFile, String groupId, String artifactId, String version, + String extension, String classifier ) + throws IOException { final RepositoryIndexer indexer = repositoryIndexManager.getRepositoryIndex( repositoryId ); @@ -65,29 +64,21 @@ public class ArtifactIndexingServiceImpl } @Override - public void deleteFromIndex( String repositoryId, - String groupId, - String artifactId, - String version, - String extension, - String classifier ) - throws IOException + public void deleteFromIndex( String repositoryId, String groupId, String artifactId, String version, + String extension, String classifier ) + throws IOException { final RepositoryIndexer indexer = repositoryIndexManager.getRepositoryIndex( repositoryId ); if ( indexer != null ) { - indexer.delete( Arrays.asList( new ArtifactInfo( repositoryId, - groupId, - artifactId, - version, - classifier, - extension ) ) ); + indexer.delete( Arrays.asList( + new ArtifactInfo( repositoryId, groupId, artifactId, version, classifier, extension ) ) ); } } @Override public SearchResults search( SearchRequest searchRequest ) - throws IOException, ParseException + throws IOException, ParseException { SearchResults searchResults = new SearchResults(); @@ -97,8 +88,8 @@ public class ArtifactIndexingServiceImpl { logger.debug( "Repository: {}", repositoryId ); - final Map<String, Collection<ArtifactInfo>> resultsMap = getResultsMap( repositoryId, - searchRequest.getQuery() ); + final Map<String, Collection<ArtifactInfo>> resultsMap = + getResultsMap( repositoryId, searchRequest.getQuery() ); if ( !resultsMap.isEmpty() ) { @@ -122,8 +113,8 @@ public class ArtifactIndexingServiceImpl final RepositoryIndexer repositoryIndex = repositoryIndexManager.getRepositoryIndex( repoId ); if ( repositoryIndex != null ) { - final Set<ArtifactInfo> artifactInfoResults = repositoryIndexManager.getRepositoryIndex( repoId ) - .search( searchRequest.getQuery() ); + final Set<ArtifactInfo> artifactInfoResults = + repositoryIndexManager.getRepositoryIndex( repoId ).search( searchRequest.getQuery() ); if ( !artifactInfoResults.isEmpty() ) { @@ -142,18 +133,17 @@ public class ArtifactIndexingServiceImpl @Override public boolean contains( SearchRequest searchRequest ) - throws IOException, ParseException + throws IOException, ParseException { return !getResultsMap( searchRequest.getRepository(), searchRequest.getQuery() ).isEmpty(); } - public Map<String, Collection<ArtifactInfo>> getResultsMap( String repositoryId, - String query ) - throws IOException, ParseException + public Map<String, Collection<ArtifactInfo>> getResultsMap( String repositoryId, String query ) + throws IOException, ParseException { Map<String, Collection<ArtifactInfo>> resultsMap = new LinkedHashMap<>(); - final Set<ArtifactInfo> artifactInfoResults = repositoryIndexManager.getRepositoryIndex( repositoryId ) - .search( query ); + final Set<ArtifactInfo> artifactInfoResults = + repositoryIndexManager.getRepositoryIndex( repositoryId ).search( query ); if ( !artifactInfoResults.isEmpty() ) { http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/indexer-examples/pom.xml ---------------------------------------------------------------------- diff --git a/indexer-examples/pom.xml b/indexer-examples/pom.xml index cf754ab..88f5bff 100644 --- a/indexer-examples/pom.xml +++ b/indexer-examples/pom.xml @@ -24,10 +24,9 @@ under the License. <groupId>org.apache.maven.indexer</groupId> <artifactId>maven-indexer</artifactId> <version>6.0-SNAPSHOT</version> - <relativePath>..</relativePath> </parent> - <artifactId>indexer-examples</artifactId> + <artifactId>maven-indexer-examples</artifactId> <packaging>pom</packaging> <name>Maven :: Indexer Examples</name> http://git-wip-us.apache.org/repos/asf/maven-indexer/blob/9c907aa6/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index aaaa508..e60ccd1 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ under the License. <parent> <groupId>org.apache.maven</groupId> <artifactId>maven-parent</artifactId> - <version>24</version> + <version>27</version> </parent> <groupId>org.apache.maven.indexer</groupId> @@ -104,6 +104,11 @@ under the License. <dependencyManagement> <dependencies> <dependency> + <groupId>org.apache.maven.indexer</groupId> + <artifactId>indexer-core</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.5</version> @@ -392,7 +397,7 @@ under the License. <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>animal-sniffer-maven-plugin</artifactId> - <version>1.11</version> + <version>1.15</version> <configuration> <signature> <groupId>org.codehaus.mojo.signature</groupId> @@ -443,23 +448,36 @@ under the License. </execution> </executions> </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-checkstyle-plugin</artifactId> + <version>2.15</version> + <configuration> + <!-- + olamy do not fail the build because of some white spaces somewhere + yup I have a lot of other smart/interesting stuff to do in my life!! + --> + <failOnViolation>false</failOnViolation> + <failsOnError>false</failsOnError> + </configuration> + </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> - <version>3.1</version> + <version>3.5.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> - <version>2.17</version> + <version>2.19.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> - <version>2.17</version> + <version>2.19.1</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> @@ -478,8 +496,8 @@ under the License. <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <configuration> - <excludes> - <exclude>README.md</exclude> + <excludes combine.children="append"> + <exclude>**/README.md</exclude> </excludes> </configuration> </plugin> @@ -499,7 +517,7 @@ under the License. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> - <version>2.9.1</version> + <version>2.10.3</version> <configuration> <groups> <group>
