Search in sources :

Example 1 with ConnectionException

use of org.apache.maven.wagon.ConnectionException 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);
        }
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) WagonConfigurationException(org.apache.maven.artifact.manager.WagonConfigurationException) UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) TransferFailedException(org.apache.maven.wagon.TransferFailedException) Debug(org.apache.maven.wagon.observers.Debug) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 2 with ConnectionException

use of org.apache.maven.wagon.ConnectionException in project maven-plugins by apache.

the class AbstractDeployMojo method deploy.

private void deploy(final File directory, final Repository repository) throws MojoExecutionException {
    // TODO: work on moving this into the deployer like the other deploy methods
    final Wagon wagon = getWagon(repository, wagonManager);
    try {
        configureWagon(wagon, repository.getId(), settings, container, getLog());
    } catch (TransferFailedException e) {
        throw new MojoExecutionException("Unable to configure Wagon: '" + repository.getProtocol() + "'", e);
    }
    try {
        final ProxyInfo proxyInfo;
        if (!isMaven3OrMore()) {
            proxyInfo = getProxyInfo(repository, wagonManager);
        } else {
            try {
                SettingsDecrypter settingsDecrypter = container.lookup(SettingsDecrypter.class);
                proxyInfo = getProxy(repository, settingsDecrypter);
            } catch (ComponentLookupException cle) {
                throw new MojoExecutionException("Unable to lookup SettingsDecrypter: " + cle.getMessage(), cle);
            }
        }
        push(directory, repository, wagon, proxyInfo, getLocales(), getDeployModuleDirectory());
        if (chmod) {
            chmod(wagon, repository, chmodOptions, chmodMode);
        }
    } finally {
        try {
            wagon.disconnect();
        } catch (ConnectionException e) {
            getLog().error("Error disconnecting wagon - ignored", e);
        }
    }
}
Also used : ProxyInfo(org.apache.maven.wagon.proxy.ProxyInfo) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) SettingsDecrypter(org.apache.maven.settings.crypto.SettingsDecrypter) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) Wagon(org.apache.maven.wagon.Wagon) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 3 with ConnectionException

use of org.apache.maven.wagon.ConnectionException in project maven-plugins by apache.

the class DefaultRepositoryCopier method scanForArtifactPaths.

protected List<String> scanForArtifactPaths(ArtifactRepository repository) {
    List<String> collected;
    try {
        Wagon wagon = wagonManager.getWagon(repository.getProtocol());
        Repository artifactRepository = new Repository(repository.getId(), repository.getUrl());
        wagon.connect(artifactRepository);
        collected = new ArrayList<String>();
        scan(wagon, "/", collected);
        wagon.disconnect();
        return collected;
    } catch (UnsupportedProtocolException e) {
        throw new RuntimeException(e);
    } catch (ConnectionException e) {
        throw new RuntimeException(e);
    } catch (AuthenticationException e) {
        throw new RuntimeException(e);
    }
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon) ConnectionException(org.apache.maven.wagon.ConnectionException)

Example 4 with ConnectionException

use of org.apache.maven.wagon.ConnectionException in project wagon-git by synergian.

the class GitWagon method openConnectionInternal.

/**
	 * {@inheritDoc}
	 */
protected void openConnectionInternal() throws ConnectionException, AuthenticationException {
    log.debug("Invoked openConnectionInternal()");
    if (git == null) {
        try {
            String url = getRepository().getUrl();
            if (url.endsWith("/"))
                url = url.substring(0, url.length() - 1);
            String remote;
            String branch;
            url = url.substring("git:".length());
            int i = url.indexOf(':');
            if (i < 0) {
                remote = url;
                branch = "master";
            } else {
                branch = url.substring(0, i);
                remote = url.substring(i + 3, url.length());
            }
            File workDir = Utils.createCheckoutDirectory(remote);
            if (!workDir.exists() || !workDir.isDirectory() || !workDir.canWrite())
                throw new ConnectionException("Unable to create working directory");
            if (safeCheckout)
                FileUtils.cleanDirectory(workDir);
            git = new GitBackend(workDir, remote, branch, log);
            git.pullAll();
        } catch (Exception e) {
            throw new ConnectionException("Unable to pull git repository: " + e.getMessage(), e);
        }
    }
}
Also used : File(java.io.File) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) FileNotFoundException(java.io.FileNotFoundException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 5 with ConnectionException

use of org.apache.maven.wagon.ConnectionException in project CorfuDB by CorfuDB.

the class QuorumFuturesFactoryTest method testException.

@Test
public void testException() throws Exception {
    CompletableFuture<String> f1 = new CompletableFuture<>();
    CompletableFuture<String> f2 = new CompletableFuture<>();
    CompletableFuture<String> f3 = new CompletableFuture<>();
    QuorumFuturesFactory.CompositeFuture<String> result = QuorumFuturesFactory.getQuorumFuture(String::compareTo, f1, f2, f3);
    f1.completeExceptionally(new ConnectionException(""));
    f3.complete("");
    try {
        Object value = result.get(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis(), TimeUnit.MILLISECONDS);
        fail();
    } catch (TimeoutException e) {
    // expected behaviour
    }
    f2.completeExceptionally(new IllegalArgumentException());
    try {
        Object value = result.get(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis(), TimeUnit.MILLISECONDS);
        fail();
    } catch (ExecutionException e) {
    // expected behaviour
    }
    assertTrue(result.isDone());
    Set<Class> set = new LinkedHashSet<>();
    for (Throwable t : result.getThrowables()) {
        set.add(t.getClass());
    }
    assertTrue(set.contains(ConnectionException.class));
    assertTrue(set.contains(IllegalArgumentException.class));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ConnectionException(org.apache.maven.wagon.ConnectionException) Test(org.junit.Test) AbstractCorfuTest(org.corfudb.AbstractCorfuTest)

Aggregations

ConnectionException (org.apache.maven.wagon.ConnectionException)6 TransferFailedException (org.apache.maven.wagon.TransferFailedException)4 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)4 Wagon (org.apache.maven.wagon.Wagon)3 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)3 File (java.io.File)2 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)2 UnsupportedProtocolException (org.apache.maven.wagon.UnsupportedProtocolException)2 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)2 Debug (org.apache.maven.wagon.observers.Debug)2 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)2 Repository (org.apache.maven.wagon.repository.Repository)2 FileNotFoundException (java.io.FileNotFoundException)1 UnknownHostException (java.net.UnknownHostException)1 LinkedHashSet (java.util.LinkedHashSet)1 Locale (java.util.Locale)1 WagonConfigurationException (org.apache.maven.artifact.manager.WagonConfigurationException)1 SettingsDecrypter (org.apache.maven.settings.crypto.SettingsDecrypter)1