1 package org.apache.archiva.indexer.maven;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.admin.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.NetworkProxy;
24 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
25 import org.apache.archiva.common.utils.FileUtils;
26 import org.apache.archiva.common.utils.PathUtil;
27 import org.apache.archiva.configuration.ArchivaConfiguration;
28 import org.apache.archiva.indexer.ArchivaIndexManager;
29 import org.apache.archiva.indexer.ArchivaIndexingContext;
30 import org.apache.archiva.indexer.IndexCreationFailedException;
31 import org.apache.archiva.indexer.IndexUpdateFailedException;
32 import org.apache.archiva.indexer.UnsupportedBaseContextException;
33 import org.apache.archiva.proxy.common.WagonFactory;
34 import org.apache.archiva.proxy.common.WagonFactoryException;
35 import org.apache.archiva.proxy.common.WagonFactoryRequest;
36 import org.apache.archiva.repository.*;
37 import org.apache.archiva.repository.features.IndexCreationEvent;
38 import org.apache.archiva.repository.features.IndexCreationFeature;
39 import org.apache.archiva.repository.features.RemoteIndexFeature;
40 import org.apache.commons.lang.StringUtils;
41 import org.apache.maven.index.*;
42 import org.apache.maven.index.context.IndexCreator;
43 import org.apache.maven.index.context.IndexingContext;
44 import org.apache.maven.index.packer.IndexPacker;
45 import org.apache.maven.index.packer.IndexPackingRequest;
46 import org.apache.maven.index.updater.IndexUpdateRequest;
47 import org.apache.maven.index.updater.IndexUpdater;
48 import org.apache.maven.index.updater.ResourceFetcher;
49 import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException;
50 import org.apache.maven.wagon.ConnectionException;
51 import org.apache.maven.wagon.ResourceDoesNotExistException;
52 import org.apache.maven.wagon.StreamWagon;
53 import org.apache.maven.wagon.TransferFailedException;
54 import org.apache.maven.wagon.Wagon;
55 import org.apache.maven.wagon.authentication.AuthenticationException;
56 import org.apache.maven.wagon.authentication.AuthenticationInfo;
57 import org.apache.maven.wagon.authorization.AuthorizationException;
58 import org.apache.maven.wagon.events.TransferEvent;
59 import org.apache.maven.wagon.events.TransferListener;
60 import org.apache.maven.wagon.proxy.ProxyInfo;
61 import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
62 import org.apache.maven.wagon.shared.http.HttpConfiguration;
63 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
64 import org.slf4j.Logger;
65 import org.slf4j.LoggerFactory;
66 import org.springframework.stereotype.Service;
68 import javax.annotation.PostConstruct;
69 import javax.inject.Inject;
70 import java.io.FileNotFoundException;
71 import java.io.IOException;
72 import java.io.InputStream;
73 import java.net.MalformedURLException;
75 import java.nio.file.Files;
76 import java.nio.file.Path;
77 import java.nio.file.Paths;
78 import java.util.Collection;
79 import java.util.List;
81 import java.util.concurrent.ConcurrentSkipListSet;
82 import java.util.stream.Collectors;
85 * Maven implementation of index manager.
86 * The index manager is a singleton, so we try to make sure, that index operations are not running
87 * parallel by synchronizing on the index path.
88 * A update operation waits for parallel running methods to finish before starting, but after a certain
89 * time of retries a IndexUpdateFailedException is thrown.
91 @Service( "archivaIndexManager#maven" )
92 public class MavenIndexManager implements ArchivaIndexManager {
94 private static final Logger log = LoggerFactory.getLogger( MavenIndexManager.class );
97 private Indexer indexer;
100 private IndexerEngine indexerEngine;
103 private List<? extends IndexCreator> indexCreators;
106 private IndexPacker indexPacker;
109 private Scanner scanner;
112 private ArchivaConfiguration archivaConfiguration;
115 private WagonFactory wagonFactory;
118 private NetworkProxyAdmin networkProxyAdmin;
121 private IndexUpdater indexUpdater;
124 private ArtifactContextProducer artifactContextProducer;
127 RepositoryRegistry repositoryRegistry;
129 public static final String DEFAULT_INDEXER_DIR = ".indexer";
131 private ConcurrentSkipListSet<Path> activeContexts = new ConcurrentSkipListSet<>( );
133 private static final int WAIT_TIME = 100;
134 private static final int MAX_WAIT = 10;
137 public static IndexingContext getMvnContext( ArchivaIndexingContext context ) throws UnsupportedBaseContextException
139 if ( !context.supports( IndexingContext.class ) )
141 log.error( "The provided archiva index context does not support the maven IndexingContext" );
142 throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" );
144 return context.getBaseContext( IndexingContext.class );
147 private Path getIndexPath( ArchivaIndexingContext ctx )
149 return PathUtil.getPathFromUri( ctx.getPath( ) );
153 interface IndexUpdateConsumer
156 void accept( IndexingContext indexingContext ) throws IndexUpdateFailedException;
160 * This method is used to do some actions around the update execution code. And to make sure, that no other
161 * method is running on the same index.
163 private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException
165 IndexingContext indexingContext = null;
168 indexingContext = getMvnContext( context );
170 catch ( UnsupportedBaseContextException e )
172 throw new IndexUpdateFailedException( "Maven index is not supported by this context", e );
174 final Path ctxPath = getIndexPath( context );
176 boolean active = false;
177 while ( loop-- > 0 && !active )
179 active = activeContexts.add( ctxPath );
182 Thread.currentThread( ).sleep( WAIT_TIME );
184 catch ( InterruptedException e )
193 function.accept( indexingContext );
197 activeContexts.remove( ctxPath );
202 throw new IndexUpdateFailedException( "Timeout while waiting for index release on context " + context.getId( ) );
207 public void pack( final ArchivaIndexingContext context ) throws IndexUpdateFailedException
209 executeUpdateFunction( context, indexingContext -> {
212 IndexPackingRequest request = new IndexPackingRequest( indexingContext,
213 indexingContext.acquireIndexSearcher( ).getIndexReader( ),
214 indexingContext.getIndexDirectoryFile( ) );
215 indexPacker.packIndex( request );
216 indexingContext.updateTimestamp( true );
218 catch ( IOException e )
220 log.error( "IOException while packing index of context " + context.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ) );
221 throw new IndexUpdateFailedException( "IOException during update of " + context.getId( ), e );
229 public void scan(final ArchivaIndexingContext context) throws IndexUpdateFailedException
231 executeUpdateFunction( context, indexingContext -> {
232 DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null );
233 ScanningRequest request = new ScanningRequest( indexingContext, listener );
234 ScanningResult result = scanner.scan( request );
235 if ( result.hasExceptions( ) )
237 log.error( "Exceptions occured during index scan of " + context.getId( ) );
238 result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach(
239 s -> log.error( "Message: " + s )
247 public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException
249 log.info( "start download remote index for remote repository {}", context.getRepository( ).getId( ) );
251 if ( !( context.getRepository( ) instanceof RemoteRepository ) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class)) )
253 throw new IndexUpdateFailedException( "The context is not associated to a remote repository with remote index " + context.getId( ) );
255 RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
256 remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
258 final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository( );
260 executeUpdateFunction( context,
264 // create a temp directory to download files
265 Path tempIndexDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".tmpIndex" );
266 Path indexCacheDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".indexCache" );
267 Files.createDirectories( indexCacheDirectory );
268 if ( Files.exists( tempIndexDirectory ) )
270 org.apache.archiva.common.utils.FileUtils.deleteDirectory( tempIndexDirectory );
272 Files.createDirectories( tempIndexDirectory );
273 tempIndexDirectory.toFile( ).deleteOnExit( );
274 String baseIndexUrl = indexingContext.getIndexUpdateUrl( );
276 String wagonProtocol = remoteUpdateUri.toURL( ).getProtocol( );
278 NetworkProxy networkProxy = null;
279 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
281 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
282 if ( StringUtils.isNotBlank( rif.getProxyId( ) ) )
286 networkProxy = networkProxyAdmin.getNetworkProxy( rif.getProxyId( ) );
288 catch ( RepositoryAdminException e )
290 log.error( "Error occured while retrieving proxy {}", e.getMessage( ) );
292 if ( networkProxy == null )
295 "your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
300 final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
301 new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders( ) ).networkProxy(
304 int readTimeout = (int) rif.getDownloadTimeout( ).toMillis( ) * 1000;
305 wagon.setReadTimeout( readTimeout );
306 wagon.setTimeout( (int) remoteRepository.getTimeout( ).toMillis( ) * 1000 );
308 if ( wagon instanceof AbstractHttpClientWagon )
310 HttpConfiguration httpConfiguration = new HttpConfiguration( );
311 HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration( );
312 httpMethodConfiguration.setUsePreemptive( true );
313 httpMethodConfiguration.setReadTimeout( readTimeout );
314 httpConfiguration.setGet( httpMethodConfiguration );
315 AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
318 wagon.addTransferListener( new DownloadListener( ) );
319 ProxyInfo proxyInfo = null;
320 if ( networkProxy != null )
322 proxyInfo = new ProxyInfo( );
323 proxyInfo.setType( networkProxy.getProtocol( ) );
324 proxyInfo.setHost( networkProxy.getHost( ) );
325 proxyInfo.setPort( networkProxy.getPort( ) );
326 proxyInfo.setUserName( networkProxy.getUsername( ) );
327 proxyInfo.setPassword( networkProxy.getPassword( ) );
329 AuthenticationInfo authenticationInfo = null;
330 if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials ) )
332 PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials( );
333 authenticationInfo = new AuthenticationInfo( );
334 authenticationInfo.setUserName( creds.getUsername( ) );
335 authenticationInfo.setPassword( new String( creds.getPassword( ) ) );
337 wagon.connect( new org.apache.maven.wagon.repository.Repository( remoteRepository.getId( ), baseIndexUrl ), authenticationInfo,
340 Path indexDirectory = indexingContext.getIndexDirectoryFile( ).toPath( );
341 if ( !Files.exists( indexDirectory ) )
343 Files.createDirectories( indexDirectory );
346 ResourceFetcher resourceFetcher =
347 new WagonResourceFetcher( log, tempIndexDirectory, wagon, remoteRepository );
348 IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
349 request.setForceFullUpdate( fullUpdate );
350 request.setLocalIndexCacheDir( indexCacheDirectory.toFile( ) );
352 indexUpdater.fetchAndUpdateIndex( request );
354 indexingContext.updateTimestamp( true );
358 catch ( AuthenticationException e )
360 log.error( "Could not login to the remote proxy for updating index of {}", remoteRepository.getId( ), e );
361 throw new IndexUpdateFailedException( "Login in to proxy failed while updating remote repository " + remoteRepository.getId( ), e );
363 catch ( ConnectionException e )
365 log.error( "Connection error during index update for remote repository {}", remoteRepository.getId( ), e );
366 throw new IndexUpdateFailedException( "Connection error during index update for remote repository " + remoteRepository.getId( ), e );
368 catch ( MalformedURLException e )
370 log.error( "URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId( ), remoteUpdateUri, e );
371 throw new IndexUpdateFailedException( "URL for remote index update of repository is not correct " + remoteUpdateUri, e );
373 catch ( IOException e )
375 log.error( "IOException during index update of remote repository {}: {}", remoteRepository.getId( ), e.getMessage( ), e );
376 throw new IndexUpdateFailedException( "IOException during index update of remote repository " + remoteRepository.getId( )
377 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
379 catch ( WagonFactoryException e )
381 log.error( "Wagon for remote index download of {} could not be created: {}", remoteRepository.getId( ), e.getMessage( ), e );
382 throw new IndexUpdateFailedException( "Error while updating the remote index of " + remoteRepository.getId( ), e );
389 public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
391 final URI ctxUri = context.getPath();
392 executeUpdateFunction(context, indexingContext -> {
393 Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
395 indexer.addArtifactsToIndex(artifacts, indexingContext);
396 } catch (IOException e) {
397 log.error("IOException while adding artifact {}", e.getMessage(), e);
398 throw new IndexUpdateFailedException("Error occured while adding artifact to index of "+context.getId()
399 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
405 public void removeArtifactsFromIndex( ArchivaIndexingContext context, Collection<URI> artifactReference ) throws IndexUpdateFailedException
407 final URI ctxUri = context.getPath();
408 executeUpdateFunction(context, indexingContext -> {
409 Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
411 indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
412 } catch (IOException e) {
413 log.error("IOException while removing artifact {}", e.getMessage(), e);
414 throw new IndexUpdateFailedException("Error occured while removing artifact from index of "+context.getId()
415 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
422 public boolean supportsRepository( RepositoryType type )
424 return type == RepositoryType.MAVEN;
428 public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException
430 log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
431 if ( repository.getType( ) != RepositoryType.MAVEN )
433 throw new UnsupportedRepositoryTypeException( repository.getType( ) );
435 IndexingContext mvnCtx = null;
438 if ( repository instanceof RemoteRepository )
440 mvnCtx = createRemoteContext( (RemoteRepository) repository );
442 else if ( repository instanceof ManagedRepository )
444 mvnCtx = createManagedContext( (ManagedRepository) repository );
447 catch ( IOException e )
449 log.error( "IOException during context creation " + e.getMessage( ), e );
450 throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( )
451 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
453 MavenIndexContext context = new MavenIndexContext( repository, mvnCtx );
459 public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
460 ArchivaIndexingContext ctx;
461 executeUpdateFunction(context, indexingContext -> {
463 indexingContext.close(true);
464 } catch (IOException e) {
465 log.warn("Index close failed");
468 FileUtils.deleteDirectory(Paths.get(context.getPath()));
469 } catch (IOException e) {
470 throw new IndexUpdateFailedException("Could not delete index files");
474 Repository repo = context.getRepository();
475 ctx = createContext(context.getRepository());
476 if (repo instanceof EditableRepository) {
477 ((EditableRepository)repo).setIndexingContext(ctx);
479 } catch (IndexCreationFailedException e) {
480 throw new IndexUpdateFailedException("Could not create index");
486 public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
490 if (context.supports(IndexingContext.class)) {
492 Path newPath = getIndexPath(repo);
493 IndexingContext ctx = context.getBaseContext(IndexingContext.class);
494 Path oldPath = ctx.getIndexDirectoryFile().toPath();
495 if (oldPath.equals(newPath)) {
496 // Nothing to do, if path does not change
499 if (!Files.exists(oldPath)) {
500 return createContext(repo);
501 } else if (context.isEmpty()) {
503 return createContext(repo);
505 context.close(false);
506 Files.move(oldPath, newPath);
507 return createContext(repo);
509 } catch (IOException e) {
510 log.error("IOException while moving index directory {}", e.getMessage(), e);
511 throw new IndexCreationFailedException("Could not recreated the index.", e);
512 } catch (UnsupportedBaseContextException e) {
513 throw new IndexCreationFailedException("The given context, is not a maven context.");
516 throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
521 public void updateLocalIndexPath(Repository repo) {
522 if (repo.supportsFeature(IndexCreationFeature.class)) {
523 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
525 icf.setLocalIndexPath(getIndexPath(repo));
526 } catch (IOException e) {
527 log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath());
532 private Path getIndexPath(Repository repo) throws IOException {
533 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
534 Path repoDir = repo.getLocalPath();
535 URI indexDir = icf.getIndexPath();
536 Path indexDirectory = null;
537 if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
540 indexDirectory = PathUtil.getPathFromUri( indexDir );
541 // not absolute so create it in repository directory
542 if ( !indexDirectory.isAbsolute( ) )
544 indexDirectory = repoDir.resolve( indexDirectory );
549 indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR );
552 if ( !Files.exists( indexDirectory ) )
554 Files.createDirectories( indexDirectory );
556 return indexDirectory;
559 private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
561 Path appServerBase = archivaConfiguration.getAppServerBaseDir( );
563 String contextKey = "remote-" + remoteRepository.getId( );
566 // create remote repository path
567 Path repoDir = remoteRepository.getLocalPath();
568 if ( !Files.exists( repoDir ) )
570 Files.createDirectories( repoDir );
573 Path indexDirectory = null;
575 // is there configured indexDirectory ?
576 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
578 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
579 indexDirectory = getIndexPath(remoteRepository);
580 String remoteIndexUrl = calculateIndexRemoteUrl( remoteRepository.getLocation( ), rif );
584 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
586 catch ( IndexFormatTooOldException e )
588 // existing index with an old lucene format so we need to delete it!!!
589 // delete it first then recreate it.
590 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
591 remoteRepository.getId( ) );
592 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
593 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
599 throw new IOException( "No remote index defined" );
603 private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException
605 return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ),
606 repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ),
612 private IndexingContext createManagedContext( ManagedRepository repository ) throws IOException
615 IndexingContext context;
616 // take care first about repository location as can be relative
617 Path repositoryDirectory = repository.getLocalPath();
619 if ( !Files.exists( repositoryDirectory ) )
623 Files.createDirectories( repositoryDirectory );
625 catch ( IOException e )
627 log.error( "Could not create directory {}", repositoryDirectory );
631 Path indexDirectory = null;
633 if ( repository.supportsFeature( IndexCreationFeature.class ) )
635 indexDirectory = getIndexPath(repository);
637 String indexUrl = repositoryDirectory.toUri( ).toURL( ).toExternalForm( );
640 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
641 context.setSearchable( repository.isScanned( ) );
643 catch ( IndexFormatTooOldException e )
645 // existing index with an old lucene format so we need to delete it!!!
646 // delete it first then recreate it.
647 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
648 repository.getId( ) );
649 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
650 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
651 context.setSearchable( repository.isScanned( ) );
657 throw new IOException( "No repository index defined" );
661 private String calculateIndexRemoteUrl( URI baseUri, RemoteIndexFeature rif )
663 if ( rif.getIndexUri( ) == null )
665 return baseUri.resolve( DEFAULT_INDEXER_DIR ).toString( );
669 return baseUri.resolve( rif.getIndexUri( ) ).toString( );
673 private static final class DownloadListener
674 implements TransferListener
676 private Logger log = LoggerFactory.getLogger( getClass( ) );
678 private String resourceName;
680 private long startTime;
682 private int totalLength = 0;
685 public void transferInitiated( TransferEvent transferEvent )
687 startTime = System.currentTimeMillis( );
688 resourceName = transferEvent.getResource( ).getName( );
689 log.debug( "initiate transfer of {}", resourceName );
693 public void transferStarted( TransferEvent transferEvent )
695 this.totalLength = 0;
696 resourceName = transferEvent.getResource( ).getName( );
697 log.info( "start transfer of {}", transferEvent.getResource( ).getName( ) );
701 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
703 log.debug( "transfer of {} : {}/{}", transferEvent.getResource( ).getName( ), buffer.length, length );
704 this.totalLength += length;
708 public void transferCompleted( TransferEvent transferEvent )
710 resourceName = transferEvent.getResource( ).getName( );
711 long endTime = System.currentTimeMillis( );
712 log.info( "end of transfer file {} {} kb: {}s", transferEvent.getResource( ).getName( ),
713 this.totalLength / 1024, ( endTime - startTime ) / 1000 );
717 public void transferError( TransferEvent transferEvent )
719 log.info( "error of transfer file {}: {}", transferEvent.getResource( ).getName( ),
720 transferEvent.getException( ).getMessage( ), transferEvent.getException( ) );
724 public void debug( String message )
726 log.debug( "transfer debug {}", message );
730 private static class WagonResourceFetcher
731 implements ResourceFetcher
736 Path tempIndexDirectory;
740 RemoteRepository remoteRepository;
742 private WagonResourceFetcher( Logger log, Path tempIndexDirectory, Wagon wagon,
743 RemoteRepository remoteRepository )
746 this.tempIndexDirectory = tempIndexDirectory;
748 this.remoteRepository = remoteRepository;
752 public void connect( String id, String url )
759 public void disconnect( )
766 public InputStream retrieve( String name )
767 throws IOException, FileNotFoundException
771 log.info( "index update retrieve file, name:{}", name );
772 Path file = tempIndexDirectory.resolve( name );
773 Files.deleteIfExists( file );
774 file.toFile( ).deleteOnExit( );
775 wagon.get( addParameters( name, remoteRepository ), file.toFile( ) );
776 return Files.newInputStream( file );
778 catch ( AuthorizationException | TransferFailedException e )
780 throw new IOException( e.getMessage( ), e );
782 catch ( ResourceDoesNotExistException e )
784 FileNotFoundException fnfe = new FileNotFoundException( e.getMessage( ) );
790 // FIXME remove crappy copy/paste
791 protected String addParameters( String path, RemoteRepository remoteRepository )
793 if ( remoteRepository.getExtraParameters( ).isEmpty( ) )
798 boolean question = false;
800 StringBuilder res = new StringBuilder( path == null ? "" : path );
802 for ( Map.Entry<String, String> entry : remoteRepository.getExtraParameters( ).entrySet( ) )
806 res.append( '?' ).append( entry.getKey( ) ).append( '=' ).append( entry.getValue( ) );
810 return res.toString( );