continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r279427 - in /maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater: DefaultUpdaterManager.java UpdaterForContinuumOneAlphaThree.java cli/UpdaterCli.java
Date Wed, 07 Sep 2005 21:25:08 GMT
Author: evenisse
Date: Wed Sep  7 14:25:03 2005
New Revision: 279427

URL: http://svn.apache.org/viewcvs?rev=279427&view=rev
Log:
Add backup and restore methods for user continuum version

Modified:
    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/UpdaterForContinuumOneAlphaThree.java
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/cli/UpdaterCli.java

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=279427&r1=279426&r2=279427&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
Wed Sep  7 14:25:03 2005
@@ -21,9 +21,11 @@
 import org.apache.maven.continuum.updater.model.Version;
 import org.apache.maven.continuum.updater.model.io.xpp3.ContinuumUpdaterXpp3Reader;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.codehaus.plexus.util.FileUtils;
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.IOException;
 import java.io.File;
 import java.util.Iterator;
 import java.util.Map;
@@ -45,7 +47,7 @@
      */
     private Map updaters;
 
-    public void execute( String version, File continuumHome )
+    public void execute( String userVersion, File continuumHome )
         throws UpdaterException
     {
         InputStream confAsStream;
@@ -73,20 +75,20 @@
         {
             Version v = (Version) i.next();
 
-            if ( v.getName().equals( version ) )
+            if ( v.getName().equals( userVersion ) )
             {
                 versionFounded = true;
             }
 
             if ( versionFounded && v.getComponentRole() != null )
             {
-                update( v, continuumHome );
+                update( userVersion, v, continuumHome );
             }
         }
 
         if ( !versionFounded )
         {
-            getLogger().warn( "There are no updater for your version(" + version + ")\n"
+ getAvailableVersions( model ) );
+            getLogger().warn( "There are no updater for your version(" + userVersion + ")\n"
+ getAvailableVersions( model ) );
         }
     }
 
@@ -112,7 +114,7 @@
         return sb.toString();
     }
 
-    private void update( Version version, File continuumHome )
+    private void update( String userVersion, Version version, File continuumHome )
         throws UpdaterException
     {
         getLogger().info( "************************************************************************"
);
@@ -121,16 +123,69 @@
 
         Updater updater = (Updater) updaters.get( version.getComponentRole() );
 
-        getLogger().info( "Update database" );
+        if ( updater == null )
+        {
+            throw new UpdaterException( "Updater " + version.getComponentRole() + " doesn't
exist." );
+        }
+
+        if ( version.equals( version.getName() ) )
+        {
+            backup( continuumHome, userVersion );
+        }
+
+        try
+        {
+            getLogger().info( "==> Update database" );
+
+            updater.updateDatabase();
 
-        updater.updateDatabase();
+            getLogger().info( "==> Update librairies" );
 
-        getLogger().info( "Update librairies" );
+            updater.updateLibraries();
 
-        updater.updateLibraries();
+            getLogger().info( "==> Update file system" );
 
-        getLogger().info( "Update file system" );
+            updater.updateFileSystem();
+        }
+        catch( UpdaterException e )
+        {
+            restore( continuumHome, userVersion );
+
+            throw e;
+        }
+    }
+
+    private void backup( File continuumHome, String userVersion )
+        throws UpdaterException
+    {
+        getLogger().info( "==> Backup Continuum " + userVersion );
 
-        updater.updateFileSystem();
+        try
+        {
+            FileUtils.copyDirectoryStructure( continuumHome,
+                                              new File( continuumHome.getParentFile(), "continuum-"
+ userVersion ) );
+        }
+        catch( IOException e )
+        {
+            throw new UpdaterException( "Can't create a continuum backup.", e );
+        }
+    }
+
+    private void restore( File continuumHome, String userVersion )
+        throws UpdaterException
+    {
+        getLogger().info( "==> Restore Continuum " + userVersion );
+
+        try
+        {
+            FileUtils.cleanDirectory( continuumHome );
+
+            FileUtils.copyDirectoryStructure( new File( continuumHome.getParentFile(), "continuum-"
+ userVersion ),
+                                              continuumHome );
+        }
+        catch( IOException e )
+        {
+            throw new UpdaterException( "Can't restore continuum.", e );
+        }
     }
 }

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=279427&r1=279426&r2=279427&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
Wed Sep  7 14:25:03 2005
@@ -21,6 +21,7 @@
 /**
  * @plexus.component
  *   role="org.apache.maven.continuum.updater.Updater"
+ *   role-hint="updateTo1.0-alpha-4"
  *
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$

Modified: maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/cli/UpdaterCli.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/cli/UpdaterCli.java?rev=279427&r1=279426&r2=279427&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/cli/UpdaterCli.java
(original)
+++ maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/cli/UpdaterCli.java
Wed Sep  7 14:25:03 2005
@@ -167,7 +167,7 @@
 
     static class CLIManager
     {
-        public static final char CONTINUUM_HOME = 'c';
+        public static final char CONTINUUM_HOME = 'p';
 
         public static final char VERSION = 'v';
 



Mime
View raw message