michael-o commented on code in PR #153:
URL: https://github.com/apache/maven-scm/pull/153#discussion_r922809389


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java:
##########
@@ -211,11 +220,12 @@ protected CheckInScmResult executeCheckInCommand( 
ScmProviderRepository repo, Sc
     //
     // ----------------------------------------------------------------------
 
-    public static Commandline createPushCommandLine( GitScmProviderRepository 
repository,
+    public Commandline createPushCommandLine( GitScmProviderRepository 
repository,
                                                      ScmFileSet fileSet, 
ScmVersion version )

Review Comment:
   indent wrong



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java:
##########
@@ -232,10 +242,18 @@ public static Commandline createPushCommandLine( 
GitScmProviderRepository reposi
     }
 
     public static Commandline createCommitCommandLine( 
GitScmProviderRepository repository, ScmFileSet fileSet,
-                                                       File messageFile )
+            File messageFile )

Review Comment:
   ditto



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml:
##########
@@ -45,16 +45,26 @@
       <artifactId>maven-scm-provider-git-commons</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit</artifactId>
-      <version>4.5.4.201711221230-r</version>
+      <artifactId>plexus-interactivity-api</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.1</version>
       <exclusions>
         <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
         </exclusion>

Review Comment:
   Why did you change positions? It makes reading the PR harder.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/pom.xml:
##########
@@ -46,6 +46,29 @@
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
     </dependency>
+    <!-- for testing SSH authentication -->
+    <dependency>
+      <groupId>org.apache.sshd</groupId>
+      <artifactId>sshd-git</artifactId>
+      <version>2.8.0</version>

Review Comment:
   Use a property for this.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkin/GitCheckInCommand.java:
##########
@@ -57,6 +58,14 @@
     extends AbstractCheckInCommand
     implements GitCommand
 {
+    private final Map<String, String> environmentVariables;
+
+    public GitCheckInCommand( Map<String, String> environmentVariables )
+    {
+        super();
+        this.environmentVariables = environmentVariables;
+    }

Review Comment:
   There should be a zero-arg ctor too, no?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/remoteinfo/GitRemoteInfoCommand.java:
##########
@@ -38,6 +40,13 @@
     extends AbstractRemoteInfoCommand
     implements GitCommand
 {
+    private final Map<String, String> environmentVariables;
+
+    public GitRemoteInfoCommand( Map<String, String> environmentVariables )
+    {
+        super();
+        this.environmentVariables = environmentVariables;
+    }

Review Comment:
   zero-arg ctor



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/test/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitExeSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,70 @@
+package org.apache.maven.scm.provider.git.gitexe.command.checkout;
+
+/*
+ * 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 java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.GeneralSecurityException;
+
+import org.apache.commons.io.FilenameUtils;
+import 
org.apache.maven.scm.provider.git.command.checkout.GitSshCheckOutCommandTckTest;
+import org.apache.maven.scm.provider.git.gitexe.GitExeScmProvider;
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+
+/**
+ *
+ */
+public class GitExeSshCheckOutCommandTckTest
+    extends GitSshCheckOutCommandTckTest
+{
+    private Path knownHostsFile;
+
+    public static final String VARIABLE_GIT_SSH_COMMAND = "GIT_SSH_COMMAND"; 
// https://git-scm.com/docs/git#Documentation/git.txt-codeGITSSHCOMMANDcode, 
requires git 2.3.0 or newer
+    public GitExeSshCheckOutCommandTckTest() throws GeneralSecurityException, 
IOException
+    {
+        super();
+    }
+
+    @Override
+    protected String getScmProvider()
+    {
+        return "git";
+    }
+
+    @Override
+    public void initRepo() throws Exception
+    {
+        super.initRepo();
+        GitScmProviderRepository providerRepository = 
(GitScmProviderRepository) getScmRepository().getProviderRepository();
+        GitExeScmProvider provider = (GitExeScmProvider) 
getScmManager().getProviderByRepository( getScmRepository() );
+        knownHostsFile = Files.createTempFile( "known-hosts", null );
+        provider.setEnvironmentVariable( VARIABLE_GIT_SSH_COMMAND, "ssh -o 
UserKnownHostsFile=" + knownHostsFile.toString() +

Review Comment:
   toString() is redundant.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gittest/src/main/java/org/apache/maven/scm/provider/git/command/checkout/GitSshCheckOutCommandTckTest.java:
##########
@@ -0,0 +1,185 @@
+package org.apache.maven.scm.provider.git.command.checkout;
+
+/*
+ * 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 java.io.IOException;
+import java.io.Writer;
+import java.nio.file.FileSystem;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.security.GeneralSecurityException;
+import java.security.KeyPair;
+import java.security.PrivateKey;
+import java.security.SecureRandom;
+import java.util.Collections;
+
+import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost;
+import org.apache.maven.scm.provider.git.GitScmTestUtils;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.tck.command.checkout.CheckOutCommandTckTest;
+import org.apache.sshd.common.config.keys.KeyUtils;
+import org.apache.sshd.git.GitLocationResolver;
+import org.apache.sshd.git.pack.GitPackCommandFactory;
+import org.apache.sshd.server.SshServer;
+import org.apache.sshd.server.auth.pubkey.KeySetPublickeyAuthenticator;
+import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator;
+import org.apache.sshd.server.session.ServerSession;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.openssl.PKCS8Generator;
+import org.bouncycastle.openssl.jcajce.JcaPEMWriter;
+import org.bouncycastle.openssl.jcajce.JcaPKCS8Generator;
+import org.bouncycastle.openssl.jcajce.JceOpenSSLPKCS8EncryptorBuilder;
+import org.bouncycastle.operator.OperatorCreationException;
+import org.bouncycastle.operator.OutputEncryptor;
+import org.bouncycastle.util.io.pem.PemObject;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ *
+ */
+public abstract class GitSshCheckOutCommandTckTest
+    extends CheckOutCommandTckTest
+{
+    protected final SshServer sshServer;
+    protected final KeyPair keyPair;
+
+    @Rule
+    public TemporaryFolder tmpDirectory = new TemporaryFolder();
+
+    protected GitSshCheckOutCommandTckTest() throws GeneralSecurityException, 
IOException
+    {
+         sshServer = CoreTestSupportUtils.setupTestServer( getClass() );
+         keyPair = CommonTestSupportUtils.generateKeyPair( 
KeyUtils.RSA_ALGORITHM, 2048 );
+         PublickeyAuthenticator authenticator = new 
KeySetPublickeyAuthenticator( "onlykey",
+                 Collections.singletonList( keyPair.getPublic() ) );
+         sshServer.setPublickeyAuthenticator( authenticator );
+    }
+
+    static void writePrivateKeyAsPkcs8( Path file, PrivateKey privateKey, 
String passphrase )
+            throws IOException, OperatorCreationException
+    {
+        final OutputEncryptor encryptor;
+        // encryption only optional
+        if ( passphrase != null )
+        {
+            //encrypted form of PKCS#8 file  
+            JceOpenSSLPKCS8EncryptorBuilder encryptorBuilder = 
+                    new JceOpenSSLPKCS8EncryptorBuilder( 
PKCS8Generator.PBE_SHA1_3DES );
+            encryptorBuilder.setRandom( new SecureRandom() );
+            encryptorBuilder.setProvider( BouncyCastleProvider.PROVIDER_NAME );
+            encryptorBuilder.setPassword( passphrase.toCharArray() );
+            encryptor = encryptorBuilder.build();
+        }
+        else 
+        {
+            encryptor = null;
+        }
+
+        PKCS8Generator pkcs8Generator = new JcaPKCS8Generator( privateKey, 
encryptor );
+        PemObject pemObject = pkcs8Generator.generate();
+        
+        try ( Writer writer = Files.newBufferedWriter( file );
+              JcaPEMWriter pw = new JcaPEMWriter( writer ) )
+        {
+            pw.writeObject( pemObject );
+        }
+        if ( file.getFileSystem().supportedFileAttributeViews().contains( 
"posix" ) )
+        {
+            // must only be readable/writeable by me
+            Files.setPosixFilePermissions( file, 
PosixFilePermissions.fromString( "rwx------" ) );
+        }
+    }
+
+    protected abstract String getScmProvider();
+
+    /** {@inheritDoc} */
+    public String getScmUrl()
+        throws Exception
+    {
+        return "scm:" + getScmProvider() + ":ssh://127.0.0.1:" + 
sshServer.getPort() + "/repository";

Review Comment:
   localhost



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/PlexusInteractivityCredentialsProvider.java:
##########
@@ -0,0 +1,101 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * 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 java.util.Arrays;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.eclipse.jgit.errors.UnsupportedCredentialItem;
+import org.eclipse.jgit.transport.CredentialItem;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * {@link CredentialsProvider} leveraging the {@link Prompter} component.
+ *
+ */
+public class PlexusInteractivityCredentialsProvider extends CredentialsProvider
+{
+    private final boolean isInteractive;

Review Comment:
   This one is never used, what is the purpose?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java:
##########
@@ -19,47 +19,22 @@
  * under the License.
  */
 
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.eclipse.jgit.api.TransportConfigCallback;
-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;
-import org.slf4j.Logger;
+import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
 
 /**
  * Implementation of {@link TransportConfigCallback} which adds
  * a public/private key identity to ssh URLs if configured.
  */
 public class JGitTransportConfigCallback implements TransportConfigCallback
 {
-    private SshSessionFactory sshSessionFactory = null;
+    private final SshdSessionFactory sshSessionFactory;
 
-    public JGitTransportConfigCallback( GitScmProviderRepository repo, Logger 
logger )
+    public JGitTransportConfigCallback( SshdSessionFactory sshSessionFactory )
     {
-        if ( repo.getFetchInfo().getProtocol().equals( "ssh" ) )

Review Comment:
   Is the value normalized to lowercase with the get?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-gitexe/src/main/java/org/apache/maven/scm/provider/git/gitexe/command/checkout/GitCheckOutCommand.java:
##########
@@ -52,6 +53,14 @@
     extends AbstractCheckOutCommand
     implements GitCommand
 {
+    private final Map<String, String> environmentVariables;
+
+    public GitCheckOutCommand( Map<String, String> environmentVariables )
+    {
+        super();
+        this.environmentVariables = environmentVariables;
+    }
+

Review Comment:
   zero-arg ctor?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/pom.xml:
##########
@@ -45,16 +45,26 @@
       <artifactId>maven-scm-provider-git-commons</artifactId>
     </dependency>
     <dependency>
-      <groupId>org.eclipse.jgit</groupId>
-      <artifactId>org.eclipse.jgit</artifactId>
-      <version>4.5.4.201711221230-r</version>
+      <artifactId>plexus-interactivity-api</artifactId>
+      <groupId>org.codehaus.plexus</groupId>
+      <version>1.1</version>
       <exclusions>
         <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
+          <groupId>org.codehaus.plexus</groupId>
+          <artifactId>plexus-container-default</artifactId>
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.jgit</groupId>
+      <artifactId>org.eclipse.jgit</artifactId>
+      <version>5.13.1.202206130422-r</version><!-- since version 6 requires 
Java 11 -->
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jgit</groupId>
+      <artifactId>org.eclipse.jgit.ssh.apache</artifactId>
+      <version>5.13.1.202206130422-r</version><!-- since version 6 requires 
Java 11 -->
+    </dependency>

Review Comment:
   Is this strictly required to test gitexe ssh alternative private key? I 
don't think so. If not, I'd recomment to remove the JGit bits from here, 
complete gitexe with whatever is required then do two JGit PRs. WDYT?



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/ScmProviderAwareSshdSessionFactory.java:
##########
@@ -0,0 +1,92 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.transport.sshd.IdentityPasswordProvider;
+import org.eclipse.jgit.transport.sshd.KeyPasswordProvider;
+import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
+import org.eclipse.jgit.util.StringUtils;
+import org.slf4j.Logger;
+
+/**
+ * {@link SshdSessionFactory} considering the settings from {@link 
GitScmProviderRepository}.
+ *
+ */
+public class ScmProviderAwareSshdSessionFactory extends SshdSessionFactory
+{
+    private final GitScmProviderRepository repo;
+    private final Logger logger;
+
+    public ScmProviderAwareSshdSessionFactory( GitScmProviderRepository repo, 
Logger logger )
+    {
+        this.repo = repo;
+        this.logger = logger;
+    }
+
+    @Override
+    protected List<Path> getDefaultIdentities( File sshDir )
+    {
+        if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) )
+        {
+            logger.debug( "Using private key at {}", repo.getPrivateKey() );
+            return Collections.singletonList( Paths.get( repo.getPrivateKey() 
) );
+        }
+        else 
+        {
+            return super.getDefaultIdentities( sshDir );
+        }
+    }
+
+    @Override
+    protected KeyPasswordProvider createKeyPasswordProvider( 
CredentialsProvider provider )
+    {
+        if ( repo.getPassphrase() != null )
+        {
+            return new IdentityPasswordProvider( provider )
+            {
+                @Override
+                public char[] getPassphrase( URIish uri, int attempt ) throws 
IOException
+                {
+                    if ( attempt > 0 )
+                    {
+                        throw new IOException( "Passphrase was not correct in 
first attempt, "
+                            + "cancel further attempts!" );

Review Comment:
   canceling



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java:
##########
@@ -19,47 +19,22 @@
  * under the License.
  */
 
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.eclipse.jgit.api.TransportConfigCallback;
-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;
-import org.slf4j.Logger;
+import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
 
 /**
  * Implementation of {@link TransportConfigCallback} which adds
  * a public/private key identity to ssh URLs if configured.
  */
 public class JGitTransportConfigCallback implements TransportConfigCallback
 {
-    private SshSessionFactory sshSessionFactory = null;
+    private final SshdSessionFactory sshSessionFactory;
 
-    public JGitTransportConfigCallback( GitScmProviderRepository repo, Logger 
logger )
+    public JGitTransportConfigCallback( SshdSessionFactory sshSessionFactory )
     {
-        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() );

Review Comment:
   Using



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/JGitScmProvider.java:
##########
@@ -54,6 +58,12 @@
 public class JGitScmProvider
     extends AbstractGitScmProvider
 {
+    @Inject
+    public JGitScmProvider( Prompter prompter )
+    {
+        CredentialsProvider.setDefault( new 
PlexusInteractivityCredentialsProvider( true, prompter ) );

Review Comment:
   The `true` looks wrong because you assume that you always run interactive 
which might not always be the case.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/PlexusInteractivityCredentialsProvider.java:
##########
@@ -0,0 +1,101 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * 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 java.util.Arrays;
+
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.eclipse.jgit.errors.UnsupportedCredentialItem;
+import org.eclipse.jgit.transport.CredentialItem;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+
+/**
+ * {@link CredentialsProvider} leveraging the {@link Prompter} component.
+ *
+ */
+public class PlexusInteractivityCredentialsProvider extends CredentialsProvider
+{
+    private final boolean isInteractive;
+    private final Prompter prompter;
+
+    public PlexusInteractivityCredentialsProvider( boolean isInteractive, 
Prompter prompter )
+    {
+        this.isInteractive = isInteractive;
+        this.prompter = prompter;
+    }
+
+    @Override
+    public boolean get( URIish uri, CredentialItem... items ) throws 
UnsupportedCredentialItem
+    {
+        for ( CredentialItem item : items )
+        {
+            try 
+            {
+                if ( item instanceof CredentialItem.YesNoType )
+                {
+                    CredentialItem.YesNoType yesNoItem = ( 
CredentialItem.YesNoType ) item;
+                    String value = prompter.prompt( item.getPromptText(), 
Arrays.asList( "yes", "no" ) );
+                    yesNoItem.setValue( value.equals( "yes" ) );
+                } 
+                else if ( item instanceof CredentialItem.Password )
+                {
+                    CredentialItem.Password passwordItem = ( 
CredentialItem.Password ) item;
+                    String password = prompter.promptForPassword( 
passwordItem.getPromptText() );
+                    passwordItem.setValue( password.toCharArray() );
+                }
+                else if ( item instanceof CredentialItem.Username )
+                {
+                    CredentialItem.Username usernameItem = ( 
CredentialItem.Username ) item;
+                    String username = prompter.prompt( 
usernameItem.getPromptText() );
+                    usernameItem.setValue( username );
+                }
+                else if ( item instanceof CredentialItem.InformationalMessage )
+                {
+                    prompter.showMessage( item.getPromptText() );
+                }
+                else
+                {
+                    throw new UnsupportedCredentialItem( uri, 
item.getClass().toString() );
+                }
+            }
+            catch ( PrompterException e )
+            {
+                throw new IllegalStateException( "Can not prompt user " + 
e.getMessage() , e );

Review Comment:
   `throw new IllegalStateException( "Cannot prompt user " , e );`



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/JGitTransportConfigCallback.java:
##########
@@ -19,47 +19,22 @@
  * under the License.
  */
 
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.Session;
-import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
 import org.eclipse.jgit.api.TransportConfigCallback;
-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;
-import org.slf4j.Logger;
+import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
 
 /**
  * Implementation of {@link TransportConfigCallback} which adds
  * a public/private key identity to ssh URLs if configured.
  */
 public class JGitTransportConfigCallback implements TransportConfigCallback
 {
-    private SshSessionFactory sshSessionFactory = null;
+    private final SshdSessionFactory sshSessionFactory;
 
-    public JGitTransportConfigCallback( GitScmProviderRepository repo, Logger 
logger )
+    public JGitTransportConfigCallback( SshdSessionFactory sshSessionFactory )
     {
-        if ( repo.getFetchInfo().getProtocol().equals( "ssh" ) )
-        {
-            if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) && 
repo.getPassphrase() == null )
-            {
-                logger.debug( "using private key: " + repo.getPrivateKey() );

Review Comment:
   Using



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/ScmProviderAwareSshdSessionFactory.java:
##########
@@ -0,0 +1,92 @@
+package org.apache.maven.scm.provider.git.jgit.command;
+
+/*
+ * 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 java.io.File;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.scm.provider.git.repository.GitScmProviderRepository;
+import org.eclipse.jgit.transport.CredentialsProvider;
+import org.eclipse.jgit.transport.URIish;
+import org.eclipse.jgit.transport.sshd.IdentityPasswordProvider;
+import org.eclipse.jgit.transport.sshd.KeyPasswordProvider;
+import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
+import org.eclipse.jgit.util.StringUtils;
+import org.slf4j.Logger;
+
+/**
+ * {@link SshdSessionFactory} considering the settings from {@link 
GitScmProviderRepository}.
+ *
+ */
+public class ScmProviderAwareSshdSessionFactory extends SshdSessionFactory
+{
+    private final GitScmProviderRepository repo;
+    private final Logger logger;
+
+    public ScmProviderAwareSshdSessionFactory( GitScmProviderRepository repo, 
Logger logger )
+    {
+        this.repo = repo;
+        this.logger = logger;
+    }
+
+    @Override
+    protected List<Path> getDefaultIdentities( File sshDir )
+    {
+        if ( !StringUtils.isEmptyOrNull( repo.getPrivateKey() ) )
+        {
+            logger.debug( "Using private key at {}", repo.getPrivateKey() );

Review Comment:
   This message looks good and this is how the other should look like



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@maven.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to