[ 
https://issues.apache.org/jira/browse/SCM-994?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568861#comment-17568861
 ] 

ASF GitHub Bot commented on SCM-994:
------------------------------------

kwin commented on code in PR #154:
URL: https://github.com/apache/maven-scm/pull/154#discussion_r925219021


##########
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,132 @@
+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 boolean interactive;
+    private final Prompter prompter;
+
+    public PlexusInteractivityCredentialsProvider( Prompter prompter )
+    {
+        this.interactive = true;
+        this.prompter = prompter;
+    }
+
+    @Override
+    public boolean get( URIish uri, CredentialItem... items ) throws 
UnsupportedCredentialItem
+    {
+        for ( CredentialItem item : items )
+        {
+            try
+            {
+                get( uri, item );
+            }
+            catch ( PrompterException e )
+            {
+                throw new IllegalStateException( "Can not prompt user " + 
e.getMessage() , e );
+            }
+        }
+        return true;
+    }
+
+    private void get( URIish uri, CredentialItem item ) throws 
PrompterException
+    {
+        if ( item instanceof CredentialItem.InformationalMessage )
+        {
+            // works even in non-interactive mode
+            prompter.showMessage( item.getPromptText() );
+        }
+        else
+        {
+            if ( !interactive )
+            {
+                throw new UnsupportedCredentialItem( uri, 
+                        "Cannot provide " + item.getClass() + " in 
non-interactive mode" );

Review Comment:
   Done in 
https://github.com/apache/maven-scm/pull/154/commits/521a09a78510a624271d8681c15e506c63b327c4.





> Add JGit CredentialsProvider based on Plexus Interactivity API
> --------------------------------------------------------------
>
>                 Key: SCM-994
>                 URL: https://issues.apache.org/jira/browse/SCM-994
>             Project: Maven SCM
>          Issue Type: Improvement
>          Components: maven-scm-provider-jgit
>            Reporter: Konrad Windszus
>            Assignee: Michael Osipov
>            Priority: Major
>             Fix For: 2.0.0-M2
>
>
> Currently the JGit provider does not provide interactive communication means, 
> e.g. for asking for a password or adding a new server to the known hosts. 
> There should be an implementation for 
> https://javadoc.io/static/org.eclipse.jgit/org.eclipse.jgit/5.13.1.202206130422-r/org/eclipse/jgit/transport/CredentialsProvider.html
>  backed by Plexus's Prompter component 
> (https://codehaus-plexus.github.io/plexus-interactivity/plexus-interactivity-api/apidocs/org/codehaus/plexus/components/interactivity/Prompter.html).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to