continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r735240 - in /continuum/trunk: continuum-data-management/data-management-jdo/ continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/ continuum-data-management/data-management-jdo/src/test/java/org...
Date Sat, 17 Jan 2009 07:27:10 GMT
Author: oching
Date: Fri Jan 16 23:27:10 2009
New Revision: 735240

URL: http://svn.apache.org/viewvc?rev=735240&view=rev
Log:
[CONTINUUM-2040]
o populate ProjectScmRoot table during import
o updated tests

Modified:
    continuum/trunk/continuum-data-management/data-management-jdo/pom.xml
    continuum/trunk/continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java
    continuum/trunk/continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java
    continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
    continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java

Modified: continuum/trunk/continuum-data-management/data-management-jdo/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-data-management/data-management-jdo/pom.xml?rev=735240&r1=735239&r2=735240&view=diff
==============================================================================
--- continuum/trunk/continuum-data-management/data-management-jdo/pom.xml (original)
+++ continuum/trunk/continuum-data-management/data-management-jdo/pom.xml Fri Jan 16 23:27:10
2009
@@ -50,6 +50,10 @@
     </dependency>
     <dependency>
       <groupId>org.apache.continuum</groupId>
+      <artifactId>continuum-commons</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.continuum</groupId>
       <artifactId>continuum-store</artifactId>
       <scope>runtime</scope>
     </dependency>

Modified: continuum/trunk/continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java?rev=735240&r1=735239&r2=735240&view=diff
==============================================================================
--- continuum/trunk/continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java
(original)
+++ continuum/trunk/continuum-data-management/data-management-jdo/src/main/java/org/apache/maven/continuum/management/JdoDataManagementTool.java
Fri Jan 16 23:27:10 2009
@@ -1,5 +1,24 @@
 package org.apache.maven.continuum.management;
 
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.continuum.dao.DaoUtils;
 import org.apache.continuum.dao.DirectoryPurgeConfigurationDao;
 import org.apache.continuum.dao.InstallationDao;
@@ -10,7 +29,9 @@
 import org.apache.continuum.dao.RepositoryPurgeConfigurationDao;
 import org.apache.continuum.dao.ScheduleDao;
 import org.apache.continuum.dao.SystemConfigurationDao;
+import org.apache.continuum.model.project.ProjectScmRoot;
 import org.apache.continuum.model.repository.LocalRepository;
+import org.apache.continuum.utils.ProjectSorter;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.ContinuumDatabase;
 import org.apache.maven.continuum.model.project.Project;
@@ -24,6 +45,9 @@
 import org.codehaus.plexus.jdo.ConfigurableJdoFactory;
 import org.codehaus.plexus.jdo.PlexusJdoUtils;
 import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.jdo.JDOHelper;
 import javax.jdo.PersistenceManagerFactory;
@@ -43,6 +67,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import java.util.Set;
 
 /**
  * JDO implementation the database management tool API.
@@ -52,6 +77,8 @@
 public class JdoDataManagementTool
     implements DataManagementTool
 {
+    private Logger log = LoggerFactory.getLogger( JdoDataManagementTool.class );
+    
     /**
      * @plexus.requirement
      */
@@ -266,12 +293,70 @@
                 projectGroup.setLocalRepository( localRepositories.get( 
                                                  Integer.valueOf( projectGroup.getLocalRepository().getId()
) ) );
             }
-
+            
             projectGroup = (ProjectGroup) PlexusJdoUtils.addObject( pmf.getPersistenceManager(),
projectGroup );
             projectGroups.put( Integer.valueOf( projectGroup.getId() ), projectGroup );
         }
+        
+        // create project scm root data (CONTINUUM-2040)
+        Map<Integer, ProjectScmRoot> projectScmRoots = new HashMap<Integer, ProjectScmRoot>();
+        Set<Integer> keys = projectGroups.keySet();
+        int id = 1;
+        for( Integer key : keys )
+        {
+            ProjectGroup projectGroup = projectGroups.get( key );            
+            String url = " ";
+            try
+            {                   
+                List<Project> projects =
+                    ProjectSorter.getSortedProjects( getProjectsByGroupIdWithDependencies(
pmf, projectGroup.getId() ),
+                                                     log );
+                for ( Iterator j = projects.iterator(); j.hasNext(); )
+                {
+                    Project project = (Project) j.next();
+                    if ( !project.getScmUrl().trim().startsWith( url ) )
+                    {
+                        url = project.getScmUrl();
+                        ProjectScmRoot projectScmRoot = new ProjectScmRoot();
+                        projectScmRoot.setId( id );                        
+                        projectScmRoot.setProjectGroup( projectGroup );
+                        projectScmRoot.setScmRootAddress( url );
+                        projectScmRoot.setState( project.getState() );
+                        
+                        projectScmRoot = (ProjectScmRoot) PlexusJdoUtils.addObject( pmf.getPersistenceManager(),
projectScmRoot );                        
+                        projectScmRoots.put( Integer.valueOf( projectScmRoot.getId() ), projectScmRoot
);
+                        id++;                                                
+                    }
+                }
+            }
+            catch ( CycleDetectedException e )
+            {
+                //skip
+                log.info( "Skipping group '" + projectGroup.getGroupId() +
+                    "' when creating ProjectScmRoot data. Cycle detected: " + e.getMessage()
);
+                continue;
+            }
+        }
     }
+    
+    private List<Project> getProjectsByGroupIdWithDependencies( PersistenceManagerFactory
pmf, int projectGroupId )
+    {
+        List<Project> allProjects =
+            PlexusJdoUtils.getAllObjectsDetached( pmf.getPersistenceManager(), Project.class,
"name ascending",
+                                                  "project-dependencies" );
+        List<Project> groupProjects = new ArrayList<Project>();
 
+        for ( Project project : allProjects )
+        {
+            if ( project.getProjectGroup().getId() == projectGroupId )
+            {
+                groupProjects.add( project );
+            }
+        }
+        
+        return groupProjects;
+    }
+    
     private static void processBuildDefinitions( List buildDefinitions, Map<Integer, Schedule>
schedules,
                                                  Map<Integer, Profile> profiles,
                                                  Map<Integer, LocalRepository> localRepositories
)

Modified: continuum/trunk/continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java?rev=735240&r1=735239&r2=735240&view=diff
==============================================================================
--- continuum/trunk/continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java
(original)
+++ continuum/trunk/continuum-data-management/data-management-jdo/src/test/java/org/apache/maven/continuum/management/DataManagementToolTest.java
Fri Jan 16 23:27:10 2009
@@ -57,7 +57,7 @@
 
         targetDirectory = createBackupDirectory();
     }
-
+    
 /*
     protected ContinuumStore createStore()
         throws Exception
@@ -76,8 +76,8 @@
 
     public void testBackupBuilds()
         throws IOException, ContinuumStoreException, XMLStreamException, Exception
-    {
-        createBuildDatabase();
+    {           
+        createBuildDatabase( true );
 
         // test sanity check
         assertBuildDatabase();
@@ -100,19 +100,19 @@
     public void testEraseBuilds()
         throws Exception
     {
-        createBuildDatabase();
+        createBuildDatabase( false );
 
         dataManagementTool.eraseDatabase();
 
-        assertEmpty();
+        assertEmpty( false );
     }
 
     public void testRestoreBuilds()
         throws Exception
     {
-        createBuildDatabase( false );
+        createBuildDatabase( false, true );
 
-        assertEmpty();
+        assertEmpty( true );
 
         File backupFile = new File( targetDirectory, BUILDS_XML );
 

Modified: continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java?rev=735240&r1=735239&r2=735240&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
(original)
+++ continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/AbstractContinuumStoreTestCase.java
Fri Jan 16 23:27:10 2009
@@ -176,13 +176,13 @@
         releaseResultDao = (ContinuumReleaseResultDao) lookup( ContinuumReleaseResultDao.class.getName()
);
     }
 
-    protected void createBuildDatabase()
+    protected void createBuildDatabase( boolean isTestFromDataManagementTool )
         throws Exception
     {
-        createBuildDatabase( true );
+        createBuildDatabase( true, isTestFromDataManagementTool );
     }
 
-    protected void createBuildDatabase( boolean addToStore )
+    protected void createBuildDatabase( boolean addToStore, boolean isTestFromDataManagementTool
)
         throws Exception
     {
         // Setting up test data
@@ -595,10 +595,41 @@
         systemConfiguration.setInitialized( true );
         systemConfiguration.setWorkingDirectory( "workingDirectory" );
 
-        if ( addToStore )
-        {
+        if ( addToStore && !isTestFromDataManagementTool )
+        {   
             systemConfiguration = systemConfigurationDao.addSystemConfiguration( systemConfiguration
);
         }
+        else
+        {
+            // hack for DataManagementTool test
+            // data-management-jdo has a dependency to continuum-commons where DefaultConfigurationService
+            //      is located. DefaultConfiguration loads the data and already adds a system
configuration, causing
+            //      this to throw an exception
+            boolean isExisting = false;
+            try
+            {
+                systemConfigurationDao.getSystemConfiguration();
+            }
+            catch ( ContinuumStoreException e )
+            {
+                isExisting = true;
+            }
+            
+            if( !isExisting )
+            {
+                systemConfiguration = systemConfigurationDao.getSystemConfiguration();
+                systemConfiguration.setBaseUrl( "baseUrl" );
+                systemConfiguration.setBuildOutputDirectory( "buildOutputDirectory" );
+                systemConfiguration.setDefaultScheduleCronExpression( "* * * * *" );
+                systemConfiguration.setDefaultScheduleDescription( "Description" );
+                systemConfiguration.setDeploymentRepositoryDirectory( "deployment" );
+                systemConfiguration.setGuestAccountEnabled( false );
+                systemConfiguration.setInitialized( true );
+                systemConfiguration.setWorkingDirectory( "workingDirectory" );
+                
+                systemConfigurationDao.updateSystemConfiguration( systemConfiguration );
+            }
+        }
         
         testProjectScmRoot = createTestProjectScmRoot( "scmRootAddress1", 1, 0, "error1",
group );
         
@@ -788,8 +819,7 @@
         store.addProjectGroup( group );
         testProjectGroup2.setId( group.getId() );
 */
-
-        assertSystemConfiguration( systemConfiguration, systemConfigurationDao.getSystemConfiguration()
);
+        assertSystemConfiguration( systemConfiguration, systemConfigurationDao.getSystemConfiguration()
);        
     }
 
     private void assertSystemConfiguration( SystemConfiguration expected, SystemConfiguration
actual )
@@ -805,14 +835,17 @@
         assertEquals( expected.getWorkingDirectory(), actual.getWorkingDirectory() );
     }
 
-    protected void assertEmpty()
+    protected void assertEmpty( boolean isTestFromDataManagementTool )
         throws ContinuumStoreException
     {
         assertEquals( 0, installationDao.getAllInstallations().size() );
         assertEquals( 0, profileDao.getAllProfilesByName().size() );
         assertEquals( 0, projectGroupDao.getAllProjectGroups().size() );
         assertEquals( 0, projectDao.getAllProjectsByName().size() );
-        assertNull( systemConfigurationDao.getSystemConfiguration() );
+        if( !isTestFromDataManagementTool )
+        {
+            assertNull( systemConfigurationDao.getSystemConfiguration() );
+        }
     }
 
     protected static BuildDefinition createTestBuildDefinition( BuildDefinition buildDefinition
)

Modified: continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java?rev=735240&r1=735239&r2=735240&view=diff
==============================================================================
--- continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
(original)
+++ continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
Fri Jan 16 23:27:10 2009
@@ -1381,7 +1381,7 @@
 
         buildResultDao = (BuildResultDao) lookup( BuildResultDao.class.getName() );
 
-        createBuildDatabase();
+        createBuildDatabase(false);
     }
 
     private static void checkProjectFetchGroup( Project project, boolean checkoutFetchGroup,



Mime
View raw message