Skip to content

Commit

Permalink
Use JGit 7.0.0 with Java 17
Browse files Browse the repository at this point in the history
JGit 7.0.0 requires Java 17.  Jenkins 2.463 requires Java 17.

Use the plugin bill of materials from 2.462.x because it is the closest
we have to 2.463.  The plugin is expected to work with any release 2.463
or later.

Adapt to removed API's in JGit 7.0.0 by replacing calls to removed API's
with the recommended equivalents.

Tested in my development environment and no issues detected.  Tests run
from a container based Jenkins controller with Windows, Linux, and FreeBSD
agents.  Tests ran on multiple weekly releases of Jenkins since 2.463.
The Linux agents include:

* Alpine
* Debian Linux 11, 12, testing, and unstable
* openSUSE
* Red Hat Enterprise Linux 8
* Rocky Linux 9
* Ubuntu 20.04, 22.04, and 24.04
  • Loading branch information
MarkEWaite committed Sep 12, 2024
1 parent 2ba4d99 commit 1189a30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
12 changes: 8 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@
</scm>

<properties>
<revision>5.0.1</revision>
<revision>6.0.0</revision>
<changelist>-SNAPSHOT</changelist>
<!-- Character set tests fail unless file.encoding is set -->
<argLine>-Dfile.encoding=${project.build.sourceEncoding}</argLine>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.440</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<jgit.version>6.10.0.202406032230-r</jgit.version>
<jenkins.baseline>2.462</jenkins.baseline>
<!-- TODO Replace with the standard jenkins.baseline references after LTS requires Java 17 -->
<!-- <jenkins.version>${jenkins.baseline}.1</jenkins.version> -->
<jenkins.version>2.463</jenkins.version>
<jgit.version>7.0.0.202409031743-r</jgit.version>
<!-- TODO JENKINS-73339 until in parent POM -->
<maven.compiler.release>17</maven.compiler.release>
<spotbugs.effort>Max</spotbugs.effort>
<spotbugs.threshold>Low</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private void doCheckoutWithResetAndRetry(String ref) throws GitException {

if (repo.resolve(ref) != null) {
// ref is either an existing reference or a shortcut to a tag or branch (without refs/heads/)
git(repo).checkout().setName(ref).setForce(true).call();
git(repo).checkout().setName(ref).setForceRefUpdate(true).call();
return;
}

Expand Down Expand Up @@ -550,7 +550,7 @@ private void doCheckout(String ref, String branch) throws GitException {
.checkout()
.setName(branch)
.setCreateBranch(true)
.setForce(true)
.setForceRefUpdate(true)
.setStartPoint(ref)
.call();
} catch (GitAPIException e) {
Expand Down Expand Up @@ -2063,7 +2063,11 @@ public boolean isCommitInRepo(ObjectId commit) throws GitException {
}
final boolean found;
try (Repository repo = getRepository()) {
found = repo.hasObject(commit);
try {
found = repo.getObjectDatabase().has(commit);
} catch (IOException ioe) {
throw new GitException(ioe);

Check warning on line 2069 in src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 2068-2069 are not covered by tests
}
}
return found;
}
Expand Down Expand Up @@ -2903,7 +2907,7 @@ public String describe(String tip) throws GitException, InterruptedException {

Map<ObjectId, Ref> tags = new HashMap<>();
for (Ref r : repo.getTags().values()) {
ObjectId key = repo.peel(r).getPeeledObjectId();
ObjectId key = repo.getRefDatabase().peel(r).getPeeledObjectId();
if (key == null) {
key = r.getObjectId();
}
Expand Down Expand Up @@ -3157,9 +3161,13 @@ public Set<GitObject> getTags() throws GitException {
String tagName = entry.getKey();
Ref tagRef = entry.getValue();
if (!tagRef.isPeeled()) {
Ref peeledRef = repo.peel(tagRef);
if (peeledRef.getPeeledObjectId() != null) {
tagRef = peeledRef; // Use peeled ref instead of annotated ref
try {
Ref peeledRef = repo.getRefDatabase().peel(tagRef);
if (peeledRef.getPeeledObjectId() != null) {
tagRef = peeledRef; // Use peeled ref instead of annotated ref
}
} catch (IOException ioe) {
throw new GitException(ioe);

Check warning on line 3170 in src/main/java/org/jenkinsci/plugins/gitclient/JGitAPIImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 3169-3170 are not covered by tests
}
}
/* Packed lightweight (non-annotated) tags can wind up peeled with no peeled obj ID */
Expand Down

0 comments on commit 1189a30

Please sign in to comment.