maven-scm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r922015 [2/2] - in /maven/scm/trunk: maven-scm-api/src/main/java/org/apache/maven/scm/command/blame/ maven-scm-api/src/main/java/org/apache/maven/scm/manager/ maven-scm-api/src/main/java/org/apache/maven/scm/provider/ maven-scm-providers/ma...
Date Thu, 11 Mar 2010 20:45:01 GMT
Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,37 @@
+package org.apache.maven.scm.provider.git.command.blame;
+
+/*
+ * 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.provider.git.GitScmTestUtils;
+import org.apache.maven.scm.tck.command.blame.BlameCommandTckTest;
+
+/**
+ * @author Evgeny Mandrikov
+ * @since 1.4
+ */
+public abstract class GitBlameCommandTckTest
+    extends BlameCommandTckTest
+{
+    public void initRepo()
+        throws Exception
+    {
+        GitScmTestUtils.initRepo( "src/test/resources/repository/", getRepositoryRoot(),
getWorkingDirectory() );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/blame/GitBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java?rev=922015&r1=922014&r2=922015&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/main/java/org/apache/maven/scm/provider/svn/AbstractSvnScmProvider.java
Thu Mar 11 20:44:59 2010
@@ -24,6 +24,7 @@ import org.apache.maven.scm.ScmException
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmResult;
 import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.blame.BlameScmResult;
 import org.apache.maven.scm.command.branch.BranchScmResult;
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
@@ -375,4 +376,14 @@ public abstract class AbstractSvnScmProv
         return (SvnInfoScmResult) executeCommand( cmd, repository, fileSet, parameters );
     }
 
+    /** {@inheritDoc} */
+    protected BlameScmResult blame( ScmProviderRepository repository, ScmFileSet fileSet,
CommandParameters parameters )
+        throws ScmException
+    {
+        SvnCommand cmd = getBlameCommand();
+
+        return (BlameScmResult) executeCommand( cmd, repository, fileSet, parameters );
+    }
+
+    protected abstract SvnCommand getBlameCommand();
 }

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/TestSvnScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/TestSvnScmProvider.java?rev=922015&r1=922014&r2=922015&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/TestSvnScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svn-commons/src/test/java/org/apache/maven/scm/provider/svn/TestSvnScmProvider.java
Thu Mar 11 20:44:59 2010
@@ -91,6 +91,11 @@ public class TestSvnScmProvider
         return null;
     }
 
+    protected SvnCommand getBlameCommand()
+    {
+        return null;
+    }
+
     protected String getRepositoryURL( File path )
     {
         return null;

Modified: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/SvnExeScmProvider.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/SvnExeScmProvider.java?rev=922015&r1=922014&r2=922015&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/SvnExeScmProvider.java
(original)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/SvnExeScmProvider.java
Thu Mar 11 20:44:59 2010
@@ -26,6 +26,7 @@ import org.apache.maven.scm.provider.svn
 import org.apache.maven.scm.provider.svn.command.info.SvnInfoItem;
 import org.apache.maven.scm.provider.svn.command.info.SvnInfoScmResult;
 import org.apache.maven.scm.provider.svn.svnexe.command.add.SvnAddCommand;
+import org.apache.maven.scm.provider.svn.svnexe.command.blame.SvnBlameCommand;
 import org.apache.maven.scm.provider.svn.svnexe.command.branch.SvnBranchCommand;
 import org.apache.maven.scm.provider.svn.svnexe.command.changelog.SvnChangeLogCommand;
 import org.apache.maven.scm.provider.svn.svnexe.command.checkin.SvnCheckInCommand;
@@ -128,6 +129,12 @@ public class SvnExeScmProvider
     }
 
     /** {@inheritDoc} */
+    protected SvnCommand getBlameCommand()
+    {
+        return new SvnBlameCommand();
+    }
+
+    /** {@inheritDoc} */
     protected String getRepositoryURL( File path )
         throws ScmException
     {

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,91 @@
+package org.apache.maven.scm.provider.svn.svnexe.command.blame;
+
+/*
+ * 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.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.scm.command.blame.AbstractBlameCommand;
+import org.apache.maven.scm.command.blame.BlameScmResult;
+import org.apache.maven.scm.provider.ScmProviderRepository;
+import org.apache.maven.scm.provider.svn.command.SvnCommand;
+import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
+import org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+
+/**
+ * @author Evgeny Mandrikov
+ * @since 1.4
+ */
+public class SvnBlameCommand
+    extends AbstractBlameCommand
+    implements SvnCommand
+{
+    /**
+     * {@inheritDoc}
+     */
+    public BlameScmResult executeBlameCommand( ScmProviderRepository repo, ScmFileSet workingDirectory,
+                                               String filename )
+        throws ScmException
+    {
+        Commandline cl = createCommandLine( (SvnScmProviderRepository) repo, workingDirectory.getBasedir(),
filename );
+
+        SvnBlameConsumer consumer = new SvnBlameConsumer( getLogger() );
+
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+        if ( getLogger().isInfoEnabled() )
+        {
+            getLogger().info( "Executing: " + SvnCommandLineUtils.cryptPassword( cl ) );
+            getLogger().info( "Working directory: " + cl.getWorkingDirectory().getAbsolutePath()
);
+        }
+
+        int exitCode;
+
+        try
+        {
+            exitCode = SvnCommandLineUtils.execute( cl, consumer, stderr, getLogger() );
+        }
+        catch ( CommandLineException ex )
+        {
+            throw new ScmException( "Error while executing command.", ex );
+        }
+
+        if ( exitCode != 0 )
+        {
+            return new BlameScmResult( cl.toString(), "The svn command failed.", stderr.getOutput(),
false );
+        }
+
+        return new BlameScmResult( cl.toString(), consumer.getLines() );
+    }
+
+    public static Commandline createCommandLine( SvnScmProviderRepository repository, File
workingDirectory,
+                                                 String filename )
+    {
+        Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine( workingDirectory, repository
);
+        cl.createArg().setValue( "blame" );
+        cl.createArg().setValue( "--xml" );
+        cl.createArg().setValue( filename );
+        return cl;
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameCommand.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,149 @@
+package org.apache.maven.scm.provider.svn.svnexe.command.blame;
+
+/*
+ * 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.command.blame.BlameLine;
+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 java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+/**
+ * @author Evgeny Mandrikov
+ * @since 1.4
+ */
+public class SvnBlameConsumer
+    extends AbstractConsumer
+{
+    private static final String SVN_TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
+
+    private static final String LINE_PATTERN = "line-number=\"(.*)\"";
+
+    private static final String REVISION_PATTERN = "revision=\"(.*)\"";
+
+    private static final String AUTHOR_PATTERN = "<author>(.*)</author>";
+
+    private static final String DATE_PATTERN = "<date>(.*)T(.*)\\.(.*)Z</date>";
+
+    /**
+     * @see #LINE_PATTERN
+     */
+    private RE lineRegexp;
+
+    /**
+     * @see #REVISION_PATTERN
+     */
+    private RE revisionRegexp;
+
+    /**
+     * @see #AUTHOR_PATTERN
+     */
+    private RE authorRegexp;
+
+    /**
+     * @see #DATE_PATTERN
+     */
+    private RE dateRegexp;
+
+    private SimpleDateFormat dateFormat;
+
+    private List lines = new ArrayList();
+
+    public SvnBlameConsumer( ScmLogger logger )
+    {
+        super( logger );
+
+        dateFormat = new SimpleDateFormat( SVN_TIMESTAMP_PATTERN );
+        dateFormat.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
+
+        try
+        {
+            lineRegexp = new RE( LINE_PATTERN );
+            revisionRegexp = new RE( REVISION_PATTERN );
+            authorRegexp = new RE( AUTHOR_PATTERN );
+            dateRegexp = new RE( DATE_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 );
+        }
+    }
+
+    private int lineNumber;
+
+    private String revision;
+
+    private String author;
+
+    public void consumeLine( String line )
+    {
+        if ( lineRegexp.match( line ) )
+        {
+            String lineNumberStr = lineRegexp.getParen( 1 );
+            lineNumber = Integer.parseInt( lineNumberStr );
+        }
+        else if ( revisionRegexp.match( line ) )
+        {
+            revision = revisionRegexp.getParen( 1 );
+        }
+        else if ( authorRegexp.match( line ) )
+        {
+            author = authorRegexp.getParen( 1 );
+        }
+        else if ( dateRegexp.match( line ) )
+        {
+            String date = dateRegexp.getParen( 1 );
+            String time = dateRegexp.getParen( 2 );
+            Date dateTime = parseDateTime( date + " " + time );
+            getLines().add( new BlameLine( dateTime, revision, author ) );
+            if ( getLogger().isDebugEnabled() )
+            {
+                getLogger().debug( "Author of line " + lineNumber + ": " + author + " ("
+ date + ")" );
+            }
+        }
+    }
+
+    protected Date parseDateTime( String dateTimeStr )
+    {
+        try
+        {
+            return dateFormat.parse( dateTimeStr );
+        }
+        catch ( ParseException e )
+        {
+            getLogger().error( "skip ParseException: " + e.getMessage() + " during parsing
date " + dateTimeStr, e );
+            return null;
+        }
+    }
+
+    public List getLines()
+    {
+        return lines;
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/main/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnBlameConsumer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,35 @@
+package org.apache.maven.scm.provider.svn.svnexe.command.blame;
+
+/*
+ * 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.provider.svn.command.blame.SvnBlameCommandTckTest;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public class SvnExeBlameCommandTckTest
+    extends SvnBlameCommandTckTest
+{
+    public void testBlameCommand()
+        throws Exception
+    {
+        super.testBlameCommand();
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svnexe/src/test/java/org/apache/maven/scm/provider/svn/svnexe/command/blame/SvnExeBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
(added)
+++ maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,56 @@
+package org.apache.maven.scm.provider.svn.command.blame;
+
+/*
+ * 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.command.blame.BlameLine;
+import org.apache.maven.scm.command.blame.BlameScmResult;
+import org.apache.maven.scm.provider.svn.SvnScmTestUtils;
+import org.apache.maven.scm.tck.command.blame.BlameCommandTckTest;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public abstract class SvnBlameCommandTckTest
+    extends BlameCommandTckTest
+{
+    public String getScmUrl()
+        throws Exception
+    {
+        return SvnScmTestUtils.getScmUrl( new File( getRepositoryRoot(), "trunk" ) );
+    }
+
+    public void initRepo()
+        throws Exception
+    {
+        SvnScmTestUtils.initializeRepository( getRepositoryRoot() );
+    }
+
+    protected void verifyResult( BlameScmResult result )
+    {
+        List lines = result.getLines();
+        assertEquals( "Expected 1 line in blame", 1, lines.size() );
+        BlameLine line = (BlameLine) lines.get( 0 );
+        assertEquals( "trygvis", line.getAuthor() );
+        assertEquals( "7", line.getRevision() );
+    }
+}

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-providers/maven-scm-providers-svn/maven-scm-provider-svntest/src/main/java/org/apache/maven/scm/provider/svn/command/blame/SvnBlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/manager/ScmManagerStub.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/manager/ScmManagerStub.java?rev=922015&r1=922014&r2=922015&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/manager/ScmManagerStub.java
(original)
+++ maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/manager/ScmManagerStub.java
Thu Mar 11 20:44:59 2010
@@ -24,6 +24,7 @@ import org.apache.maven.scm.ScmException
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmVersion;
 import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.blame.BlameScmResult;
 import org.apache.maven.scm.command.branch.BranchScmResult;
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
@@ -441,4 +442,11 @@ public class ScmManagerStub
         return this.getProviderByRepository( repository ).update( repository, fileSet, version,
lastUpdate,
                                                                   datePattern );
     }
+
+    /** {@inheritDoc} */
+    public BlameScmResult blame( ScmRepository repository, ScmFileSet fileSet, String filename
)
+        throws ScmException
+    {
+        return this.getProviderByRepository( repository ).blame( repository, fileSet, filename
);
+    }
 }

Modified: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/provider/ScmProviderStub.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/provider/ScmProviderStub.java?rev=922015&r1=922014&r2=922015&view=diff
==============================================================================
--- maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/provider/ScmProviderStub.java
(original)
+++ maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/provider/ScmProviderStub.java
Thu Mar 11 20:44:59 2010
@@ -26,6 +26,7 @@ import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmTagParameters;
 import org.apache.maven.scm.ScmVersion;
 import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.blame.BlameScmResult;
 import org.apache.maven.scm.command.branch.BranchScmResult;
 import org.apache.maven.scm.command.changelog.ChangeLogScmResult;
 import org.apache.maven.scm.command.checkin.CheckInScmResult;
@@ -100,6 +101,8 @@ public class ScmProviderStub
 
     private ExportScmResult exportScmResult;
 
+    private BlameScmResult blameScmResult;
+
     /**
      * Create a new ScmProviderStub with bogus (not null) attributes
      */
@@ -119,6 +122,7 @@ public class ScmProviderStub
         setTagScmResult( new TagScmResult( "", "", "", true ) );
         setUnEditScmResult( new UnEditScmResult( "", "", "", true ) );
         setUpdateScmResult( new UpdateScmResult( "", "", "", true ) );
+        setBlameScmResult( new BlameScmResult( "", "", "", true ) );
     }
 
     /** {@inheritDoc} */
@@ -295,6 +299,15 @@ public class ScmProviderStub
         return listScmResult;
     }
 
+    public void setBlameScmResult( BlameScmResult blameScmResult ) {
+        this.blameScmResult = blameScmResult;
+    }
+
+    public BlameScmResult getBlameScmResult()
+    {
+        return blameScmResult;
+    }
+
     /** {@inheritDoc} */
     public ScmProviderRepository makeProviderScmRepository( String scmSpecificUrl, char delimiter
)
         throws ScmRepositoryException
@@ -695,4 +708,11 @@ public class ScmProviderStub
     {
         return getUnEditScmResult();
     }
+
+    /** {@inheritDoc} */
+    public BlameScmResult blame( ScmRepository repository, ScmFileSet fileSet, String filename
)
+        throws ScmException
+    {
+        return getBlameScmResult();
+    }
 }

Added: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
URL: http://svn.apache.org/viewvc/maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java?rev=922015&view=auto
==============================================================================
--- maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
(added)
+++ maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
Thu Mar 11 20:44:59 2010
@@ -0,0 +1,114 @@
+package org.apache.maven.scm.tck.command.blame;
+
+/*
+ * 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.ScmFileSet;
+import org.apache.maven.scm.ScmTckTestCase;
+import org.apache.maven.scm.ScmTestCase;
+import org.apache.maven.scm.command.blame.BlameLine;
+import org.apache.maven.scm.command.blame.BlameScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.manager.ScmManager;
+import org.apache.maven.scm.provider.ScmProvider;
+import org.apache.maven.scm.repository.ScmRepository;
+
+import java.util.Date;
+
+/**
+ * @author Evgeny Mandrikov
+ */
+public abstract class BlameCommandTckTest
+    extends ScmTckTestCase
+{
+    private static final String COMMIT_MSG = "Second changelog";
+
+    public void testBlameCommand()
+        throws Exception
+    {
+        ScmRepository repository = getScmRepository();
+        ScmManager manager = getScmManager();
+        ScmProvider provider = manager.getProviderByRepository( getScmRepository() );
+        ScmFileSet fileSet = new ScmFileSet( getWorkingCopy() );
+
+        BlameScmResult result;
+        BlameLine line;
+
+        // === readme.txt ===
+        result = manager.blame( repository, fileSet, "readme.txt" );
+        assertNotNull( "The command returned a null result.", result );
+        assertResultIsSuccess( result );
+        assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
+        line = (BlameLine) result.getLines().get( 0 );
+        String initialRevision = line.getRevision();
+
+        //Make a timestamp that we know are after initial revision but before the second
+        Date timeBeforeSecond = new Date(); // Current time
+        // pause a couple seconds...
+        Thread.sleep( 2000 );
+        //Make a change to the readme.txt and commit the change
+        ScmTestCase.makeFile( getWorkingCopy(), "/readme.txt", "changed readme.txt" );
+        CheckInScmResult checkInResult = provider.checkIn( getScmRepository(), fileSet, COMMIT_MSG
);
+        assertTrue( "Unable to checkin changes to the repository", checkInResult.isSuccess()
);
+
+        result = manager.blame( repository, fileSet, "readme.txt" );
+
+        // pause a couple seconds...
+        Thread.sleep( 2000 );
+        Date timeAfterSecond = new Date(); // Current time
+
+        assertNotNull( "The command returned a null result.", result );
+        assertResultIsSuccess( result );
+
+        assertEquals( "Expected 1 line in blame", 1, result.getLines().size() );
+        line = (BlameLine) result.getLines().get( 0 );
+
+        assertNotNull( "Expected not null author", line.getAuthor() );
+        assertNotNull( "Expected not null revision", line.getRevision() );
+        assertNotNull( "Expected not null date", line.getDate() );
+
+        assertTrue( "Expected another revision", !initialRevision.equals( line.getRevision()
) );
+        if ( isTestDateTime() )
+        {
+            assertDateBetween( timeBeforeSecond, timeAfterSecond, line.getDate() );
+        }
+
+        // === pom.xml ===
+        result = manager.blame( repository, fileSet, "pom.xml" );
+
+        assertNotNull( "The command returned a null result.", result );
+
+        assertResultIsSuccess( result );
+
+        verifyResult( result );
+    }
+
+    protected boolean isTestDateTime()
+    {
+        return true;
+    }
+
+    protected void assertDateBetween( Date start, Date end, Date actual )
+    {
+        assertTrue( "Expected date between " + start + " and " + end + ", but was " + actual,
+                    start.before( actual ) && actual.before( end ) );
+    }
+
+    protected abstract void verifyResult( BlameScmResult result );
+}

Propchange: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/scm/trunk/maven-scm-test/src/main/java/org/apache/maven/scm/tck/command/blame/BlameCommandTckTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message