Skip to content

Commit 7d038eb

Browse files
authored
Merge pull request #1127 from olamy/apache-mina-ssh
Use Apache Mina, remove trilead for ssh connectivity
2 parents d4b5aec + 463189f commit 7d038eb

29 files changed

+1165
-850
lines changed

pom.xml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
</scm>
5959

6060
<properties>
61-
<revision>4.8.0</revision>
61+
<revision>5.0.0</revision>
6262
<changelist>-SNAPSHOT</changelist>
6363
<!-- Character set tests fail unless file.encoding is set -->
6464
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
@@ -207,16 +207,24 @@
207207
<groupId>org.jenkins-ci.plugins</groupId>
208208
<artifactId>structs</artifactId>
209209
</dependency>
210-
<dependency>
211-
<groupId>org.jenkins-ci.plugins</groupId>
212-
<artifactId>trilead-api</artifactId>
213-
</dependency>
214210
<dependency>
215211
<groupId>com.googlecode.json-simple</groupId>
216212
<artifactId>json-simple</artifactId>
217213
<version>1.1.1</version>
218214
<scope>test</scope>
219215
</dependency>
216+
<dependency>
217+
<groupId>io.github.sparsick.testcontainers.gitserver</groupId>
218+
<artifactId>testcontainers-gitserver</artifactId>
219+
<version>0.8.0</version>
220+
<scope>test</scope>
221+
<exclusions>
222+
<exclusion>
223+
<groupId>ch.qos.logback</groupId>
224+
<artifactId>*</artifactId>
225+
</exclusion>
226+
</exclusions>
227+
</dependency>
220228
<dependency>
221229
<groupId>io.jenkins.configuration-as-code</groupId>
222230
<artifactId>test-harness</artifactId>
@@ -234,8 +242,9 @@
234242
<scope>test</scope>
235243
</dependency>
236244
<dependency>
237-
<groupId>org.jenkins-ci.plugins</groupId>
238-
<artifactId>git-server</artifactId>
245+
<groupId>org.awaitility</groupId>
246+
<artifactId>awaitility</artifactId>
247+
<version>4.2.1</version>
239248
<scope>test</scope>
240249
</dependency>
241250
<dependency>
@@ -262,6 +271,12 @@
262271
<version>3.4</version>
263272
<scope>test</scope>
264273
</dependency>
274+
<dependency>
275+
<groupId>org.testcontainers</groupId>
276+
<artifactId>testcontainers</artifactId>
277+
<version>1.19.8</version>
278+
<scope>test</scope>
279+
</dependency>
265280
</dependencies>
266281

267282
<repositories>
@@ -280,6 +295,15 @@
280295

281296
<build>
282297
<plugins>
298+
<plugin>
299+
<groupId>org.apache.maven.plugins</groupId>
300+
<artifactId>maven-surefire-plugin</artifactId>
301+
<configuration>
302+
<systemPropertyVariables>
303+
<org.jenkinsci.plugins.gitclient.verifier.SshHostKeyVerificationStrategy.jgit_known_hosts_file>${project.build.directory}/ssh/know_hosts</org.jenkinsci.plugins.gitclient.verifier.SshHostKeyVerificationStrategy.jgit_known_hosts_file>
304+
</systemPropertyVariables>
305+
</configuration>
306+
</plugin>
283307
<plugin>
284308
<groupId>org.apache.maven.plugins</groupId>
285309
<artifactId>maven-javadoc-plugin</artifactId>

src/main/java/org/jenkinsci/plugins/gitclient/Git.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.logging.Level;
1515
import java.util.logging.Logger;
1616
import jenkins.model.Jenkins;
17-
import org.jenkinsci.plugins.gitclient.jgit.PreemptiveAuthHttpClientConnectionFactory;
1817
import org.jenkinsci.plugins.gitclient.verifier.HostKeyVerifierFactory;
1918
import org.jenkinsci.plugins.gitclient.verifier.NoHostKeyVerificationStrategy;
2019

@@ -42,6 +41,7 @@ public class Git implements Serializable {
4241
private TaskListener listener;
4342
private EnvVars env;
4443
private String exe;
44+
private HostKeyVerifierFactory hostKeyFactory;
4545

4646
/**
4747
* Constructor for a Git object. Either <code>Git.with(listener, env)</code>
@@ -116,6 +116,11 @@ public Git using(String exe) {
116116
return this;
117117
}
118118

119+
public Git withHostKeyVerifierFactory(HostKeyVerifierFactory hostKeyFactory) {
120+
this.hostKeyFactory = hostKeyFactory;
121+
return this;
122+
}
123+
119124
/**
120125
* {@link org.jenkinsci.plugins.gitclient.GitClient} implementation. The {@link org.jenkinsci.plugins.gitclient.GitClient} interface
121126
* provides the key operations which can be performed on a git repository.
@@ -125,14 +130,15 @@ public Git using(String exe) {
125130
* @throws java.lang.InterruptedException if interrupted.
126131
*/
127132
public GitClient getClient() throws IOException, InterruptedException {
128-
HostKeyVerifierFactory hostKeyFactory;
129-
if (Jenkins.getInstanceOrNull() == null) {
130-
LOGGER.log(Level.FINE, "No Jenkins instance, skipping host key checking by default");
131-
hostKeyFactory = new NoHostKeyVerificationStrategy().getVerifier();
132-
} else {
133-
hostKeyFactory = GitHostKeyVerificationConfiguration.get()
134-
.getSshHostKeyVerificationStrategy()
135-
.getVerifier();
133+
if (this.hostKeyFactory == null) {
134+
if (Jenkins.getInstanceOrNull() == null) {
135+
LOGGER.log(Level.FINE, "No Jenkins instance, skipping host key checking by default");
136+
this.hostKeyFactory = new NoHostKeyVerificationStrategy().getVerifier();
137+
} else {
138+
this.hostKeyFactory = GitHostKeyVerificationConfiguration.get()
139+
.getSshHostKeyVerificationStrategy()
140+
.getVerifier();
141+
}
136142
}
137143
jenkins.MasterToSlaveFileCallable<GitClient> callable = new GitAPIMasterToSlaveFileCallable(hostKeyFactory);
138144
GitClient git = (repository != null ? repository.act(callable) : callable.invoke(null, null));
@@ -199,9 +205,7 @@ public GitClient invoke(File f, VirtualChannel channel) throws IOException, Inte
199205
}
200206

201207
if (JGitApacheTool.MAGIC_EXENAME.equalsIgnoreCase(exe)) {
202-
final PreemptiveAuthHttpClientConnectionFactory factory =
203-
new PreemptiveAuthHttpClientConnectionFactory();
204-
return new JGitAPIImpl(f, listener, factory, hostKeyFactory);
208+
return new JGitAPIImpl(f, listener, hostKeyFactory);
205209
}
206210
// Ensure we return a backward compatible GitAPI, even API only claim to provide a GitClient
207211
GitAPI gitAPI = new GitAPI(exe, f, listener, env);

0 commit comments

Comments
 (0)