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.IndexCreationFeature;
38 import org.apache.archiva.repository.features.RemoteIndexFeature;
39 import org.apache.commons.lang.StringUtils;
40 import org.apache.maven.index.*;
41 import org.apache.maven.index.context.IndexCreator;
42 import org.apache.maven.index.context.IndexingContext;
43 import org.apache.maven.index.packer.IndexPacker;
44 import org.apache.maven.index.packer.IndexPackingRequest;
45 import org.apache.maven.index.updater.IndexUpdateRequest;
46 import org.apache.maven.index.updater.IndexUpdater;
47 import org.apache.maven.index.updater.ResourceFetcher;
48 import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException;
49 import org.apache.maven.wagon.ConnectionException;
50 import org.apache.maven.wagon.ResourceDoesNotExistException;
51 import org.apache.maven.wagon.StreamWagon;
52 import org.apache.maven.wagon.TransferFailedException;
53 import org.apache.maven.wagon.Wagon;
54 import org.apache.maven.wagon.authentication.AuthenticationException;
55 import org.apache.maven.wagon.authentication.AuthenticationInfo;
56 import org.apache.maven.wagon.authorization.AuthorizationException;
57 import org.apache.maven.wagon.events.TransferEvent;
58 import org.apache.maven.wagon.events.TransferListener;
59 import org.apache.maven.wagon.proxy.ProxyInfo;
60 import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
61 import org.apache.maven.wagon.shared.http.HttpConfiguration;
62 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
63 import org.slf4j.Logger;
64 import org.slf4j.LoggerFactory;
65 import org.springframework.stereotype.Service;
67 import javax.inject.Inject;
68 import java.io.FileNotFoundException;
69 import java.io.IOException;
70 import java.io.InputStream;
71 import java.net.MalformedURLException;
73 import java.nio.file.Files;
74 import java.nio.file.Path;
75 import java.nio.file.Paths;
76 import java.util.Collection;
77 import java.util.List;
79 import java.util.concurrent.ConcurrentSkipListSet;
80 import java.util.stream.Collectors;
83 * Maven implementation of index manager.
84 * The index manager is a singleton, so we try to make sure, that index operations are not running
85 * parallel by synchronizing on the index path.
86 * A update operation waits for parallel running methods to finish before starting, but after a certain
87 * time of retries a IndexUpdateFailedException is thrown.
89 @Service( "archivaIndexManager#maven" )
90 public class MavenIndexManager implements ArchivaIndexManager
93 private static final Logger log = LoggerFactory.getLogger( MavenIndexManager.class );
96 private Indexer indexer;
99 private IndexerEngine indexerEngine;
102 private List<? extends IndexCreator> indexCreators;
105 private IndexPacker indexPacker;
108 private Scanner scanner;
111 private ArchivaConfiguration archivaConfiguration;
114 private WagonFactory wagonFactory;
117 private NetworkProxyAdmin networkProxyAdmin;
120 private IndexUpdater indexUpdater;
123 private ArtifactContextProducer artifactContextProducer;
125 private ConcurrentSkipListSet<Path> activeContexts = new ConcurrentSkipListSet<>( );
127 private static final int WAIT_TIME = 100;
128 private static final int MAX_WAIT = 10;
131 public static IndexingContext getMvnContext( ArchivaIndexingContext context ) throws UnsupportedBaseContextException
133 if ( !context.supports( IndexingContext.class ) )
135 log.error( "The provided archiva index context does not support the maven IndexingContext" );
136 throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" );
138 return context.getBaseContext( IndexingContext.class );
141 private Path getIndexPath( ArchivaIndexingContext ctx )
143 return PathUtil.getPathFromUri( ctx.getPath( ) );
147 interface IndexUpdateConsumer
150 void accept( IndexingContext indexingContext ) throws IndexUpdateFailedException;
154 * This method is used to do some actions around the update execution code. And to make sure, that no other
155 * method is running on the same index.
157 private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException
159 IndexingContext indexingContext = null;
162 indexingContext = getMvnContext( context );
164 catch ( UnsupportedBaseContextException e )
166 throw new IndexUpdateFailedException( "Maven index is not supported by this context", e );
168 final Path ctxPath = getIndexPath( context );
170 boolean active = false;
171 while ( loop-- > 0 && !active )
173 active = activeContexts.add( ctxPath );
176 Thread.currentThread( ).sleep( WAIT_TIME );
178 catch ( InterruptedException e )
187 function.accept( indexingContext );
191 activeContexts.remove( ctxPath );
196 throw new IndexUpdateFailedException( "Timeout while waiting for index release on context " + context.getId( ) );
201 public void pack( final ArchivaIndexingContext context ) throws IndexUpdateFailedException
203 executeUpdateFunction( context, indexingContext -> {
206 IndexPackingRequest request = new IndexPackingRequest( indexingContext,
207 indexingContext.acquireIndexSearcher( ).getIndexReader( ),
208 indexingContext.getIndexDirectoryFile( ) );
209 indexPacker.packIndex( request );
210 indexingContext.updateTimestamp( true );
212 catch ( IOException e )
214 log.error( "IOException while packing index of context " + context.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ) );
215 throw new IndexUpdateFailedException( "IOException during update of " + context.getId( ), e );
223 public void scan(final ArchivaIndexingContext context) throws IndexUpdateFailedException
225 executeUpdateFunction( context, indexingContext -> {
226 DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null );
227 ScanningRequest request = new ScanningRequest( indexingContext, listener );
228 ScanningResult result = scanner.scan( request );
229 if ( result.hasExceptions( ) )
231 log.error( "Exceptions occured during index scan of " + context.getId( ) );
232 result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach(
233 s -> log.error( "Message: " + s )
241 public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException
243 log.info( "start download remote index for remote repository {}", context.getRepository( ).getId( ) );
245 if ( !( context.getRepository( ) instanceof RemoteRepository ) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class)) )
247 throw new IndexUpdateFailedException( "The context is not associated to a remote repository with remote index " + context.getId( ) );
249 RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
250 remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
252 final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository( );
254 executeUpdateFunction( context,
258 // create a temp directory to download files
259 Path tempIndexDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".tmpIndex" );
260 Path indexCacheDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".indexCache" );
261 Files.createDirectories( indexCacheDirectory );
262 if ( Files.exists( tempIndexDirectory ) )
264 org.apache.archiva.common.utils.FileUtils.deleteDirectory( tempIndexDirectory );
266 Files.createDirectories( tempIndexDirectory );
267 tempIndexDirectory.toFile( ).deleteOnExit( );
268 String baseIndexUrl = indexingContext.getIndexUpdateUrl( );
270 String wagonProtocol = remoteUpdateUri.toURL( ).getProtocol( );
272 NetworkProxy networkProxy = null;
273 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
275 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
276 if ( StringUtils.isNotBlank( rif.getProxyId( ) ) )
280 networkProxy = networkProxyAdmin.getNetworkProxy( rif.getProxyId( ) );
282 catch ( RepositoryAdminException e )
284 log.error( "Error occured while retrieving proxy {}", e.getMessage( ) );
286 if ( networkProxy == null )
289 "your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
294 final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
295 new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders( ) ).networkProxy(
298 int readTimeout = (int) rif.getDownloadTimeout( ).toMillis( ) * 1000;
299 wagon.setReadTimeout( readTimeout );
300 wagon.setTimeout( (int) remoteRepository.getTimeout( ).toMillis( ) * 1000 );
302 if ( wagon instanceof AbstractHttpClientWagon )
304 HttpConfiguration httpConfiguration = new HttpConfiguration( );
305 HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration( );
306 httpMethodConfiguration.setUsePreemptive( true );
307 httpMethodConfiguration.setReadTimeout( readTimeout );
308 httpConfiguration.setGet( httpMethodConfiguration );
309 AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
312 wagon.addTransferListener( new DownloadListener( ) );
313 ProxyInfo proxyInfo = null;
314 if ( networkProxy != null )
316 proxyInfo = new ProxyInfo( );
317 proxyInfo.setType( networkProxy.getProtocol( ) );
318 proxyInfo.setHost( networkProxy.getHost( ) );
319 proxyInfo.setPort( networkProxy.getPort( ) );
320 proxyInfo.setUserName( networkProxy.getUsername( ) );
321 proxyInfo.setPassword( networkProxy.getPassword( ) );
323 AuthenticationInfo authenticationInfo = null;
324 if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials ) )
326 PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials( );
327 authenticationInfo = new AuthenticationInfo( );
328 authenticationInfo.setUserName( creds.getUsername( ) );
329 authenticationInfo.setPassword( new String( creds.getPassword( ) ) );
331 wagon.connect( new org.apache.maven.wagon.repository.Repository( remoteRepository.getId( ), baseIndexUrl ), authenticationInfo,
334 Path indexDirectory = indexingContext.getIndexDirectoryFile( ).toPath( );
335 if ( !Files.exists( indexDirectory ) )
337 Files.createDirectories( indexDirectory );
340 ResourceFetcher resourceFetcher =
341 new WagonResourceFetcher( log, tempIndexDirectory, wagon, remoteRepository );
342 IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
343 request.setForceFullUpdate( fullUpdate );
344 request.setLocalIndexCacheDir( indexCacheDirectory.toFile( ) );
346 indexUpdater.fetchAndUpdateIndex( request );
348 indexingContext.updateTimestamp( true );
352 catch ( AuthenticationException e )
354 log.error( "Could not login to the remote proxy for updating index of {}", remoteRepository.getId( ), e );
355 throw new IndexUpdateFailedException( "Login in to proxy failed while updating remote repository " + remoteRepository.getId( ), e );
357 catch ( ConnectionException e )
359 log.error( "Connection error during index update for remote repository {}", remoteRepository.getId( ), e );
360 throw new IndexUpdateFailedException( "Connection error during index update for remote repository " + remoteRepository.getId( ), e );
362 catch ( MalformedURLException e )
364 log.error( "URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId( ), remoteUpdateUri, e );
365 throw new IndexUpdateFailedException( "URL for remote index update of repository is not correct " + remoteUpdateUri, e );
367 catch ( IOException e )
369 log.error( "IOException during index update of remote repository {}: {}", remoteRepository.getId( ), e.getMessage( ), e );
370 throw new IndexUpdateFailedException( "IOException during index update of remote repository " + remoteRepository.getId( )
371 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
373 catch ( WagonFactoryException e )
375 log.error( "Wagon for remote index download of {} could not be created: {}", remoteRepository.getId( ), e.getMessage( ), e );
376 throw new IndexUpdateFailedException( "Error while updating the remote index of " + remoteRepository.getId( ), e );
383 public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
385 final URI ctxUri = context.getPath();
386 executeUpdateFunction(context, indexingContext -> {
387 Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
389 indexer.addArtifactsToIndex(artifacts, indexingContext);
390 } catch (IOException e) {
391 log.error("IOException while adding artifact {}", e.getMessage(), e);
392 throw new IndexUpdateFailedException("Error occured while adding artifact to index of "+context.getId()
393 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
399 public void removeArtifactsFromIndex( ArchivaIndexingContext context, Collection<URI> artifactReference ) throws IndexUpdateFailedException
401 final URI ctxUri = context.getPath();
402 executeUpdateFunction(context, indexingContext -> {
403 Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
405 indexer.deleteArtifactsFromIndex(artifacts, indexingContext);
406 } catch (IOException e) {
407 log.error("IOException while removing artifact {}", e.getMessage(), e);
408 throw new IndexUpdateFailedException("Error occured while removing artifact from index of "+context.getId()
409 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
416 public boolean supportsRepository( RepositoryType type )
418 return type == RepositoryType.MAVEN;
422 public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException
424 log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
425 if ( repository.getType( ) != RepositoryType.MAVEN )
427 throw new UnsupportedRepositoryTypeException( repository.getType( ) );
429 IndexingContext mvnCtx = null;
432 if ( repository instanceof RemoteRepository )
434 mvnCtx = createRemoteContext( (RemoteRepository) repository );
436 else if ( repository instanceof ManagedRepository )
438 mvnCtx = createManagedContext( (ManagedRepository) repository );
441 catch ( IOException e )
443 log.error( "IOException during context creation " + e.getMessage( ), e );
444 throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( )
445 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
447 MavenIndexContext context = new MavenIndexContext( repository, mvnCtx );
453 public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
454 ArchivaIndexingContext ctx;
455 executeUpdateFunction(context, indexingContext -> {
457 indexingContext.close(true);
458 } catch (IOException e) {
459 log.warn("Index close failed");
462 FileUtils.deleteDirectory(Paths.get(context.getPath()));
463 } catch (IOException e) {
464 throw new IndexUpdateFailedException("Could not delete index files");
468 Repository repo = context.getRepository();
469 ctx = createContext(context.getRepository());
470 if (repo instanceof EditableRepository) {
471 ((EditableRepository)repo).setIndexingContext(ctx);
473 } catch (IndexCreationFailedException e) {
474 throw new IndexUpdateFailedException("Could not create index");
480 public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
484 if (context.supports(IndexingContext.class)) {
486 Path newPath = getIndexPath(repo);
487 IndexingContext ctx = context.getBaseContext(IndexingContext.class);
488 Path oldPath = ctx.getIndexDirectoryFile().toPath();
489 if (oldPath.equals(newPath)) {
490 // Nothing to do, if path does not change
493 if (!Files.exists(oldPath)) {
494 return createContext(repo);
495 } else if (context.isEmpty()) {
497 return createContext(repo);
499 context.close(false);
500 Files.move(oldPath, newPath);
501 return createContext(repo);
503 } catch (IOException e) {
504 log.error("IOException while moving index directory {}", e.getMessage(), e);
505 throw new IndexCreationFailedException("Could not recreated the index.", e);
506 } catch (UnsupportedBaseContextException e) {
507 throw new IndexCreationFailedException("The given context, is not a maven context.");
510 throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
514 private Path getIndexPath(Repository repo) throws IOException {
515 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
516 Path repoDir = repo.getLocalPath();
517 URI indexDir = icf.getIndexPath();
518 Path indexDirectory = null;
519 if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
522 indexDirectory = PathUtil.getPathFromUri( indexDir );
523 // not absolute so create it in repository directory
524 if ( !indexDirectory.isAbsolute( ) )
526 indexDirectory = repoDir.resolve( indexDirectory );
531 indexDirectory = repoDir.resolve( ".index" );
534 if ( !Files.exists( indexDirectory ) )
536 Files.createDirectories( indexDirectory );
538 return indexDirectory;
541 private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
543 Path appServerBase = archivaConfiguration.getAppServerBaseDir( );
545 String contextKey = "remote-" + remoteRepository.getId( );
548 // create remote repository path
549 Path repoDir = remoteRepository.getLocalPath();
550 if ( !Files.exists( repoDir ) )
552 Files.createDirectories( repoDir );
555 Path indexDirectory = null;
557 // is there configured indexDirectory ?
558 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
560 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
561 indexDirectory = getIndexPath(remoteRepository);
562 String remoteIndexUrl = calculateIndexRemoteUrl( remoteRepository.getLocation( ), rif );
566 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
568 catch ( IndexFormatTooOldException e )
570 // existing index with an old lucene format so we need to delete it!!!
571 // delete it first then recreate it.
572 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
573 remoteRepository.getId( ) );
574 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
575 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
581 throw new IOException( "No remote index defined" );
585 private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException
587 return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ),
588 repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ),
594 private IndexingContext createManagedContext( ManagedRepository repository ) throws IOException
597 IndexingContext context;
598 // take care first about repository location as can be relative
599 Path repositoryDirectory = repository.getLocalPath();
601 if ( !Files.exists( repositoryDirectory ) )
605 Files.createDirectories( repositoryDirectory );
607 catch ( IOException e )
609 log.error( "Could not create directory {}", repositoryDirectory );
613 Path indexDirectory = null;
615 if ( repository.supportsFeature( IndexCreationFeature.class ) )
617 indexDirectory = getIndexPath(repository);
619 String indexUrl = repositoryDirectory.toUri( ).toURL( ).toExternalForm( );
622 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
623 context.setSearchable( repository.isScanned( ) );
625 catch ( IndexFormatTooOldException e )
627 // existing index with an old lucene format so we need to delete it!!!
628 // delete it first then recreate it.
629 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
630 repository.getId( ) );
631 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
632 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
633 context.setSearchable( repository.isScanned( ) );
639 throw new IOException( "No repository index defined" );
643 private String calculateIndexRemoteUrl( URI baseUri, RemoteIndexFeature rif )
645 if ( rif.getIndexUri( ) == null )
647 return baseUri.resolve( ".index" ).toString( );
651 return baseUri.resolve( rif.getIndexUri( ) ).toString( );
655 private static final class DownloadListener
656 implements TransferListener
658 private Logger log = LoggerFactory.getLogger( getClass( ) );
660 private String resourceName;
662 private long startTime;
664 private int totalLength = 0;
667 public void transferInitiated( TransferEvent transferEvent )
669 startTime = System.currentTimeMillis( );
670 resourceName = transferEvent.getResource( ).getName( );
671 log.debug( "initiate transfer of {}", resourceName );
675 public void transferStarted( TransferEvent transferEvent )
677 this.totalLength = 0;
678 resourceName = transferEvent.getResource( ).getName( );
679 log.info( "start transfer of {}", transferEvent.getResource( ).getName( ) );
683 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
685 log.debug( "transfer of {} : {}/{}", transferEvent.getResource( ).getName( ), buffer.length, length );
686 this.totalLength += length;
690 public void transferCompleted( TransferEvent transferEvent )
692 resourceName = transferEvent.getResource( ).getName( );
693 long endTime = System.currentTimeMillis( );
694 log.info( "end of transfer file {} {} kb: {}s", transferEvent.getResource( ).getName( ),
695 this.totalLength / 1024, ( endTime - startTime ) / 1000 );
699 public void transferError( TransferEvent transferEvent )
701 log.info( "error of transfer file {}: {}", transferEvent.getResource( ).getName( ),
702 transferEvent.getException( ).getMessage( ), transferEvent.getException( ) );
706 public void debug( String message )
708 log.debug( "transfer debug {}", message );
712 private static class WagonResourceFetcher
713 implements ResourceFetcher
718 Path tempIndexDirectory;
722 RemoteRepository remoteRepository;
724 private WagonResourceFetcher( Logger log, Path tempIndexDirectory, Wagon wagon,
725 RemoteRepository remoteRepository )
728 this.tempIndexDirectory = tempIndexDirectory;
730 this.remoteRepository = remoteRepository;
734 public void connect( String id, String url )
741 public void disconnect( )
748 public InputStream retrieve( String name )
749 throws IOException, FileNotFoundException
753 log.info( "index update retrieve file, name:{}", name );
754 Path file = tempIndexDirectory.resolve( name );
755 Files.deleteIfExists( file );
756 file.toFile( ).deleteOnExit( );
757 wagon.get( addParameters( name, remoteRepository ), file.toFile( ) );
758 return Files.newInputStream( file );
760 catch ( AuthorizationException | TransferFailedException e )
762 throw new IOException( e.getMessage( ), e );
764 catch ( ResourceDoesNotExistException e )
766 FileNotFoundException fnfe = new FileNotFoundException( e.getMessage( ) );
772 // FIXME remove crappy copy/paste
773 protected String addParameters( String path, RemoteRepository remoteRepository )
775 if ( remoteRepository.getExtraParameters( ).isEmpty( ) )
780 boolean question = false;
782 StringBuilder res = new StringBuilder( path == null ? "" : path );
784 for ( Map.Entry<String, String> entry : remoteRepository.getExtraParameters( ).entrySet( ) )
788 res.append( '?' ).append( entry.getKey( ) ).append( '=' ).append( entry.getValue( ) );
792 return res.toString( );