You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by tr...@apache.org on 2004/10/29 13:52:03 UTC
cvs commit: maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/update AbstractUpdateCommandTest.java
trygvis 2004/10/29 04:52:03
Modified: maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/checkout
LocalCheckOutCommand.java
maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/update
LocalUpdateCommand.java
maven-scm-providers/maven-scm-provider-local/src/main/resources/META-INF/plexus
components.xml
maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/checkout
LocalCheckoutCommandTest.java
maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/update
AbstractUpdateCommandTest.java
Added: maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/checkin
LocalCheckInCommand.java
maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/checkin
LocalCheckInCommandTest.java
Log:
o Adding a check in command.
Revision Changes Path
1.1 maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/checkin/LocalCheckInCommand.java
Index: LocalCheckInCommand.java
===================================================================
package org.apache.maven.scm.provider.local.command.checkin;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.scm.ScmFileStatus;
import org.apache.maven.scm.command.checkin.AbstractCheckInCommand;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
import org.apache.maven.scm.provider.ScmProviderRepository;
import org.apache.maven.scm.provider.local.command.LocalCommand;
import org.apache.maven.scm.provider.local.repository.LocalScmProviderRepository;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
* @version $Id: LocalCheckInCommand.java,v 1.1 2004/10/29 11:52:03 trygvis Exp $
*/
public class LocalCheckInCommand
extends AbstractCheckInCommand
implements LocalCommand
{
protected CheckInScmResult executeCheckInCommand( ScmProviderRepository repo, File workingDirectory, String message, String tag, File[] files )
throws ScmException
{
LocalScmProviderRepository repository = (LocalScmProviderRepository) repo;
if ( !StringUtils.isEmpty( tag ) )
{
throw new ScmException( "The local scm doesn't support tags." );
}
File root = new File( repository.getRoot() );
String module = repository.getModule();
File source = new File( root, module );
File baseDestination = workingDirectory;
if ( !workingDirectory.exists() )
{
throw new ScmException( "The working directory doesn't exist (" + workingDirectory.getAbsolutePath() + ")." );
}
if ( !root.exists() )
{
throw new ScmException( "The base directory doesn't exist (" + root.getAbsolutePath() + ")." );
}
if ( !source.exists() )
{
throw new ScmException( "The module directory doesn't exist (" + source.getAbsolutePath() + ")." );
}
List checkedInFiles = new ArrayList();
try
{
// Only copy files newer than in the repo
File repoRoot = new File( repository.getRoot(), repository.getModule() );
Iterator it = FileUtils.getFiles( workingDirectory, "**", null ).iterator();
while ( it.hasNext() )
{
File file = (File) it.next();
String path = file.getAbsolutePath().substring( workingDirectory.getAbsolutePath().length());
File repoFile = new File( repoRoot, path );
ScmFileStatus status;
if ( repoFile.exists() )
{
String repoFileContents = FileUtils.fileRead( repoFile );
String fileContents = FileUtils.fileRead( file );
System.err.println("fileContents:" + fileContents);
System.err.println("repoFileContents:" + repoFileContents);
if ( fileContents.equals( repoFileContents ) )
{
continue;
}
status = ScmFileStatus.CHECKED_IN;
}
else
{
status = ScmFileStatus.ADDED;
}
FileUtils.copyFile( file, repoFile );
System.err.println(new ScmFile( path, status ));
checkedInFiles.add( new ScmFile( path, status ) );
}
}
catch( IOException ex )
{
throw new ScmException( "Error while checking in the files.", ex );
}
return new CheckInScmResult( checkedInFiles );
}
}
1.5 +2 -2 maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/checkout/LocalCheckOutCommand.java
Index: LocalCheckOutCommand.java
===================================================================
RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/checkout/LocalCheckOutCommand.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- LocalCheckOutCommand.java 28 Oct 2004 13:07:51 -0000 1.4
+++ LocalCheckOutCommand.java 29 Oct 2004 11:52:03 -0000 1.5
@@ -87,7 +87,7 @@
throw new ScmException( "Could not create destination directory '" + baseDestination.getAbsolutePath() + "'." );
}
- getLogger().debug( "Checking out '" + source.getAbsolutePath() + "' to '" + baseDestination.getAbsolutePath() + "'." );
+ getLogger().info( "Checking out '" + source.getAbsolutePath() + "' to '" + baseDestination.getAbsolutePath() + "'." );
List fileList;
1.4 +2 -2 maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/update/LocalUpdateCommand.java
Index: LocalUpdateCommand.java
===================================================================
RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/java/org/apache/maven/scm/provider/local/command/update/LocalUpdateCommand.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- LocalUpdateCommand.java 28 Oct 2004 13:07:51 -0000 1.3
+++ LocalUpdateCommand.java 29 Oct 2004 11:52:03 -0000 1.4
@@ -85,7 +85,7 @@
try
{
- getLogger().debug( "Updating '" + baseDestination.getAbsolutePath() + "' from '" + source.getAbsolutePath() + "'." );
+ getLogger().info( "Updating '" + baseDestination.getAbsolutePath() + "' from '" + source.getAbsolutePath() + "'." );
List fileList = FileUtils.getFiles( source.getAbsoluteFile(), "**", null );
1.3 +6 -0 maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/resources/META-INF/plexus/components.xml
Index: components.xml
===================================================================
RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-local/src/main/resources/META-INF/plexus/components.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- components.xml 26 Oct 2004 12:02:10 -0000 1.2
+++ components.xml 29 Oct 2004 11:52:03 -0000 1.3
@@ -15,6 +15,12 @@
<component>
<role>org.apache.maven.scm.provider.local.command.LocalCommand</role>
+ <role-hint>check-in</role-hint>
+ <implementation>org.apache.maven.scm.provider.local.command.checkin.LocalCheckInCommand</implementation>
+ </component>
+
+ <component>
+ <role>org.apache.maven.scm.provider.local.command.LocalCommand</role>
<role-hint>check-out</role-hint>
<implementation>org.apache.maven.scm.provider.local.command.checkout.LocalCheckOutCommand</implementation>
</component>
1.1 maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/checkin/LocalCheckInCommandTest.java
Index: LocalCheckInCommandTest.java
===================================================================
package org.apache.maven.scm.provider.local.command.checkin;
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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 org.apache.maven.scm.ScmException;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
import org.apache.maven.scm.manager.ScmManager;
import org.apache.maven.scm.provider.local.AbstractLocalScmTest;
import org.apache.maven.scm.repository.ScmRepository;
import org.codehaus.plexus.util.FileUtils;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a>
* @version $Id: LocalCheckInCommandTest.java,v 1.1 2004/10/29 11:52:03 trygvis Exp $
*/
public class LocalCheckInCommandTest
extends AbstractLocalScmTest
{
private final static String module = "test-repo";
private final File repositoryRoot;
private final File workingDirectory;
public LocalCheckInCommandTest()
{
repositoryRoot = getTestFile( "target/local-scm-test/repository" );
workingDirectory = getTestFile( "target/local-scm-test/checked-out" );
}
public void testCheckInWithTag()
throws Exception
{
ScmManager scmManager = getScmManager();
try
{
scmManager.checkOut( makeScmRepository( "scm:local:src/test/repositories:" + module ), getWorkingDirectory(), "my-tag" );
fail( "Expected ScmException" );
}
catch( ScmException ex )
{
// expected
}
}
public void testTestScmWithRelativePath()
throws Exception
{
ciTest( "scm:local:target/local-scm-test/repository:" + module );
}
public void testTestScmWithAbsolutePath()
throws Exception
{
ciTest( "scm:local:" + repositoryRoot.getAbsolutePath() + ":" + module );
}
private void ciTest( String scmUrl )
throws Exception
{
// ----------------------------------------------------------------------
// Initialize directories
// ----------------------------------------------------------------------
FileUtils.deleteDirectory( repositoryRoot );
FileUtils.deleteDirectory( workingDirectory );
assertTrue( repositoryRoot.mkdirs() );
assertTrue( workingDirectory.mkdirs() );
// ----------------------------------------------------------------------
// Make the repository
// ----------------------------------------------------------------------
File moduleRoot = new File( repositoryRoot, module );
makeFile( moduleRoot, "/pom.xml" );
makeFile( moduleRoot, "/src/main/java/Application.java" );
// ----------------------------------------------------------------------
// Make the working directory
// ----------------------------------------------------------------------
makeFile( workingDirectory, "/pom.xml", "changed pom.xml" );
makeFile( workingDirectory, "/readme.txt" );
makeFile( workingDirectory, "/src/main/java/Application.java" );
makeFile( workingDirectory, "/src/test/java/Test.java" );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
ScmManager scmManager = (ScmManager) lookup( ScmManager.ROLE );
ScmRepository repository = scmManager.makeScmRepository( scmUrl );
CheckInScmResult result = scmManager.checkIn( repository, workingDirectory, null, "o Message." );
// ----------------------------------------------------------------------
// Assert the repository
// ----------------------------------------------------------------------
assertNotNull( result );
assertTrue( "The command wasn't sucessfully executed.", result.isSuccess() );
assertNull( "The provider message wasn't null", result.getProviderMessage() );
assertNull( "The command output wasn't null.", result.getCommandOutput() );
assertNotNull( "The checked in files list was null.", result.getCheckedInFiles() );
assertTrue( "The checked in files list didn't contain the expected number of elements. Expected: 3, was: " + result.getCheckedInFiles().size(),
result.getCheckedInFiles().size() == 3 );
}
}
1.6 +4 -9 maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/checkout/LocalCheckoutCommandTest.java
Index: LocalCheckoutCommandTest.java
===================================================================
RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/checkout/LocalCheckoutCommandTest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalCheckoutCommandTest.java 28 Oct 2004 23:27:32 -0000 1.5
+++ LocalCheckoutCommandTest.java 29 Oct 2004 11:52:03 -0000 1.6
@@ -37,11 +37,6 @@
public class LocalCheckoutCommandTest
extends AbstractLocalScmTest
{
- protected String getModule()
- {
- return "test-repo/checkout";
- }
-
public void testCheckOutWithTag()
throws Exception
{
@@ -49,7 +44,7 @@
try
{
- scmManager.checkOut( makeScmRepository( "scm:local:src/test/repositories:test-repo" ), getWorkingDirectory(), "my-tag" );
+ scmManager.checkOut( makeScmRepository( "scm:local:src/test/repository:test-repo" ), getWorkingDirectory(), "my-tag" );
fail( "Expected ScmException" );
}
@@ -62,13 +57,13 @@
public void testTestScmWithRelativePath()
throws Exception
{
- coTest( "scm:local:src/test/repositories:test-repo" );
+ coTest( "scm:local:src/test/repository:test-repo" );
}
public void testTestScmWithAbsolutePath()
throws Exception
{
- coTest( "scm:local|" + getTestPath( "src/test/repositories" ) + "|test-repo" );
+ coTest( "scm:local|" + getTestPath( "src/test/repository" ) + "|test-repo" );
}
private void coTest( String scmUrl )
1.5 +1 -42 maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/update/AbstractUpdateCommandTest.java
Index: AbstractUpdateCommandTest.java
===================================================================
RCS file: /home/cvs/maven-scm/maven-scm-providers/maven-scm-provider-local/src/test/java/org/apache/maven/scm/provider/local/command/update/AbstractUpdateCommandTest.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- AbstractUpdateCommandTest.java 28 Oct 2004 23:27:32 -0000 1.4
+++ AbstractUpdateCommandTest.java 29 Oct 2004 11:52:03 -0000 1.5
@@ -17,8 +17,6 @@
*/
import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
@@ -250,44 +248,5 @@
assertTrue( "Missing file: '" + file.getAbsolutePath() + "'.", file.exists() );
assertTrue( "File isn't a directory: '" + file.getAbsolutePath() + "'.", file.isDirectory() );
- }
-
- // ----------------------------------------------------------------------
- // Util methods
- // ----------------------------------------------------------------------
-
- protected void makeDirectory( File basedir, String fileName )
- {
- File dir = new File( basedir, fileName );
-
- if ( !dir.exists() )
- {
- assertTrue( dir.mkdirs() );
- }
- }
-
- protected void makeFile( File basedir, String fileName )
- throws IOException
- {
- makeFile( basedir, fileName, fileName );
- }
-
- protected void makeFile( File basedir, String fileName, String contents )
- throws IOException
- {
- File file = new File( basedir, fileName );
-
- File parent = file.getParentFile();
-
- if ( !parent.exists() )
- {
- assertTrue( parent.mkdirs() );
- }
-
- FileWriter writer = new FileWriter( file );
-
- writer.write( contents );
-
- writer.close();
}
}