Search in sources :

Example 6 with TransferFailedException

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

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

the class GitWagon method fillInputData.

/**
 * {@inheritDoc}
 */
public void fillInputData(InputData inputData) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    log.debug("Invoked fillInputData()");
    Resource resource = inputData.getResource();
    File file = new File(git.workDir, resource.getName());
    if (!file.exists()) {
        throw new ResourceDoesNotExistException("File: " + file + " does not exist");
    }
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(file));
        inputData.setInputStream(in);
        resource.setContentLength(file.length());
        resource.setLastModified(file.lastModified());
    } catch (FileNotFoundException e) {
        throw new TransferFailedException("Could not read from file: " + file.getAbsolutePath(), e);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Resource(org.apache.maven.wagon.resource.Resource) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) TransferFailedException(org.apache.maven.wagon.TransferFailedException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) FileInputStream(java.io.FileInputStream)

Example 8 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException in project gradle by gradle.

the class RepositoryTransportDeployWagon method put.

@Override
public final void put(File file, String resourceName) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    Resource resource = new Resource(resourceName);
    this.transferEventSupport.fireTransferInitiated(transferEvent(resource, TRANSFER_INITIATED, REQUEST_PUT));
    try {
        ReadableContent content = new MavenTransferLoggingFileResource(file, resource);
        getDelegate().putRemoteFile(content, resourceName);
    } catch (Exception e) {
        this.transferEventSupport.fireTransferError(transferEvent(resource, e, REQUEST_PUT));
        throw new TransferFailedException(String.format("Could not write to resource '%s'", resourceName), e);
    }
    this.transferEventSupport.fireTransferCompleted(transferEvent(resource, TRANSFER_COMPLETED, REQUEST_PUT));
}
Also used : ReadableContent(org.gradle.internal.resource.ReadableContent) FileReadableContent(org.gradle.internal.resource.local.FileReadableContent) Resource(org.apache.maven.wagon.resource.Resource) TransferFailedException(org.apache.maven.wagon.TransferFailedException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) ConnectionException(org.apache.maven.wagon.ConnectionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) IOException(java.io.IOException) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) GradleException(org.gradle.api.GradleException) TransferFailedException(org.apache.maven.wagon.TransferFailedException)

Example 9 with TransferFailedException

use of org.apache.maven.wagon.TransferFailedException 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);
    }
}
Also used : Locale(java.util.Locale) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) AuthorizationException(org.apache.maven.wagon.authorization.AuthorizationException) AuthenticationException(org.apache.maven.wagon.authentication.AuthenticationException) File(java.io.File) TransferFailedException(org.apache.maven.wagon.TransferFailedException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) Debug(org.apache.maven.wagon.observers.Debug) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) ConnectionException(org.apache.maven.wagon.ConnectionException)

Aggregations

TransferFailedException (org.apache.maven.wagon.TransferFailedException)9 ConnectionException (org.apache.maven.wagon.ConnectionException)5 ResourceDoesNotExistException (org.apache.maven.wagon.ResourceDoesNotExistException)4 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)4 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)4 File (java.io.File)3 Wagon (org.apache.maven.wagon.Wagon)3 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)3 Resource (org.apache.maven.wagon.resource.Resource)3 IOException (java.io.IOException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)2 Debug (org.apache.maven.wagon.observers.Debug)2 Repository (org.apache.maven.wagon.repository.Repository)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1