// just do your best to delete this.
}
basedir.mkdirs();
PlexusContainer container = new DefaultPlexusContainer();
IndexCreator min = container.lookup( IndexCreator.class, "min" );
IndexCreator jar = container.lookup( IndexCreator.class, "jarContent" );
List<IndexCreator> creators = new ArrayList<IndexCreator>();
creators.add( min );
creators.add( jar );
String repositoryId = "test";
String repositoryUrl = "http://localhost:8081/nexus/content/groups/sonatype-public/";
// String repositoryUrl = "http://repository.sonatype.org/content/groups/public/";
// String repositoryUrl = "http://repository.sonatype.org/content/groups/sonatype/";
String indexUrl = repositoryUrl + ".index";
IndexingContext ctx =
new DefaultIndexingContext( repositoryId, repositoryId, basedir, basedir, repositoryUrl, indexUrl,
creators, true );
// craft the Wagon based Resource
TransferListener tl = new TransferListener()
{
private int col = 0;
private int count = 0;
private int mb = 0;
public void transferStarted( final TransferEvent transferEvent )
{
System.out.println( "Started transfer: " + transferEvent.getResource().getName() );
}
public void transferProgress( final TransferEvent transferEvent, final byte[] buffer, final int length )
{
if ( buffer == null )
{
return;
}
count += buffer.length;
if ( ( count / ONE_MEGABYTE ) > mb )
{
if ( col > 80 )
{
System.out.println();
col = 0;
}
System.out.print( '.' );
col++;
mb++;
}
}
public void transferInitiated( final TransferEvent transferEvent )
{
}
public void transferError( final TransferEvent transferEvent )
{
System.out.println( "[ERROR]: " + transferEvent.getException().getLocalizedMessage() );
transferEvent.getException().printStackTrace();
}
public void transferCompleted( final TransferEvent transferEvent )
{
System.out.println( "\nCompleted transfer: " + transferEvent.getResource().getName() + " ("
+ (double) ( count / ONE_MEGABYTE ) + " MB)" );
}
public void debug( final String message )
{
System.out.println( "[DEBUG]: " + message );
}
};
WagonHelper wh = new WagonHelper( container );
WagonFetcher wf = wh.getWagonResourceFetcher( tl, null, null );
IndexUpdateRequest updateRequest = new IndexUpdateRequest( ctx, wf );
container.lookup( IndexUpdater.class ).fetchAndUpdateIndex( updateRequest );
}