Skip to content

Commit bbaa5e1

Browse files
author
jicheng
committed
fix: address Jenkins hosting requirements and spotbugs issues
1 parent bc57b1d commit bbaa5e1

9 files changed

Lines changed: 84 additions & 43 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @jenkinsci/active-git-branches-plugin-developers

.github/dependabot.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "maven"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
- package-ecosystem: "github-actions"
8+
directory: "/"
9+
schedule:
10+
interval: "daily"

.github/workflows/cd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: CD
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
9+
jobs:
10+
cd:
11+
uses: jenkins-infra/github-reusable-workflows/.github/workflows/maven-cd.yaml@v0
12+
secrets: inherit
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Jenkins Security Scan
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
pull_request:
8+
branches:
9+
- master
10+
- main
11+
12+
jobs:
13+
security-scan:
14+
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2

.mvn/extensions.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
2+
<extension>
3+
<groupId>io.jenkins.tools.incrementals</groupId>
4+
<artifactId>git-changelist-maven-extension</artifactId>
5+
<version>1.7</version>
6+
</extension>
7+
</extensions>

.mvn/maven.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Dchangelist.format=%d.v%s

Jenkinsfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
buildPlugin(
2+
useContainerAgent: true,
3+
configurations: [
4+
[platform: 'linux', jdk: 21],
5+
[platform: 'windows', jdk: 17],
6+
])

pom.xml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<parent>
66
<groupId>org.jenkins-ci.plugins</groupId>
77
<artifactId>plugin</artifactId>
8-
<version>4.75</version>
8+
<version>5.28</version>
99
<relativePath />
1010
</parent>
1111

1212
<groupId>io.jenkins.plugins</groupId>
13-
<artifactId>active-git-branches-plugin</artifactId>
14-
<version>1.0.0-SNAPSHOT</version>
13+
<artifactId>active-git-branches</artifactId>
14+
<version>${changelist}</version>
1515
<packaging>hpi</packaging>
1616

1717
<name>Active Git Branches Parameter</name>
@@ -24,18 +24,27 @@
2424
</license>
2525
</licenses>
2626

27+
<scm>
28+
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
29+
<developerConnection>scm:git:https://github.com/${gitHubRepo}.git</developerConnection>
30+
<url>https://github.com/${gitHubRepo}</url>
31+
<tag>${scmTag}</tag>
32+
</scm>
33+
2734
<properties>
28-
<jenkins.version>2.387.3</jenkins.version>
29-
<java.level>11</java.level>
35+
<changelist>999999-SNAPSHOT</changelist>
36+
<jenkins.baseline>2.492</jenkins.baseline>
37+
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
3038
<gitHubRepo>jenkinsci/active-git-branches-plugin</gitHubRepo>
39+
<hpi.strictBundledArtifacts>true</hpi.strictBundledArtifacts>
3140
</properties>
3241

3342
<dependencyManagement>
3443
<dependencies>
3544
<dependency>
3645
<groupId>io.jenkins.tools.bom</groupId>
37-
<artifactId>bom-2.387.x</artifactId>
38-
<version>2543.vfb_1a_5fb_9496d</version>
46+
<artifactId>bom-${jenkins.baseline}.x</artifactId>
47+
<version>5473.vb_9533d9e5d88</version>
3948
<scope>import</scope>
4049
<type>pom</type>
4150
</dependency>

src/main/java/io/jenkins/plugins/activegitbranches/ActiveGitBranchesParameterDefinition.java

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public Void invoke(org.eclipse.jgit.lib.Repository repo, hudson.remoting.Virtual
207207
org.eclipse.jgit.revwalk.RevCommit commit = walk.parseCommit(ref.getObjectId());
208208
long commitTime = commit.getCommitTime() * 1000L;
209209
branchInfos.add(new BranchInfo(branchName, commitTime));
210-
} catch (Exception e) {
210+
} catch (IOException e) {
211211
// If we can't parse commit, treat as old
212212
branchInfos.add(new BranchInfo(branchName, 0L));
213213
}
@@ -231,28 +231,6 @@ public Void invoke(org.eclipse.jgit.lib.Repository repo, hudson.remoting.Virtual
231231
return branchInfos.subList(0, maxBranchCount);
232232
}
233233

234-
List<BranchInfo> limitedList = new ArrayList<>();
235-
int count = 0;
236-
237-
// First pass: add all branches that fit in the limit
238-
for (BranchInfo info : branchInfos) {
239-
boolean isAlwaysIncluded = matchesAlwaysInclude(info.getName());
240-
241-
if (count < maxBranchCount || isAlwaysIncluded) {
242-
limitedList.add(info);
243-
if (!isAlwaysIncluded) {
244-
count++; // Only count towards limit if NOT always included
245-
// Wait, if we don't count always included branches, we might end up with many branches.
246-
// Alternative strategy: Always included branches take priority, then fill up to maxBranchCount with others.
247-
} else {
248-
// If it IS always included, we add it. Does it consume a slot?
249-
// The requirement: "符合正则的分支不是最近活跃的分支也可以展示选项"
250-
// It implies they should be added EVEN IF they would fall out of the Top N.
251-
// So they are exceptions to the limit.
252-
}
253-
}
254-
}
255-
256234
// Let's refine the logic:
257235
// 1. Identify branches that MUST be included.
258236
// 2. Identify other branches that are candidates.
@@ -338,25 +316,28 @@ private boolean matchesBranchFilter(String branchName) {
338316
}
339317

340318
private File createTempDirectory() throws IOException {
341-
File tempDir = File.createTempFile("jenkins-git-branches-", "");
342-
tempDir.delete();
343-
tempDir.mkdirs();
344-
return tempDir;
319+
return java.nio.file.Files.createTempDirectory("jenkins-git-branches-").toFile();
345320
}
346321

347322
private void deleteDirectory(File directory) {
348323
if (directory != null && directory.exists()) {
349-
File[] files = directory.listFiles();
350-
if (files != null) {
351-
for (File file : files) {
352-
if (file.isDirectory()) {
353-
deleteDirectory(file);
354-
} else {
355-
file.delete();
324+
try {
325+
java.nio.file.Files.walkFileTree(directory.toPath(), new java.nio.file.SimpleFileVisitor<java.nio.file.Path>() {
326+
@Override
327+
public java.nio.file.FileVisitResult visitFile(java.nio.file.Path file, java.nio.file.attribute.BasicFileAttributes attrs) throws IOException {
328+
java.nio.file.Files.delete(file);
329+
return java.nio.file.FileVisitResult.CONTINUE;
356330
}
357-
}
331+
332+
@Override
333+
public java.nio.file.FileVisitResult postVisitDirectory(java.nio.file.Path dir, IOException exc) throws IOException {
334+
java.nio.file.Files.delete(dir);
335+
return java.nio.file.FileVisitResult.CONTINUE;
336+
}
337+
});
338+
} catch (IOException e) {
339+
LOGGER.log(Level.WARNING, "Failed to delete temp directory: " + directory, e);
358340
}
359-
directory.delete();
360341
}
361342
}
362343

0 commit comments

Comments
 (0)