maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject maven-scm git commit: [SCM-819] Integrity blame command fixes. fixes #9
Date Tue, 05 Apr 2016 03:34:57 GMT
Repository: maven-scm
Updated Branches:
  refs/heads/master 5c303e41f -> 3aab5fda6


[SCM-819] Integrity blame command fixes.
fixes #9

Signed-off-by: olivier lamy <olamy@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/maven-scm/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-scm/commit/3aab5fda
Tree: http://git-wip-us.apache.org/repos/asf/maven-scm/tree/3aab5fda
Diff: http://git-wip-us.apache.org/repos/asf/maven-scm/diff/3aab5fda

Branch: refs/heads/master
Commit: 3aab5fda6cb1bcf83da67bac29a9731047e923f1
Parents: 5c303e4
Author: olivier lamy <olamy@apache.org>
Authored: Tue Apr 5 13:20:30 2016 +1000
Committer: olivier lamy <olamy@apache.org>
Committed: Tue Apr 5 13:20:30 2016 +1000

----------------------------------------------------------------------
 .../command/blame/IntegrityBlameCommand.java    | 69 ++++++++++++++++++--
 1 file changed, 62 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-scm/blob/3aab5fda/maven-scm-providers/maven-scm-provider-integrity/src/main/java/org/apache/maven/scm/provider/integrity/command/blame/IntegrityBlameCommand.java
----------------------------------------------------------------------
diff --git a/maven-scm-providers/maven-scm-provider-integrity/src/main/java/org/apache/maven/scm/provider/integrity/command/blame/IntegrityBlameCommand.java
b/maven-scm-providers/maven-scm-provider-integrity/src/main/java/org/apache/maven/scm/provider/integrity/command/blame/IntegrityBlameCommand.java
index 1989a44..e910911 100644
--- a/maven-scm-providers/maven-scm-provider-integrity/src/main/java/org/apache/maven/scm/provider/integrity/command/blame/IntegrityBlameCommand.java
+++ b/maven-scm-providers/maven-scm-provider-integrity/src/main/java/org/apache/maven/scm/provider/integrity/command/blame/IntegrityBlameCommand.java
@@ -25,7 +25,6 @@ import org.apache.maven.scm.ScmResult;
 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.integrity.APISession;
 import org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
@@ -57,25 +56,81 @@ public class IntegrityBlameCommand
         }
         BlameScmResult result;
         IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
-        APISession api = iRepo.getAPISession();
         // Since the si annotate command is not completely API ready, we will use the CLI
for this command
+        // Ensure shell 'si' client is connected.
+        doShellConnect( iRepo, workingDirectory );
+        result = doShellAnnotate( iRepo, workingDirectory, filename );
+
+        return result;
+    }
+
+    /**
+     * Execute 'si connect' command in current shell.
+     *
+     * @param iRepo            the Integrity repository instance.
+     * @param workingDirectory the SCM working directory.
+     * @throws ScmException if connect command failed.
+     */
+    private void doShellConnect( IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory
)
+        throws ScmException
+    {
+        Commandline shell = new Commandline();
+        shell.setWorkingDirectory( workingDirectory.getBasedir() );
+        shell.setExecutable( "si" );
+        shell.createArg().setValue( "connect" );
+        shell.createArg().setValue( "--hostname=" + iRepo.getHost() );
+        shell.createArg().setValue( "--port=" + iRepo.getPort() );
+        shell.createArg().setValue( "--user=" + iRepo.getUser() );
+        shell.createArg().setValue( "--batch" );
+        shell.createArg().setValue( "--password=" + iRepo.getPassword() );
+        CommandLineUtils.StringStreamConsumer shellConsumer = new CommandLineUtils.StringStreamConsumer();
+
+        try
+        {
+            getLogger().debug( "Executing: " + CommandLineUtils.toString( shell.getCommandline()
) );
+            int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer, shellConsumer
);
+            if ( exitCode != 0 )
+            {
+                throw new ScmException( "Can't login to integrity. Message : " + shellConsumer.toString()
);
+            }
+        }
+        catch ( CommandLineException cle )
+        {
+            getLogger().error( "Command Line Connect Exception: " + cle.getMessage() );
+            throw new ScmException( "Can't login to integrity. Message : " + cle.getMessage()
);
+        }
+
+    }
+
+    /**
+     * Execute 'si annotate' command in current shell and process output as {@link BlameScmResult}
instance.
+     *
+     * @param iRepo            the Integrity repository instance.
+     * @param workingDirectory the SCM working directory.
+     * @param filename         the file name.
+     * @return the {@link BlameScmResult} instance.
+     */
+    private BlameScmResult doShellAnnotate( IntegrityScmProviderRepository iRepo, ScmFileSet
workingDirectory,
+                                            String filename )
+    {
+        BlameScmResult result;
         Commandline shell = new Commandline();
         shell.setWorkingDirectory( workingDirectory.getBasedir() );
         shell.setExecutable( "si" );
         shell.createArg().setValue( "annotate" );
-        shell.createArg().setValue( "--hostname=" + api.getHostName() );
-        shell.createArg().setValue( "--port=" + api.getPort() );
-        shell.createArg().setValue( "--user=" + api.getUserName() );
+        shell.createArg().setValue( "--hostname=" + iRepo.getHost() );
+        shell.createArg().setValue( "--port=" + iRepo.getPort() );
+        shell.createArg().setValue( "--user=" + iRepo.getUser() );
         shell.createArg().setValue( "--fields=date,revision,author" );
         shell.createArg().setValue( '"' + filename + '"' );
         IntegrityBlameConsumer shellConsumer = new IntegrityBlameConsumer( getLogger() );
 
         try
         {
-            getLogger().debug( "Executing: " + shell.getCommandline() );
+            getLogger().debug( "Executing: " + CommandLineUtils.toString( shell.getCommandline()
) );
             int exitCode = CommandLineUtils.executeCommandLine( shell, shellConsumer,
                                                                 new CommandLineUtils.StringStreamConsumer()
);
-            boolean success = ( exitCode == 128 ? false : true );
+            boolean success = ( exitCode == 0 ? true : false );
             ScmResult scmResult =
                 new ScmResult( shell.getCommandline().toString(), "", "Exit Code: " + exitCode,
success );
             return new BlameScmResult( shellConsumer.getBlameList(), scmResult );


Mime
View raw message