continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r280572 - in /maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater: DefaultUpdaterManager.java Updater.java UpdaterForContinuumOneAlphaThree.java
Date Tue, 13 Sep 2005 14:53:16 GMT
Author: evenisse
Date: Tue Sep 13 07:53:11 2005
New Revision: 280572

URL: http://svn.apache.org/viewcvs?rev=280572&view=rev
Log:
my last changes in updater. Not usable for the moment. I'll finish it in beta-1

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/Updater.java
    maven/continuum/trunk/continuum-updater/src/main/java/org/apache/maven/continuum/updater/UpdaterForContinuumOneAlphaThree.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=280572&r1=280571&r2=280572&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
Tue Sep 13 07:53:11 2005
@@ -24,16 +24,21 @@
 import org.codehaus.plexus.PlexusConstants;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.archiver.UnArchiver;
+import org.codehaus.plexus.component.repository.io.PlexusTools;
+import org.codehaus.plexus.configuration.PlexusConfiguration;
 import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.context.ContextException;
+import org.codehaus.plexus.jdo.JdoFactory;
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.StringUtils;
 
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.IOException;
 import java.io.File;
+import java.io.FileReader;
 import java.net.URL;
 import java.util.Iterator;
 import java.util.Map;
@@ -181,15 +186,62 @@
 
         try
         {
-            backup( continuumHome, userVersion );
+            backup( continuumHome, version.getName() );
 
             updateContinuumFiles( continuumHome, model );
 
             getLogger().info( "==> Update database" );
 
-            updater.updateDatabase();
+            File oldApplicationXml = updater.getOldApplicationXml( getBackupDirectory( continuumHome,
+                                                                                       version.getName()
) );
+
+            FileUtils.copyFile( oldApplicationXml, getApplicationXmlBackup( oldApplicationXml
) );
+
+            String applicationXmlContent = FileUtils.fileRead( oldApplicationXml );
+
+            StringUtils.replace( applicationXmlContent, "<role>org.codehaus.plexus.jdo.JdoFactory</role>",
+                "<role>org.codehaus.plexus.jdo.JdoFactory</role>\n<role-hint>"+
version.getName() + "</role-hint>");
+
+            FileUtils.fileWrite( oldApplicationXml.getAbsolutePath(), applicationXmlContent
);
+
+            //Load old application.xml
+            addConfiguration( oldApplicationXml );
+
+            File newApplicationXml = updater.getNewApplicationXml( continuumHome );
+
+            FileUtils.copyFile( newApplicationXml, getApplicationXmlBackup( newApplicationXml
) );
+
+            applicationXmlContent = FileUtils.fileRead( newApplicationXml );
+
+            StringUtils.replace( applicationXmlContent, "<role>org.codehaus.plexus.jdo.JdoFactory</role>",
+                "<role>org.codehaus.plexus.jdo.JdoFactory</role>\n<role-hint>"+
version.getName() + "-new</role-hint>");
+
+            FileUtils.fileWrite( newApplicationXml.getAbsolutePath(), applicationXmlContent
);
+
+            //Load new application.xml
+            addConfiguration( newApplicationXml );
+
+            try
+            {
+                //load jdo factories
+                JdoFactory oldFactory = (JdoFactory) container.lookup( JdoFactory.ROLE, version.getName()
);
+
+                JdoFactory newFactory = (JdoFactory) container.lookup( JdoFactory.ROLE, version.getName()
+ "-new" );
+
+                updater.updateDatabase( oldFactory, newFactory );
+            }
+            finally
+            {
+                FileUtils.copyFile( getApplicationXmlBackup( oldApplicationXml ), oldApplicationXml
);
+
+                getApplicationXmlBackup( oldApplicationXml ).delete();
+
+                FileUtils.copyFile( getApplicationXmlBackup( newApplicationXml ), newApplicationXml
);
+
+                getApplicationXmlBackup( newApplicationXml ).delete();
+            }
         }
-        catch( UpdaterException e )
+        catch( Exception e )
         {
             e.printStackTrace();
 
@@ -199,12 +251,12 @@
         }
     }
 
-    private void backup( File continuumHome, String userVersion )
+    private void backup( File continuumHome, String version )
         throws UpdaterException
     {
-        File backupDir = new File( continuumHome.getParentFile(), "continuum-" + userVersion
);
+        File backupDir = getBackupDirectory( continuumHome, version );
 
-        getLogger().info( "==> Backup Continuum " + userVersion + " to " + backupDir.getAbsolutePath()
);
+        getLogger().info( "==> Backup Continuum " + version + " to " + backupDir.getAbsolutePath()
);
 
         try
         {
@@ -227,7 +279,7 @@
         {
             FileUtils.cleanDirectory( continuumHome );
 
-            FileUtils.copyDirectoryStructure( new File( continuumHome.getParentFile(), "continuum-"
+ userVersion ),
+            FileUtils.copyDirectoryStructure( getBackupDirectory( continuumHome, userVersion
),
                                               continuumHome );
         }
         catch( IOException e )
@@ -236,6 +288,16 @@
         }
     }
 
+    private File getBackupDirectory( File continuumHome, String version )
+    {
+        return new File( continuumHome.getParentFile(), "continuum-" + version );
+    }
+
+    private File getApplicationXmlBackup( File applicationXml )
+    {
+        return new File( applicationXml.getParentFile(), "application.xml.backup" );
+    }
+
     private void updateContinuumFiles( File continuumHome, UpdaterModel model )
         throws UpdaterException
     {
@@ -308,5 +370,13 @@
         throws ContextException
     {
         container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
+    }
+
+    private void addConfiguration( File config )
+        throws Exception
+    {
+        PlexusConfiguration appConfig = PlexusTools.buildConfiguration( config.getPath(),
new FileReader( config ) );
+
+        //TODO: Add configuration to the container
     }
 }

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=280572&r1=280571&r2=280572&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
Tue Sep 13 07:53:11 2005
@@ -17,6 +17,9 @@
  */
 
 import org.apache.maven.continuum.updater.exception.UpdaterException;
+import org.codehaus.plexus.jdo.JdoFactory;
+
+import java.io.File;
 
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -28,6 +31,10 @@
 
     String getReleaseUrl();
 
-    void updateDatabase()
+    File getOldApplicationXml( File continuumHome );
+
+    File getNewApplicationXml( File continuumHome );
+
+    void updateDatabase( JdoFactory oldFactory, JdoFactory newFactory )
         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=280572&r1=280571&r2=280572&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
Tue Sep 13 07:53:11 2005
@@ -16,7 +16,32 @@
  * limitations under the License.
  */
 
+import org.apache.maven.continuum.model.project.BuildResult;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectDeveloper;
+import org.apache.maven.continuum.model.project.ProjectNotifier;
+import org.apache.maven.continuum.model.scm.ScmResult;
+import org.apache.maven.continuum.project.v1_0_alpha_3.AntProject;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ContinuumBuild;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ContinuumDeveloper;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ContinuumNotifier;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ContinuumProject;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ContinuumJPoxStore;
+import org.apache.maven.continuum.project.v1_0_alpha_3.MavenOneProject;
+import org.apache.maven.continuum.project.v1_0_alpha_3.MavenTwoProject;
+import org.apache.maven.continuum.project.v1_0_alpha_3.ShellProject;
+import org.apache.maven.continuum.scm.v1_0_alpha_3.CheckOutScmResult;
+import org.apache.maven.continuum.scm.v1_0_alpha_3.UpdateScmResult;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.apache.maven.continuum.updater.exception.UpdaterException;
+import org.codehaus.plexus.jdo.JdoFactory;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
 
 /**
  * @plexus.component
@@ -29,14 +54,235 @@
 public class UpdaterForContinuumOneAlphaThree
     implements Updater
 {
+    private ContinuumStore oldStore;
+
+    private ContinuumStore store;
+
     public String getReleaseUrl()
     {
         return "http://www.apache.org/dist/maven/binaries/continuum-1.0-alpha-4-bin.zip";
     }
 
-    public void updateDatabase()
+    public File getOldApplicationXml( File continuumHome )
+    {
+        return new File( continuumHome, "apps/continuum/conf/application.xml" );
+    }
+
+    public File getNewApplicationXml( File continuumHome )
+    {
+        return new File( continuumHome, "apps/continuum/conf/application.xml" );
+    }
+
+    public void updateDatabase( JdoFactory oldFactory, JdoFactory newFactory )
         throws UpdaterException
     {
-        //throw new UpdaterException( "Not implemented." );
+        //throw new UpdaterException( "Update database not implemented." );
+    }
+
+    private Project convertProject( ContinuumProject oldProject )
+        throws ContinuumStoreException
+    {
+        Project project = new Project();
+
+        project.setId( new Integer( oldProject.getId() ).intValue() );
+
+        project.setName( oldProject.getName() );
+
+        project.setScmUrl( oldProject.getScmUrl() );
+
+        project.setVersion( oldProject.getVersion() );
+
+        project.setWorkingDirectory( oldProject.getWorkingDirectory() );
+
+        project.setState( oldProject.getState() );
+
+        project.setExecutorId( oldProject.getExecutorId() );
+
+        project.setLatestBuildId( new Integer( oldProject.getLastBuildId() ).intValue() );
+
+        //oldProject.getPreviousBuildId() => don't exist in new model
+
+        project.setBuildNumber( oldProject.getBuildNumber() );
+
+        for ( Iterator i = oldProject.getBuilds().iterator(); i.hasNext(); )
+        {
+            ContinuumBuild oldBuildResult = (ContinuumBuild) i.next();
+
+            project.addBuildResult( convertBuildResult( oldBuildResult, project ) );
+        }
+
+        project.setCheckoutResult( convertScmResult( oldProject.getCheckOutScmResult() )
);
+
+        //oldProject.getCheckOutErrorMessage() => don't exist in new model
+        //oldProject.getCheckOutErrorException() => don't exist in new model
+        //mailType => don't exist in new model
+
+        project.addBuildDefinition( convertBuildDefinition( oldProject ) );
+
+        project.setUrl( oldProject.getUrl() );
+
+        project.setGroupId( oldProject.getGroupId() );
+
+        //oldProject.getTestOutputDirectory() => don't exist in new model
+
+        for ( Iterator i = oldProject.getDevelopers().iterator(); i.hasNext(); )
+        {
+            ContinuumDeveloper oldDeveloper = (ContinuumDeveloper) i.next();
+
+            project.addDeveloper( convertDeveloper( oldDeveloper ) );
+        }
+
+        for ( Iterator i = oldProject.getNotifiers().iterator(); i.hasNext(); )
+        {
+            ContinuumNotifier oldNotifier = (ContinuumNotifier) i.next();
+
+            project.addNotifier( convertNotifier( oldNotifier ) );
+        }
+
+        project.setProjectGroup( store.getDefaultProjectGroup() );
+        return project;
+    }
+
+    private BuildDefinition convertBuildDefinition( ContinuumProject oldProject )
+    {
+        String executorId = oldProject.getExecutorId();
+
+        BuildDefinition bd = new BuildDefinition();
+
+        bd.setArguments( oldProject.getCommandLineArguments() );
+
+        if ( "maven-1".equals( executorId ) )
+        {
+            bd.setBuildFile( "project.xml" );
+        }
+        else if ( "maven2".equals( executorId ) )
+        {
+            bd.setBuildFile( "pom.xml" );
+        }
+
+        if ( oldProject instanceof MavenOneProject )
+        {
+            MavenOneProject project = (MavenOneProject) oldProject;
+
+            bd.setGoals( project.getGoals() );
+        }
+        if ( oldProject instanceof MavenTwoProject )
+        {
+            MavenTwoProject project = (MavenTwoProject) oldProject;
+
+            bd.setGoals( project.getGoals() );
+        }
+        if ( oldProject instanceof AntProject )
+        {
+            AntProject project = (AntProject) oldProject;
+
+            bd.setBuildFile( project.getExecutable() );
+
+            bd.setGoals( project.getTargets() );
+        }
+        if ( oldProject instanceof ShellProject )
+        {
+            ShellProject project = (ShellProject) oldProject;
+
+            bd.setBuildFile( project.getExecutable() );
+        }
+
+        //bd.setSchedule(); ==> TODO
+
+        return bd;
+    }
+
+    private ProjectDeveloper convertDeveloper( ContinuumDeveloper oldDeveloper )
+    {
+        ProjectDeveloper developer = new ProjectDeveloper();
+
+        developer.setScmId( oldDeveloper.getId() );
+
+        developer.setName( oldDeveloper.getName() );
+
+        developer.setEmail( oldDeveloper.getEmail() );
+
+        return developer;
+    }
+
+    private ProjectNotifier convertNotifier( ContinuumNotifier oldNotifier )
+    {
+        ProjectNotifier notifier = new ProjectNotifier();
+
+        notifier.setType( oldNotifier.getType());
+
+        Map oldConf = oldNotifier.getConfiguration();
+
+        Map conf = new HashMap();
+
+        for ( Iterator i = oldConf.keySet().iterator(); i.hasNext(); )
+        {
+            String key = (String) i.next();
+
+            conf.put( key, oldConf.get( key ) );
+        }
+
+        notifier.setConfiguration( conf );
+
+        return notifier;
+    }
+
+    private BuildResult convertBuildResult( ContinuumBuild oldBuildResult, Project newProject
)
+    {
+        BuildResult buildResult = new BuildResult();
+
+        buildResult.setProject( newProject );
+
+        buildResult.setId( new Integer( oldBuildResult.getId() ).intValue() );
+
+        buildResult.setState( oldBuildResult.getState() );
+
+        if ( oldBuildResult.isForced() )
+        {
+            buildResult.setTrigger( 1 );
+        }
+
+        buildResult.setStartTime( oldBuildResult.getStartTime() );
+
+        buildResult.setEndTime( oldBuildResult.getEndTime() );
+
+        buildResult.setError( oldBuildResult.getError() );
+
+        buildResult.setSuccess( oldBuildResult.isSuccess() );
+
+        //standardOutput => don't exist in new model
+        //standardError => don't exist in new model
+
+        buildResult.setExitCode( oldBuildResult.getExitCode() );
+
+        buildResult.setScmResult( convertScmResult( oldBuildResult.getUpdateScmResult() )
);
+
+        return buildResult;
+    }
+
+    private ScmResult convertScmResult( CheckOutScmResult oldScmResult )
+    {
+        ScmResult scmResult = new ScmResult();
+
+        scmResult.setSuccess( oldScmResult.isSuccess() );
+
+        scmResult.setProviderMessage( oldScmResult.getProviderMessage() );
+
+        scmResult.setCommandOutput( oldScmResult.getCommandOutput() );
+
+        return scmResult;
+    }
+
+    private ScmResult convertScmResult( UpdateScmResult oldScmResult )
+    {
+        ScmResult scmResult = new ScmResult();
+
+        scmResult.setSuccess( oldScmResult.isSuccess() );
+
+        scmResult.setProviderMessage( oldScmResult.getProviderMessage() );
+
+        scmResult.setCommandOutput( oldScmResult.getCommandOutput() );
+
+        return scmResult;
     }
 }



Mime
View raw message