Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[maven-release-plugin] copy for tag nexus-indexer-1.2.1

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/tags/nexus-indexer-1.2.1@3549 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information...
commit 505f8eb85a0be4b155cf91832149c1377618c906 2 parents 105c86b + bede2e0
mpowers authored
7 src/main/java/org/sonatype/nexus/index/context/DefaultIndexingContext.java
View
@@ -267,9 +267,12 @@ private void deleteIndexFiles()
{
String[] names = indexDirectory.list();
- for ( int i = 0; i < names.length; i++ )
+ if ( names != null )
{
- indexDirectory.deleteFile( names[i] );
+ for ( int i = 0; i < names.length; i++ )
+ {
+ indexDirectory.deleteFile( names[i] );
+ }
}
IndexUtils.deleteTimestamp( indexDirectory );
19 src/main/java/org/sonatype/nexus/index/updater/IndexDataReader.java
View
@@ -48,9 +48,14 @@ public IndexDataReadResult readIndex( IndexWriter w, IndexingContext context )
long timestamp = dis.readLong();
- Date date = new Date( timestamp );
+ Date date = null;
- IndexUtils.updateTimestamp( w.getDirectory(), date );
+ if ( timestamp != -1 )
+ {
+ date = new Date( timestamp );
+
+ IndexUtils.updateTimestamp( w.getDirectory(), date );
+ }
int n = 0;
@@ -58,7 +63,7 @@ public IndexDataReadResult readIndex( IndexWriter w, IndexingContext context )
while ( ( doc = readDocument() ) != null )
{
w.addDocument( IndexUtils.updateDocument( doc, context ) );
-
+
n++;
}
@@ -157,14 +162,14 @@ private final static String readUTF( DataInput in )
case 5:
case 6:
case 7:
- /* 0xxxxxxx*/
+ /* 0xxxxxxx */
count++;
chararr[chararr_count++] = (char) c;
break;
case 12:
case 13:
- /* 110x xxxx 10xx xxxx*/
+ /* 110x xxxx 10xx xxxx */
count += 2;
if ( count > utflen )
{
@@ -179,7 +184,7 @@ private final static String readUTF( DataInput in )
break;
case 14:
- /* 1110 xxxx 10xx xxxx 10xx xxxx */
+ /* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if ( count > utflen )
{
@@ -195,7 +200,7 @@ private final static String readUTF( DataInput in )
break;
default:
- /* 10xx xxxx, 1111 xxxx */
+ /* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException( "malformed input around byte " + count );
}
}
5 src/main/java/org/sonatype/nexus/index/updater/IndexDataWriter.java
View
@@ -11,6 +11,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Date;
import java.util.List;
import java.util.zip.GZIPOutputStream;
@@ -77,7 +78,9 @@ public void writeHeader( IndexingContext context )
throws IOException
{
dos.writeByte( VERSION );
- dos.writeLong( context.getTimestamp().getTime() );
+
+ Date timestamp = context.getTimestamp();
+ dos.writeLong( timestamp == null ? -1 : timestamp.getTime() );
}
public int writeDocuments( IndexReader r, List<Integer> docIndexes )
64 src/test/java/org/sonatype/nexus/index/updater/IndexDataTest.java
View
@@ -36,7 +36,7 @@ protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
throws Exception
{
indexDir = new RAMDirectory();
-
+
context = nexusIndexer.addIndexingContext(
"test-default",
"test",
@@ -51,10 +51,10 @@ protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
nexusIndexer.scan( context );
Date timestamp = context.getTimestamp();
-
+
assertNotNull( timestamp );
- // save and restore index to be used by common tests
+ // save and restore index to be used by common tests
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -68,27 +68,63 @@ protected void prepareNexusIndexer( NexusIndexer nexusIndexer )
Date newTimestamp = DefaultIndexUpdater.unpackIndexData( is, newDir, context );
assertEquals( timestamp, newTimestamp );
-
+
context.replace( newDir );
}
-
+
+ public void testEmptyContext()
+ throws Exception
+ {
+ indexDir = new RAMDirectory();
+
+ context = nexusIndexer.addIndexingContext(
+ "test-default",
+ "test",
+ repo,
+ indexDir,
+ null,
+ null,
+ NexusIndexer.DEFAULT_INDEX );
+
+ assertNull( context.getTimestamp() ); // unknown upon creation
+
+ // save and restore index to be used by common tests
+ // the point is that this is virgin context, and timestamp is null,
+ // and it should remain null
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ IndexDataWriter dw = new IndexDataWriter( bos );
+ dw.write( context, null );
+
+ ByteArrayInputStream is = new ByteArrayInputStream( bos.toByteArray() );
+
+ newDir = new RAMDirectory();
+
+ Date newTimestamp = DefaultIndexUpdater.unpackIndexData( is, newDir, context );
+
+ assertEquals( null, newTimestamp );
+
+ context.replace( newDir );
+ }
+
public void testData()
throws Exception
{
IndexReader r1 = context.getIndexReader();
-
+
Map<String, ArtifactInfo> r1map = readIndex( r1 );
-
+
IndexReader r2 = IndexReader.open( newDir );
Map<String, ArtifactInfo> r2map = readIndex( r2 );
-
+
for ( Entry<String, ArtifactInfo> e : r1map.entrySet() )
{
String key = e.getKey();
assertTrue( "Expected for find " + key, r2map.containsKey( key ) );
}
-
+
assertEquals( r1map.size(), r2map.size() );
}
@@ -96,20 +132,20 @@ public void testData()
throws CorruptIndexException,
IOException
{
- Map<String,ArtifactInfo> map = new HashMap<String, ArtifactInfo>();
+ Map<String, ArtifactInfo> map = new HashMap<String, ArtifactInfo>();
for ( int i = 0; i < r1.maxDoc(); i++ )
{
Document document = r1.document( i );
-
+
ArtifactInfo ai = IndexUtils.constructArtifactInfo( document, context );
-
- if( ai != null)
+
+ if ( ai != null )
{
map.put( ai.getUinfo(), ai );
}
}
-
+
return map;
}
Please sign in to comment.
Something went wrong with that request. Please try again.