protected void createIndex( String repository, List<File> filesToBeIndexed, boolean scan )
throws Exception
{
IndexingContext context = nexusIndexer.getIndexingContexts().get( repository );
if ( context != null )
{
nexusIndexer.removeIndexingContext( context, true );
}
File indexerDirectory = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer" );
if ( indexerDirectory.exists() )
{
FileUtils.deleteDirectory( indexerDirectory );
}
assertFalse( indexerDirectory.exists() );
File lockFile = new File( FileUtil.getBasedir(), "/target/repos/" + repository + "/.indexer/write.lock" );
if ( lockFile.exists() )
{
lockFile.delete();
}
assertFalse( lockFile.exists() );
File repo = new File( FileUtil.getBasedir(), "src/test/" + repository );
assertTrue( repo.exists() );
File indexDirectory =
new File( FileUtil.getBasedir(), "target/index/test-" + Long.toString( System.currentTimeMillis() ) );
indexDirectory.deleteOnExit();
FileUtils.deleteDirectory( indexDirectory );
context = nexusIndexer.addIndexingContext( repository, repository, repo, indexDirectory,
repo.toURI().toURL().toExternalForm(),
indexDirectory.toURI().toURL().toString(),
search.getAllIndexCreators() );
// minimize datas in memory
context.getIndexWriter().setMaxBufferedDocs( -1 );
context.getIndexWriter().setRAMBufferSizeMB( 1 );
for ( File artifactFile : filesToBeIndexed )
{
assertTrue( "file not exists " + artifactFile.getPath(), artifactFile.exists() );
ArtifactContext ac = artifactContextProducer.getArtifactContext( context, artifactFile );
if ( artifactFile.getPath().endsWith( ".pom" ) )
{
ac.getArtifactInfo().fextension = "pom";
ac.getArtifactInfo().packaging = "pom";
ac.getArtifactInfo().classifier = "pom";
}
nexusIndexer.addArtifactToIndex( ac, context );
context.updateTimestamp( true );
}
if ( scan )
{
nexusIndexer.scan( context, new ArtifactScanListener(), false );
}
// force flushing
context.getIndexWriter().commit();
context.setSearchable( true );
}