1 package org.apache.archiva.repository.index.mock;
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.*;
29 import org.apache.archiva.proxy.common.WagonFactory;
30 import org.apache.archiva.proxy.common.WagonFactoryException;
31 import org.apache.archiva.proxy.common.WagonFactoryRequest;
32 import org.apache.archiva.repository.*;
33 import org.apache.archiva.repository.features.IndexCreationFeature;
34 import org.apache.archiva.repository.features.RemoteIndexFeature;
35 import org.apache.commons.lang.StringUtils;
36 import org.apache.maven.index.*;
37 import org.apache.maven.index.context.IndexCreator;
38 import org.apache.maven.index.context.IndexingContext;
39 import org.apache.maven.index.packer.IndexPacker;
40 import org.apache.maven.index.packer.IndexPackingRequest;
41 import org.apache.maven.index.updater.IndexUpdateRequest;
42 import org.apache.maven.index.updater.IndexUpdater;
43 import org.apache.maven.index.updater.ResourceFetcher;
44 import org.apache.maven.index_shaded.lucene.index.IndexFormatTooOldException;
45 import org.apache.maven.wagon.*;
46 import org.apache.maven.wagon.authentication.AuthenticationException;
47 import org.apache.maven.wagon.authentication.AuthenticationInfo;
48 import org.apache.maven.wagon.authorization.AuthorizationException;
49 import org.apache.maven.wagon.events.TransferEvent;
50 import org.apache.maven.wagon.events.TransferListener;
51 import org.apache.maven.wagon.proxy.ProxyInfo;
52 import org.apache.maven.wagon.shared.http.AbstractHttpClientWagon;
53 import org.apache.maven.wagon.shared.http.HttpConfiguration;
54 import org.apache.maven.wagon.shared.http.HttpMethodConfiguration;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
57 import org.springframework.stereotype.Service;
59 import javax.inject.Inject;
60 import java.io.FileNotFoundException;
61 import java.io.IOException;
62 import java.io.InputStream;
63 import java.net.MalformedURLException;
65 import java.nio.file.Files;
66 import java.nio.file.Path;
67 import java.nio.file.Paths;
68 import java.util.Collection;
69 import java.util.List;
71 import java.util.concurrent.ConcurrentSkipListSet;
72 import java.util.stream.Collectors;
75 * @author Martin Stockhammer <martin_s@apache.org>
77 @Service("archivaIndexManager#maven")
78 public class ArchivaIndexManagerMock implements ArchivaIndexManager {
79 private static final Logger log = LoggerFactory.getLogger( ArchivaIndexManagerMock.class );
82 private Indexer indexer;
85 private IndexerEngine indexerEngine;
88 private List<? extends IndexCreator> indexCreators;
91 private IndexPacker indexPacker;
94 private Scanner scanner;
97 private ArchivaConfiguration archivaConfiguration;
100 private WagonFactory wagonFactory;
103 private NetworkProxyAdmin networkProxyAdmin;
107 private ArtifactContextProducer artifactContextProducer;
109 private ConcurrentSkipListSet<Path> activeContexts = new ConcurrentSkipListSet<>( );
111 private static final int WAIT_TIME = 100;
112 private static final int MAX_WAIT = 10;
115 public static IndexingContext getMvnContext(ArchivaIndexingContext context ) throws UnsupportedBaseContextException
117 if ( !context.supports( IndexingContext.class ) )
119 log.error( "The provided archiva index context does not support the maven IndexingContext" );
120 throw new UnsupportedBaseContextException( "The context does not support the Maven IndexingContext" );
122 return context.getBaseContext( IndexingContext.class );
125 private Path getIndexPath( ArchivaIndexingContext ctx )
127 return PathUtil.getPathFromUri( ctx.getPath( ) );
131 interface IndexUpdateConsumer
134 void accept( IndexingContext indexingContext ) throws IndexUpdateFailedException;
138 * This method is used to do some actions around the update execution code. And to make sure, that no other
139 * method is running on the same index.
141 private void executeUpdateFunction( ArchivaIndexingContext context, IndexUpdateConsumer function ) throws IndexUpdateFailedException
143 IndexingContext indexingContext = null;
146 indexingContext = getMvnContext( context );
148 catch ( UnsupportedBaseContextException e )
150 throw new IndexUpdateFailedException( "Maven index is not supported by this context", e );
152 final Path ctxPath = getIndexPath( context );
154 boolean active = false;
155 while ( loop-- > 0 && !active )
157 active = activeContexts.add( ctxPath );
160 Thread.currentThread( ).sleep( WAIT_TIME );
162 catch ( InterruptedException e )
171 function.accept( indexingContext );
175 activeContexts.remove( ctxPath );
180 throw new IndexUpdateFailedException( "Timeout while waiting for index release on context " + context.getId( ) );
185 public void pack( final ArchivaIndexingContext context ) throws IndexUpdateFailedException
187 executeUpdateFunction( context, indexingContext -> {
190 IndexPackingRequest request = new IndexPackingRequest( indexingContext,
191 indexingContext.acquireIndexSearcher( ).getIndexReader( ),
192 indexingContext.getIndexDirectoryFile( ) );
193 indexPacker.packIndex( request );
194 indexingContext.updateTimestamp( true );
196 catch ( IOException e )
198 log.error( "IOException while packing index of context " + context.getId( ) + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ) );
199 throw new IndexUpdateFailedException( "IOException during update of " + context.getId( ), e );
207 public void scan(final ArchivaIndexingContext context) throws IndexUpdateFailedException
209 executeUpdateFunction( context, indexingContext -> {
210 DefaultScannerListener listener = new DefaultScannerListener( indexingContext, indexerEngine, true, null );
211 ScanningRequest request = new ScanningRequest( indexingContext, listener );
212 ScanningResult result = scanner.scan( request );
213 if ( result.hasExceptions( ) )
215 log.error( "Exceptions occured during index scan of " + context.getId( ) );
216 result.getExceptions( ).stream( ).map( e -> e.getMessage( ) ).distinct( ).limit( 5 ).forEach(
217 s -> log.error( "Message: " + s )
225 public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException
227 log.info( "start download remote index for remote repository {}", context.getRepository( ).getId( ) );
229 if ( !( context.getRepository( ) instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class)) )
231 throw new IndexUpdateFailedException( "The context is not associated to a remote repository with remote index " + context.getId( ) );
233 RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
234 remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
236 final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository( );
238 executeUpdateFunction( context,
242 // create a temp directory to download files
243 Path tempIndexDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".tmpIndex" );
244 Path indexCacheDirectory = Paths.get( indexingContext.getIndexDirectoryFile( ).getParent( ), ".indexCache" );
245 Files.createDirectories( indexCacheDirectory );
246 if ( Files.exists( tempIndexDirectory ) )
248 org.apache.archiva.common.utils.FileUtils.deleteDirectory( tempIndexDirectory );
250 Files.createDirectories( tempIndexDirectory );
251 tempIndexDirectory.toFile( ).deleteOnExit( );
252 String baseIndexUrl = indexingContext.getIndexUpdateUrl( );
254 String wagonProtocol = remoteUpdateUri.toURL( ).getProtocol( );
256 NetworkProxy networkProxy = null;
257 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
259 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
260 if ( StringUtils.isNotBlank( rif.getProxyId( ) ) )
264 networkProxy = networkProxyAdmin.getNetworkProxy( rif.getProxyId( ) );
266 catch ( RepositoryAdminException e )
268 log.error( "Error occured while retrieving proxy {}", e.getMessage( ) );
270 if ( networkProxy == null )
273 "your remote repository is configured to download remote index trought a proxy we cannot find id:{}",
278 final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(
279 new WagonFactoryRequest( wagonProtocol, remoteRepository.getExtraHeaders( ) ).networkProxy(
282 int readTimeout = (int) rif.getDownloadTimeout( ).toMillis( ) * 1000;
283 wagon.setReadTimeout( readTimeout );
284 wagon.setTimeout( (int) remoteRepository.getTimeout( ).toMillis( ) * 1000 );
286 if ( wagon instanceof AbstractHttpClientWagon)
288 HttpConfiguration httpConfiguration = new HttpConfiguration( );
289 HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration( );
290 httpMethodConfiguration.setUsePreemptive( true );
291 httpMethodConfiguration.setReadTimeout( readTimeout );
292 httpConfiguration.setGet( httpMethodConfiguration );
293 AbstractHttpClientWagon.class.cast( wagon ).setHttpConfiguration( httpConfiguration );
296 wagon.addTransferListener( new DownloadListener( ) );
297 ProxyInfo proxyInfo = null;
298 if ( networkProxy != null )
300 proxyInfo = new ProxyInfo( );
301 proxyInfo.setType( networkProxy.getProtocol( ) );
302 proxyInfo.setHost( networkProxy.getHost( ) );
303 proxyInfo.setPort( networkProxy.getPort( ) );
304 proxyInfo.setUserName( networkProxy.getUsername( ) );
305 proxyInfo.setPassword( networkProxy.getPassword( ) );
307 AuthenticationInfo authenticationInfo = null;
308 if ( remoteRepository.getLoginCredentials( ) != null && ( remoteRepository.getLoginCredentials( ) instanceof PasswordCredentials) )
310 PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials( );
311 authenticationInfo = new AuthenticationInfo( );
312 authenticationInfo.setUserName( creds.getUsername( ) );
313 authenticationInfo.setPassword( new String( creds.getPassword( ) ) );
315 wagon.connect( new org.apache.maven.wagon.repository.Repository( remoteRepository.getId( ), baseIndexUrl ), authenticationInfo,
318 Path indexDirectory = indexingContext.getIndexDirectoryFile( ).toPath( );
319 if ( !Files.exists( indexDirectory ) )
321 Files.createDirectories( indexDirectory );
324 ResourceFetcher resourceFetcher =
325 new WagonResourceFetcher( log, tempIndexDirectory, wagon, remoteRepository );
326 IndexUpdateRequest request = new IndexUpdateRequest( indexingContext, resourceFetcher );
327 request.setForceFullUpdate( fullUpdate );
328 request.setLocalIndexCacheDir( indexCacheDirectory.toFile( ) );
330 // indexUpdater.fetchAndUpdateIndex( request );
332 indexingContext.updateTimestamp( true );
336 catch ( AuthenticationException e )
338 log.error( "Could not login to the remote proxy for updating index of {}", remoteRepository.getId( ), e );
339 throw new IndexUpdateFailedException( "Login in to proxy failed while updating remote repository " + remoteRepository.getId( ), e );
341 catch ( ConnectionException e )
343 log.error( "Connection error during index update for remote repository {}", remoteRepository.getId( ), e );
344 throw new IndexUpdateFailedException( "Connection error during index update for remote repository " + remoteRepository.getId( ), e );
346 catch ( MalformedURLException e )
348 log.error( "URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId( ), remoteUpdateUri, e );
349 throw new IndexUpdateFailedException( "URL for remote index update of repository is not correct " + remoteUpdateUri, e );
351 catch ( IOException e )
353 log.error( "IOException during index update of remote repository {}: {}", remoteRepository.getId( ), e.getMessage( ), e );
354 throw new IndexUpdateFailedException( "IOException during index update of remote repository " + remoteRepository.getId( )
355 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
357 catch ( WagonFactoryException e )
359 log.error( "Wagon for remote index download of {} could not be created: {}", remoteRepository.getId( ), e.getMessage( ), e );
360 throw new IndexUpdateFailedException( "Error while updating the remote index of " + remoteRepository.getId( ), e );
367 public void addArtifactsToIndex( final ArchivaIndexingContext context, final Collection<URI> artifactReference ) throws IndexUpdateFailedException
369 final URI ctxUri = context.getPath();
370 executeUpdateFunction(context, indexingContext -> {
371 Collection<ArtifactContext> artifacts = artifactReference.stream().map(r -> artifactContextProducer.getArtifactContext(indexingContext, Paths.get(ctxUri.resolve(r)).toFile())).collect(Collectors.toList());
373 indexer.addArtifactsToIndex(artifacts, indexingContext);
374 } catch (IOException e) {
375 log.error("IOException while adding artifact {}", e.getMessage(), e);
376 throw new IndexUpdateFailedException("Error occured while adding artifact to index of "+context.getId()
377 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
383 public void removeArtifactsFromIndex( ArchivaIndexingContext context, 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.deleteArtifactsFromIndex(artifacts, indexingContext);
390 } catch (IOException e) {
391 log.error("IOException while removing artifact {}", e.getMessage(), e);
392 throw new IndexUpdateFailedException("Error occured while removing artifact from index of "+context.getId()
393 + (StringUtils.isNotEmpty(e.getMessage()) ? ": "+e.getMessage() : ""));
400 public boolean supportsRepository( RepositoryType type )
402 return type == RepositoryType.MAVEN;
406 public ArchivaIndexingContext createContext( Repository repository ) throws IndexCreationFailedException
408 log.debug("Creating context for repo {}, type: {}", repository.getId(), repository.getType());
409 if ( repository.getType( ) != RepositoryType.MAVEN )
411 throw new UnsupportedRepositoryTypeException( repository.getType( ) );
413 IndexingContext mvnCtx = null;
416 if ( repository instanceof RemoteRepository )
418 mvnCtx = createRemoteContext( (RemoteRepository) repository );
420 else if ( repository instanceof ManagedRepository )
422 mvnCtx = createManagedContext( (ManagedRepository) repository );
425 catch ( IOException e )
427 log.error( "IOException during context creation " + e.getMessage( ), e );
428 throw new IndexCreationFailedException( "Could not create index context for repository " + repository.getId( )
429 + ( StringUtils.isNotEmpty( e.getMessage( ) ) ? ": " + e.getMessage( ) : "" ), e );
431 MavenIndexContextMock context = new MavenIndexContextMock( repository, mvnCtx );
437 public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
438 ArchivaIndexingContext ctx;
439 executeUpdateFunction(context, indexingContext -> {
441 indexingContext.close(true);
442 } catch (IOException e) {
443 log.warn("Index close failed");
446 FileUtils.deleteDirectory(Paths.get(context.getPath()));
447 } catch (IOException e) {
448 throw new IndexUpdateFailedException("Could not delete index files");
452 Repository repo = context.getRepository();
453 ctx = createContext(context.getRepository());
454 if (repo instanceof EditableRepository) {
455 ((EditableRepository)repo).setIndexingContext(ctx);
457 } catch (IndexCreationFailedException e) {
458 throw new IndexUpdateFailedException("Could not create index");
464 public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
468 if (context.supports(IndexingContext.class)) {
470 Path newPath = getIndexPath(repo);
471 IndexingContext ctx = context.getBaseContext(IndexingContext.class);
472 Path oldPath = ctx.getIndexDirectoryFile().toPath();
473 if (oldPath.equals(newPath)) {
474 // Nothing to do, if path does not change
477 if (!Files.exists(oldPath)) {
478 return createContext(repo);
479 } else if (context.isEmpty()) {
481 return createContext(repo);
483 context.close(false);
484 Files.move(oldPath, newPath);
485 return createContext(repo);
487 } catch (IOException e) {
488 log.error("IOException while moving index directory {}", e.getMessage(), e);
489 throw new IndexCreationFailedException("Could not recreated the index.", e);
490 } catch (UnsupportedBaseContextException e) {
491 throw new IndexCreationFailedException("The given context, is not a maven context.");
494 throw new IndexCreationFailedException("Bad context type. This is not a maven context.");
498 private Path getIndexPath(Repository repo) throws IOException {
499 IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
500 Path repoDir = repo.getLocalPath();
501 URI indexDir = icf.getIndexPath();
502 Path indexDirectory = null;
503 if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
506 indexDirectory = PathUtil.getPathFromUri( indexDir );
507 // not absolute so create it in repository directory
508 if ( !indexDirectory.isAbsolute( ) )
510 indexDirectory = repoDir.resolve( indexDirectory );
515 indexDirectory = repoDir.resolve( ".index" );
518 if ( !Files.exists( indexDirectory ) )
520 Files.createDirectories( indexDirectory );
522 return indexDirectory;
525 private IndexingContext createRemoteContext(RemoteRepository remoteRepository ) throws IOException
527 Path appServerBase = archivaConfiguration.getAppServerBaseDir( );
529 String contextKey = "remote-" + remoteRepository.getId( );
532 // create remote repository path
533 Path repoDir = remoteRepository.getLocalPath();
534 if ( !Files.exists( repoDir ) )
536 Files.createDirectories( repoDir );
539 Path indexDirectory = null;
541 // is there configured indexDirectory ?
542 if ( remoteRepository.supportsFeature( RemoteIndexFeature.class ) )
544 RemoteIndexFeature rif = remoteRepository.getFeature( RemoteIndexFeature.class ).get( );
545 indexDirectory = getIndexPath(remoteRepository);
546 String remoteIndexUrl = calculateIndexRemoteUrl( remoteRepository.getLocation( ), rif );
550 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
552 catch ( IndexFormatTooOldException e )
554 // existing index with an old lucene format so we need to delete it!!!
555 // delete it first then recreate it.
556 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
557 remoteRepository.getId( ) );
558 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
559 return getIndexingContext( remoteRepository, contextKey, repoDir, indexDirectory, remoteIndexUrl );
565 throw new IOException( "No remote index defined" );
569 private IndexingContext getIndexingContext( Repository repository, String contextKey, Path repoDir, Path indexDirectory, String indexUrl ) throws IOException
571 return indexer.createIndexingContext( contextKey, repository.getId( ), repoDir.toFile( ), indexDirectory.toFile( ),
572 repository.getLocation( ) == null ? null : repository.getLocation( ).toString( ),
578 private IndexingContext createManagedContext( ManagedRepository repository ) throws IOException
581 IndexingContext context;
582 // take care first about repository location as can be relative
583 Path repositoryDirectory = repository.getLocalPath();
585 if ( !Files.exists( repositoryDirectory ) )
589 Files.createDirectories( repositoryDirectory );
591 catch ( IOException e )
593 log.error( "Could not create directory {}", repositoryDirectory );
597 Path indexDirectory = null;
599 if ( repository.supportsFeature( IndexCreationFeature.class ) )
601 indexDirectory = getIndexPath(repository);
603 String indexUrl = repositoryDirectory.toUri( ).toURL( ).toExternalForm( );
606 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
607 context.setSearchable( repository.isScanned( ) );
609 catch ( IndexFormatTooOldException e )
611 // existing index with an old lucene format so we need to delete it!!!
612 // delete it first then recreate it.
613 log.warn( "the index of repository {} is too old we have to delete and recreate it", //
614 repository.getId( ) );
615 org.apache.archiva.common.utils.FileUtils.deleteDirectory( indexDirectory );
616 context = getIndexingContext( repository, repository.getId( ), repositoryDirectory, indexDirectory, indexUrl );
617 context.setSearchable( repository.isScanned( ) );
623 throw new IOException( "No repository index defined" );
627 private String calculateIndexRemoteUrl( URI baseUri, RemoteIndexFeature rif )
629 if ( rif.getIndexUri( ) == null )
631 return baseUri.resolve( ".index" ).toString( );
635 return baseUri.resolve( rif.getIndexUri( ) ).toString( );
639 private static final class DownloadListener
640 implements TransferListener
642 private Logger log = LoggerFactory.getLogger( getClass( ) );
644 private String resourceName;
646 private long startTime;
648 private int totalLength = 0;
651 public void transferInitiated( TransferEvent transferEvent )
653 startTime = System.currentTimeMillis( );
654 resourceName = transferEvent.getResource( ).getName( );
655 log.debug( "initiate transfer of {}", resourceName );
659 public void transferStarted( TransferEvent transferEvent )
661 this.totalLength = 0;
662 resourceName = transferEvent.getResource( ).getName( );
663 log.info( "start transfer of {}", transferEvent.getResource( ).getName( ) );
667 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
669 log.debug( "transfer of {} : {}/{}", transferEvent.getResource( ).getName( ), buffer.length, length );
670 this.totalLength += length;
674 public void transferCompleted( TransferEvent transferEvent )
676 resourceName = transferEvent.getResource( ).getName( );
677 long endTime = System.currentTimeMillis( );
678 log.info( "end of transfer file {} {} kb: {}s", transferEvent.getResource( ).getName( ),
679 this.totalLength / 1024, ( endTime - startTime ) / 1000 );
683 public void transferError( TransferEvent transferEvent )
685 log.info( "error of transfer file {}: {}", transferEvent.getResource( ).getName( ),
686 transferEvent.getException( ).getMessage( ), transferEvent.getException( ) );
690 public void debug( String message )
692 log.debug( "transfer debug {}", message );
696 private static class WagonResourceFetcher
697 implements ResourceFetcher
702 Path tempIndexDirectory;
706 RemoteRepository remoteRepository;
708 private WagonResourceFetcher( Logger log, Path tempIndexDirectory, Wagon wagon,
709 RemoteRepository remoteRepository )
712 this.tempIndexDirectory = tempIndexDirectory;
714 this.remoteRepository = remoteRepository;
718 public void connect( String id, String url )
725 public void disconnect( )
732 public InputStream retrieve(String name )
733 throws IOException, FileNotFoundException
737 log.info( "index update retrieve file, name:{}", name );
738 Path file = tempIndexDirectory.resolve( name );
739 Files.deleteIfExists( file );
740 file.toFile( ).deleteOnExit( );
741 wagon.get( addParameters( name, remoteRepository ), file.toFile( ) );
742 return Files.newInputStream( file );
744 catch ( AuthorizationException | TransferFailedException e )
746 throw new IOException( e.getMessage( ), e );
748 catch ( ResourceDoesNotExistException e )
750 FileNotFoundException fnfe = new FileNotFoundException( e.getMessage( ) );
756 // FIXME remove crappy copy/paste
757 protected String addParameters( String path, RemoteRepository remoteRepository )
759 if ( remoteRepository.getExtraParameters( ).isEmpty( ) )
764 boolean question = false;
766 StringBuilder res = new StringBuilder( path == null ? "" : path );
768 for ( Map.Entry<String, String> entry : remoteRepository.getExtraParameters( ).entrySet( ) )
772 res.append( '?' ).append( entry.getKey( ) ).append( '=' ).append( entry.getValue( ) );
776 return res.toString( );