Skip to content

Commit 3a709da

Browse files
authored
Merge pull request #935 from jenkinsci/java-17
Run OpenRewrite on all files to migrate to Java 17
2 parents cf046f9 + b9bd6da commit 3a709da

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+689
-688
lines changed

plugin/pom.xml

+38-38
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,19 @@
44
<parent>
55
<groupId>org.jvnet.hudson.plugins</groupId>
66
<artifactId>analysis-pom</artifactId>
7-
<version>10.4.0</version>
7+
<version>10.5.0</version>
88
<relativePath />
99
</parent>
1010

11-
<artifactId>git-forensics</artifactId>
1211
<groupId>io.jenkins.plugins</groupId>
12+
<artifactId>git-forensics</artifactId>
13+
<version>3.2.0-SNAPSHOT</version>
1314
<packaging>hpi</packaging>
1415
<name>Git Forensics Plugin</name>
15-
<version>3.2.0-SNAPSHOT</version>
1616

1717
<description>Jenkins plug-in that mines and analyzes data from a Git repository.</description>
1818
<url>https://github.com/jenkinsci/git-forensics-plugin</url>
1919

20-
<properties>
21-
<module.name>${project.groupId}.git.forensics</module.name>
22-
23-
<!-- Library Dependencies Versions -->
24-
<eclipse-collections.version>9.2.0</eclipse-collections.version>
25-
<testcontainers.version>1.20.5</testcontainers.version>
26-
27-
<!-- Maven Surefire ArgLine -->
28-
<argLine>-Djava.awt.headless=true -Xmx1024m -Djenkins.test.timeout=1000 --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED</argLine>
29-
</properties>
30-
3120
<licenses>
3221
<license>
3322
<name>MIT license</name>
@@ -43,6 +32,24 @@
4332
</developer>
4433
</developers>
4534

35+
<scm>
36+
<connection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
37+
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
38+
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
39+
<tag>v1.6.0</tag>
40+
</scm>
41+
42+
<properties>
43+
<module.name>${project.groupId}.git.forensics</module.name>
44+
45+
<!-- Library Dependencies Versions -->
46+
<eclipse-collections.version>9.2.0</eclipse-collections.version>
47+
<testcontainers.version>1.20.5</testcontainers.version>
48+
49+
<!-- Maven Surefire ArgLine -->
50+
<argLine>-Djava.awt.headless=true -Xmx1024m -Djenkins.test.timeout=1000 --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED</argLine>
51+
</properties>
52+
4653
<dependencies>
4754
<!-- Project Dependencies -->
4855
<dependency>
@@ -154,6 +161,23 @@
154161
</dependency>
155162

156163
</dependencies>
164+
<repositories>
165+
<repository>
166+
<id>incrementals.jenkins-ci.org</id>
167+
<url>https://repo.jenkins-ci.org/incrementals/</url>
168+
</repository>
169+
<repository>
170+
<id>repo.jenkins-ci.org</id>
171+
<url>https://repo.jenkins-ci.org/public/</url>
172+
</repository>
173+
</repositories>
174+
175+
<pluginRepositories>
176+
<pluginRepository>
177+
<id>repo.jenkins-ci.org</id>
178+
<url>https://repo.jenkins-ci.org/public/</url>
179+
</pluginRepository>
180+
</pluginRepositories>
157181

158182
<build>
159183
<plugins>
@@ -182,30 +206,6 @@
182206

183207
</plugins>
184208
</build>
185-
<scm>
186-
<connection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
187-
<developerConnection>scm:git:[email protected]:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
188-
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
189-
<tag>v1.6.0</tag>
190-
</scm>
191-
192-
<repositories>
193-
<repository>
194-
<id>incrementals.jenkins-ci.org</id>
195-
<url>https://repo.jenkins-ci.org/incrementals/</url>
196-
</repository>
197-
<repository>
198-
<id>repo.jenkins-ci.org</id>
199-
<url>https://repo.jenkins-ci.org/public/</url>
200-
</repository>
201-
</repositories>
202-
203-
<pluginRepositories>
204-
<pluginRepository>
205-
<id>repo.jenkins-ci.org</id>
206-
<url>https://repo.jenkins-ci.org/public/</url>
207-
</pluginRepository>
208-
</pluginRepositories>
209209

210210
</project>
211211

plugin/src/main/java/io/jenkins/plugins/forensics/git/blame/GitBlamer.java

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package io.jenkins.plugins.forensics.git.blame;
22

3-
import java.io.IOException;
4-
import java.util.Optional;
5-
import java.util.stream.StreamSupport;
6-
73
import org.eclipse.jgit.api.BlameCommand;
84
import org.eclipse.jgit.api.Git;
95
import org.eclipse.jgit.api.errors.GitAPIException;
106
import org.eclipse.jgit.api.errors.JGitInternalException;
117
import org.eclipse.jgit.blame.BlameResult;
128
import org.eclipse.jgit.lib.ObjectId;
13-
import org.eclipse.jgit.lib.PersonIdent;
149
import org.eclipse.jgit.lib.Repository;
1510
import org.eclipse.jgit.revwalk.RevCommit;
1611

@@ -19,6 +14,11 @@
1914
import edu.umd.cs.findbugs.annotations.CheckForNull;
2015
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
2116

17+
import java.io.IOException;
18+
import java.io.Serial;
19+
import java.util.Optional;
20+
import java.util.stream.StreamSupport;
21+
2222
import org.jenkinsci.plugins.gitclient.GitClient;
2323
import hudson.plugins.git.GitException;
2424
import hudson.remoting.VirtualChannel;
@@ -45,6 +45,7 @@
4545
// TODO: Blame needs only run for new warnings
4646
@SuppressFBWarnings(value = "SE", justification = "GitClient implementation is Serializable")
4747
class GitBlamer extends Blamer {
48+
@Serial
4849
private static final long serialVersionUID = -619059996626444900L;
4950

5051
static final String NO_HEAD_ERROR = "Could not retrieve HEAD commit, aborting";
@@ -70,13 +71,13 @@ class GitBlamer extends Blamer {
7071

7172
@Override
7273
public Blames blame(final FileLocations locations, final FilteredLog log) {
73-
Blames blames = new Blames();
74+
var blames = new Blames();
7475
try {
7576
log.logInfo("Invoking Git blamer to create author and commit information for %d affected files",
7677
locations.size());
7778
log.logInfo("-> GIT_COMMIT env = '%s'", gitCommit);
7879

79-
ObjectId headCommit = git.revParse(gitCommit);
80+
var headCommit = git.revParse(gitCommit);
8081
if (headCommit == null) {
8182
log.logError(NO_HEAD_ERROR);
8283
return blames;
@@ -106,6 +107,7 @@ public Blames blame(final FileLocations locations, final FilteredLog log) {
106107
* Starts the blame commands.
107108
*/
108109
static class BlameCallback extends AbstractRepositoryCallback<RemoteResultWrapper<Blames>> {
110+
@Serial
109111
private static final long serialVersionUID = 8794666938104738260L;
110112
private static final int WHOLE_FILE = 0;
111113

@@ -129,15 +131,15 @@ public RemoteResultWrapper<Blames> invoke(final Repository repository, final Vir
129131
log.logInfo("-> Git commit ID = '%s'", headCommit.getName());
130132
log.logInfo("-> Git working tree = '%s'", getWorkTree(repository));
131133

132-
BlameRunner blameRunner = new BlameRunner(repository, headCommit);
133-
LastCommitRunner lastCommitRunner = new LastCommitRunner(repository);
134+
var blameRunner = new BlameRunner(repository, headCommit);
135+
var lastCommitRunner = new LastCommitRunner(repository);
134136

135-
FileBlameBuilder builder = new FileBlameBuilder();
137+
var builder = new FileBlameBuilder();
136138
for (String file : locations.getFiles()) {
137139
run(builder, file, blameRunner, lastCommitRunner, log);
138140

139141
if (Thread.interrupted()) { // Cancel request by user
140-
String message = "Blaming has been interrupted while computing blame information";
142+
var message = "Blaming has been interrupted while computing blame information";
141143
log.logInfo(message);
142144

143145
throw new InterruptedException(message);
@@ -168,13 +170,13 @@ public RemoteResultWrapper<Blames> invoke(final Repository repository, final Vir
168170
void run(final FileBlameBuilder builder, final String relativePath, final BlameRunner blameRunner,
169171
final LastCommitRunner lastCommitRunner, final FilteredLog log) {
170172
try {
171-
BlameResult blame = blameRunner.run(relativePath);
173+
var blame = blameRunner.run(relativePath);
172174
if (blame == null) {
173175
log.logError("- no blame results for file '%s'", relativePath);
174176
}
175177
else {
176178
for (int line : locations.getLines(relativePath)) {
177-
FileBlame fileBlame = builder.build(relativePath);
179+
var fileBlame = builder.build(relativePath);
178180
if (line <= 0) {
179181
fillWithLastCommit(relativePath, fileBlame, lastCommitRunner);
180182
}
@@ -194,7 +196,7 @@ else if (line <= blame.getResultContents().size()) {
194196
private void fillWithBlameResult(final String fileName, final FileBlame fileBlame, final BlameResult blame,
195197
final int line, final FilteredLog log) {
196198
int lineIndex = line - 1; // first line is index 0
197-
PersonIdent who = blame.getSourceAuthor(lineIndex);
199+
var who = blame.getSourceAuthor(lineIndex);
198200
if (who == null) {
199201
who = blame.getSourceCommitter(lineIndex);
200202
}
@@ -206,7 +208,7 @@ private void fillWithBlameResult(final String fileName, final FileBlame fileBlam
206208
fileBlame.setName(line, who.getName());
207209
fileBlame.setEmail(line, who.getEmailAddress());
208210
}
209-
RevCommit commit = blame.getSourceCommit(lineIndex);
211+
var commit = blame.getSourceCommit(lineIndex);
210212
if (commit == null) {
211213
log.logError("- no commit ID and time found for line %d in file %s", lineIndex, fileName);
212214
}
@@ -220,9 +222,9 @@ private void fillWithLastCommit(final String relativePath, final FileBlame fileB
220222
final LastCommitRunner lastCommitRunner) throws GitAPIException {
221223
Optional<RevCommit> commit = lastCommitRunner.run(relativePath);
222224
if (commit.isPresent()) {
223-
RevCommit revCommit = commit.get();
225+
var revCommit = commit.get();
224226
fileBlame.setCommit(WHOLE_FILE, revCommit.getName());
225-
PersonIdent who = revCommit.getAuthorIdent();
227+
var who = revCommit.getAuthorIdent();
226228
if (who == null) {
227229
who = revCommit.getCommitterIdent();
228230
}
@@ -248,7 +250,7 @@ static class BlameRunner {
248250

249251
@CheckForNull
250252
BlameResult run(final String fileName) throws GitAPIException {
251-
BlameCommand blame = new BlameCommand(repo);
253+
var blame = new BlameCommand(repo);
252254
blame.setFilePath(fileName);
253255
blame.setStartCommit(headCommit);
254256
return blame.call();
@@ -266,7 +268,7 @@ static class LastCommitRunner {
266268
}
267269

268270
Optional<RevCommit> run(final String fileName) throws GitAPIException {
269-
try (Git git = new Git(repo)) {
271+
try (var git = new Git(repo)) {
270272
Iterable<RevCommit> commits = git.log().addPath(fileName).call();
271273

272274
return StreamSupport.stream(commits.spliterator(), false).findFirst();

plugin/src/main/java/io/jenkins/plugins/forensics/git/blame/GitBlamerFactory.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package io.jenkins.plugins.forensics.git.blame;
22

3-
import java.util.Optional;
4-
53
import edu.hm.hafner.util.FilteredLog;
64
import edu.hm.hafner.util.PathUtil;
75

8-
import org.jenkinsci.plugins.gitclient.GitClient;
6+
import java.util.Optional;
7+
98
import hudson.Extension;
109
import hudson.FilePath;
1110
import hudson.model.Run;
@@ -17,7 +16,7 @@
1716
import io.jenkins.plugins.forensics.git.util.GitRepositoryValidator;
1817

1918
/**
20-
* A {@link BlamerFactory} for Git. Handles Git repositories that do not have option ShallowClone set.
19+
* A {@link BlamerFactory} for Git. Handles Git repositories that do not have the option ShallowClone set.
2120
*
2221
* @author Ullrich Hafner
2322
*/
@@ -26,9 +25,9 @@ public class GitBlamerFactory extends BlamerFactory {
2625
@Override
2726
public Optional<Blamer> createBlamer(final SCM scm, final Run<?, ?> build,
2827
final FilePath workTree, final TaskListener listener, final FilteredLog logger) {
29-
GitRepositoryValidator validator = new GitRepositoryValidator(scm, build, workTree, listener, logger);
28+
var validator = new GitRepositoryValidator(scm, build, workTree, listener, logger);
3029
if (validator.isGitRepository()) {
31-
GitClient client = validator.createClient();
30+
var client = validator.createClient();
3231
logger.logInfo("-> Git blamer successfully created in working tree '%s'",
3332
new PathUtil().getAbsolutePath(client.getWorkTree().getRemote()));
3433
return Optional.of(new GitBlamer(client, validator.getHead()));

plugin/src/main/java/io/jenkins/plugins/forensics/git/blame/package-info.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Provides classes to run `git blame`. Using this service, plugins can show in which Git revisions the lines of a file
33
* have been modified by what authors. This information can be used to discover the original commit that is the origin
4-
* for a piece of problematic code.
4+
* of a problematic code snippet.
55
*/
66
@DefaultAnnotation(NonNull.class)
77
package io.jenkins.plugins.forensics.git.blame;

0 commit comments

Comments
 (0)