Search in sources :

Example 1 with UnsupportedProtocolException

use of org.apache.maven.wagon.UnsupportedProtocolException in project maven-archetype by apache.

the class RemoteCatalogArchetypeDataSource method getWagon.

private Wagon getWagon(String protocol) throws UnsupportedProtocolException {
    if (protocol == null) {
        throw new UnsupportedProtocolException("Unspecified protocol");
    }
    String hint = protocol.toLowerCase(java.util.Locale.ENGLISH);
    Wagon wagon = wagons.get(hint);
    if (wagon == null) {
        throw new UnsupportedProtocolException("Cannot find wagon which supports the requested protocol: " + protocol);
    }
    return wagon;
}
Also used : UnsupportedProtocolException(org.apache.maven.wagon.UnsupportedProtocolException) Wagon(org.apache.maven.wagon.Wagon)

Example 2 with UnsupportedProtocolException

use of org.apache.maven.wagon.UnsupportedProtocolException 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 3 with UnsupportedProtocolException

use of org.apache.maven.wagon.UnsupportedProtocolException 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)

Aggregations

UnsupportedProtocolException (org.apache.maven.wagon.UnsupportedProtocolException)3 Wagon (org.apache.maven.wagon.Wagon)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)2 ConnectionException (org.apache.maven.wagon.ConnectionException)2 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)2 Repository (org.apache.maven.wagon.repository.Repository)2 UnknownHostException (java.net.UnknownHostException)1 WagonConfigurationException (org.apache.maven.artifact.manager.WagonConfigurationException)1 TransferFailedException (org.apache.maven.wagon.TransferFailedException)1 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)1 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)1 Debug (org.apache.maven.wagon.observers.Debug)1 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)1