Author: dantran Date: Fri Nov 17 08:46:55 2006 New Revision: 476208 URL: http://svn.apache.org/viewvc?view=rev&rev=476208 Log: SCM-249: Remove restriction to require ScmFileSet's basedir not to be the same with user working directory. Clean up tests to use infrastructure provided by ScmTestCase base class
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/checkout/StarteamCheckOutCommand.java maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommand.java maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommandTest.java maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommandTest.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/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/StarteamCommandLineUtils.java?view=diff&rev=476208&r1=476207&r2=476208 ============================================================================== --- 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 Fri Nov 17 08:46:55 2006 @@ -120,6 +120,14 @@ return cl; } + /** + * Create stcmd command base on ScmFileSet contents. + * The fileset can not have more then one files. + * @param action + * @param scmFileSet + * @param repo + * @return + */ public static Commandline createStarteamBaseCommandLine( String action, ScmFileSet scmFileSet, StarteamScmProviderRepository repo ) { @@ -137,6 +145,10 @@ return cl; } + + //Perform an scm action on a single file where the orignal + // url and local directory ( -p and -fp options ) are altered + // to deal with single file File file = (File) scmFileSet.getFileList().get( 0 ); Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommand.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommand.java?view=diff&rev=476208&r1=476207&r2=476208 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommand.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommand.java Fri Nov 17 08:46:55 2006 @@ -45,7 +45,7 @@ protected CheckOutScmResult executeCheckOutCommand( ScmProviderRepository repo, ScmFileSet fileSet, String tag ) throws ScmException { - if ( fileSet.getFiles().length != 0 ) + if ( fileSet.getFileList().size() != 0 ) { throw new ScmException( "This provider doesn't support checking out subsets of a directory" ); } @@ -58,7 +58,7 @@ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); - Commandline cl = createCommandLine( repository, fileSet.getBasedir(), tag ); + Commandline cl = createCommandLine( repository, fileSet, tag ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); @@ -74,9 +74,9 @@ // // ---------------------------------------------------------------------- - public static Commandline createCommandLine( StarteamScmProviderRepository repo, File workingDirectory, String tag ) + public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet baseDir, String tag ) { - Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "co", workingDirectory, repo ); + Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "co", baseDir, repo ); if ( tag != null && tag.trim().length() != 0 ) { Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommand.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommand.java?view=diff&rev=476208&r1=476207&r2=476208 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommand.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommand.java Fri Nov 17 08:46:55 2006 @@ -30,6 +30,7 @@ import org.codehaus.plexus.util.cli.Commandline; import java.io.File; +import java.util.List; /** * @author <a href="mailto:[EMAIL PROTECTED]">Dan T. Tran</a> @@ -51,11 +52,11 @@ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); - File[] checkInFiles = fileSet.getFiles(); + List remvoveFiles = fileSet.getFileList(); - if ( checkInFiles.length == 0 ) + if ( remvoveFiles.size() == 0 ) { - Commandline cl = createCommandLine( repository, fileSet.getBasedir() ); + Commandline cl = createCommandLine( repository, fileSet ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); @@ -67,9 +68,11 @@ else { //update only interested files already on the local disk - for ( int i = 0; i < checkInFiles.length; ++i ) + for ( int i = 0; i < remvoveFiles.size(); ++i ) { - Commandline cl = createCommandLine( repository, checkInFiles[i] ); + File fileToBeRemoved = (File) remvoveFiles.get( i ); + ScmFileSet scmFileSet = new ScmFileSet( fileSet.getBasedir(), fileToBeRemoved ); + Commandline cl = createCommandLine( repository, scmFileSet ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); @@ -85,21 +88,19 @@ } - public static Commandline createCommandLine( StarteamScmProviderRepository repo, File dirOrFile ) + public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet dirOrFile ) { Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "remove", dirOrFile, repo ); - if ( dirOrFile.isDirectory() ) + if ( dirOrFile.getFileList().size() == 0 ) { cl.createArgument().setValue( "-is" ); } else { - cl.createArgument().setValue( dirOrFile.getName() ); + File fileToBeRemoved = (File) dirOrFile.getFileList().get(0); + cl.createArgument().setValue( fileToBeRemoved.getName() ); } - - //remove working file(s) - //cl.createArgument().setValue( "-df" ); return cl; } Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommandTest.java?view=diff&rev=476208&r1=476207&r2=476208 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/checkout/StarteamCheckOutCommandTest.java Fri Nov 17 08:46:55 2006 @@ -16,14 +16,13 @@ * limitations under the License. */ +import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmTestCase; import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils; import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository; import org.apache.maven.scm.repository.ScmRepository; import org.codehaus.plexus.util.cli.Commandline; -import java.io.File; - /** * @author <a href="mailto:[EMAIL PROTECTED]">Emmanuel Venisse</a> * @version $Id$ @@ -31,43 +30,36 @@ public class StarteamCheckOutCommandTest extends ScmTestCase { - public void testGetCommandLineWithWorkingDirectory() + public void testGetCommandLine() throws Exception { - //note that workDir must exists, make should have already created it - File workDir = new File( getBasedir() + "/target" ); - - String workDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( workDir.getAbsolutePath() ); - - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", workDir, "myTag", - "stcmd co -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl " + "-fp " + - workDirAbsolutePath + " -vl myTag -is" ); - } - - public void testGetCommandLineWithWorkingDirectoryAsAbsolutePath() - throws Exception - { - File workDir = new File( getBasedir() + "/target" ); - - String workDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( workDir.getAbsolutePath() ); - - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", workDir.getAbsoluteFile(), - "myTag", "stcmd co -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl " + - "-fp " + workDirAbsolutePath + " -vl myTag -is" ); + ScmFileSet workingCopy = new ScmFileSet( this.getWorkingCopy() ); + + String workDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( workingCopy.getBasedir().getAbsolutePath() ); + + String starteamUrl = "user:[EMAIL PROTECTED]:1234/project/view"; + String mavenUrl = "scm:starteam:" + starteamUrl; + + String expectedCmd = "stcmd co -x -nologo -stop" + + " -p " + starteamUrl + + " -fp " + workDirAbsolutePath + + " -vl myTag -is" ; + + testCommandLine( mavenUrl, workingCopy, "myTag", expectedCmd ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - private void testCommandLine( String scmUrl, File workDir, String tag, String commandLine ) + private void testCommandLine( String scmUrl, ScmFileSet workingCopy, String tag, String commandLine ) throws Exception { ScmRepository repo = getScmManager().makeScmRepository( scmUrl ); StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository(); - Commandline cl = StarteamCheckOutCommand.createCommandLine( repository, workDir, tag ); + Commandline cl = StarteamCheckOutCommand.createCommandLine( repository, workingCopy, tag ); assertEquals( commandLine, cl.toString() ); } Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommandTest.java URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommandTest.java?view=diff&rev=476208&r1=476207&r2=476208 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/remove/StarteamRemoveCommandTest.java Fri Nov 17 08:46:55 2006 @@ -16,6 +16,7 @@ * limitations under the License. */ +import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.ScmTestCase; import org.apache.maven.scm.provider.starteam.command.StarteamCommandLineUtils; import org.apache.maven.scm.provider.starteam.repository.StarteamScmProviderRepository; @@ -30,37 +31,41 @@ public class StarteamRemoveCommandTest extends ScmTestCase { - + public void testGetCommandLineWithFileOnRoot() throws Exception { + ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "testfile.txt" ) ); - File testFile = new File( "testfile" ); - - File testFileDir = testFile.getAbsoluteFile().getParentFile(); - - String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ); - - String expectedCmd = "stcmd remove -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl" + " -fp " + - testFileDirAbsolutePath + " testfile"; + String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( getWorkingCopy().getPath() ); - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", testFile, "", expectedCmd ); + String starteamUrl = "user:[EMAIL PROTECTED]:1234/project/view"; + String mavenUrl = "scm:starteam:" + starteamUrl; + + String expectedCmd = "stcmd remove -x -nologo -stop" + + " -p " + starteamUrl + + " -fp " + testFileDirAbsolutePath + + " testfile.txt" ; + + testCommandLine( mavenUrl, fileSet, "", expectedCmd ); } public void testGetCommandLineWithFileInSubDir() throws Exception { - File testFile = new File( "target/testfile" ); - - File testFileDir = testFile.getAbsoluteFile().getParentFile(); - - String testFileDirAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFileDir.getAbsolutePath() ); - - String expectedCmd = "stcmd remove -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl/target" + - " -fp " + testFileDirAbsolutePath + " testfile"; + ScmFileSet fileSet = new ScmFileSet( getWorkingCopy(), new File( "dir/testfile.txt" ) ); - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", testFile, null, expectedCmd ); + String starteamUrl = "user:[EMAIL PROTECTED]:1234/project/view"; + String mavenUrl = "scm:starteam:" + starteamUrl; + + String localDirectory = StarteamCommandLineUtils.toJavaPath( getWorkingDirectory().getPath() + "/dir" ); + String expectedCmd = "stcmd remove -x -nologo -stop" + + " -p " + starteamUrl + "/dir" + + " -fp " + localDirectory + + " testfile.txt" ; + + testCommandLine( mavenUrl, fileSet, null, expectedCmd ); } @@ -68,14 +73,14 @@ // // ---------------------------------------------------------------------- - private void testCommandLine( String scmUrl, File fileName, String crPath, String commandLine ) + private void testCommandLine( String scmUrl, ScmFileSet fileSet, String crPath, String commandLine ) throws Exception { ScmRepository repo = getScmManager().makeScmRepository( scmUrl ); StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository(); - Commandline cl = StarteamRemoveCommand.createCommandLine( repository, fileName ); + Commandline cl = StarteamRemoveCommand.createCommandLine( repository, fileSet ); assertEquals( commandLine, cl.toString() ); }