You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/02/08 12:06:08 UTC
svn commit: r1241864 - in /maven/scm/trunk:
maven-scm-api/src/main/java/org/apache/maven/scm/
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/
maven-scm-providers...
Author: olamy
Date: Wed Feb 8 11:06:08 2012
New Revision: 1241864
URL: http://svn.apache.org/viewvc?rev=1241864&view=rev
Log:
[SCM-664] Git short revision number (emulate command git rev-parse --short=LENGTH)
Submitted by Voronetskyy Yevgen.
Modified:
maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java
maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTckTest.java
Modified: maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java?rev=1241864&r1=1241863&r2=1241864&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java (original)
+++ maven/scm/trunk/maven-scm-api/src/main/java/org/apache/maven/scm/CommandParameter.java Wed Feb 8 11:06:08 2012
@@ -68,10 +68,17 @@ public class CommandParameter
new CommandParameter( "run_changelog_with_update" );
public static final CommandParameter SCM_TAG_PARAMETERS = new CommandParameter( "ScmTagParameters" );
-
+
public static final CommandParameter SCM_BRANCH_PARAMETERS = new CommandParameter( "ScmBranchParameters" );
-
- public static final CommandParameter SCM_MKDIR_CREATE_IN_LOCAL = new CommandParameter( "createInLocal" );
+
+ public static final CommandParameter SCM_MKDIR_CREATE_IN_LOCAL = new CommandParameter( "createInLocal" );
+
+ /**
+ * Parameter used only for Git SCM and simulate the <code>git rev-parse --short=lenght</code> command.
+ *
+ * @since 1.7
+ */
+ public static final CommandParameter SCM_SHORT_REVISION_LENGTH = new CommandParameter( "shortRevisionLength" );
/**
Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java?rev=1241864&r1=1241863&r2=1241864&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java (original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommand.java Wed Feb 8 11:06:08 2012
@@ -19,6 +19,7 @@ package org.apache.maven.scm.provider.gi
* under the License.
*/
+import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
@@ -34,13 +35,14 @@ import org.codehaus.plexus.util.cli.Comm
/**
* @author Olivier Lamy
* @since 1.5
- *
*/
public class GitInfoCommand
- extends AbstractCommand
+ extends AbstractCommand
implements GitCommand
{
+ public static final int NO_REVISION_LENGTH = -1;
+
@Override
protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet,
CommandParameters parameters )
@@ -50,7 +52,7 @@ public class GitInfoCommand
GitInfoConsumer consumer = new GitInfoConsumer( getLogger(), fileSet );
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
- Commandline cli = createCommandLine( repository, fileSet );
+ Commandline cli = createCommandLine( repository, fileSet, parameters );
int exitCode = GitCommandLineUtils.execute( cli, consumer, stderr, getLogger() );
if ( exitCode != 0 )
@@ -60,14 +62,43 @@ public class GitInfoCommand
return new InfoScmResult( cli.toString(), consumer.getInfoItems() );
}
- public static Commandline createCommandLine( ScmProviderRepository repository, ScmFileSet fileSet )
+ public static Commandline createCommandLine( ScmProviderRepository repository, ScmFileSet fileSet,
+ CommandParameters parameters )
+ throws ScmException
{
Commandline cli = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(), "rev-parse" );
cli.createArg().setValue( "--verify" );
+ final int revLength = getRevisionLength( parameters );
+ if ( revLength
+ > NO_REVISION_LENGTH )// set the --short key only if revision length parameter is passed and different from -1
+ {
+ cli.createArg().setValue( "--short=" + revLength );
+ }
cli.createArg().setValue( "HEAD" );
return cli;
}
+ /**
+ * Get the revision length from the parameters
+ *
+ * @param parameters
+ * @return -1 if parameter {@link CommandParameter.SCM_SHORT_REVISION_LENGTH} is absent, <br/> and otherwise - the length to be applied for the revision formatting
+ * @throws ScmException
+ * @since 1.7
+ */
+ private static int getRevisionLength( final CommandParameters parameters )
+ throws ScmException
+ {
+ if ( parameters == null )
+ {
+ return NO_REVISION_LENGTH;
+ }
+ else
+ {
+ return parameters.getInt( CommandParameter.SCM_SHORT_REVISION_LENGTH, NO_REVISION_LENGTH );
+ }
+ }
+
}
Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTckTest.java?rev=1241864&r1=1241863&r2=1241864&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTckTest.java (original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/info/GitInfoCommandTckTest.java Wed Feb 8 11:06:08 2012
@@ -19,8 +19,7 @@ package org.apache.maven.scm.provider.gi
* under the License.
*/
-import java.io.File;
-
+import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmTestCase;
@@ -30,25 +29,75 @@ import org.apache.maven.scm.provider.Scm
import org.apache.maven.scm.provider.git.GitScmTestUtils;
import org.codehaus.plexus.PlexusTestCase;
+import java.io.File;
+
/**
* @author Olivier Lamy
*/
public class GitInfoCommandTckTest
extends ScmTestCase
{
-
- public void testInfoCommand() throws Exception
+
+ public void testInfoCommand()
+ throws Exception
{
GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );
ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
ScmProviderRepository repository = provider.makeProviderScmRepository( getRepositoryRoot() );
assertNotNull( repository );
- InfoScmResult result = provider.info( repository, new ScmFileSet( getRepositoryRoot() ), new CommandParameters() );
+ InfoScmResult result =
+ provider.info( repository, new ScmFileSet( getRepositoryRoot() ), new CommandParameters() );
assertNotNull( result );
assertEquals( "cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767", result.getInfoItems().get( 0 ).getRevision() );
//
}
-
+
+ public void testInfoCommandWithShortRevision()
+ throws Exception
+ {
+ GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );
+ ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
+ ScmProviderRepository repository = provider.makeProviderScmRepository( getRepositoryRoot() );
+ assertNotNull( repository );
+ CommandParameters commandParameters = new CommandParameters();
+ commandParameters.setInt( CommandParameter.SCM_SHORT_REVISION_LENGTH, 6 );
+ InfoScmResult result = provider.info( repository, new ScmFileSet( getRepositoryRoot() ), commandParameters );
+ assertNotNull( result );
+ assertEquals( "revision must be short, exactly 6 digits ", "cd3c0d",
+ result.getInfoItems().get( 0 ).getRevision() );
+ }
+
+ public void testInfoCommandWithNegativeShortRevision()
+ throws Exception
+ {
+ GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );
+ ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
+ ScmProviderRepository repository = provider.makeProviderScmRepository( getRepositoryRoot() );
+ assertNotNull( repository );
+ CommandParameters commandParameters = new CommandParameters();
+ commandParameters.setInt( CommandParameter.SCM_SHORT_REVISION_LENGTH, GitInfoCommand.NO_REVISION_LENGTH );
+ InfoScmResult result = provider.info( repository, new ScmFileSet( getRepositoryRoot() ), commandParameters );
+ assertNotNull( result );
+ assertEquals( "revision should not be short", "cd3c0dfacb65955e6fbb35c56cc5b1bf8ce4f767",
+ result.getInfoItems().get( 0 ).getRevision() );
+ }
+
+
+ public void testInfoCommandWithZeroShortRevision()
+ throws Exception
+ {
+ GitScmTestUtils.initRepo( "src/test/resources/git/info", getRepositoryRoot(), getWorkingCopy() );
+ ScmProvider provider = getScmManager().getProviderByUrl( getScmUrl() );
+ ScmProviderRepository repository = provider.makeProviderScmRepository( getRepositoryRoot() );
+ assertNotNull( repository );
+ CommandParameters commandParameters = new CommandParameters();
+ commandParameters.setInt( CommandParameter.SCM_SHORT_REVISION_LENGTH, 0 );
+ InfoScmResult result = provider.info( repository, new ScmFileSet( getRepositoryRoot() ), commandParameters );
+ assertNotNull( result );
+ assertTrue( "revision should be not empty, minimum 4 (see git help rev-parse --short)",
+ result.getInfoItems().get( 0 ).getRevision().length() >= 4 );
+ }
+
protected File getRepositoryRoot()
{
return PlexusTestCase.getTestFile( "target/scm-test/repository/git/info" );
@@ -59,10 +108,9 @@ public class GitInfoCommandTckTest
{
return GitScmTestUtils.getScmUrl( getRepositoryRoot(), "git" );
}
-
+
protected File getWorkingCopy()
{
return PlexusTestCase.getTestFile( "target/scm-test/git/info" );
- }
-
+ }
}