You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2011/06/08 17:34:30 UTC
svn commit: r1133437 -
/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
Author: cstamas
Date: Wed Jun 8 15:34:30 2011
New Revision: 1133437
URL: http://svn.apache.org/viewvc?rev=1133437&view=rev
Log:
MINDEXER-30: Fixing the AlreadyClosedException problem, tested with previous two UTs
Modified:
maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
Modified: maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java
URL: http://svn.apache.org/viewvc/maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java?rev=1133437&r1=1133436&r2=1133437&view=diff
==============================================================================
--- maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java (original)
+++ maven/indexer/trunk/indexer-core/src/main/java/org/apache/maven/index/packer/DefaultIndexPacker.java Wed Jun 8 15:34:30 2011
@@ -107,97 +107,110 @@ public class DefaultIndexPacker
Properties info = null;
+ final IndexingContext context = request.getContext();
+
+ context.lock();
+
try
{
- // Note that for incremental indexes to work properly, a valid index.properties file
- // must be present
- info = readIndexProperties( request );
-
- if ( request.isCreateIncrementalChunks() )
+ try
{
- List<Integer> chunk = incrementalHandler.getIncrementalUpdates( request, info );
+ // Note that for incremental indexes to work properly, a valid index.properties file
+ // must be present
+ info = readIndexProperties( request );
- if ( chunk == null )
- {
- getLogger().debug( "Problem with Chunks, forcing regeneration of whole index" );
- incrementalHandler.initializeProperties( info );
- }
- else if ( chunk.isEmpty() )
+ if ( request.isCreateIncrementalChunks() )
{
- getLogger().debug( "No incremental changes, not writing new incremental chunk" );
- }
- else
- {
- File file =
- new File( request.getTargetDir(), //
- IndexingContext.INDEX_FILE_PREFIX + "."
- + info.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ) + ".gz" );
-
- writeIndexData( request.getContext(), //
- chunk, file );
+ List<Integer> chunk = incrementalHandler.getIncrementalUpdates( request, info );
- if ( request.isCreateChecksumFiles() )
+ if ( chunk == null )
+ {
+ getLogger().debug( "Problem with Chunks, forcing regeneration of whole index" );
+ incrementalHandler.initializeProperties( info );
+ }
+ else if ( chunk.isEmpty() )
{
- FileUtils.fileWrite(
- new File( file.getParentFile(), file.getName() + ".sha1" ).getAbsolutePath(),
- DigesterUtils.getSha1Digest( file ) );
-
- FileUtils.fileWrite(
- new File( file.getParentFile(), file.getName() + ".md5" ).getAbsolutePath(),
- DigesterUtils.getMd5Digest( file ) );
+ getLogger().debug( "No incremental changes, not writing new incremental chunk" );
+ }
+ else
+ {
+ File file =
+ new File( request.getTargetDir(), //
+ IndexingContext.INDEX_FILE_PREFIX + "."
+ + info.getProperty( IndexingContext.INDEX_CHUNK_COUNTER ) + ".gz" );
+
+ writeIndexData( request.getContext(), //
+ chunk, file );
+
+ if ( request.isCreateChecksumFiles() )
+ {
+ FileUtils.fileWrite(
+ new File( file.getParentFile(), file.getName() + ".sha1" ).getAbsolutePath(),
+ DigesterUtils.getSha1Digest( file ) );
+
+ FileUtils.fileWrite(
+ new File( file.getParentFile(), file.getName() + ".md5" ).getAbsolutePath(),
+ DigesterUtils.getMd5Digest( file ) );
+ }
}
}
}
- }
- catch ( IOException e )
- {
- getLogger().info( "Unable to read properties file, will force index regeneration" );
- info = new Properties();
- incrementalHandler.initializeProperties( info );
- }
-
- Date timestamp = request.getContext().getTimestamp();
-
- if ( timestamp == null )
- {
- timestamp = new Date( 0 ); // never updated
- }
-
- if ( request.getFormats().contains( IndexPackingRequest.IndexFormat.FORMAT_LEGACY ) )
- {
- info.setProperty( IndexingContext.INDEX_LEGACY_TIMESTAMP, format( timestamp ) );
+ catch ( IOException e )
+ {
+ getLogger().info( "Unable to read properties file, will force index regeneration" );
+ info = new Properties();
+ incrementalHandler.initializeProperties( info );
+ }
- writeIndexArchive( request.getContext(), legacyFile );
+ Date timestamp = request.getContext().getTimestamp();
- if ( request.isCreateChecksumFiles() )
+ if ( timestamp == null )
{
- FileUtils.fileWrite(
- new File( legacyFile.getParentFile(), legacyFile.getName() + ".sha1" ).getAbsolutePath(),
- DigesterUtils.getSha1Digest( legacyFile ) );
-
- FileUtils.fileWrite(
- new File( legacyFile.getParentFile(), legacyFile.getName() + ".md5" ).getAbsolutePath(),
- DigesterUtils.getMd5Digest( legacyFile ) );
+ timestamp = new Date( 0 ); // never updated
}
- }
- if ( request.getFormats().contains( IndexPackingRequest.IndexFormat.FORMAT_V1 ) )
- {
- info.setProperty( IndexingContext.INDEX_TIMESTAMP, format( timestamp ) );
+ if ( request.getFormats().contains( IndexPackingRequest.IndexFormat.FORMAT_LEGACY ) )
+ {
+ info.setProperty( IndexingContext.INDEX_LEGACY_TIMESTAMP, format( timestamp ) );
- writeIndexData( request.getContext(), null, v1File );
+ writeIndexArchive( request.getContext(), legacyFile );
- if ( request.isCreateChecksumFiles() )
+ if ( request.isCreateChecksumFiles() )
+ {
+ FileUtils.fileWrite(
+ new File( legacyFile.getParentFile(), legacyFile.getName() + ".sha1" ).getAbsolutePath(),
+ DigesterUtils.getSha1Digest( legacyFile ) );
+
+ FileUtils.fileWrite(
+ new File( legacyFile.getParentFile(), legacyFile.getName() + ".md5" ).getAbsolutePath(),
+ DigesterUtils.getMd5Digest( legacyFile ) );
+ }
+ }
+
+ if ( request.getFormats().contains( IndexPackingRequest.IndexFormat.FORMAT_V1 ) )
{
- FileUtils.fileWrite( new File( v1File.getParentFile(), v1File.getName() + ".sha1" ).getAbsolutePath(),
- DigesterUtils.getSha1Digest( v1File ) );
+ info.setProperty( IndexingContext.INDEX_TIMESTAMP, format( timestamp ) );
+
+ writeIndexData( request.getContext(), null, v1File );
- FileUtils.fileWrite( new File( v1File.getParentFile(), v1File.getName() + ".md5" ).getAbsolutePath(),
- DigesterUtils.getMd5Digest( v1File ) );
+ if ( request.isCreateChecksumFiles() )
+ {
+ FileUtils.fileWrite(
+ new File( v1File.getParentFile(), v1File.getName() + ".sha1" ).getAbsolutePath(),
+ DigesterUtils.getSha1Digest( v1File ) );
+
+ FileUtils.fileWrite(
+ new File( v1File.getParentFile(), v1File.getName() + ".md5" ).getAbsolutePath(),
+ DigesterUtils.getMd5Digest( v1File ) );
+ }
}
- }
- writeIndexProperties( request, info );
+ writeIndexProperties( request, info );
+ }
+ finally
+ {
+ context.unlock();
+ }
}
private Properties readIndexProperties( IndexPackingRequest request )