Permalink
Browse files

NEXUS-3020: IndexerCli will now properly close the indexing context o…

…n completion

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/trunk/nexus-indexer@5588 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information...
1 parent bad5362 commit 0dce0ecf5746ad61aca50bd9f4b13eef8ad24f77 dbradicich committed Nov 19, 2009
@@ -315,49 +315,57 @@ private void index( final CommandLine cli, PlexusContainer plexus )
}
NexusIndexer indexer = plexus.lookup( NexusIndexer.class );
-
- long tstart = System.currentTimeMillis();
-
- IndexingContext context = indexer.addIndexingContext( //
- repositoryName, // context id
- repositoryName, // repository id
- repositoryFolder, // repository folder
- indexFolder, // index folder
- null, // repositoryUrl
- null, // index update url
- indexers );
-
- IndexPacker packer = plexus.lookup( IndexPacker.class );
-
- ArtifactScanningListener listener = new IndexerListener( context, debug, quiet );
-
- indexer.scan( context, listener, true );
-
- IndexPackingRequest request = new IndexPackingRequest( context, outputFolder );
-
- request.setCreateChecksumFiles( createChecksums );
-
- request.setCreateIncrementalChunks( createIncrementalChunks );
-
- if ( createLegacyIndex )
- {
- request.setFormats( Arrays.asList( IndexFormat.FORMAT_LEGACY, IndexFormat.FORMAT_V1 ) );
- }
- else
- {
- request.setFormats( Arrays.asList( IndexFormat.FORMAT_V1 ) );
- }
-
- if ( chunkCount != null )
+ IndexingContext context = null;
+
+ try
{
- request.setMaxIndexChunks( chunkCount.intValue() );
+ long tstart = System.currentTimeMillis();
+
+ context = indexer.addIndexingContext( //
+ repositoryName, // context id
+ repositoryName, // repository id
+ repositoryFolder, // repository folder
+ indexFolder, // index folder
+ null, // repositoryUrl
+ null, // index update url
+ indexers );
+
+ IndexPacker packer = plexus.lookup( IndexPacker.class );
+
+ ArtifactScanningListener listener = new IndexerListener( context, debug, quiet );
+
+ indexer.scan( context, listener, true );
+
+ IndexPackingRequest request = new IndexPackingRequest( context, outputFolder );
+
+ request.setCreateChecksumFiles( createChecksums );
+
+ request.setCreateIncrementalChunks( createIncrementalChunks );
+
+ if ( createLegacyIndex )
+ {
+ request.setFormats( Arrays.asList( IndexFormat.FORMAT_LEGACY, IndexFormat.FORMAT_V1 ) );
+ }
+ else
+ {
+ request.setFormats( Arrays.asList( IndexFormat.FORMAT_V1 ) );
+ }
+
+ if ( chunkCount != null )
+ {
+ request.setMaxIndexChunks( chunkCount.intValue() );
+ }
+
+ packIndex( packer, request, debug, quiet );
+
+ if( !quiet )
+ {
+ printStats( tstart );
+ }
}
-
- packIndex( packer, request, debug, quiet );
-
- if( !quiet )
+ finally
{
- printStats( tstart );
+ indexer.removeIndexingContext( context, false );
}
}
@@ -126,7 +126,7 @@ public void testMissingArgs()
assertEquals( output, 1, code );
assertTrue( "Should print bad usage", output.contains( usage ) );
- assertFalse( "No index file was generated", new File( INDEX_DIR ).exists() );
+ assertFalse( "Index file was generated", new File( INDEX_DIR ).exists() );
}
public void testAbrvsRequiredArgs()
@@ -191,11 +191,11 @@ private void assertIndexFiles( final String indexDir )
throws Exception
{
IndexingContext context = null;
+ NexusIndexer indexer = lookup( NexusIndexer.class );
try
{
List<IndexCreator> indexCreators = getContainer().lookupList( IndexCreator.class );
- NexusIndexer indexer = lookup( NexusIndexer.class );
context =
indexer.addIndexingContext( "index", "index", new File( TEST_REPO ), new File( indexDir ), null, null,
indexCreators );
@@ -210,10 +210,7 @@ private void assertIndexFiles( final String indexDir )
}
finally
{
- if ( context != null )
- {
- context.close( false );
- }
+ indexer.removeIndexingContext( context, true );
}
}

0 comments on commit 0dce0ec

Please sign in to comment.