Skip to content

Commit

Permalink
upgrade some plugins fix parent pom for samples
Browse files Browse the repository at this point in the history
Signed-off-by: olivier lamy <olamy@apache.org>
  • Loading branch information
olamy committed Mar 1, 2016
1 parent a5039e5 commit 9c907aa
Show file tree
Hide file tree
Showing 14 changed files with 214 additions and 238 deletions.
1 change: 0 additions & 1 deletion indexer-cli/pom.xml
Expand Up @@ -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) -->
Expand Down
4 changes: 1 addition & 3 deletions indexer-examples/indexer-examples-basic/pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>

Expand Down
Expand Up @@ -19,14 +19,6 @@
* 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;
Expand Down Expand Up @@ -74,6 +66,14 @@
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 )
Expand Down Expand Up @@ -105,7 +105,7 @@ public 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 );
Expand All @@ -131,7 +131,7 @@ public void perform()
// 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
Expand Down Expand Up @@ -175,8 +175,9 @@ else if ( updateResult.getTimestamp().equals( centralContextCurrentTimestamp ) )
}
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();
Expand All @@ -198,15 +199,15 @@ else if ( updateResult.getTimestamp().equals( centralContextCurrentTimestamp ) )
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() + ")" );
}
}
}
Expand Down Expand Up @@ -238,7 +239,7 @@ else if ( updateResult.getTimestamp().equals( centralContextCurrentTimestamp ) )
// 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()
Expand All @@ -259,7 +260,8 @@ public boolean accepts( final IndexingContext ctx, final ArtifactInfo ai )
}
};

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 );
Expand All @@ -271,7 +273,8 @@ public boolean accepts( final IndexingContext ctx, final ArtifactInfo ai )
// 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();
Expand All @@ -291,25 +294,29 @@ public boolean accepts( final IndexingContext ctx, final ArtifactInfo ai )

// 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 );
Expand Down Expand Up @@ -344,8 +351,9 @@ public void searchGroupedAndDump( Indexer nexusIndexer, String descr, Query q, G
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();
}

Expand Down
6 changes: 2 additions & 4 deletions indexer-examples/indexer-examples-spring/pom.xml
Expand Up @@ -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>
Expand Down Expand Up @@ -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>

Expand All @@ -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>

Expand Down
Expand Up @@ -19,17 +19,17 @@
* 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;
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.
Expand All @@ -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;
Expand All @@ -63,7 +61,7 @@ public List<IndexCreator> getIndexersAsList()
List<IndexCreator> indexersAsList = new ArrayList<>();
for ( Map.Entry entry : indexers.entrySet() )
{
indexersAsList.add( ( IndexCreator ) entry.getValue() );
indexersAsList.add( (IndexCreator) entry.getValue() );
}

return indexersAsList;
Expand Down
Expand Up @@ -19,16 +19,16 @@
* 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.
*
Expand All @@ -39,7 +39,7 @@
public class RepositoryIndexManager
{

private static final Logger logger = LoggerFactory.getLogger( RepositoryIndexManager.class );
private static final Logger LOGGER = LoggerFactory.getLogger( RepositoryIndexManager.class );

/**
* K: repositoryId
Expand All @@ -50,6 +50,7 @@ public class RepositoryIndexManager

public RepositoryIndexManager()
{
// no op
}

/**
Expand All @@ -67,15 +68,15 @@ private void close()
{
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 );
}
}
}
Expand All @@ -95,8 +96,7 @@ public RepositoryIndexer getRepositoryIndex( String repositoryId )
return indexes.get( repositoryId );
}

public RepositoryIndexer addRepositoryIndex( String repositoryId,
RepositoryIndexer value )
public RepositoryIndexer addRepositoryIndex( String repositoryId, RepositoryIndexer value )
{
return indexes.put( repositoryId, value );
}
Expand Down

0 comments on commit 9c907aa

Please sign in to comment.