You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ev...@apache.org on 2005/09/09 00:34:27 UTC

svn commit: r279662 - in /maven/continuum/trunk/continuum-updater: ./ src/main/java/org/apache/maven/continuum/updater/ src/main/java/org/apache/maven/continuum/updater/util/

Author: evenisse
Date: Thu Sep  8 15:34:15 2005
New Revision: 279662

URL: http://svn.apache.org/viewcvs?rev=279662&view=rev
Log:
Add new features to updater process :

o download latest continuum release file
o backup old continuum
o clean continuum home directory
o extract new continuum in continuum home directory
o restore the backup if updater fail

Added:
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java   (with props)
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java   (with props)
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java   (with props)
Modified:
    maven/continuum/trunk/continuum-updater/pom.xml
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/DefaultUpdaterManager.java
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/Updater.java
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.java

Modified: maven/continuum/trunk/continuum-updater/pom.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/pom.xml?rev=279662&r1=279661&r2=279662&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-updater/pom.xml (original)
+++ maven/continuum/trunk/continuum-updater/pom.xml Thu Sep  8 15:34:15 2005
@@ -24,8 +24,23 @@
     </dependency>
     <dependency>
       <groupId>plexus</groupId>
-      <artifactId>plexus-container-default</artifactId>
-      <version>1.0-alpha-6-SNAPSHOT</version>
+      <artifactId>plexus-archiver</artifactId>
+      <version>1.0-alpha-1</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-provider-api</artifactId>
+      <version>1.0-alpha-4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-http-lightweight</artifactId>
+      <version>1.0-alpha-4</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.wagon</groupId>
+      <artifactId>wagon-ftp</artifactId>
+      <version>1.0-alpha-4</version>
     </dependency>
   </dependencies>
   <build>

Modified: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/DefaultUpdaterManager.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/DefaultUpdaterManager.java?rev=279662&r1=279661&r2=279662&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/DefaultUpdaterManager.java (original)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/DefaultUpdaterManager.java Thu Sep  8 15:34:15 2005
@@ -20,13 +20,21 @@
 import org.apache.maven.continuum.updater.model.UpdaterModel;
 import org.apache.maven.continuum.updater.model.Version;
 import org.apache.maven.continuum.updater.model.io.xpp3.ContinuumUpdaterXpp3Reader;
+import org.apache.maven.continuum.updater.util.WagonManager;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.util.FileUtils;
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.File;
+import java.net.URL;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -39,7 +47,7 @@
  */
 public class DefaultUpdaterManager
     extends AbstractLogEnabled
-    implements UpdaterManager
+    implements UpdaterManager, Contextualizable
 {
     /**
      * @plexus.requirement
@@ -47,6 +55,16 @@
      */
     private Map updaters;
 
+    /**
+     * @plexus.requirement
+     *   role="org.apache.maven.continuum.updater.util.WagonManager"
+     */
+    private WagonManager wagonManager;
+
+    private PlexusContainer container;
+
+    private File newContinuumFile;
+
     public void execute( String userVersion, File continuumHome )
         throws UpdaterException
     {
@@ -71,6 +89,8 @@
 
         boolean versionFounded = false;
 
+        newContinuumFile = downloadContinuum( model, continuumHome );
+
         for( Iterator i = model.getVersions().iterator(); i.hasNext(); )
         {
             Version v = (Version) i.next();
@@ -114,6 +134,41 @@
         return sb.toString();
     }
 
+    private File downloadContinuum( UpdaterModel model, File continuumHome )
+        throws UpdaterException
+    {
+        File downloadedFile = null;
+
+        try
+        {
+            String latestUpdaterComponentRole = ( (Version) model.getVersions().get( model.getVersions().size() - 2 ) )
+                .getComponentRole();
+
+            Updater latestUpdater = (Updater) updaters.get( latestUpdaterComponentRole );
+
+            URL url = new URL( latestUpdater.getReleaseUrl() );
+
+            String filename = url.getFile().substring( url.getFile().lastIndexOf( "/" ) + 1 );
+
+            downloadedFile = new File( continuumHome.getParentFile(), filename );
+
+            getLogger().info( "==> Download " + url + " in " + downloadedFile.getAbsolutePath() );
+
+            if ( downloadedFile.exists() )
+            {
+                downloadedFile.delete();
+            }
+
+            wagonManager.getFile( url, downloadedFile, "warn" );
+        }
+        catch ( Exception e )
+        {
+            throw new UpdaterException( "Can't download the new release", e );
+        }
+
+        return downloadedFile;
+    }
+
     private void update( String userVersion, Version version, File continuumHome )
         throws UpdaterException
     {
@@ -128,42 +183,41 @@
             throw new UpdaterException( "Updater " + version.getComponentRole() + " doesn't exist." );
         }
 
-        if ( version.equals( version.getName() ) )
-        {
-            backup( continuumHome, userVersion );
-        }
-
         try
         {
-            getLogger().info( "==> Update database" );
-
-            updater.updateDatabase();
-
-            getLogger().info( "==> Update librairies" );
+            if ( userVersion.equals( version.getName() ) )
+            {
+                backup( continuumHome, userVersion );
 
-            updater.updateLibraries();
+                updateContinuumFiles( continuumHome );
+            }
 
-            getLogger().info( "==> Update file system" );
+            getLogger().info( "==> Update database" );
 
-            updater.updateFileSystem();
+            updater.updateDatabase();
         }
         catch( UpdaterException e )
         {
+            e.printStackTrace();
+
             restore( continuumHome, userVersion );
 
-            throw e;
+            System.exit( 1 );
         }
     }
 
     private void backup( File continuumHome, String userVersion )
         throws UpdaterException
     {
-        getLogger().info( "==> Backup Continuum " + userVersion );
+        File backupDir = new File( continuumHome.getParentFile(), "continuum-" + userVersion );
+
+        getLogger().info( "==> Backup Continuum " + userVersion + " to " + backupDir.getAbsolutePath() );
 
         try
         {
-            FileUtils.copyDirectoryStructure( continuumHome,
-                                              new File( continuumHome.getParentFile(), "continuum-" + userVersion ) );
+            FileUtils.deleteDirectory( backupDir);
+
+            FileUtils.copyDirectoryStructure( continuumHome, backupDir);
         }
         catch( IOException e )
         {
@@ -187,5 +241,77 @@
         {
             throw new UpdaterException( "Can't restore continuum.", e );
         }
+    }
+
+    private void updateContinuumFiles( File continuumHome )
+        throws UpdaterException
+    {
+        getLogger().info( "==> Update Continuum files." );
+
+        try
+        {
+            FileUtils.cleanDirectory( continuumHome );
+
+            // Extract new continuum version
+            UnArchiver unArchiver = (UnArchiver) container.lookup( UnArchiver.ROLE,
+                                                                   FileUtils.extension( newContinuumFile.getName() ) );
+
+            unArchiver.setSourceFile( newContinuumFile );
+
+            File destDir = new File( newContinuumFile.getParentFile(),
+                                    FileUtils.basename( newContinuumFile.getName() ) + "tmp" );
+
+            destDir.mkdirs();
+
+            unArchiver.setDestDirectory( destDir );
+
+            unArchiver.extract();
+
+            newContinuumFile.delete();
+
+            String[] listDirs = destDir.list();
+
+            if ( listDirs.length != 1 && !new File( destDir, listDirs[0] ).isDirectory() )
+            {
+                throw new UpdaterException( "This archive is in a wrong format." );
+            }
+
+            FileUtils.copyDirectoryStructure( new File(  destDir, listDirs[0] ), continuumHome );
+
+            FileUtils.deleteDirectory( destDir );
+
+            // Extract continuum app
+            File appsDir = new File( continuumHome, "apps" );
+
+            listDirs = appsDir.list();
+
+            if ( listDirs.length != 1 && new File( appsDir, listDirs[0] ).isDirectory()
+                 && !"jar".equals( FileUtils.extension( listDirs[0] ) ) )
+            {
+                throw new UpdaterException( "Don't have a jar in apps directory." );
+            }
+
+            File appsJar = new File( appsDir, listDirs[0] );
+
+            unArchiver.setSourceFile( appsJar );
+
+            File continuumAppDir = new File( appsDir, "continuum" );
+
+            continuumAppDir.mkdirs();
+
+            unArchiver.setDestDirectory( continuumAppDir );
+
+            unArchiver.extract();
+        }
+        catch ( Exception e )
+        {
+            throw new UpdaterException( "Can't update continuum files.", e );
+        }
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
     }
 }

Modified: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/Updater.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/Updater.java?rev=279662&r1=279661&r2=279662&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/Updater.java (original)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/Updater.java Thu Sep  8 15:34:15 2005
@@ -26,12 +26,8 @@
 {
     static String ROLE = Updater.class.getName();
 
-    void updateDatabase()
-        throws UpdaterException;
-
-    void updateLibraries()
-        throws UpdaterException;
+    String getReleaseUrl();
 
-    void updateFileSystem()
+    void updateDatabase()
         throws UpdaterException;
 }

Modified: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.java?rev=279662&r1=279661&r2=279662&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.java (original)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.java Thu Sep  8 15:34:15 2005
@@ -29,18 +29,14 @@
 public class UpdaterForContinuumOneAlphaThree
     implements Updater
 {
-    public void updateDatabase()
-        throws UpdaterException
+    public String getReleaseUrl()
     {
+        return "http://www.apache.org/dist/maven/binaries/continuum-1.0-alpha-4-bin.zip";
     }
 
-    public void updateLibraries()
-        throws UpdaterException
-    {
-    }
-
-    public void updateFileSystem()
+    public void updateDatabase()
         throws UpdaterException
     {
+        //throw new UpdaterException( "Not implemented." );
     }
 }

Added: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java?rev=279662&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java (added)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java Thu Sep  8 15:34:15 2005
@@ -0,0 +1,38 @@
+package org.apache.maven.continuum.updater.util;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.wagon.TransferFailedException;
+
+/**
+ * Occurs when a download checksum fails.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class ChecksumFailedException extends TransferFailedException
+{
+    public ChecksumFailedException( String s )
+    {
+        super( s );
+    }
+    
+    public ChecksumFailedException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+}

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/ChecksumFailedException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java?rev=279662&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java (added)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java Thu Sep  8 15:34:15 2005
@@ -0,0 +1,368 @@
+package org.apache.maven.continuum.updater.util;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.wagon.ConnectionException;
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.UnsupportedProtocolException;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.authentication.AuthenticationException;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.apache.maven.wagon.authorization.AuthorizationException;
+import org.apache.maven.wagon.events.TransferListener;
+import org.apache.maven.wagon.observers.ChecksumObserver;
+import org.apache.maven.wagon.providers.http.LightweightHttpWagon;
+import org.apache.maven.wagon.providers.ftp.FtpWagon;
+import org.apache.maven.wagon.proxy.ProxyInfo;
+import org.apache.maven.wagon.repository.Repository;
+import org.codehaus.plexus.PlexusConstants;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
+import org.codehaus.plexus.context.Context;
+import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.security.NoSuchAlgorithmException;
+import java.net.URL;
+
+/**
+ * @plexus.component
+ *   role="org.apache.maven.continuum.updater.util.WagonManager"
+ *
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public class DefaultWagonManager
+    extends AbstractLogEnabled
+    implements WagonManager
+{
+    public static final String CHECKSUM_POLICY_FAIL = "fail";
+
+    public static final String CHECKSUM_POLICY_IGNORE = "ignore";
+
+    private PlexusContainer container;
+
+    private TransferListener downloadMonitor;
+
+    public Wagon getWagon( String protocol )
+        throws UnsupportedProtocolException
+    {
+        Wagon wagon = null;
+
+/*
+        try
+        {
+            wagon = (Wagon) embedder.lookup( Wagon.ROLE, protocol );
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new UnsupportedProtocolException(
+                "Cannot find wagon which supports the requested protocol: " + protocol, e );
+        }
+*/
+        if ( "http".equals( protocol ) )
+        {
+            wagon = new LightweightHttpWagon();
+        }
+        else if ( "ftp".equals( protocol ) )
+        {
+            wagon = new FtpWagon();
+        }
+
+        return wagon;
+    }
+
+    public void getFile( URL url, File destination, String checksumPolicy )
+        throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException
+    {
+        // TODO: better excetpions - transfer failed is not enough?
+
+        Wagon wagon;
+
+        String protocol = url.getProtocol();
+
+        String remotePath = url.getPath();
+        try
+        {
+            wagon = getWagon( protocol );
+        }
+        catch ( UnsupportedProtocolException e )
+        {
+            throw new TransferFailedException( "Unsupported Protocol: ", e );
+        }
+
+        if ( downloadMonitor != null )
+        {
+            wagon.addTransferListener( downloadMonitor );
+        }
+
+        ChecksumObserver md5ChecksumObserver;
+
+        ChecksumObserver sha1ChecksumObserver;
+
+        try
+        {
+            md5ChecksumObserver = new ChecksumObserver( "MD5" );
+
+            wagon.addTransferListener( md5ChecksumObserver );
+
+            sha1ChecksumObserver = new ChecksumObserver( "SHA-1" );
+
+            wagon.addTransferListener( sha1ChecksumObserver );
+        }
+        catch ( NoSuchAlgorithmException e )
+        {
+            throw new TransferFailedException( "Unable to add checksum methods", e );
+        }
+
+        File temp = new File( destination + ".tmp" );
+
+        temp.deleteOnExit();
+
+        try
+        {
+            wagon.connect( new Repository( "continuum", protocol + "://" + url.getHost() ), null, null );
+
+            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;
+
+                // This should take care of creating destination directory now on
+                wagon.get( remotePath, temp );
+
+                // keep the checksum files from showing up on the download monitor...
+                if ( downloadMonitor != null )
+                {
+                    wagon.removeTransferListener( downloadMonitor );
+                }
+
+                // try to verify the SHA-1 checksum for this file.
+                try
+                {
+                    verifyChecksum( sha1ChecksumObserver, temp, remotePath, ".sha1", wagon );
+                }
+                catch ( ChecksumFailedException e )
+                {
+                    // if we catch a ChecksumFailedException, 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 )
+                    {
+                        getLogger().warn( "*** CHECKSUM FAILED - " + e.getMessage() + " - RETRYING" );
+                        retry = true;
+                    }
+                    else
+                    {
+                        handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
+                    }
+                }
+                catch ( ResourceDoesNotExistException sha1TryException )
+                {
+                    getLogger().debug( "SHA1 not found, trying MD5", sha1TryException );
+
+                    // if this IS NOT a ChecksumFailedException, it was a problem with transfer/read of the checksum
+                    // file...we'll try again with the MD5 checksum.
+                    try
+                    {
+                        verifyChecksum( md5ChecksumObserver, temp, remotePath, ".md5", wagon );
+                    }
+                    catch ( ChecksumFailedException e )
+                    {
+                        // if we also fail to verify based on the MD5 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
+                        {
+                            handleChecksumFailure( checksumPolicy, e.getMessage(), e.getCause() );
+                        }
+                    }
+                    catch ( ResourceDoesNotExistException md5TryException )
+                    {
+                        // this was a failed transfer, and we don't want to retry.
+                        handleChecksumFailure( checksumPolicy, "Error retrieving checksum file for " + remotePath,
+                                               md5TryException );
+                    }
+                }
+
+                // reinstate the download monitor...
+                if ( downloadMonitor != null )
+                {
+                    wagon.addTransferListener( downloadMonitor );
+                }
+
+                // unset the firstRun flag, so we don't get caught in an infinite loop...
+                firstRun = false;
+            }
+        }
+        catch ( ConnectionException e )
+        {
+            throw new TransferFailedException( "Connection failed: ", e );
+        }
+        catch ( AuthenticationException e )
+        {
+            throw new TransferFailedException( "Authentication failed: ", e );
+        }
+        catch ( AuthorizationException e )
+        {
+            throw new TransferFailedException( "Authorization failed: ", e );
+        }
+        finally
+        {
+            disconnectWagon( wagon );
+
+            releaseWagon( wagon );
+        }
+
+        if ( !temp.exists() )
+        {
+            throw new ResourceDoesNotExistException( "Downloaded file does not exist: " + temp );
+        }
+
+        // The temporary file is named destination + ".tmp" and is done this way to ensure
+        // that the temporary file is in the same file system as the destination because the
+        // File.renameTo operation doesn't really work across file systems.
+        // So we will attempt to do a File.renameTo for efficiency and atomicity, if this fails
+        // then we will use a brute force copy and delete the temporary file.
+
+        if ( !temp.renameTo( destination ) )
+        {
+            try
+            {
+                FileUtils.copyFile( temp, destination );
+
+                temp.delete();
+            }
+            catch ( IOException e )
+            {
+                throw new TransferFailedException( "Error copying temporary file to the final destination: ", e );
+            }
+        }
+    }
+
+    private void handleChecksumFailure( String checksumPolicy, String message, Throwable cause )
+        throws ChecksumFailedException
+    {
+        if ( CHECKSUM_POLICY_FAIL.equals( checksumPolicy ) )
+        {
+            throw new ChecksumFailedException( message, cause );
+        }
+        else if ( !CHECKSUM_POLICY_IGNORE.equals( checksumPolicy ) )
+        {
+            // warn if it is set to anything other than ignore
+            getLogger().warn( "*** CHECKSUM FAILED - " + message + " - IGNORING" );
+        }
+        // otherwise it is ignore
+    }
+
+    private void verifyChecksum( ChecksumObserver checksumObserver, File destination, String remotePath,
+                                 String checksumFileExtension, Wagon wagon )
+        throws ResourceDoesNotExistException, TransferFailedException, AuthorizationException
+    {
+        try
+        {
+            // grab it first, because it's about to change...
+            String actualChecksum = checksumObserver.getActualChecksum();
+
+            File checksumFile = new File( destination + checksumFileExtension );
+
+            checksumFile.deleteOnExit();
+
+            wagon.get( remotePath + checksumFileExtension, checksumFile );
+
+            String expectedChecksum = FileUtils.fileRead( checksumFile );
+
+            // remove whitespaces at the end
+            expectedChecksum = expectedChecksum.trim();
+
+            // check for 'MD5 (name) = CHECKSUM'
+            if ( expectedChecksum.startsWith( "MD5" ) )
+            {
+                int lastSpacePos = expectedChecksum.lastIndexOf( ' ' );
+
+                expectedChecksum = expectedChecksum.substring( lastSpacePos + 1 );
+            }
+            else
+            {
+                // remove everything after the first space (if available)
+                int spacePos = expectedChecksum.indexOf( ' ' );
+
+                if ( spacePos != -1 )
+                {
+                    expectedChecksum = expectedChecksum.substring( 0, spacePos );
+                }
+            }
+            if ( !expectedChecksum.equals( actualChecksum ) )
+            {
+                throw new ChecksumFailedException( "Checksum failed on download: local = '" + actualChecksum +
+                    "'; remote = '" + expectedChecksum + "'" );
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Invalid checksum file", e );
+        }
+    }
+
+    private void disconnectWagon( Wagon wagon )
+    {
+        try
+        {
+            wagon.disconnect();
+        }
+        catch ( ConnectionException e )
+        {
+            getLogger().error( "Problem disconnecting from wagon - ignoring: " + e.getMessage() );
+        }
+    }
+
+    private void releaseWagon( Wagon wagon )
+    {
+/*
+        try
+        {
+            container.release( wagon );
+        }
+        catch ( ComponentLifecycleException e )
+        {
+            getLogger().error( "Problem releasing wagon - ignoring: " + e.getMessage() );
+        }
+*/
+    }
+
+    public void contextualize( Context context )
+        throws ContextException
+    {
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+}

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/DefaultWagonManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java?rev=279662&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java (added)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java Thu Sep  8 15:34:15 2005
@@ -0,0 +1,36 @@
+package org.apache.maven.continuum.updater.util;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.wagon.ResourceDoesNotExistException;
+import org.apache.maven.wagon.TransferFailedException;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public interface WagonManager
+{
+    static String ROLE = WagonManager.class.getName();
+
+    void getFile( URL url, File destination, String checksumPolicy )
+        throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException;
+
+}

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/util/WagonManager.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"