Package org.apache.maven.wagon

Examples of org.apache.maven.wagon.Wagon


        File tmpResource = null;

        File workingDirectory = createWorkingDirectory( repository );
        try
        {
            Wagon wagon = null;
            try
            {
                RepositoryURL repoUrl = remoteRepository.getURL();
                String protocol = repoUrl.getProtocol();
                wagon = (Wagon) wagonFactory.getWagon( "wagon#" + protocol );
                if ( wagon == null )
                {
                    throw new ProxyException( "Unsupported target repository protocol: " + protocol );
                }

                boolean connected = connectToRepository( connector, wagon, remoteRepository );
                if ( connected )
                {
                    tmpResource = new File( workingDirectory, resource.getName() );
                    transferSimpleFile( wagon, remoteRepository, remotePath, repository, resource, tmpResource );

                    // TODO: these should be used to validate the download based on the policies, not always downloaded
                    // to
                    // save on connections since md5 is rarely used
                    tmpSha1 =
                        transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
                                          ".sha1" );
                    tmpMd5 =
                        transferChecksum( wagon, remoteRepository, remotePath, repository, resource, workingDirectory,
                                          ".md5" );
                }
            }
            catch ( NotFoundException e )
            {
                urlFailureCache.cacheFailure( url );
                throw e;
            }
            catch ( NotModifiedException e )
            {
                // Do not cache url here.
                throw e;
            }
            catch ( ProxyException e )
            {
                urlFailureCache.cacheFailure( url );
                throw e;
            }
            finally
            {
                if ( wagon != null )
                {
                    try
                    {
                        wagon.disconnect();
                    }
                    catch ( ConnectionException e )
                    {
                        log.warn( "Unable to disconnect wagon.", e );
                    }
View Full Code Here


                        {
                            URL url = file.getURL();
                            String endPointUrl = url.getProtocol() + "://" + url.getAuthority();
                            // Repository Id should be ignored by Wagon ...
                            Repository repository = new Repository( "additonal-configs", endPointUrl );
                            Wagon wagon = wagonManager.getWagon( repository );;
                            if ( logger.isDebugEnabled() )
                            {
                                Debug debug = new Debug();
                                wagon.addSessionListener( debug );
                                wagon.addTransferListener( debug );
                            }
                            wagon.setTimeout( 1000 );
                            Settings settings = mavenSettingsBuilder.buildSettings();
                            ProxyInfo proxyInfo = null;
                            if ( settings != null && settings.getActiveProxy() != null )
                            {
                                Proxy settingsProxy = settings.getActiveProxy();

                                proxyInfo = new ProxyInfo();
                                proxyInfo.setHost( settingsProxy.getHost() );
                                proxyInfo.setType( settingsProxy.getProtocol() );
                                proxyInfo.setPort( settingsProxy.getPort() );
                                proxyInfo.setNonProxyHosts( settingsProxy.getNonProxyHosts() );
                                proxyInfo.setUserName( settingsProxy.getUsername() );
                                proxyInfo.setPassword( settingsProxy.getPassword() );                               
                            }
                               
                            if ( proxyInfo != null )
                            {
                                wagon.connect( repository, wagonManager.getAuthenticationInfo( repository.getId() ), proxyInfo );
                            }
                            else
                            {
                                wagon.connect( repository, wagonManager.getAuthenticationInfo( repository.getId() ) );
                            }
                           
                            wagon.get( url.getPath(), projectRelativeFile );
                        }
                    }
                    else
                    {
                        FileUtils.fileWrite( projectRelativeFile.getAbsolutePath(), file.getContent() );
View Full Code Here

        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 );
            }
View Full Code Here

    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, siteTool.getAvailableLocales( locales ),
                  getDeployModuleDirectory() );

            if ( chmod )
            {
                chmod( wagon, repository, chmodOptions, chmodMode );
            }
        }
        finally
        {
            try
            {
                wagon.disconnect();
            }
            catch ( ConnectionException e )
            {
                getLog().error( "Error disconnecting wagon - ignored", e );
            }
View Full Code Here

    }

    private Wagon getWagon( final Repository repository, final WagonManager manager )
        throws MojoExecutionException
    {
        final Wagon wagon;

        try
        {
            wagon = manager.getWagon( repository );
        }
        catch ( UnsupportedProtocolException e )
        {
            String shortMessage = "Unsupported protocol: '" + repository.getProtocol() + "' for site deployment to "
                + "distributionManagement.site.url=" + repository.getUrl() + ".";
            String longMessage =
                "\n" + shortMessage + "\n" + "Currently supported protocols are: " + getSupportedProtocols() + ".\n"
                    + "    Protocols may be added through wagon providers.\n" + "    For more information, see "
                    + "http://maven.apache.org/plugins/maven-site-plugin/examples/adding-deploy-protocol.html";

            getLog().error( longMessage );

            throw new MojoExecutionException( shortMessage );
        }
        catch ( TransferFailedException e )
        {
            throw new MojoExecutionException( "Unable to configure Wagon: '" + repository.getProtocol() + "'", e );
        }

        if ( !wagon.supportsDirectoryCopy() )
        {
            throw new MojoExecutionException(
                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
        }
View Full Code Here

    String[] segments = this.url.split("/");
    String file = segments[segments.length - 1];
    String repoUrl = this.url.substring(0, this.url.length() - file.length());
    Repository repository = new Repository(repoUrl, repoUrl);
   
    Wagon wagon = this.wagonManager.getWagon(repository.getProtocol());
    // TODO: this should be retrieved from wagonManager
    com.googlecode.ConsoleDownloadMonitor downloadMonitor = new com.googlecode.ConsoleDownloadMonitor();
    wagon.addTransferListener(downloadMonitor);
    wagon.connect(repository);
    wagon.get(file, outputFile);
    wagon.disconnect();
    wagon.removeTransferListener(downloadMonitor);
  }
View Full Code Here

        {
            String remoteRepo = (String) i.next();

            Repository repository = new Repository( "repo" + count, remoteRepo.trim() );

            final Wagon wagon = new DefaultWagonFactory().getWagon( repository.getProtocol() );

            if ( listener != null )
            {
                wagon.addTransferListener( listener );
            }

            ChecksumObserver md5ChecksumObserver = null;
            ChecksumObserver sha1ChecksumObserver = null;
            try
            {
                md5ChecksumObserver = new ChecksumObserver( "MD5" );
                wagon.addTransferListener( md5ChecksumObserver );

                sha1ChecksumObserver = new ChecksumObserver( "SHA-1" );
                wagon.addTransferListener( sha1ChecksumObserver );
            }
            catch ( NoSuchAlgorithmException e )
            {
                throw new ChecksumVerificationException( "Unable to add checksum methods: " + e.getMessage(), e );
            }

            File destination = artifact.getFile();
            String remotePath = artifact.getUrlPath();
            File temp = new File( destination + ".tmp" );
            temp.deleteOnExit();
            boolean downloaded = false;

            try
            {
                wagon.connect( repository, proxyInfo );

                boolean firstRun = true;
                boolean retry = true;

                // this will run at most twice. The first time, the firstRun flag is turned off, and if the retry flag
                // is set on the first run, it will be turned off and not re-set on the second try. This is because the
                // only way the retry flag can be set is if ( firstRun == true ).
                while ( firstRun || retry )
                {
                    // reset the retry flag.
                    retry = false;

                    downloaded = wagon.getIfNewer( remotePath, temp, destination.lastModified() );
                    if ( !downloaded && firstRun )
                    {
                        log.info( getMessage( "skip.download.message" ) );
                    }

                    if ( downloaded )
                    {
                        // keep the checksum files from showing up on the download monitor...
                        if ( listener != null )
                        {
                            wagon.removeTransferListener( listener );
                        }

                        // try to verify the MD5 checksum for this file.
                        try
                        {
                            verifyChecksum( md5ChecksumObserver, destination, temp, remotePath, ".md5", wagon );
                        }
                        catch ( ChecksumVerificationException e )
                        {
                            // if we catch a ChecksumVerificationException, it means the transfer/read succeeded, but the checksum
                            // doesn't match. This could be a problem with the server (ibiblio HTTP-200 error page), so we'll
                            // try this up to two times. On the second try, we'll handle it as a bona-fide error, based on the
                            // repository's checksum checking policy.
                            if ( firstRun )
                            {
                                log.warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
                                retry = true;
                            }
                            else
                            {
                                throw new ChecksumVerificationException( e.getMessage(), e.getCause() );
                            }
                        }
                        catch ( ResourceDoesNotExistException md5TryException )
                        {
                            log.debug( "MD5 not found, trying SHA1", md5TryException );

                            // if this IS NOT a ChecksumVerificationException, it was a problem with transfer/read of the checksum
                            // file...we'll try again with the SHA-1 checksum.
                            try
                            {
                                verifyChecksum( sha1ChecksumObserver, destination, temp, remotePath, ".sha1", wagon );
                            }
                            catch ( ChecksumVerificationException e )
                            {
                                // if we also fail to verify based on the SHA-1 checksum, and the checksum transfer/read
                                // succeeded, then we need to determine whether to retry or handle it as a failure.
                                if ( firstRun )
                                {
                                    retry = true;
                                }
                                else
                                {
                                    throw new ChecksumVerificationException( e.getMessage(), e.getCause() );
                                }
                            }
                            catch ( ResourceDoesNotExistException sha1TryException )
                            {
                                // this was a failed transfer, and we don't want to retry.
                                throw new ChecksumVerificationException( "Error retrieving checksum file for "
                                    + remotePath, sha1TryException );
                            }
                        }
                    }

                    // Artifact was found, continue checking additional remote repos (if any)
                    // in case there is a newer version (i.e. snapshots) in another repo
                    artifactFound = true;

                    if ( !artifact.isSnapshot() )
                    {
                        break;
                    }

                    // reinstate the download monitor...
                    if ( listener != null )
                    {
                        wagon.addTransferListener( listener );
                    }

                    // unset the firstRun flag, so we don't get caught in an infinite loop...
                    firstRun = false;
                }

            }
            catch ( ResourceDoesNotExistException e )
            {
                // Multiple repositories may exist, and if the file is not found
                // in just one of them, it's no problem, and we don't want to
                // even print out an error.
                // if it's not found at all, artifactFound will be false, and the
                // build _will_ break, and the user will get an error message
                log.debug( "File not found on one of the repos", e );
            }
            catch ( Exception e )
            {
                // If there are additional remote repos, then ignore exception
                // as artifact may be found in another remote repo. If there
                // are no more remote repos to check and the artifact wasn't found in
                // a previous remote repo, then artifactFound is false indicating
                // that the artifact could not be found in any of the remote repos
                //
                // arguably, we need to give the user better control (another command-
                // line switch perhaps) of what to do in this case? Maven already has
                // a command-line switch to work in offline mode, but what about when
                // one of two or more remote repos is unavailable? There may be multiple
                // remote repos for redundancy, in which case you probably want the build
                // to continue. There may however be multiple remote repos because some
                // artifacts are on one, and some are on another. In this case, you may
                // want the build to break.
                //
                // print a warning, in any case, so user catches on to mistyped
                // hostnames, or other snafus
                // FIXME: localize this message
                log.warn( "Error retrieving artifact from [" + repository.getUrl() + "]: " + e );
                log.debug( "Error details", e );
            }
            finally
            {
                try
                {
                    wagon.disconnect();
                }
                catch ( ConnectionException e )
                {
                    log.debug( "Error disconnecting wagon", e );
                }
View Full Code Here

        }

        public final Wagon getWagon( final String protocol )
        {
            // TODO: don't initialise the wagons all the time - use a session
            Wagon ret;
            final Class aClass = (Class) map.get( protocol );
            if ( aClass == null )
            {
                log.info( "Unknown protocol: `" + protocol + "'. Trying file wagon" );
                ret = new FileWagon();
View Full Code Here

        String file = url.substring( index + 1 );
        url = url.substring( 0, index );

        Repository repository = new Repository( "httputils", url );

        Wagon wagon;
        if ( "http".equals( repository.getProtocol() ) )
        {
            wagon = new HttpWagon();
        }
        else
        {
            wagon = new FileWagon();
        }
        wagon.addTransferListener( new BootstrapDownloadMeter() );

        ProxyInfo proxyInfo = null;
        if ( proxyHost != null )
        {
            proxyInfo = new ProxyInfo();
            proxyInfo.setHost( proxyHost );
            proxyInfo.setPort( Integer.valueOf( proxyPort ).intValue() );
            proxyInfo.setUserName( proxyUserName );
            proxyInfo.setPassword( proxyPassword );
            proxyInfo.setNtlmHost( loginHost );
            proxyInfo.setNtlmDomain( loginDomain );
        }

        try
        {
            wagon.connect( repository, proxyInfo );
            wagon.getIfNewer( file, destinationFile, timestamp );
        }
        catch ( Exception e )
        {
            throw new IOException( "Transfer failure: " + e );
        }
        finally
        {
            try
            {
                wagon.disconnect();
            }
            catch ( ConnectionException e )
            {
                log.debug( "Failure to disconnect", e );
            }
View Full Code Here

            throw new ContinuumException( "The URL to the site is not defined." );
        }

        Repository repository = new Repository( id, url );

        Wagon wagon;
        try
        {
            wagon = wagonManager.getWagon( repository.getProtocol() );
        }
        catch ( UnsupportedProtocolException e )
        {
            throw new ContinuumException( "Unsupported protocol: '" + repository.getProtocol() + "'", e );
        }

        if ( !wagon.supportsDirectoryCopy() )
        {
            throw new ContinuumException(
                "Wagon protocol '" + repository.getProtocol() + "' doesn't support directory copying" );
        }

        try
        {
            if ( log.isDebugEnabled() )
            {
                Debug debug = new Debug();

                wagon.addSessionListener( debug );
                wagon.addTransferListener( debug );
            }

            ProxyInfo proxyInfo = getProxyInfo( repository );

            if ( proxyInfo != null )
            {
                wagon.connect( repository, getAuthenticationInfo( id ), proxyInfo );
            }
            else
            {
                wagon.connect( repository, getAuthenticationInfo( id ) );
            }

            File buildOutputFile = configurationService.getBuildOutputFile( build.getId(), build.getProject().getId() );

            wagon.put( buildOutputFile, BUILD_OUTPUT_FILE_NAME );

            // TODO: current wagon uses zip which will use the umask on remote host instead of honouring our settings
            //  Force group writeable
            if ( wagon instanceof CommandExecutor )
            {
                CommandExecutor exec = (CommandExecutor) wagon;
                exec.executeCommand( "chmod -Rf g+w " + repository.getBasedir() );
            }
        }
        catch ( ConfigurationException e )
        {
            throw new ContinuumException( "Error uploading build results to deployed site.", e );
        }
        catch ( ResourceDoesNotExistException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        catch ( TransferFailedException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        catch ( AuthorizationException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        catch ( ConnectionException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        catch ( AuthenticationException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        catch ( CommandExecutionException e )
        {
            throw new ContinuumException( "Error uploading site", e );
        }
        finally
        {
            try
            {
                wagon.disconnect();
            }
            catch ( ConnectionException e )
            {
                log.error( "Error disconnecting wagon - ignored", e );
            }
View Full Code Here

TOP

Related Classes of org.apache.maven.wagon.Wagon

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.