Skip to content

Commit bc80784

Browse files
committed
Add support for SSH transport with JGit and plugin git operation
1 parent 96dfce8 commit bc80784

File tree

24 files changed

+819
-127
lines changed

24 files changed

+819
-127
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ target/
33
!**/src/main/**/target/
44
!**/src/test/**/target/
55

6-
### Plugins Directory ###
7-
test-plugins
8-
96
### Log file ###
107
logs/
118

129
### IntelliJ IDEA ###
1310
.idea/
11+
!.idea/runConfigurations/
12+
!.idea/.gitignore/
1413
*.iws
1514
*.iml
1615
*.ipr
@@ -34,6 +33,8 @@ build/
3433
!**/src/main/**/build/
3534
!**/src/test/**/build/
3635

36+
!**/test/resources/**/.git
37+
3738
### VS Code ###
3839
.vscode/
3940

.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Jenkinsfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
@Library('pipeline-library@pull/893/head') _
2+
13
// While this isn't a plugin, it is much simpler to reuse the pipeline code for CI
24
// allowing easy windows / linux testing and producing incrementals
35
// the only feature that buildPlugin has that relates to plugins is allowing you to test against multiple jenkins versions
46
buildPlugin(
57
useContainerAgent: false,
8+
useArtifactCachingProxy: false,
69
configurations: [
710
[platform: 'linux', jdk: 21],
811
[platform: 'windows', jdk: 21],

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ From there you need to save both ID of installation (found on URL)
104104

105105
## Global option
106106

107-
- `--debug` or `-d`: (optional) Enables debug mode. Defaults to false.
107+
- `--debug`: (optional) Enables debug mode. Defaults to false.
108108

109109

110-
- `--cache-path` or `-c`: (optional) Custom path to the cache directory. Defaults to `${user.home}/.cache/jenkins-plugin-modernizer-cli`.
110+
- `--cache-path`: (optional) Custom path to the cache directory. Defaults to `${user.home}/.cache/jenkins-plugin-modernizer-cli`.
111111

112112

113-
- `--maven-home` or `-m`: (optional) Path to the Maven home directory. Required if both `MAVEN_HOME` and `M2_HOME` environment variables are not set. The minimum required version is 3.9.7.
113+
- `--maven-home`: (optional) Path to the Maven home directory. Required if both `MAVEN_HOME` and `M2_HOME` environment variables are not set. The minimum required version is 3.9.7.
114114

115115

116116
- `--clean-local-data` (optional) Deletes the local plugin directory before running the tool.

plugin-modernizer-cli/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
<include>**/*ITCase.java</include>
123123
</includes>
124124
<environmentVariables>
125+
<MAVEN_LOCAL_REPO>${maven.repo.local}</MAVEN_LOCAL_REPO>
125126
<MAVEN_HOME>${project.build.directory}/apache-maven-${maven.version}</MAVEN_HOME>
126127
<GH_TOKEN>fake-token</GH_TOKEN>
127128
<GH_OWNER>fake-owner</GH_OWNER>

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/command/BuildMetadataCommand.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.jenkins.tools.pluginmodernizer.core.config.Config;
77
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
88
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
9+
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
10+
import java.nio.file.Path;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113
import picocli.CommandLine;
@@ -27,6 +29,14 @@ public class BuildMetadataCommand implements ICommand {
2729
@CommandLine.ArgGroup(exclusive = true, multiplicity = "1")
2830
private PluginOptions pluginOptions;
2931

32+
/**
33+
* Path to the authentication key in case of private repo
34+
*/
35+
@CommandLine.Option(
36+
names = {"--ssh-private-key"},
37+
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
38+
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;
39+
3040
/**
3141
* Global options for all commands
3242
*/
@@ -44,12 +54,21 @@ public Config setup(Config.Builder builder) {
4454
options.config(builder);
4555
envOptions.config(builder);
4656
pluginOptions.config(builder);
47-
return builder.withRecipe(Settings.FETCH_METADATA_RECIPE).build();
57+
return builder.withSshPrivateKey(sshPrivateKey)
58+
.withRecipe(Settings.FETCH_METADATA_RECIPE)
59+
.build();
4860
}
4961

5062
@Override
51-
public Integer call() throws Exception {
63+
public Integer call() {
5264
PluginModernizer modernizer = getModernizer();
65+
try {
66+
modernizer.validate();
67+
} catch (ModernizerException e) {
68+
LOG.error("Validation error");
69+
LOG.error(e.getMessage());
70+
return 1;
71+
}
5372
modernizer.start();
5473
return 0;
5574
}

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/command/ValidateCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.jenkins.tools.pluginmodernizer.core.config.Config;
77
import io.jenkins.tools.pluginmodernizer.core.impl.PluginModernizer;
88
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113
import picocli.CommandLine;
@@ -53,7 +55,13 @@ public Integer call() throws Exception {
5355
try {
5456
modernizer.validate();
5557
LOG.info("GitHub owner: {}", modernizer.getGithubOwner());
58+
if (Files.isRegularFile(Path.of(modernizer.getSshPrivateKeyPath()))) {
59+
LOG.info("SSH key path: {}", modernizer.getSshPrivateKeyPath());
60+
} else {
61+
LOG.info("SSH key not set. Will use GitHub token for Git operation");
62+
}
5663
LOG.info("Maven home: {}", modernizer.getMavenHome());
64+
LOG.info("Maven local repository: {}", modernizer.getMavenLocalRepo());
5765
LOG.info("Maven version: {}", modernizer.getMavenVersion());
5866
LOG.info("Java version: {}", modernizer.getJavaVersion());
5967
LOG.info("Cache path: {}", modernizer.getCachePath());

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/options/GitHubOptions.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.jenkins.tools.pluginmodernizer.core.config.Config;
44
import io.jenkins.tools.pluginmodernizer.core.config.Settings;
5+
import java.nio.file.Path;
56
import picocli.CommandLine;
67

78
/**
@@ -15,6 +16,14 @@
1516
commandListHeading = "%nCommands:%n")
1617
public class GitHubOptions implements IOption {
1718

19+
/**
20+
* Path to the authentication key
21+
*/
22+
@CommandLine.Option(
23+
names = {"--ssh-private-key"},
24+
description = "Path to the authentication key for GitHub. Default to ~/.ssh/id_rsa")
25+
private Path sshPrivateKey = Settings.SSH_PRIVATE_KEY;
26+
1827
@CommandLine.Option(
1928
names = {"-g", "--github-owner"},
2029
description = "GitHub owner for forked repositories.")
@@ -46,6 +55,7 @@ public void config(Config.Builder builder) {
4655
builder.withGitHubOwner(githubOwner)
4756
.withGitHubAppId(githubAppId)
4857
.withGitHubAppSourceInstallationId(githubAppSourceInstallationId)
49-
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId);
58+
.withGitHubAppTargetInstallationId(githubAppTargetInstallationId)
59+
.withSshPrivateKey(sshPrivateKey);
5060
}
5161
}

plugin-modernizer-cli/src/main/java/io/jenkins/tools/pluginmodernizer/cli/options/GlobalOptions.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,25 @@
2020
public class GlobalOptions implements IOption {
2121

2222
@CommandLine.Option(
23-
names = {"-d", "--debug"},
23+
names = {"--debug"},
2424
description = "Enable debug logging.")
2525
public boolean debug;
2626

2727
@CommandLine.Option(
28-
names = {"-c", "--cache-path"},
28+
names = {"--cache-path"},
2929
description = "Path to the cache directory.")
3030
public Path cachePath = Settings.DEFAULT_CACHE_PATH;
3131

3232
@CommandLine.Option(
33-
names = {"-m", "--maven-home"},
33+
names = {"--maven-home"},
3434
description = "Path to the Maven Home directory.")
3535
public Path mavenHome = Settings.DEFAULT_MAVEN_HOME;
3636

37+
@CommandLine.Option(
38+
names = {"--maven-local-repo"},
39+
description = "Path to the Maven local repository.")
40+
public Path mavenLocalRepo = Settings.DEFAULT_MAVEN_LOCAL_REPO;
41+
3742
/**
3843
* Create a new config build for the global options
3944
*/
@@ -45,7 +50,8 @@ public void config(Config.Builder builder) {
4550
!cachePath.endsWith(Settings.CACHE_SUBDIR)
4651
? cachePath.resolve(Settings.CACHE_SUBDIR)
4752
: cachePath)
48-
.withMavenHome(mavenHome);
53+
.withMavenHome(mavenHome)
54+
.withMavenLocalRepo(mavenLocalRepo);
4955
}
5056

5157
/**

plugin-modernizer-cli/src/main/resources/logback.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@
4343
<logger name="java.lang.ProcessBuilder" level="WARN" />
4444
<logger name="java.lang.Shutdown" level="WARN" />
4545
<logger name="java.lang.Runtime" level="WARN" />
46-
<logger name="org.eclipse.jgit.internal.storage.file" level="INFO" />
47-
<logger name="org.eclipse.jgit.internal.util" level="INFO" />
46+
<logger name="org.apache.mina.core" level="WARN" />
47+
<logger name="org.apache.sshd.client" level="WARN" />
48+
<logger name="org.apache.sshd.client.keyverifier" level="ERROR" />
49+
<logger name="org.apache.sshd.common" level="WARN" />
50+
<logger name="org.apache.sshd.git.transport" level="WARN" />
51+
<logger name="org.eclipse.jgit.internal" level="WARN" />
4852
<logger name="org.eclipse.jgit.transport" level="INFO" />
4953
<logger name="org.eclipse.jgit.util" level="INFO" />
5054
<logger name="sun.net.www.protocol.http" level="INFO" />

0 commit comments

Comments
 (0)