use of org.apache.maven.wagon.observers.Debug in project maven-plugins by apache.
the class RepositoryUtils method dependencyExistsInRepo.
/**
* @param repo not null
* @param artifact not null
* @return <code>true</code> if the artifact exists in the given repo, <code>false</code> otherwise or if
* the repo is blacklisted.
*/
public boolean dependencyExistsInRepo(ArtifactRepository repo, Artifact artifact) {
if (repo.isBlacklisted()) {
if (log.isDebugEnabled()) {
log.debug("The repo '" + repo.getId() + "' is black listed - Ignored it");
}
return false;
}
if (UNKNOWN_HOSTS.contains(repo.getUrl())) {
if (log.isDebugEnabled()) {
log.debug("The repo url '" + repo.getUrl() + "' is unknown - Ignored it");
}
return false;
}
repo = wagonManager.getMirrorRepository(repo);
String id = repo.getId();
Repository repository = new Repository(id, repo.getUrl());
Wagon wagon;
try {
wagon = wagonManager.getWagon(repository);
} catch (UnsupportedProtocolException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
} catch (WagonConfigurationException e) {
logError("Unsupported protocol: '" + repo.getProtocol() + "'", e);
return false;
}
wagon.setTimeout(1000);
if (log.isDebugEnabled()) {
Debug debug = new Debug();
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
}
try {
// FIXME when upgrading to maven 3.x : this must be changed.
AuthenticationInfo auth = wagonManager.getAuthenticationInfo(repo.getId());
ProxyInfo proxyInfo = getProxyInfo();
if (proxyInfo != null) {
wagon.connect(repository, auth, proxyInfo);
} else {
wagon.connect(repository, auth);
}
return wagon.resourceExists(StringUtils.replace(getDependencyUrlFromRepository(artifact, repo), repo.getUrl(), ""));
} catch (ConnectionException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AuthenticationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (TransferFailedException e) {
if (e.getCause() instanceof UnknownHostException) {
log.error("Unknown host " + e.getCause().getMessage() + " - ignored it");
UNKNOWN_HOSTS.add(repo.getUrl());
} else {
logError("Unable to determine if resource " + artifact + " exists in " + repo.getUrl(), e);
}
return false;
} catch (AuthorizationException e) {
logError("Unable to connect to: " + repo.getUrl(), e);
return false;
} catch (AbstractMethodError e) {
log.error("Wagon " + wagon.getClass().getName() + " does not support the resourceExists method");
return false;
} finally {
try {
wagon.disconnect();
} catch (ConnectionException e) {
logError("Error disconnecting wagon - ignored", e);
}
}
}
use of org.apache.maven.wagon.observers.Debug in project maven-plugins by apache.
the class AbstractDeployMojo method push.
private void push(final File inputDirectory, final Repository repository, final Wagon wagon, final ProxyInfo proxyInfo, final List<Locale> localesList, final String relativeDir) throws MojoExecutionException {
AuthenticationInfo authenticationInfo = wagonManager.getAuthenticationInfo(repository.getId());
getLog().debug("authenticationInfo with id '" + repository.getId() + "': " + ((authenticationInfo == null) ? "-" : authenticationInfo.getUserName()));
try {
if (getLog().isDebugEnabled()) {
Debug debug = new Debug();
wagon.addSessionListener(debug);
wagon.addTransferListener(debug);
}
if (proxyInfo != null) {
getLog().debug("connect with proxyInfo");
wagon.connect(repository, authenticationInfo, proxyInfo);
} else if (proxyInfo == null && authenticationInfo != null) {
getLog().debug("connect with authenticationInfo and without proxyInfo");
wagon.connect(repository, authenticationInfo);
} else {
getLog().debug("connect without authenticationInfo and without proxyInfo");
wagon.connect(repository);
}
getLog().info("Pushing " + inputDirectory);
// Default is first in the list
final String defaultLocale = localesList.get(0).getLanguage();
for (Locale locale : localesList) {
if (locale.getLanguage().equals(defaultLocale)) {
// TODO: this also uploads the non-default locales,
// is there a way to exclude directories in wagon?
getLog().info(" >>> to " + repository.getUrl() + relativeDir);
wagon.putDirectory(inputDirectory, relativeDir);
} else {
getLog().info(" >>> to " + repository.getUrl() + locale.getLanguage() + "/" + relativeDir);
wagon.putDirectory(new File(inputDirectory, locale.getLanguage()), locale.getLanguage() + "/" + relativeDir);
}
}
} catch (ResourceDoesNotExistException e) {
throw new MojoExecutionException("Error uploading site", e);
} catch (TransferFailedException e) {
throw new MojoExecutionException("Error uploading site", e);
} catch (AuthorizationException e) {
throw new MojoExecutionException("Error uploading site", e);
} catch (ConnectionException e) {
throw new MojoExecutionException("Error uploading site", e);
} catch (AuthenticationException e) {
throw new MojoExecutionException("Error uploading site", e);
}
}
Aggregations