[maven-scm] branch master updated: [SCM-919] Fix codecheck violations in JGit provider

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[maven-scm] branch master updated: [SCM-919] Fix codecheck violations in JGit provider

Michael Osipov-2
This is an automated email from the ASF dual-hosted git repository.

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-scm.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a133a5  [SCM-919] Fix codecheck violations in JGit provider
2a133a5 is described below

commit 2a133a5fe3e75647dc84a6e62fa2700e633cd3a6
Author: Clemens Quoss <[hidden email]>
AuthorDate: Thu Feb 7 21:00:29 2019 +0100

    [SCM-919] Fix codecheck violations in JGit provider
   
    This closes #89
---
 .../jgit/command/JGitTransportConfigCallback.java  | 87 ++++++++++++++--------
 .../scm/provider/git/jgit/command/JGitUtils.java   |  4 +-
 .../jgit/command/checkout/JGitCheckOutCommand.java | 22 ++++--
 .../git/jgit/command/list/JGitListCommand.java     |  2 +-
 .../command/remoteinfo/JGitRemoteInfoCommand.java  |  2 +-
 5 files changed, 74 insertions(+), 43 deletions(-)

diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java
index 7b13af5..07aa961 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java
@@ -25,7 +25,11 @@ import com.jcraft.jsch.Session;
 import org.apache.maven.scm.log.ScmLogger;
 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.eclipse.jgit.api.TransportConfigCallback;
-import org.eclipse.jgit.transport.*;
+import org.eclipse.jgit.transport.JschConfigSessionFactory;
+import org.eclipse.jgit.transport.OpenSshConfig;
+import org.eclipse.jgit.transport.SshSessionFactory;
+import org.eclipse.jgit.transport.SshTransport;
+import org.eclipse.jgit.transport.Transport;
 import org.eclipse.jgit.util.FS;
 import org.eclipse.jgit.util.StringUtils;
 
@@ -33,73 +37,94 @@ import org.eclipse.jgit.util.StringUtils;
  * Implementation of {@link TransportConfigCallback} which adds
  * a public/private key identity to ssh URLs if configured.
  */
-public class JGitTransportConfigCallback implements TransportConfigCallback {
+public class JGitTransportConfigCallback implements TransportConfigCallback
+{
     private SshSessionFactory sshSessionFactory = null;
 
-    public JGitTransportConfigCallback(GitScmProviderRepository repo, ScmLogger logger) {
-        if (repo.getFetchInfo().getProtocol().equals("ssh")) {
-            if (!StringUtils.isEmptyOrNull(repo.getPrivateKey()) && repo.getPassphrase() == null) {
-                logger.debug("using private key with passphrase: " + repo.getPrivateKey());
-                sshSessionFactory = new UnprotectedPrivateKeySessionFactory(repo);
-            } else if (!StringUtils.isEmptyOrNull(repo.getPrivateKey()) && repo.getPassphrase() != null) {
-                logger.debug("using private key: " + repo.getPrivateKey());
-                sshSessionFactory = new ProtectedPrivateKeyFileSessionFactory(repo);
-            } else {
+    public JGitTransportConfigCallback( GitScmProviderRepository repo, ScmLogger logger )
+    {
+        if ( repo.getFetchInfo().getProtocol().equals( "ssh" ) )
+        {
+            if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) && repo.getPassphrase() == null )
+            {
+                logger.debug( "using private key: " + repo.getPrivateKey() );
+                sshSessionFactory = new UnprotectedPrivateKeySessionFactory( repo );
+            }
+            else if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) && repo.getPassphrase() != null )
+            {
+                logger.debug( "using private key with passphrase: " + repo.getPrivateKey() );
+                sshSessionFactory = new ProtectedPrivateKeyFileSessionFactory( repo );
+            }
+            else
+            {
                 sshSessionFactory = new SimpleSessionFactory();
             }
         }
     }
 
     @Override
-    public void configure(Transport transport) {
-        if (transport instanceof SshTransport) {
+    public void configure( Transport transport )
+    {
+        if ( transport instanceof SshTransport )
+        {
             SshTransport sshTransport = (SshTransport) transport;
-            sshTransport.setSshSessionFactory(sshSessionFactory);
+            sshTransport.setSshSessionFactory( sshSessionFactory );
         }
     }
 
-    static private class SimpleSessionFactory extends JschConfigSessionFactory {
+    private static class SimpleSessionFactory extends JschConfigSessionFactory
+    {
         @Override
-        protected void configure(OpenSshConfig.Host host, Session session) {
+        protected void configure( OpenSshConfig.Host host, Session session )
+        {
         }
     }
 
-    static private abstract class PrivateKeySessionFactory extends SimpleSessionFactory {
+    private abstract static class PrivateKeySessionFactory extends SimpleSessionFactory
+    {
         private final GitScmProviderRepository repo;
 
-        public GitScmProviderRepository getRepo() {
+        GitScmProviderRepository getRepo()
+        {
             return repo;
         }
 
-        public PrivateKeySessionFactory(GitScmProviderRepository repo) {
+        PrivateKeySessionFactory( GitScmProviderRepository repo )
+        {
             this.repo = repo;
         }
     }
 
-    static private class UnprotectedPrivateKeySessionFactory extends PrivateKeySessionFactory {
+    private static class UnprotectedPrivateKeySessionFactory extends PrivateKeySessionFactory
+    {
 
-        public UnprotectedPrivateKeySessionFactory(GitScmProviderRepository repo) {
-            super(repo);
+        UnprotectedPrivateKeySessionFactory( GitScmProviderRepository repo )
+        {
+            super( repo );
         }
 
         @Override
-        protected JSch createDefaultJSch(FS fs) throws JSchException {
-            JSch defaultJSch = super.createDefaultJSch(fs);
-            defaultJSch.addIdentity(getRepo().getPrivateKey());
+        protected JSch createDefaultJSch( FS fs ) throws JSchException
+        {
+            JSch defaultJSch = super.createDefaultJSch( fs );
+            defaultJSch.addIdentity( getRepo().getPrivateKey() );
             return defaultJSch;
         }
     }
 
-    static private class ProtectedPrivateKeyFileSessionFactory extends PrivateKeySessionFactory {
+    private static class ProtectedPrivateKeyFileSessionFactory extends PrivateKeySessionFactory
+    {
 
-        public ProtectedPrivateKeyFileSessionFactory(GitScmProviderRepository repo) {
-            super(repo);
+        ProtectedPrivateKeyFileSessionFactory( GitScmProviderRepository repo )
+        {
+            super( repo );
         }
 
         @Override
-        protected JSch createDefaultJSch(FS fs) throws JSchException {
-            JSch defaultJSch = super.createDefaultJSch(fs);
-            defaultJSch.addIdentity(getRepo().getPrivateKey(), getRepo().getPassphrase());
+        protected JSch createDefaultJSch( FS fs ) throws JSchException
+        {
+            JSch defaultJSch = super.createDefaultJSch( fs );
+            defaultJSch.addIdentity( getRepo().getPrivateKey(), getRepo().getPassphrase() );
             return defaultJSch;
         }
     }
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
index 3e3a4f4..32ada25 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitUtils.java
@@ -188,8 +188,8 @@ public class JGitUtils
         throws GitAPIException, InvalidRemoteException, TransportException
     {
         CredentialsProvider credentials = JGitUtils.prepareSession( logger, git, repo );
-        PushCommand command = git.push().setRefSpecs(refSpec).setCredentialsProvider(credentials)
-                .setTransportConfigCallback(new JGitTransportConfigCallback(repo, logger));
+        PushCommand command = git.push().setRefSpecs( refSpec ).setCredentialsProvider( credentials )
+                .setTransportConfigCallback( new JGitTransportConfigCallback( repo, logger ) );
 
         Iterable<PushResult> pushResultList = command.call();
         for ( PushResult pushResult : pushResultList )
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java
index ea1f1dd..0ba09b7 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/checkout/JGitCheckOutCommand.java
@@ -36,7 +36,11 @@ import org.apache.maven.scm.provider.git.jgit.command.branch.JGitBranchCommand;
 import org.apache.maven.scm.provider.git.jgit.command.remoteinfo.JGitRemoteInfoCommand;
 import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.codehaus.plexus.util.StringUtils;
-import org.eclipse.jgit.api.*;
+import org.eclipse.jgit.api.CloneCommand;
+import org.eclipse.jgit.api.FetchCommand;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.PullCommand;
+import org.eclipse.jgit.api.TransportConfigCallback;
 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ProgressMonitor;
 import org.eclipse.jgit.revwalk.RevCommit;
@@ -113,8 +117,8 @@ public class JGitCheckOutCommand
                 command.setCredentialsProvider( credentials ).setBranch( branch ).setDirectory( fileSet.getBasedir() );
 
                 TransportConfigCallback transportConfigCallback = new JGitTransportConfigCallback(
-                        (GitScmProviderRepository) repo, getLogger());
-                command.setTransportConfigCallback(transportConfigCallback);
+                        (GitScmProviderRepository) repo, getLogger() );
+                command.setTransportConfigCallback( transportConfigCallback );
 
                 command.setProgressMonitor( monitor );
                 git = command.call();
@@ -136,7 +140,7 @@ public class JGitCheckOutCommand
                 // git repo exists, so we must git-pull the changes
                 CredentialsProvider credentials = JGitUtils.prepareSession( getLogger(), git, repository );
                 TransportConfigCallback transportConfigCallback = new JGitTransportConfigCallback(
-                        (GitScmProviderRepository) repo, getLogger());
+                        (GitScmProviderRepository) repo, getLogger() );
 
                 if ( version != null && StringUtils.isNotEmpty( version.getName() ) && ( version instanceof ScmTag ) )
                 {
@@ -146,16 +150,18 @@ public class JGitCheckOutCommand
                     // In fact, a tag in git may be in multiple branches. This occurs if
                     // you create a branch after the tag has been created
                     getLogger().debug( "fetch..." );
-                    FetchCommand command = git.fetch().setCredentialsProvider(credentials).setProgressMonitor(monitor);
-                    command.setTransportConfigCallback(transportConfigCallback);
+                    FetchCommand command = git.fetch().setCredentialsProvider( credentials )
+                            .setProgressMonitor( monitor );
+                    command.setTransportConfigCallback( transportConfigCallback );
                     command.call();
 
                 }
                 else
                 {
                     getLogger().debug( "pull..." );
-                    PullCommand command = git.pull().setCredentialsProvider(credentials).setProgressMonitor(monitor);
-                    command.setTransportConfigCallback(transportConfigCallback);
+                    PullCommand command = git.pull().setCredentialsProvider( credentials )
+                            .setProgressMonitor( monitor );
+                    command.setTransportConfigCallback( transportConfigCallback );
                     command.call();
                 }
             }
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/list/JGitListCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/list/JGitListCommand.java
index 937fa1d..220e9ce 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/list/JGitListCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/list/JGitListCommand.java
@@ -64,7 +64,7 @@ public class JGitListCommand
             List<ScmFile> list = new ArrayList<ScmFile>();
             Collection<Ref> lsResult = git.lsRemote().setCredentialsProvider( credentials )
                     .setTransportConfigCallback(
-                            new JGitTransportConfigCallback((GitScmProviderRepository) repo, getLogger()))
+                            new JGitTransportConfigCallback( (GitScmProviderRepository) repo, getLogger() ) )
                     .call();
             for ( Ref ref : lsResult )
             {
diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/remoteinfo/JGitRemoteInfoCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/remoteinfo/JGitRemoteInfoCommand.java
index 451be02..6a22e33 100644
--- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/remoteinfo/JGitRemoteInfoCommand.java
+++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/remoteinfo/JGitRemoteInfoCommand.java
@@ -63,7 +63,7 @@ public class JGitRemoteInfoCommand
 
             LsRemoteCommand lsCommand =
                 git.lsRemote().setRemote( repo.getPushUrl() ).setCredentialsProvider( credentials )
-                        .setTransportConfigCallback(new JGitTransportConfigCallback(repo, getLogger()));
+                        .setTransportConfigCallback( new JGitTransportConfigCallback( repo, getLogger() ) );
 
             Map<String, String> tag = new HashMap<String, String>();
             Collection<Ref> allTags = lsCommand.setHeads( false ).setTags( true ).call();