maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r755751 - in /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/update/ test/java/org/apache/maven/scm/provider/git/gitexe/command/update/ t...
Date Wed, 18 Mar 2009 21:52:02 GMT
Author: olamy
Date: Wed Mar 18 21:52:02 2009
New Revision: 755751

URL: http://svn.apache.org/viewvc?rev=755751&view=rev
Log:
[SCM-441] NPE when using Git SCM 1.2-SNAPSHOT
Submitted by Mark Struberg 


Added:
    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/update/GitLatestRevisionCommandConsumer.java
  (with props)
    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/update/GitLatestRevisionCommandConsumerTest.java
  (with props)
    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/update/GitUpdateCommandTest.java
  (with props)
    maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/update/git-update-latest-rev.out
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/update/GitUpdateCommand.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/update/GitUpdateCommandConsumerTest.java

Added: 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/update/GitLatestRevisionCommandConsumer.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/update/GitLatestRevisionCommandConsumer.java?rev=755751&view=auto
==============================================================================
--- 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/update/GitLatestRevisionCommandConsumer.java
(added)
+++ 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/update/GitLatestRevisionCommandConsumer.java
Wed Mar 18 21:52:02 2009
@@ -0,0 +1,100 @@
+package org.apache.maven.scm.provider.git.gitexe.command.update;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.maven.scm.log.ScmLogger;
+import org.apache.maven.scm.util.AbstractConsumer;
+import org.apache.regexp.RE;
+import org.apache.regexp.RESyntaxException;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @version $Id$
+ */
+public class GitLatestRevisionCommandConsumer
+    extends AbstractConsumer
+{
+
+    /**
+     * The pattern used to match git log latest revision lines
+     */
+    private static final String LATESTREV_PATTERN = "^commit \\s*(.*)";
+
+    /**
+     * The regular expression used to match git log latest revision lines
+     */
+    private RE latestRevRegexp;
+
+    private String latestRevision;
+
+    public GitLatestRevisionCommandConsumer( ScmLogger logger )
+    {
+        super( logger );
+
+        try
+        {
+            latestRevRegexp = new RE( LATESTREV_PATTERN );
+        }
+        catch ( RESyntaxException ex )
+        {
+            throw new RuntimeException(
+                                        "INTERNAL ERROR: Could not create regexp to parse
git log file. This shouldn't happen. Something is probably wrong with the oro installation.",
+                                        ex );
+        }
+
+    }
+
+    /** {@inheritDoc} */
+    public void consumeLine( String line )
+    {
+        if ( getLogger().isDebugEnabled() )
+        {
+            getLogger().debug( "GitLatestRevisionCommandConsumer consumeLine : " + line );
+        }
+        if ( line == null || StringUtils.isEmpty( line ) )
+        {
+            return;
+        }
+
+        processGetLatestRevision( line );
+    }
+
+    public String getLatestRevision()
+    {
+        return latestRevision;
+    }
+
+    /**
+     * Process the current input line for the latest revision
+     *
+     * @param line A line of text from the git log output
+     */
+    private void processGetLatestRevision( String line )
+    {
+        if ( !latestRevRegexp.match( line ) )
+        {
+            return;
+        }
+
+        latestRevision = latestRevRegexp.getParen( 1 );
+    }
+
+}

Propchange: 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/update/GitLatestRevisionCommandConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 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/update/GitLatestRevisionCommandConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

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/update/GitUpdateCommand.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/update/GitUpdateCommand.java?rev=755751&r1=755750&r2=755751&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/update/GitUpdateCommand.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/update/GitUpdateCommand.java
Wed Mar 18 21:52:02 2009
@@ -19,6 +19,8 @@
  * under the License.
  */
 
+import java.io.File;
+
 import org.apache.maven.scm.ScmBranch;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
@@ -63,7 +65,7 @@
 
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
 
-        Commandline cl = createCommandLine( repository, fileSet, scmVersion );
+        Commandline cl = createCommandLine( repository, fileSet.getBasedir(), scmVersion
);
         exitCode = GitCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
         if ( exitCode != 0 )
         {
@@ -74,7 +76,23 @@
             return new UpdateScmResult( cl.toString(), "The git-pull origin master command
failed.",
                                         stderr.getOutput(), false );
         }
-        return new UpdateScmResultWithRevision( cl.toString(), consumer.getUpdatedFiles(),
null );
+        
+        // now let's get the latest version
+        Commandline clRev = createLatestRevisionCommandLine( repository, fileSet.getBasedir(),
scmVersion );
+        GitLatestRevisionCommandConsumer consumerRev = new GitLatestRevisionCommandConsumer(
getLogger() );
+        exitCode = GitCommandLineUtils.execute( clRev, consumerRev, stderr, getLogger() );
+        if ( exitCode != 0 )
+        {
+            if ( getLogger().isWarnEnabled() )
+            {
+                getLogger().warn( "failed to update git, return code " + exitCode );
+            }
+            return new UpdateScmResult( cl.toString(), "The git-log command failed.",
+                                        stderr.getOutput(), false );
+        }
+        String latestRevision = consumerRev.getLatestRevision();
+        
+        return new UpdateScmResultWithRevision( cl.toString(), consumer.getUpdatedFiles(),
latestRevision );
     }
 
     /** {@inheritDoc} */
@@ -89,9 +107,9 @@
     /**
      * create the command line for updating the current branch with the info from the foreign
repository. 
      */
-    public static Commandline createCommandLine( GitScmProviderRepository repository, ScmFileSet
fileSet, ScmVersion scmVersion ) 
+    public static Commandline createCommandLine( GitScmProviderRepository repository, File
workingDirectory, ScmVersion scmVersion ) 
     {
-        Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( fileSet.getBasedir(),
"pull" );
+        Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "pull"
);
         
         cl.createArg().setLine( "origin" );
 
@@ -107,4 +125,34 @@
         
         return cl;
     }
+    
+    /**
+     * @param scmVersion a valid branch or <code>null</code> if the master branch
should be taken
+     * @return CommandLine for getting the latest commit on the given branch
+     */
+    public static Commandline createLatestRevisionCommandLine(GitScmProviderRepository repository,
File workingDirectory,
+                                                               ScmVersion scmVersion)
+    {
+        Commandline cl = GitCommandLineUtils.getBaseGitCommandLine( workingDirectory, "log"
);
+        
+        // only show exactly 1 commit
+        cl.createArg().setValue( "-n1" ); 
+        
+        // same as --topo-order, but ensure ordering of merges
+        cl.createArg().setValue( "--date-order" );
+        
+        if ( scmVersion != null && scmVersion instanceof ScmBranch && 
+             scmVersion.getName() != null && scmVersion.getName().length() > 0
)
+        {
+            // if any branch is given, lets take em
+            cl.createArg().setValue( scmVersion.getName() );
+        }
+        else
+        {
+            // otherwise we work on the master branch
+            cl.createArg().setValue( "master" );
+        }
+        
+        return cl;
+    }
 }

Added: 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/update/GitLatestRevisionCommandConsumerTest.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/update/GitLatestRevisionCommandConsumerTest.java?rev=755751&view=auto
==============================================================================
--- 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/update/GitLatestRevisionCommandConsumerTest.java
(added)
+++ 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/update/GitLatestRevisionCommandConsumerTest.java
Wed Mar 18 21:52:02 2009
@@ -0,0 +1,77 @@
+package org.apache.maven.scm.provider.git.gitexe.command.update;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.Reader;
+
+import org.apache.maven.scm.log.DefaultLog;
+import org.codehaus.plexus.PlexusTestCase;
+import org.codehaus.plexus.util.ReaderFactory;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @since 1.2
+ * @version $Id$
+ */
+public class GitLatestRevisionCommandConsumerTest
+    extends PlexusTestCase
+{
+    public void testUpToDate()
+        throws Exception
+    {
+
+        GitLatestRevisionCommandConsumer consumer = buildGitLatestRevisionCommandConsumer(
"/src/test/resources/git/update/git-update-latest-rev.out" );
+
+        String latestRev = consumer.getLatestRevision();
+
+        assertNotNull( latestRev );
+        assertEquals( "a300c56a341bae8d0eb5ec4ed5551a11c75a5a6e", latestRev );
+    }
+
+    
+    // utils methods
+
+    private GitLatestRevisionCommandConsumer buildGitLatestRevisionCommandConsumer( String
fileName )
+        throws Exception
+    {
+        GitLatestRevisionCommandConsumer consumer = new GitLatestRevisionCommandConsumer(
new DefaultLog() );
+
+        BufferedReader r = getGitLogBufferedReader( fileName );
+
+        String line;
+
+        while ( ( line = r.readLine() ) != null )
+        {
+            //System.out.println(" line " + line );
+            consumer.consumeLine( line );
+        }
+        return consumer;
+    }
+
+    private BufferedReader getGitLogBufferedReader( String fileName )
+        throws Exception
+    {
+        File f = getTestFile( fileName );
+        Reader reader = ReaderFactory.newReader( f, "UTF-8" );
+        return new BufferedReader( reader );
+    }
+}

Propchange: 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/update/GitLatestRevisionCommandConsumerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 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/update/GitLatestRevisionCommandConsumerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

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/update/GitUpdateCommandConsumerTest.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/update/GitUpdateCommandConsumerTest.java?rev=755751&r1=755750&r2=755751&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/update/GitUpdateCommandConsumerTest.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/update/GitUpdateCommandConsumerTest.java
Wed Mar 18 21:52:02 2009
@@ -98,8 +98,10 @@
     
     
     
-    // utils methods
-
+    // ----------------------------------------------------------------------
+    // private helper functions
+    // ----------------------------------------------------------------------
+    
     private void assertOneUpdate( String fileName )
         throws Exception
     {

Added: 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/update/GitUpdateCommandTest.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/update/GitUpdateCommandTest.java?rev=755751&view=auto
==============================================================================
--- 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/update/GitUpdateCommandTest.java
(added)
+++ 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/update/GitUpdateCommandTest.java
Wed Mar 18 21:52:02 2009
@@ -0,0 +1,89 @@
+package org.apache.maven.scm.provider.git.gitexe.command.update;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.maven.scm.ScmBranch;
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.ScmVersion;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
+ * @version $Id$
+ */
+public class GitUpdateCommandTest
+    extends ScmTestCase
+{
+    public void testCommandLineNoBranch()
+        throws Exception
+    {
+        testCommandLine( "scm:git:http://foo.com/git", null, "git pull origin master" );
+    }
+
+    public void testCommandLineWithBranch()
+    throws Exception
+    {
+        testCommandLine( "scm:git:http://foo.com/git", new ScmBranch( "mybranch" ), "git
pull origin mybranch" );
+    }
+
+
+    public void testCommandLineLatestRevision()
+        throws Exception
+    {
+        testLatestRevisionCommandLine( "scm:git:http://foo.com/git", null, "git log -n1 --date-order
master"  );
+    }
+    
+    // ----------------------------------------------------------------------
+    // private helper functions
+    // ----------------------------------------------------------------------
+
+    private void testCommandLine( String scmUrl, ScmVersion branch, String commandLine )
+        throws Exception
+    {
+        File workingDirectory = getTestFile( "target/git-update-command-test" );
+
+        ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
+
+        GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
+
+        Commandline cl = GitUpdateCommand.createCommandLine( gitRepository, workingDirectory,
branch );
+
+        assertCommandLine( commandLine, workingDirectory, cl );
+    }
+
+    private void testLatestRevisionCommandLine( String scmUrl, ScmBranch branch, String commandLine
)
+    throws Exception
+    {
+        File workingDirectory = getTestFile( "target/git-update-command-test" );
+    
+        ScmRepository repository = getScmManager().makeScmRepository( scmUrl );
+    
+        GitScmProviderRepository gitRepository = (GitScmProviderRepository) repository.getProviderRepository();
+    
+        Commandline cl = GitUpdateCommand.createLatestRevisionCommandLine( gitRepository,
workingDirectory, branch );
+    
+        assertCommandLine( commandLine, workingDirectory, cl );
+    }
+
+}

Propchange: 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/update/GitUpdateCommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 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/update/GitUpdateCommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Revision Id

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/update/git-update-latest-rev.out
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/update/git-update-latest-rev.out?rev=755751&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/update/git-update-latest-rev.out
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/resources/git/update/git-update-latest-rev.out
Wed Mar 18 21:52:02 2009
@@ -0,0 +1,5 @@
+commit a300c56a341bae8d0eb5ec4ed5551a11c75a5a6e
+Author: Mark Struberg <struberg@yahoo.de>
+Date:   Wed Mar 18 15:59:31 2009 +0100
+
+    No msg



Mime
View raw message