[ https://issues.apache.org/jira/browse/SCM-994?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568541#comment-17568541 ]
ASF GitHub Bot commented on SCM-994: ------------------------------------ kwin commented on code in PR #154: URL: https://github.com/apache/maven-scm/pull/154#discussion_r924459618 ########## 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,106 @@ +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 isInteractive; Review Comment: Done in https://github.com/apache/maven-scm/pull/154/commits/617c43e02f33474dc9fc2c17ee400f874d18d789 ########## 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,106 @@ +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 isInteractive; + private final Prompter prompter; + + public PlexusInteractivityCredentialsProvider( Prompter prompter ) + { + this.isInteractive = true; + 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 ); + } + } + return true; + } + + public void setInteractive( boolean isInteractive ) Review Comment: Done in https://github.com/apache/maven-scm/pull/154/commits/617c43e02f33474dc9fc2c17ee400f874d18d789 > 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 > Priority: Major > > 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)