mirror of https://github.com/apache/archiva.git
fix unit tests in archiva-scheduler-indexing
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197140 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
42edbc5ca5
commit
c215c38616
|
@ -175,8 +175,8 @@ public class DefaultDownloadRemoteIndexScheduler
|
||||||
|
|
||||||
DownloadRemoteIndexTaskRequest downloadRemoteIndexTaskRequest =
|
DownloadRemoteIndexTaskRequest downloadRemoteIndexTaskRequest =
|
||||||
new DownloadRemoteIndexTaskRequest().setRemoteRepository( remoteRepository ).setNetworkProxy(
|
new DownloadRemoteIndexTaskRequest().setRemoteRepository( remoteRepository ).setNetworkProxy(
|
||||||
networkProxy ).setFullDownload( fullDownload ).setWagonFactory( wagonFactory ).setNexusIndexer(
|
networkProxy ).setFullDownload( fullDownload ).setWagonFactory(
|
||||||
nexusIndexer ).setIndexUpdater( indexUpdater );
|
wagonFactory ).setRemoteRepositoryAdmin( remoteRepositoryAdmin ).setIndexUpdater( indexUpdater );
|
||||||
|
|
||||||
if ( now )
|
if ( now )
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,13 +18,14 @@ package org.apache.archiva.scheduler.indexing;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.archiva.admin.model.RepositoryAdminException;
|
||||||
import org.apache.archiva.admin.model.beans.NetworkProxy;
|
import org.apache.archiva.admin.model.beans.NetworkProxy;
|
||||||
import org.apache.archiva.admin.model.beans.RemoteRepository;
|
import org.apache.archiva.admin.model.beans.RemoteRepository;
|
||||||
|
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
|
||||||
import org.apache.archiva.proxy.common.WagonFactory;
|
import org.apache.archiva.proxy.common.WagonFactory;
|
||||||
import org.apache.archiva.proxy.common.WagonFactoryException;
|
import org.apache.archiva.proxy.common.WagonFactoryException;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.lang.time.StopWatch;
|
import org.apache.commons.lang.time.StopWatch;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
|
||||||
import org.apache.maven.index.context.IndexingContext;
|
import org.apache.maven.index.context.IndexingContext;
|
||||||
import org.apache.maven.index.updater.IndexUpdateRequest;
|
import org.apache.maven.index.updater.IndexUpdateRequest;
|
||||||
import org.apache.maven.index.updater.IndexUpdater;
|
import org.apache.maven.index.updater.IndexUpdater;
|
||||||
|
@ -67,7 +68,7 @@ public class DownloadRemoteIndexTask
|
||||||
|
|
||||||
private RemoteRepository remoteRepository;
|
private RemoteRepository remoteRepository;
|
||||||
|
|
||||||
private NexusIndexer nexusIndexer;
|
private RemoteRepositoryAdmin remoteRepositoryAdmin;
|
||||||
|
|
||||||
private WagonFactory wagonFactory;
|
private WagonFactory wagonFactory;
|
||||||
|
|
||||||
|
@ -83,12 +84,12 @@ public class DownloadRemoteIndexTask
|
||||||
List<String> runningRemoteDownloadIds )
|
List<String> runningRemoteDownloadIds )
|
||||||
{
|
{
|
||||||
this.remoteRepository = downloadRemoteIndexTaskRequest.getRemoteRepository();
|
this.remoteRepository = downloadRemoteIndexTaskRequest.getRemoteRepository();
|
||||||
this.nexusIndexer = downloadRemoteIndexTaskRequest.getNexusIndexer( );
|
|
||||||
this.wagonFactory = downloadRemoteIndexTaskRequest.getWagonFactory();
|
this.wagonFactory = downloadRemoteIndexTaskRequest.getWagonFactory();
|
||||||
this.networkProxy = downloadRemoteIndexTaskRequest.getNetworkProxy();
|
this.networkProxy = downloadRemoteIndexTaskRequest.getNetworkProxy();
|
||||||
this.fullDownload = downloadRemoteIndexTaskRequest.isFullDownload();
|
this.fullDownload = downloadRemoteIndexTaskRequest.isFullDownload();
|
||||||
this.runningRemoteDownloadIds = runningRemoteDownloadIds;
|
this.runningRemoteDownloadIds = runningRemoteDownloadIds;
|
||||||
this.indexUpdater = downloadRemoteIndexTaskRequest.getIndexUpdater();
|
this.indexUpdater = downloadRemoteIndexTaskRequest.getIndexUpdater();
|
||||||
|
this.remoteRepositoryAdmin = downloadRemoteIndexTaskRequest.getRemoteRepositoryAdmin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
|
@ -106,20 +107,18 @@ public class DownloadRemoteIndexTask
|
||||||
}
|
}
|
||||||
this.runningRemoteDownloadIds.add( this.remoteRepository.getId() );
|
this.runningRemoteDownloadIds.add( this.remoteRepository.getId() );
|
||||||
}
|
}
|
||||||
|
File tempIndexDirectory = null;
|
||||||
StopWatch stopWatch = new StopWatch();
|
StopWatch stopWatch = new StopWatch();
|
||||||
stopWatch.start();
|
stopWatch.start();
|
||||||
log.info( "start download remote index for remote repository " + this.remoteRepository.getId( ) );
|
|
||||||
IndexingContext indexingContext =
|
|
||||||
nexusIndexer.getIndexingContexts( ).get( "remote-" + remoteRepository.getId( ) );
|
|
||||||
|
|
||||||
// TODO check if null ? normally not as created by DefaultDownloadRemoteIndexScheduler#startup
|
|
||||||
|
|
||||||
// create a temp directory to download files
|
|
||||||
final File tempIndexDirectory = new File( indexingContext.getIndexDirectoryFile( ).getParent( ), ".tmpIndex" );
|
|
||||||
File indexCacheDirectory = new File( indexingContext.getIndexDirectoryFile( ).getParent( ), ".indexCache" );
|
|
||||||
indexCacheDirectory.mkdirs();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
log.info( "start download remote index for remote repository " + this.remoteRepository.getId() );
|
||||||
|
IndexingContext indexingContext = remoteRepositoryAdmin.createIndexContext( this.remoteRepository );
|
||||||
|
|
||||||
|
// create a temp directory to download files
|
||||||
|
tempIndexDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex" );
|
||||||
|
File indexCacheDirectory = new File( indexingContext.getIndexDirectoryFile().getParent(), ".indexCache" );
|
||||||
|
indexCacheDirectory.mkdirs();
|
||||||
if ( tempIndexDirectory.exists() )
|
if ( tempIndexDirectory.exists() )
|
||||||
{
|
{
|
||||||
FileUtils.deleteDirectory( tempIndexDirectory );
|
FileUtils.deleteDirectory( tempIndexDirectory );
|
||||||
|
@ -158,58 +157,15 @@ public class DownloadRemoteIndexTask
|
||||||
indexDirectory.mkdirs();
|
indexDirectory.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceFetcher resourceFetcher = new ResourceFetcher( )
|
ResourceFetcher resourceFetcher = new WagonResourceFetcher( log, tempIndexDirectory, wagon );
|
||||||
{
|
|
||||||
public void connect( String id, String url )
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
//no op
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disconnect( )
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
// no op
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream retrieve( String name )
|
|
||||||
throws IOException, FileNotFoundException
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
log.info( "index update retrieve file, name:{}", name );
|
|
||||||
File file = new File( tempIndexDirectory, name );
|
|
||||||
if ( file.exists( ) )
|
|
||||||
{
|
|
||||||
file.delete( );
|
|
||||||
}
|
|
||||||
file.deleteOnExit();
|
|
||||||
wagon.get( name, file );
|
|
||||||
return new FileInputStream( file );
|
|
||||||
}
|
|
||||||
catch ( AuthorizationException e )
|
|
||||||
{
|
|
||||||
throw new IOException( e.getMessage( ) );
|
|
||||||
}
|
|
||||||
catch ( TransferFailedException e )
|
|
||||||
{
|
|
||||||
throw new IOException( e.getMessage( ) );
|
|
||||||
}
|
|
||||||
catch ( ResourceDoesNotExistException e )
|
|
||||||
{
|
|
||||||
throw new FileNotFoundException( e.getMessage( ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
|
IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
|
||||||
request.setForceFullUpdate( this.fullDownload );
|
request.setForceFullUpdate( this.fullDownload );
|
||||||
request.setLocalIndexCacheDir( indexCacheDirectory );
|
request.setLocalIndexCacheDir( indexCacheDirectory );
|
||||||
|
|
||||||
this.indexUpdater.fetchAndUpdateIndex( request );
|
this.indexUpdater.fetchAndUpdateIndex( request );
|
||||||
stopWatch.stop();
|
stopWatch.stop();
|
||||||
log.info( "time to download remote repository index for repository {}: {} s",
|
log.info( "time to download remote repository index for repository {}: {} s", this.remoteRepository.getId(),
|
||||||
this.remoteRepository.getId( ), ( stopWatch.getTime( ) / 1000 ) );
|
( stopWatch.getTime() / 1000 ) );
|
||||||
}
|
}
|
||||||
catch ( MalformedURLException e )
|
catch ( MalformedURLException e )
|
||||||
{
|
{
|
||||||
|
@ -236,6 +192,11 @@ public class DownloadRemoteIndexTask
|
||||||
log.error( e.getMessage(), e );
|
log.error( e.getMessage(), e );
|
||||||
throw new RuntimeException( e.getMessage(), e );
|
throw new RuntimeException( e.getMessage(), e );
|
||||||
}
|
}
|
||||||
|
catch ( RepositoryAdminException e )
|
||||||
|
{
|
||||||
|
log.error( e.getMessage(), e );
|
||||||
|
throw new RuntimeException( e.getMessage(), e );
|
||||||
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
deleteDirectoryQuiet( tempIndexDirectory );
|
deleteDirectoryQuiet( tempIndexDirectory );
|
||||||
|
@ -322,4 +283,64 @@ public class DownloadRemoteIndexTask
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class WagonResourceFetcher
|
||||||
|
implements ResourceFetcher
|
||||||
|
{
|
||||||
|
|
||||||
|
Logger log;
|
||||||
|
|
||||||
|
File tempIndexDirectory;
|
||||||
|
|
||||||
|
Wagon wagon;
|
||||||
|
|
||||||
|
private WagonResourceFetcher( Logger log, File tempIndexDirectory, Wagon wagon )
|
||||||
|
{
|
||||||
|
this.log = log;
|
||||||
|
this.tempIndexDirectory = tempIndexDirectory;
|
||||||
|
this.wagon = wagon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void connect( String id, String url )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
//no op
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnect()
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputStream retrieve( String name )
|
||||||
|
throws IOException, FileNotFoundException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
log.info( "index update retrieve file, name:{}", name );
|
||||||
|
File file = new File( tempIndexDirectory, name );
|
||||||
|
if ( file.exists() )
|
||||||
|
{
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
file.deleteOnExit();
|
||||||
|
wagon.get( name, file );
|
||||||
|
return new FileInputStream( file );
|
||||||
|
}
|
||||||
|
catch ( AuthorizationException e )
|
||||||
|
{
|
||||||
|
throw new IOException( e.getMessage() );
|
||||||
|
}
|
||||||
|
catch ( TransferFailedException e )
|
||||||
|
{
|
||||||
|
throw new IOException( e.getMessage() );
|
||||||
|
}
|
||||||
|
catch ( ResourceDoesNotExistException e )
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException( e.getMessage() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.scheduler.indexing;
|
||||||
|
|
||||||
import org.apache.archiva.admin.model.beans.NetworkProxy;
|
import org.apache.archiva.admin.model.beans.NetworkProxy;
|
||||||
import org.apache.archiva.admin.model.beans.RemoteRepository;
|
import org.apache.archiva.admin.model.beans.RemoteRepository;
|
||||||
|
import org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin;
|
||||||
import org.apache.archiva.proxy.common.WagonFactory;
|
import org.apache.archiva.proxy.common.WagonFactory;
|
||||||
import org.apache.maven.index.NexusIndexer;
|
import org.apache.maven.index.NexusIndexer;
|
||||||
import org.apache.maven.index.updater.IndexUpdater;
|
import org.apache.maven.index.updater.IndexUpdater;
|
||||||
|
@ -32,7 +33,7 @@ public class DownloadRemoteIndexTaskRequest
|
||||||
{
|
{
|
||||||
private RemoteRepository remoteRepository;
|
private RemoteRepository remoteRepository;
|
||||||
|
|
||||||
private NexusIndexer nexusIndexer;
|
private RemoteRepositoryAdmin remoteRepositoryAdmin;
|
||||||
|
|
||||||
private WagonFactory wagonFactory;
|
private WagonFactory wagonFactory;
|
||||||
|
|
||||||
|
@ -58,16 +59,6 @@ public class DownloadRemoteIndexTaskRequest
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NexusIndexer getNexusIndexer()
|
|
||||||
{
|
|
||||||
return nexusIndexer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DownloadRemoteIndexTaskRequest setNexusIndexer( NexusIndexer nexusIndexer )
|
|
||||||
{
|
|
||||||
this.nexusIndexer = nexusIndexer;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WagonFactory getWagonFactory()
|
public WagonFactory getWagonFactory()
|
||||||
{
|
{
|
||||||
|
@ -112,4 +103,15 @@ public class DownloadRemoteIndexTaskRequest
|
||||||
this.indexUpdater = indexUpdater;
|
this.indexUpdater = indexUpdater;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
|
||||||
|
{
|
||||||
|
return remoteRepositoryAdmin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DownloadRemoteIndexTaskRequest setRemoteRepositoryAdmin( RemoteRepositoryAdmin remoteRepositoryAdmin )
|
||||||
|
{
|
||||||
|
this.remoteRepositoryAdmin = remoteRepositoryAdmin;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue