use of org.apache.maven.wagon.shared.http.HttpMethodConfiguration in project archiva by apache.
the class DefaultRemoteRepositoriesService method checkRemoteConnectivity.
@Override
public Boolean checkRemoteConnectivity(String repositoryId) throws ArchivaRestServiceException {
try {
RemoteRepository remoteRepository = remoteRepositoryAdmin.getRemoteRepository(repositoryId);
if (remoteRepository == null) {
log.warn("ignore scheduleDownloadRemote for repo with id {} as not exists", repositoryId);
return Boolean.FALSE;
}
NetworkProxy networkProxy = null;
if (StringUtils.isNotBlank(remoteRepository.getRemoteDownloadNetworkProxyId())) {
networkProxy = networkProxyAdmin.getNetworkProxy(remoteRepository.getRemoteDownloadNetworkProxyId());
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", remoteRepository.getRemoteDownloadNetworkProxyId());
}
}
String wagonProtocol = new URL(remoteRepository.getUrl()).getProtocol();
final Wagon wagon = wagonFactory.getWagon(//
new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
// hardcoded value as it's a check of the remote repo connectivity
wagon.setReadTimeout(checkReadTimeout);
wagon.setTimeout(checkTimeout);
if (wagon instanceof AbstractHttpClientWagon) {
HttpMethodConfiguration httpMethodConfiguration = //
new HttpMethodConfiguration().setUsePreemptive(//
true).setReadTimeout(checkReadTimeout);
HttpConfiguration httpConfiguration = new HttpConfiguration().setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
ProxyInfo proxyInfo = null;
if (networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(networkProxy.getProtocol());
proxyInfo.setHost(networkProxy.getHost());
proxyInfo.setPort(networkProxy.getPort());
proxyInfo.setUserName(networkProxy.getUsername());
proxyInfo.setPassword(networkProxy.getPassword());
}
String url = StringUtils.stripEnd(remoteRepository.getUrl(), "/");
wagon.connect(new Repository(remoteRepository.getId(), url), proxyInfo);
// MRM-1933, there are certain servers that do not allow browsing
if (!(StringUtils.isEmpty(remoteRepository.getCheckPath()) || "/".equals(remoteRepository.getCheckPath()))) {
return wagon.resourceExists(remoteRepository.getCheckPath());
} else {
// we only check connectivity as remote repo can be empty
// MRM-1909: Wagon implementation appends a slash already
wagon.getFileList("");
}
return Boolean.TRUE;
} catch (TransferFailedException e) {
log.info("TransferFailedException :{}", e.getMessage());
return Boolean.FALSE;
} catch (Exception e) {
// This service returns either true or false, Exception cannot be handled by the clients
log.debug("Exception occured on connectivity test.", e);
log.info("Connection exception: {}", e.getMessage());
return Boolean.FALSE;
}
}
use of org.apache.maven.wagon.shared.http.HttpMethodConfiguration in project archiva by apache.
the class DownloadRemoteIndexTask method run.
@Override
public void run() {
// so short lock : not sure we need it
synchronized (this.runningRemoteDownloadIds) {
if (this.runningRemoteDownloadIds.contains(this.remoteRepository.getId())) {
// skip it as it's running
log.info("skip download index remote for repo {} it's already running", this.remoteRepository.getId());
return;
}
this.runningRemoteDownloadIds.add(this.remoteRepository.getId());
}
Path tempIndexDirectory = null;
StopWatch stopWatch = new StopWatch();
stopWatch.start();
try {
log.info("start download remote index for remote repository {}", this.remoteRepository.getId());
if (this.remoteRepository.getIndexingContext() == null) {
throw new IndexNotFoundException("No index context set for repository " + remoteRepository.getId());
}
if (this.remoteRepository.getType() != RepositoryType.MAVEN) {
throw new RepositoryException("Bad repository type");
}
if (!this.remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
throw new RepositoryException("Repository does not support RemotIndexFeature " + remoteRepository.getId());
}
RemoteIndexFeature rif = this.remoteRepository.getFeature(RemoteIndexFeature.class).get();
IndexingContext indexingContext = this.remoteRepository.getIndexingContext().getBaseContext(IndexingContext.class);
// create a temp directory to download files
tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = this.remoteRepository.getLocation().getScheme();
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, this.remoteRepository.getExtraHeaders()).networkProxy(this.networkProxy));
// FIXME olamy having 2 config values
wagon.setReadTimeout((int) rif.getDownloadTimeout().toMillis());
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis());
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout((int) rif.getDownloadTimeout().toMillis());
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
ProxyInfo proxyInfo = null;
if (this.networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(this.networkProxy.getProtocol());
proxyInfo.setHost(this.networkProxy.getHost());
proxyInfo.setPort(this.networkProxy.getPort());
proxyInfo.setUserName(this.networkProxy.getUsername());
proxyInfo.setPassword(this.networkProxy.getPassword());
}
AuthenticationInfo authenticationInfo = null;
if (this.remoteRepository.getLoginCredentials() != null && this.remoteRepository.getLoginCredentials() instanceof PasswordCredentials) {
PasswordCredentials creds = (PasswordCredentials) this.remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
log.debug("Connection to {}, authInfo={}", this.remoteRepository.getId(), authenticationInfo);
wagon.connect(new Repository(this.remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
log.debug("Downloading index file to {}", indexDirectory);
log.debug("Index cache dir {}", indexCacheDirectory);
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(this.fullDownload);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
IndexUpdateResult result = this.indexUpdater.fetchAndUpdateIndex(request);
log.debug("Update result success: {}", result.isSuccessful());
stopWatch.stop();
log.info("time update index from remote for repository {}: {}ms", this.remoteRepository.getId(), (stopWatch.getTime()));
// index packing optionnal ??
// IndexPackingRequest indexPackingRequest =
// new IndexPackingRequest( indexingContext, indexingContext.getIndexDirectoryFile() );
// indexPacker.packIndex( indexPackingRequest );
indexingContext.updateTimestamp(true);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e.getMessage(), e);
} finally {
deleteDirectoryQuiet(tempIndexDirectory);
this.runningRemoteDownloadIds.remove(this.remoteRepository.getId());
}
log.info("end download remote index for remote repository {}", this.remoteRepository.getId());
}
use of org.apache.maven.wagon.shared.http.HttpMethodConfiguration in project archiva by apache.
the class MavenIndexManager method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
ProxyInfo proxyInfo = null;
if (networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(networkProxy.getProtocol());
proxyInfo.setHost(networkProxy.getHost());
proxyInfo.setPort(networkProxy.getPort());
proxyInfo.setUserName(networkProxy.getUsername());
proxyInfo.setPassword(networkProxy.getPassword());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
indexUpdater.fetchAndUpdateIndex(request);
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
use of org.apache.maven.wagon.shared.http.HttpMethodConfiguration in project archiva by apache.
the class ArchivaIndexManagerMock method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
ProxyInfo proxyInfo = null;
if (networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(networkProxy.getProtocol());
proxyInfo.setHost(networkProxy.getHost());
proxyInfo.setPort(networkProxy.getPort());
proxyInfo.setUserName(networkProxy.getUsername());
proxyInfo.setPassword(networkProxy.getPassword());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
// indexUpdater.fetchAndUpdateIndex( request );
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
use of org.apache.maven.wagon.shared.http.HttpMethodConfiguration in project archiva by apache.
the class ArchivaIndexManagerMock method update.
@Override
public void update(final ArchivaIndexingContext context, final boolean fullUpdate) throws IndexUpdateFailedException {
log.info("start download remote index for remote repository {}", context.getRepository().getId());
URI remoteUpdateUri;
if (!(context.getRepository() instanceof RemoteRepository) || !(context.getRepository().supportsFeature(RemoteIndexFeature.class))) {
throw new IndexUpdateFailedException("The context is not associated to a remote repository with remote index " + context.getId());
} else {
RemoteIndexFeature rif = context.getRepository().getFeature(RemoteIndexFeature.class).get();
remoteUpdateUri = context.getRepository().getLocation().resolve(rif.getIndexUri());
}
final RemoteRepository remoteRepository = (RemoteRepository) context.getRepository();
executeUpdateFunction(context, indexingContext -> {
try {
// create a temp directory to download files
Path tempIndexDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".tmpIndex");
Path indexCacheDirectory = Paths.get(indexingContext.getIndexDirectoryFile().getParent(), ".indexCache");
Files.createDirectories(indexCacheDirectory);
if (Files.exists(tempIndexDirectory)) {
org.apache.archiva.common.utils.FileUtils.deleteDirectory(tempIndexDirectory);
}
Files.createDirectories(tempIndexDirectory);
tempIndexDirectory.toFile().deleteOnExit();
String baseIndexUrl = indexingContext.getIndexUpdateUrl();
String wagonProtocol = remoteUpdateUri.toURL().getProtocol();
NetworkProxy networkProxy = null;
if (remoteRepository.supportsFeature(RemoteIndexFeature.class)) {
RemoteIndexFeature rif = remoteRepository.getFeature(RemoteIndexFeature.class).get();
if (StringUtils.isNotBlank(rif.getProxyId())) {
try {
networkProxy = networkProxyAdmin.getNetworkProxy(rif.getProxyId());
} catch (RepositoryAdminException e) {
log.error("Error occured while retrieving proxy {}", e.getMessage());
}
if (networkProxy == null) {
log.warn("your remote repository is configured to download remote index trought a proxy we cannot find id:{}", rif.getProxyId());
}
}
final StreamWagon wagon = (StreamWagon) wagonFactory.getWagon(new WagonFactoryRequest(wagonProtocol, remoteRepository.getExtraHeaders()).networkProxy(networkProxy));
int readTimeout = (int) rif.getDownloadTimeout().toMillis() * 1000;
wagon.setReadTimeout(readTimeout);
wagon.setTimeout((int) remoteRepository.getTimeout().toMillis() * 1000);
if (wagon instanceof AbstractHttpClientWagon) {
HttpConfiguration httpConfiguration = new HttpConfiguration();
HttpMethodConfiguration httpMethodConfiguration = new HttpMethodConfiguration();
httpMethodConfiguration.setUsePreemptive(true);
httpMethodConfiguration.setReadTimeout(readTimeout);
httpConfiguration.setGet(httpMethodConfiguration);
AbstractHttpClientWagon.class.cast(wagon).setHttpConfiguration(httpConfiguration);
}
wagon.addTransferListener(new DownloadListener());
ProxyInfo proxyInfo = null;
if (networkProxy != null) {
proxyInfo = new ProxyInfo();
proxyInfo.setType(networkProxy.getProtocol());
proxyInfo.setHost(networkProxy.getHost());
proxyInfo.setPort(networkProxy.getPort());
proxyInfo.setUserName(networkProxy.getUsername());
proxyInfo.setPassword(networkProxy.getPassword());
}
AuthenticationInfo authenticationInfo = null;
if (remoteRepository.getLoginCredentials() != null && (remoteRepository.getLoginCredentials() instanceof PasswordCredentials)) {
PasswordCredentials creds = (PasswordCredentials) remoteRepository.getLoginCredentials();
authenticationInfo = new AuthenticationInfo();
authenticationInfo.setUserName(creds.getUsername());
authenticationInfo.setPassword(new String(creds.getPassword()));
}
wagon.connect(new org.apache.maven.wagon.repository.Repository(remoteRepository.getId(), baseIndexUrl), authenticationInfo, proxyInfo);
Path indexDirectory = indexingContext.getIndexDirectoryFile().toPath();
if (!Files.exists(indexDirectory)) {
Files.createDirectories(indexDirectory);
}
ResourceFetcher resourceFetcher = new WagonResourceFetcher(log, tempIndexDirectory, wagon, remoteRepository);
IndexUpdateRequest request = new IndexUpdateRequest(indexingContext, resourceFetcher);
request.setForceFullUpdate(fullUpdate);
request.setLocalIndexCacheDir(indexCacheDirectory.toFile());
// indexUpdater.fetchAndUpdateIndex( request );
indexingContext.updateTimestamp(true);
}
} catch (AuthenticationException e) {
log.error("Could not login to the remote proxy for updating index of {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Login in to proxy failed while updating remote repository " + remoteRepository.getId(), e);
} catch (ConnectionException e) {
log.error("Connection error during index update for remote repository {}", remoteRepository.getId(), e);
throw new IndexUpdateFailedException("Connection error during index update for remote repository " + remoteRepository.getId(), e);
} catch (MalformedURLException e) {
log.error("URL for remote index update of remote repository {} is not correct {}", remoteRepository.getId(), remoteUpdateUri, e);
throw new IndexUpdateFailedException("URL for remote index update of repository is not correct " + remoteUpdateUri, e);
} catch (IOException e) {
log.error("IOException during index update of remote repository {}: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("IOException during index update of remote repository " + remoteRepository.getId() + (StringUtils.isNotEmpty(e.getMessage()) ? ": " + e.getMessage() : ""), e);
} catch (WagonFactoryException e) {
log.error("Wagon for remote index download of {} could not be created: {}", remoteRepository.getId(), e.getMessage(), e);
throw new IndexUpdateFailedException("Error while updating the remote index of " + remoteRepository.getId(), e);
}
});
}
Aggregations