maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r326584 - in /maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src: main/java/org/apache/maven/scm/provider/starteam/command/ main/java/org/apache/maven/scm/provider/starteam/command/add/ main/java/org/apache/maven/scm/provid...
Date Wed, 19 Oct 2005 15:37:27 GMT
Author: evenisse
Date: Wed Oct 19 08:37:15 2005
New Revision: 326584

URL: http://svn.apache.org/viewcvs?rev=326584&view=rev
Log:
PR: SCM-62
Submitted by Dan Tran
Fix commands when working directory contains ".."

Modified:
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumer.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumer.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveConsumer.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumerTest.java
    maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumerTest.java

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java
Wed Oct 19 08:37:15 2005
@@ -25,6 +25,7 @@
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
 import java.io.File;
+import java.io.IOException;
 
 /**
  * Command line construction utility.
@@ -166,4 +167,37 @@
             throw new ScmException( "Error while executing command.", ex );
         }
     }
+    
+    /**
+     * Given 2 paths, make sure parent and child are on the same tree
+     * return the port of child that not in parent 
+     * @param parent
+     * @param child
+     * @return
+     */
+    public static String getRelativeChildDirectory( String parent, String child )
+    {
+        //expect parentDir contains childDir
+        try 
+        {
+            String childPath = new File( child ).getCanonicalFile().getPath().replace( '\\',
'/' );
+        
+            String parentPath = new File( parent ).getCanonicalFile().getPath().replace(
'\\', '/' );
+            
+            if ( !childPath.startsWith( parentPath ) )
+            {  
+                throw new IllegalStateException();
+            }
+            
+            String retDir = "." + childPath.substring( parentPath.length() );
+
+            return retDir;
+            
+        }
+        catch ( IOException e )
+        {
+            throw new IllegalStateException( "Unable to convert to canonical path of either
" + parent + " or " + child );
+        }
+    }
+    
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumer.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumer.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumer.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumer.java
Wed Oct 19 08:37:15 2005
@@ -19,6 +19,7 @@
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileStatus;
 import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
 import java.util.ArrayList;
@@ -98,16 +99,22 @@
     {
         String dirPath = line.substring( pos + DIR_MARKER.length(), line.length() - 1 ).replace(
'\\', '/' );
 
-        if ( !dirPath.startsWith( workingDirectory ) )
+        try 
         {
-            logger.info( "Working directory: " + workingDirectory );
-
-            logger.info( "Checkin directory path: " + dirPath );
-
-            throw new IllegalStateException( "Working and checkin directories are not on
the same tree" );
+            this.currentDir = StarteamCommandLineUtils.getRelativeChildDirectory( this.workingDirectory,
dirPath );
+        }
+        catch ( IllegalStateException e )
+        {
+            String error = "Working and checkout directories are not on the same tree";
+            
+            logger.error( error );
+            
+            logger.error( "Working directory: " + workingDirectory );
+            
+            logger.error( "Checked out directory: " + dirPath );
+            
+            throw new IllegalStateException( error );
         }
-
-        this.currentDir = "." + dirPath.substring( workingDirectory.length() );
     }
 
     private void processAddedFile( String line, int pos )

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumer.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumer.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumer.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumer.java
Wed Oct 19 08:37:15 2005
@@ -16,14 +16,17 @@
  * limitations under the License.
  */
 
+import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileStatus;
 import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.io.File;
+import java.io.IOException;
 
 /**
  * @author <a href="mailto:dantran@gmail.com">Dan T. Tran</a>
@@ -98,17 +101,24 @@
     private void processDirectory( String line, int pos )
     {
         String dirPath = line.substring( pos + DIR_MARKER.length(), line.length() - 1 ).replace(
'\\', '/' );
-
-        if ( !dirPath.startsWith( workingDirectory ) )
+        
+        try 
         {
-            logger.info( "Working directory: " + workingDirectory );
-
-            logger.info( "Checked out directory: " + dirPath );
-
-            throw new IllegalStateException( "Working and check out directories are not on
the same tree" );
+            this.currentDir = StarteamCommandLineUtils.getRelativeChildDirectory( this.workingDirectory,
dirPath );
+        }
+        catch ( IllegalStateException e )
+        {
+            String error = "Working and checkout directories are not on the same tree";
+            
+            logger.error( error );
+            
+            logger.error( "Working directory: " + workingDirectory );
+            
+            logger.error( "Checked out directory: " + dirPath );
+            
+            throw new IllegalStateException( error );
         }
 
-        this.currentDir = "." + dirPath.substring( workingDirectory.length() );
     }
 
     private void processCheckedOutFile( String line, int pos )

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveConsumer.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveConsumer.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveConsumer.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveConsumer.java
Wed Oct 19 08:37:15 2005
@@ -19,6 +19,7 @@
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileStatus;
 import org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils;
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
 import java.util.ArrayList;
@@ -98,16 +99,22 @@
     {
         String dirPath = line.substring( pos + DIR_MARKER.length(), line.length() - 1 ).replace(
'\\', '/' );
 
-        if ( !dirPath.startsWith( workingDirectory ) )
+        try 
         {
-            logger.info( "Working directory: " + workingDirectory );
-
-            logger.info( "Checkin directory path: " + dirPath );
-
-            throw new IllegalStateException( "Working and remove directories are not on the
same tree" );
+            this.currentDir = StarteamCommandLineUtils.getRelativeChildDirectory( this.workingDirectory,
dirPath );
+        }
+        catch ( IllegalStateException e )
+        {
+            String error = "Working and checkout directories are not on the same tree";
+            
+            logger.error( error );
+            
+            logger.error( "Working directory: " + workingDirectory );
+            
+            logger.error( "Checked out directory: " + dirPath );
+            
+            throw new IllegalStateException( error );
         }
-
-        this.currentDir = "." + dirPath.substring( workingDirectory.length() );
     }
 
     private void processRemovedFile( String line, int pos )

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumerTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumerTest.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumerTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/add/StarteamAddConsumerTest.java
Wed Oct 19 08:37:15 2005
@@ -76,4 +76,5 @@
         
         
     }
+    
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumerTest.java
URL: http://svn.apache.org/viewcvs/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumerTest.java?rev=326584&r1=326583&r2=326584&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumerTest.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutConsumerTest.java
Wed Oct 19 08:37:15 2005
@@ -50,12 +50,10 @@
 		
     };
     
-    public void testParse()
+    private void testParse( File basedir )
         throws Exception
     {
         
-		File basedir = new File( "/usr/scm-starteam/driver" );
-        
         StarteamCheckOutConsumer consumer = new StarteamCheckOutConsumer( new DefaultLog(),
basedir );
 
         for ( int i = 0; i < TEST_OUTPUT.length; ++ i )
@@ -79,4 +77,21 @@
         }
         
     }
+    
+    public void testParseWithNoRelativeWorkingDirectory()
+        throws Exception
+    {
+        File basedir = new File( "/usr/scm-starteam/driver" );
+        
+        testParse( basedir );
+    }
+    
+    public void testParseWithRelativeWorkingDirectory()
+        throws Exception
+    {
+        File basedir = new File( "/usr/scm-starteam/junk/junk2/../../driver" );
+
+        testParse( basedir );
+    }
+    
 }



Mime
View raw message