continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r697436 - /continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Date Sun, 21 Sep 2008 00:37:01 GMT
Author: ctan
Date: Sat Sep 20 17:37:00 2008
New Revision: 697436

URL: http://svn.apache.org/viewvc?rev=697436&view=rev
Log:
handle creation of projectscmroot for an existing db

Modified:
    continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java

Modified: continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=697436&r1=697435&r2=697436&view=diff
==============================================================================
--- continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ continuum/branches/continuum-transient-state/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Sat Sep 20 17:37:00 2008
@@ -30,7 +30,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
-import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -2092,14 +2091,7 @@
             
             if ( projectScmRoot == null )
             {
-                projectScmRoot = new ProjectScmRoot();
-                
-                projectScmRoot.setProjectGroup( projectGroup );
-                
-                projectScmRoot.setScmRootAddress( url );
-                
-                projectScmRoot = projectScmRootDao.addProjectScmRoot( projectScmRoot );
-
+                projectScmRoot = createProjectScmRoot( projectGroup, url );
             }
 
             /* add the project group loaded from database, which has more info, like id */
@@ -3010,6 +3002,18 @@
 
         for ( Project project : projectDao.getAllProjectsByNameWithBuildDetails() )
         {
+            if ( project.getScmRootAddress() == null || StringUtils.isEmpty( project.getScmRootAddress()
) )
+            {
+                try
+                {
+                    setScmRootAddressForProject( project );
+                }
+                catch ( ContinuumException e )
+                {
+                    throw new InitializationException( "Database is corrupted.", e );
+                }
+            }
+            
             for ( ProjectNotifier notifier : (List<ProjectNotifier>) project.getNotifiers()
)
             {
                 if ( StringUtils.isEmpty( notifier.getType() ) )
@@ -3753,4 +3757,78 @@
             throw logAndCreateException( "Error while creating enqueuing object.", e );
         }
     }
+
+    private void setScmRootAddressForProject( Project project )
+        throws ContinuumException
+    {
+        boolean found = false;
+
+        ProjectGroup projectGroup = project.getProjectGroup();
+
+        List<ProjectScmRoot> scmRoots = projectScmRootDao.getProjectScmRootByProjectGroup(
projectGroup.getId() );
+        
+        for ( ProjectScmRoot scmRoot : scmRoots )
+        {
+            if ( project.getScmUrl().startsWith( scmRoot.getScmRootAddress() ) )
+            {
+                project.setScmRootAddress( scmRoot.getScmRootAddress() );
+                found = true;
+                break;
+            }
+        }
+        
+        if ( !found )
+        {
+            createProjectScmRootForProjectGroup( projectGroup );
+            setScmRootAddressForProject( project );
+        }
+    }
+
+    private void createProjectScmRootForProjectGroup( ProjectGroup projectGroup )
+        throws ContinuumException
+    {
+        List<Project> projectsList;
+
+        try
+        {
+            projectsList = getProjectsInBuildOrder( projectDao.getProjectsWithDependenciesByGroupId(
projectGroup.getId() ) );
+        }
+        catch ( CycleDetectedException e )
+        {
+            throw new ContinuumException( "Error while retrieving projects", e );
+        }
+
+        int counter = 0;
+        String url = "";
+
+        for ( Project project : projectsList )
+        {
+            if ( counter == 0 || !project.getScmUrl().startsWith( url ) )
+            {
+                // this is a root
+                url = project.getScmUrl();
+                createProjectScmRoot( projectGroup, url );
+            }
+            counter++;
+        }
+    }
+    
+    private ProjectScmRoot createProjectScmRoot( ProjectGroup projectGroup, String url )
+        throws ContinuumException
+    {
+        ProjectScmRoot projectScmRoot = new ProjectScmRoot();
+        
+        projectScmRoot.setProjectGroup( projectGroup );
+        
+        projectScmRoot.setScmRootAddress( url );
+        
+        try
+        {
+            return projectScmRootDao.addProjectScmRoot( projectScmRoot );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumException( "Error while creating project scm root with scm
root address:" + url );
+        }
+    }
 }



Mime
View raw message