You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by oc...@apache.org on 2009/04/30 11:53:07 UTC

svn commit: r770135 - in /continuum/branches/continuum-flat-multi-module/continuum-commons: ./ src/main/java/org/apache/maven/continuum/utils/ src/test/java/org/apache/maven/continuum/utils/

Author: oching
Date: Thu Apr 30 09:53:07 2009
New Revision: 770135

URL: http://svn.apache.org/viewvc?rev=770135&view=rev
Log:
[CONTINUUM-2193]
o determine correct working directory of multi-module projects checked out in a single directory
o added tests

Added:
    continuum/branches/continuum-flat-multi-module/continuum-commons/src/test/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryServiceTest.java
Modified:
    continuum/branches/continuum-flat-multi-module/continuum-commons/pom.xml
    continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ChrootJailWorkingDirectoryService.java
    continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryService.java

Modified: continuum/branches/continuum-flat-multi-module/continuum-commons/pom.xml
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-commons/pom.xml?rev=770135&r1=770134&r2=770135&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-commons/pom.xml (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-commons/pom.xml Thu Apr 30 09:53:07 2009
@@ -97,5 +97,32 @@
       <artifactId>continuum-test</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.jmock</groupId>
+      <artifactId>jmock-junit3</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <!-- dependency of jmock3 -->
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib-nodep</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <!-- dependency of jmock3 -->
+    <dependency>
+      <groupId>org.objenesis</groupId>
+      <artifactId>objenesis</artifactId>  
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>jmock</groupId>
+      <artifactId>jmock</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Modified: continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ChrootJailWorkingDirectoryService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ChrootJailWorkingDirectoryService.java?rev=770135&r1=770134&r2=770135&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ChrootJailWorkingDirectoryService.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/ChrootJailWorkingDirectoryService.java Thu Apr 30 09:53:07 2009
@@ -20,6 +20,8 @@
  */
 
 import java.io.File;
+import java.util.List;
+
 import javax.annotation.Resource;
 
 import org.apache.maven.continuum.configuration.ConfigurationService;
@@ -71,4 +73,9 @@
         f = new File( f, getConfigurationService().getWorkingDirectory().getPath() );
         return new File( f, Integer.toString( project.getId() ) );
     }
+    
+    public File getWorkingDirectory( Project project, String projectScmRoot, List<Project> projects )
+    {
+        return null;
+    }
 }

Modified: continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryService.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryService.java?rev=770135&r1=770134&r2=770135&view=diff
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryService.java (original)
+++ continuum/branches/continuum-flat-multi-module/continuum-commons/src/main/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryService.java Thu Apr 30 09:53:07 2009
@@ -21,9 +21,11 @@
 
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.model.project.Project;
+import org.codehaus.plexus.util.StringUtils;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.util.List;
 
 import javax.annotation.Resource;
 
@@ -54,15 +56,52 @@
 
     public File getWorkingDirectory( Project project )
     {
+        return getWorkingDirectory( project, null, null );
+    }
+    
+    /**
+     * 
+     * @param project
+     * @param projectScmRoot
+     * @param projects projects under the same projectScmRoot
+     * @return
+     */
+    public File getWorkingDirectory( Project project, String projectScmRoot, List<Project> projects )
+    {
 //        TODO: Enable, this is what we really want
 //        ContinuumProjectGroup projectGroup = project.getProjectGroup();
 //
 //        return new File( projectGroup.getWorkingDirectory(),
 //                         project.getPath() );
-
-        if ( project.getWorkingDirectory() == null )
-        {
-            project.setWorkingDirectory( Integer.toString( project.getId() ) );
+        
+        if ( project.getWorkingDirectory() == null || "".equals( project.getWorkingDirectory() ) )
+        {   
+            if( projectScmRoot == null || "".equals( projectScmRoot ) )
+            {
+                project.setWorkingDirectory( Integer.toString( project.getId() ) );
+            }
+            else
+            {
+                if( projects != null && !projects.isEmpty() )
+                {
+                    // the root project should have the lowest id since it's always added first
+                    Project rootProject = projects.get( 0 );
+                    for( Project projectUnderScmRoot : projects )
+                    {
+                        if( projectUnderScmRoot.getId() < rootProject.getId() )
+                        {
+                            rootProject = projectUnderScmRoot;
+                        }
+                    }
+                    
+                    // determine the path
+                    String projectScmUrl = project.getScmUrl();                    
+                    int indexDiff = StringUtils.differenceAt( projectScmUrl, projectScmRoot );
+                    
+                    String pathToProject = projectScmUrl.substring( indexDiff );      
+                    project.setWorkingDirectory( Integer.toString( rootProject.getId() ) + pathToProject );
+                }
+            }
         }
 
         File workDir;
@@ -86,8 +125,20 @@
         }
         else
         {
-            workDir = new File( getConfigurationService().getWorkingDirectory(), project.getWorkingDirectory() );
+            File baseWorkingDir = getConfigurationService().getWorkingDirectory();            
+            
+            // windows path
+            if( baseWorkingDir.getPath().indexOf( '\\' ) != -1 )
+            {
+                project.setWorkingDirectory( project.getWorkingDirectory().replace( '/', '\\' ) );
+                workDir = new File( baseWorkingDir.getPath() + "\\" + project.getWorkingDirectory() );
+            }
+            else
+            {
+                workDir = new File( baseWorkingDir, project.getWorkingDirectory() );
+            }            
         }
+        
         return workDir;
     }
 }

Added: continuum/branches/continuum-flat-multi-module/continuum-commons/src/test/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-flat-multi-module/continuum-commons/src/test/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryServiceTest.java?rev=770135&view=auto
==============================================================================
--- continuum/branches/continuum-flat-multi-module/continuum-commons/src/test/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryServiceTest.java (added)
+++ continuum/branches/continuum-flat-multi-module/continuum-commons/src/test/java/org/apache/maven/continuum/utils/DefaultWorkingDirectoryServiceTest.java Thu Apr 30 09:53:07 2009
@@ -0,0 +1,131 @@
+package org.apache.maven.continuum.utils;
+
+/*
+ * 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 java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.codehaus.plexus.spring.PlexusInSpringTestCase;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.integration.junit3.JUnit3Mockery;
+
+/**
+ * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
+ * @version 
+ */
+public class DefaultWorkingDirectoryServiceTest
+    extends PlexusInSpringTestCase
+{
+    private DefaultWorkingDirectoryService workingDirectoryService;
+    
+    private Mockery context;
+    
+    private ConfigurationService configurationService;
+    
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+        
+        context = new JUnit3Mockery();
+        
+        configurationService = context.mock( ConfigurationService.class );
+        
+        workingDirectoryService = ( DefaultWorkingDirectoryService ) lookup( WorkingDirectoryService.class );
+        
+        workingDirectoryService.setConfigurationService( configurationService );
+    }
+    
+    public void testGetWorkingDirectoryOfSingleCheckoutMultiModules()
+        throws Exception
+    {
+        ProjectGroup pGroup = new ProjectGroup();
+        pGroup.setId( 1 );
+        
+        List<Project> projects = new ArrayList<Project>();
+        
+        Project project = new Project();        
+        project.setId( 7 );
+        project.setGroupId( "org.apache.continuum" );
+        project.setArtifactId( "module-a" );
+        project.setVersion( "1.0-SNAPSHOT" );
+        project.setScmUrl( "scm:local:src/test-projects:flat-multi-module/module-a" );
+        
+        projects.add( project );
+        
+        Project otherProject = new Project();        
+        otherProject.setId( 8 );
+        otherProject.setGroupId( "org.apache.continuum" );
+        otherProject.setArtifactId( "module-b" );
+        otherProject.setVersion( "1.0-SNAPSHOT" );
+        otherProject.setScmUrl( "scm:local:src/test-projects:flat-multi-module/module-b" );
+        
+        projects.add( otherProject );
+        
+        otherProject = new Project();        
+        otherProject.setId( 6 );
+        otherProject.setGroupId( "org.apache.continuum" );
+        otherProject.setArtifactId( "parent-project" );
+        otherProject.setVersion( "1.0-SNAPSHOT" );
+        otherProject.setScmUrl( "scm:local:src/test-projects:flat-multi-module/parent-project" );
+        
+        projects.add( otherProject );
+                
+        final File unixBaseWorkingDirectory = new File( "/target/working-directory" );        
+     
+        final File windowsBaseWorkingDirectory = new File( "c:\\target\\working-directory" );
+        
+        context.checking( new Expectations()
+        {
+            {
+                one( configurationService ).getWorkingDirectory();
+                will( returnValue( unixBaseWorkingDirectory ) );
+                
+                one( configurationService ).getWorkingDirectory();
+                will( returnValue( windowsBaseWorkingDirectory ) );
+            }} );
+        
+     // test if unix path
+        File projectWorkingDirectory =
+            workingDirectoryService.getWorkingDirectory( project, "scm:local:src/test-projects:flat-multi-module",
+                                                         projects );
+        
+        assertEquals( "Incorrect working directory for multi-module project", "/target/working-directory/6/module-a",
+                      projectWorkingDirectory.getPath() );
+            
+        project.setWorkingDirectory( null );
+        
+     // test if windows path
+        projectWorkingDirectory =
+            workingDirectoryService.getWorkingDirectory( project, "scm:local:src/test-projects:flat-multi-module",
+                                                         projects );
+        
+        assertEquals( "Incorrect working directory for multi-module project", "c:\\target\\working-directory\\6\\module-a",
+                      projectWorkingDirectory.getPath() );
+
+    }
+    
+    
+}