Author: dantran Date: Sat Nov 18 00:02:58 2006 New Revision: 476464 URL: http://svn.apache.org/viewvc?view=rev&rev=476464 Log: SCM-249: fix starteam update command
Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommand.java maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommandTest.java Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommand.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/update/StarteamUpdateCommand.java?view=diff&rev=476464&r1=476463&r2=476464 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommand.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/main/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommand.java Sat Nov 18 00:02:58 2006 @@ -33,6 +33,7 @@ import org.codehaus.plexus.util.cli.StreamConsumer; import java.io.File; +import java.util.List; /** * @author <a href="mailto:[EMAIL PROTECTED]">Dan T. Tran</a> @@ -58,12 +59,12 @@ CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); - File[] checkInFiles = fileSet.getFiles(); + List updateFiles = fileSet.getFileList(); - if ( checkInFiles.length == 0 ) + if ( updateFiles.size() == 0 ) { //update everything - Commandline cl = createCommandLine( repository, fileSet.getBasedir(), tag ); + Commandline cl = createCommandLine( repository, fileSet, tag ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); @@ -86,9 +87,11 @@ else { //update only interested files already on the local disk - for ( int i = 0; i < checkInFiles.length; ++i ) + for ( int i = 0; i < updateFiles.size(); ++i ) { - Commandline cl = createCommandLine( repository, checkInFiles[i], tag ); + File updateFile = (File) updateFiles.get( i ); + ScmFileSet scmFileSet = new ScmFileSet( fileSet.getBasedir(), updateFile ); + Commandline cl = createCommandLine( repository, scmFileSet, tag ); int exitCode = StarteamCommandLineUtils.executeCommandline( cl, consumer, stderr, getLogger() ); @@ -108,9 +111,9 @@ // // ---------------------------------------------------------------------- - public static Commandline createCommandLine( StarteamScmProviderRepository repo, File dirOrFile, String tag ) + public static Commandline createCommandLine( StarteamScmProviderRepository repo, ScmFileSet fileSet, String tag ) { - Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "co", dirOrFile, repo ); + Commandline cl = StarteamCommandLineUtils.createStarteamBaseCommandLine( "co", fileSet, repo ); cl.createArgument().setValue( "-merge" ); @@ -123,13 +126,14 @@ cl.createArgument().setValue( tag ); } - if ( dirOrFile.isDirectory() ) + if ( fileSet.getFileList().size() == 0 ) { cl.createArgument().setValue( "-is" ); } else { - cl.createArgument().setValue( dirOrFile.getName() ); + File updateFile = (File) fileSet.getFileList().get( 0 ); + cl.createArgument().setValue( updateFile.getName() ); } return cl; Modified: maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommandTest.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/update/StarteamUpdateCommandTest.java?view=diff&rev=476464&r1=476463&r2=476464 ============================================================================== --- maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommandTest.java (original) +++ maven/scm/trunk/maven-scm-providers/maven-scm-provider-starteam/src/test/java/org/apache/maven/scm/provider/starteam/command/update/StarteamUpdateCommandTest.java Sat Nov 18 00:02:58 2006 @@ -34,60 +34,74 @@ public void testGetCommandLineWithWorkingDirectory() throws Exception { - File workDir = new File( getBasedir() + "/target" ); - - String absolutePath = 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 " + - absolutePath + " -merge -neverprompt -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 + + " -merge -neverprompt -vl myTag -is" ; + + testCommandLine( mavenUrl, workingCopy, "myTag", expectedCmd ); + } public void testGetCommandLineWithFileOnRoot() throws Exception { - System.out.println( "testGetCommandLineWithFileOnRoot" ); - - File testFile = new File( "testfile" ); - - String testFileAbsolutePath = StarteamCommandLineUtils.toJavaPath( testFile.getAbsoluteFile().getParent() ); - - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", testFile, "myTag", - "stcmd co -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl " + "-fp " + - testFileAbsolutePath + " -merge -neverprompt -vl myTag " + "testfile" ); + ScmFileSet workingCopy = new ScmFileSet( this.getWorkingCopy(), new File( "test.txt") ); + + 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 + + " -merge -neverprompt -vl myTag" + + " test.txt"; + + testCommandLine( mavenUrl, workingCopy, "myTag", expectedCmd ); } public void testGetCommandLineWithFileInSubDir() throws Exception { - ScmFileSet fileSet = new ScmFileSet( new File( getBasedir() ), "**/*.java", null ); - - File [] files = fileSet.getFiles(); - - File testFile = files[0]; - - String absolutePath = StarteamCommandLineUtils.toJavaPath( testFile.getAbsoluteFile().getParent() ); - - testCommandLine( "scm:starteam:myusername:[EMAIL PROTECTED]:1234/projecturl", testFile, "myTag", - "stcmd co -x -nologo -stop -p myusername:[EMAIL PROTECTED]:1234/projecturl/" + - StarteamCommandLineUtils.toJavaPath( testFile.getParent() ) + " -fp " + absolutePath + - " -merge -neverprompt -vl myTag " + testFile.getName() ); + ScmFileSet workingCopy = new ScmFileSet( this.getWorkingCopy(), new File( "subdir/test.txt" ) ); + + 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 + "/subdir" + + " -fp " + workDirAbsolutePath + "/subdir" + + " -merge -neverprompt -vl myTag" + + " test.txt"; + + testCommandLine( mavenUrl, workingCopy, "myTag", expectedCmd ); } // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- - private void testCommandLine( String scmUrl, File testFileOrDir, String tag, String commandLine ) + private void testCommandLine( String scmUrl, ScmFileSet fileSet, String tag, String commandLine ) throws Exception { ScmRepository repo = getScmManager().makeScmRepository( scmUrl ); StarteamScmProviderRepository repository = (StarteamScmProviderRepository) repo.getProviderRepository(); - Commandline cl = StarteamUpdateCommand.createCommandLine( repository, testFileOrDir, tag ); + Commandline cl = StarteamUpdateCommand.createCommandLine( repository, fileSet, tag ); System.out.println( commandLine );