Skip to content

Commit

Permalink
Use Apache Mina, remove trilead
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy committed May 27, 2024
1 parent cc3dc2d commit fc4ba45
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 436 deletions.
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,17 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ssh-credentials</artifactId>
<exclusions>
<exclusion>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>trilead-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.eclipse.jgit.api.AddNoteCommand;
import org.eclipse.jgit.api.CommitCommand;
Expand Down Expand Up @@ -111,15 +112,17 @@
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.SshConstants;
import org.eclipse.jgit.transport.SshSessionFactory;
import org.eclipse.jgit.transport.TagOpt;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.sshd.SshdSessionFactory;
import org.eclipse.jgit.transport.sshd.SshdSessionFactoryBuilder;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.TreeFilter;
import org.jenkinsci.plugins.gitclient.jgit.PreemptiveAuthHttpClientConnectionFactory;
import org.jenkinsci.plugins.gitclient.trilead.SmartCredentialsProvider;
import org.jenkinsci.plugins.gitclient.trilead.TrileadSessionFactory;
import org.jenkinsci.plugins.gitclient.jgit.SmartCredentialsProvider;
import org.jenkinsci.plugins.gitclient.verifier.HostKeyVerifierFactory;

/**
Expand Down Expand Up @@ -166,7 +169,7 @@ public class JGitAPIImpl extends LegacyCompatibleGitAPIImpl {

// to avoid rogue plugins from clobbering what we use, always
// make a point of overwriting it with ours.
SshSessionFactory.setInstance(new TrileadSessionFactory(hostKeyFactory, listener));
SshSessionFactory.setInstance(buildSshdSessionFactory());

if (httpConnectionFactory != null) {
httpConnectionFactory.setCredentialsProvider(asSmartCredentialsProvider());
Expand All @@ -175,6 +178,15 @@ public class JGitAPIImpl extends LegacyCompatibleGitAPIImpl {
}
}

protected SshdSessionFactory buildSshdSessionFactory() {
return new SshdSessionFactoryBuilder()
// CHECK could it be different on slave?
.setHomeDirectory(SystemUtils.getUserHome())
.setSshDirectory(new File(SystemUtils.getUserHome(), SshConstants.SSH_DIR))
.withDefaultConnectorFactory()
.build(null);
}

/**
* clearCredentials.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jenkinsci.plugins.gitclient.trilead;
package org.jenkinsci.plugins.gitclient.jgit;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
Expand All @@ -12,10 +12,10 @@
* Provides the credential to authenticate Git connection.
*
* <p>
* For HTTP transport we work through {@link org.eclipse.jgit.transport.CredentialsProvider},
* in which case this must be supplied with a {@link com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials}.
* For SSH transport, {@link org.jenkinsci.plugins.gitclient.trilead.TrileadSessionFactory}
* downcasts {@link org.eclipse.jgit.transport.CredentialsProvider} to this class.
* For HTTP transport we work through {@link CredentialsProvider},
* in which case this must be supplied with a {@link StandardUsernamePasswordCredentials}.
* For SSH transport, {@link MinaSessionFactory}
* downcasts {@link CredentialsProvider} to this class.
*
* @author Kohsuke Kawaguchi
*/
Expand All @@ -29,8 +29,8 @@ public class CredentialsProviderImpl extends CredentialsProvider {
/**
* Constructor for CredentialsProviderImpl.
*
* @param listener a {@link hudson.model.TaskListener} object.
* @param cred a {@link com.cloudbees.plugins.credentials.common.StandardUsernameCredentials} object.
* @param listener a {@link TaskListener} object.
* @param cred a {@link StandardUsernameCredentials} object.
*/
public CredentialsProviderImpl(TaskListener listener, StandardUsernameCredentials cred) {
this.listener = listener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
import org.eclipse.jgit.transport.http.apache.TemporaryBufferEntity;
import org.eclipse.jgit.transport.http.apache.internal.HttpApacheText;
import org.eclipse.jgit.util.TemporaryBuffer;
import org.jenkinsci.plugins.gitclient.trilead.SmartCredentialsProvider;

/**
* A {@link HttpConnection} which uses {@link HttpClient} and attempts to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.net.URL;
import org.eclipse.jgit.transport.http.HttpConnection;
import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.jenkinsci.plugins.gitclient.trilead.SmartCredentialsProvider;

public class PreemptiveAuthHttpClientConnectionFactory implements HttpConnectionFactory {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jenkinsci.plugins.gitclient.trilead;
package org.jenkinsci.plugins.gitclient.jgit;

import com.cloudbees.plugins.credentials.common.PasswordCredentials;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
Expand Down Expand Up @@ -32,7 +32,7 @@ public class SmartCredentialsProvider extends CredentialsProvider {
/**
* Constructor for SmartCredentialsProvider.
*
* @param listener a {@link hudson.model.TaskListener} object.
* @param listener a {@link TaskListener} object.
*/
public SmartCredentialsProvider(TaskListener listener) {
this.listener = listener;
Expand Down Expand Up @@ -63,7 +63,7 @@ public synchronized void addCredentials(String url, StandardCredentials credenti
* Adds credentials to be used when there are not url specific credentials defined.
*
* @param credentials the credentials to use.
* @see #addCredentials(String, com.cloudbees.plugins.credentials.common.StandardCredentials)
* @see #addCredentials(String, StandardCredentials)
* @since 1.2.0
*/
public synchronized void addDefaultCredentials(StandardCredentials credentials) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jenkinsci.plugins.gitclient.trilead;
package org.jenkinsci.plugins.gitclient.jgit;

import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import org.eclipse.jgit.transport.CredentialItem;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit fc4ba45

Please sign in to comment.