Skip to content

Commit

Permalink
Refresh plugin for October 2024 (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Nov 25, 2024
1 parent 3d770d5 commit ae68af2
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @jenkinsci/build-failure-analyzer-plugin-developers
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
---
version: 2
updates:
- package-ecosystem: "maven"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
7 changes: 5 additions & 2 deletions .github/workflows/jenkins-security-scan.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Jenkins Security Scan
# For more information, see: https://www.jenkins.io/doc/developer/security/scan/
---
name: Jenkins Security Scan

on:
Expand All @@ -17,5 +20,5 @@ jobs:
security-scan:
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
with:
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
java-version: 11 # What version of Java to set up for the build.
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
# java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into the default branch
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 8 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
target
bin

# mvn hpi:run
work

# IntelliJ IDEA project files
*.iml
*.iws
*.ipr
work
.DS_Store
.idea

# Eclipse project files
.settings
.classpath
.project
.settings
2 changes: 1 addition & 1 deletion .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>io.jenkins.tools.incrementals</groupId>
<artifactId>git-changelist-maven-extension</artifactId>
<version>1.1</version>
<version>1.8</version>
</extension>
</extensions>
3 changes: 2 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
buildPlugin(useContainerAgent: true, configurations: [
[ platform: 'linux', jdk: '17' ],
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 17],
])
34 changes: 11 additions & 23 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sonyericsson.jenkins.plugins.bfa</groupId>
Expand All @@ -10,16 +11,16 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.67</version>
<version>5.2</version>
</parent>

<properties>
<revision>2.5.4</revision>
<changelist>-SNAPSHOT</changelist>
<jenkins.version>2.475</jenkins.version>
<!-- TODO JENKINS-73339 until in parent POM -->
<jenkins-test-harness.version>2254.vcff7a_d4969e5</jenkins-test-harness.version>
<maven.compiler.release>17</maven.compiler.release>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<checkstyle.version>3.1.1</checkstyle.version>
<no-test-jar>false</no-test-jar>
</properties>
Expand Down Expand Up @@ -285,28 +286,15 @@
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.462.x</artifactId>
<version>3234.v5ca_5154341ef</version>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3559.vb_5b_81183b_d23</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<!-- TODO JENKINS-73339 until in parent POM, work around https://github.com/jenkinsci/plugin-pom/issues/936 -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<reuseForks>false</reuseForks>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down Expand Up @@ -347,9 +335,9 @@
</plugins>
</build>
<scm>
<connection>scm:git:https://github.com/jenkinsci/build-failure-analyzer-plugin.git</connection>
<developerConnection>scm:git:[email protected]:jenkinsci/build-failure-analyzer-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/build-failure-analyzer-plugin</url>
<connection>scm:git:https://github.com/${gitHubRepo}.git</connection>
<developerConnection>scm:git:[email protected]:${gitHubRepo}.git</developerConnection>
<url>https://github.com/${gitHubRepo}</url>
<tag>${scmTag}</tag>
</scm>
<reporting>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import hudson.model.Run;
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import java.util.List;

Expand All @@ -45,7 +45,7 @@ public class IndicationAnnotatorFactory extends ConsoleAnnotatorFactory {

@Override
public ConsoleAnnotator newInstance(Object context) {
StaplerRequest currentRequest = Stapler.getCurrentRequest();
StaplerRequest2 currentRequest = Stapler.getCurrentRequest2();
if (currentRequest == null) {
//Accessed through some other means than http, so lets assume it is not a human.
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -797,7 +797,7 @@ public KnowledgeBase.KnowledgeBaseDescriptor getKnowledgeBaseDescriptor(String d


@Override
public boolean configure(StaplerRequest req, JSONObject o) {
public boolean configure(StaplerRequest2 req, JSONObject o) {
KnowledgeBase existingKb = knowledgeBase;
req.bindJSON(this, o);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
import hudson.model.BuildBadgeAction;
import hudson.model.Run;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

Expand Down Expand Up @@ -157,7 +157,7 @@ public Object readResolve() {
* @param resp the stapler response.
* @return the correct FoundFailureCause.
*/
public FoundFailureCause getDynamic(String token, StaplerRequest req, StaplerResponse resp) {
public FoundFailureCause getDynamic(String token, StaplerRequest2 req, StaplerResponse2 resp) {
try {
int causeNumber = Integer.parseInt(token) - 1;
if (causeNumber >= 0 && causeNumber < foundFailureCauses.size()) {
Expand All @@ -178,7 +178,7 @@ public FoundFailureCause getDynamic(String token, StaplerRequest req, StaplerRes
* @param resp the stapler response
* @throws IOException if so.
*/
public void doIndex(StaplerRequest req, StaplerResponse resp) throws IOException {
public void doIndex(StaplerRequest2 req, StaplerResponse2 resp) throws IOException {
resp.sendRedirect2("../../failure-cause-management");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public String getUserProvidedExpression() {
* Override this method to provide more validation.
*
* @return {@link hudson.util.FormValidation#ok()} if everything is well.
* @see IndicationDescriptor#doHelp(org.kohsuke.stapler.StaplerRequest, org.kohsuke.stapler.StaplerResponse)
* @see IndicationDescriptor#doHelp(org.kohsuke.stapler.StaplerRequest2, org.kohsuke.stapler.StaplerResponse2)
*/
public FormValidation validate() {
return IndicationDescriptor.checkPattern(getUserProvidedExpression());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
import org.kohsuke.stapler.Ancestor;
import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -176,7 +176,7 @@ public void removeRunActions(MatrixBuild build) {

/**
* Shortcut method to
* {@link #getDefault()}.{@link ScanMode#doPerformScan(ScanOnDemandBaseAction, StaplerRequest, StaplerResponse)}
* {@link #getDefault()}.{@link ScanMode#doPerformScan(ScanOnDemandBaseAction, StaplerRequest2, StaplerResponse2)}
* If the user clicks on scan on the default scanmode page.
*
* @param request the request
Expand All @@ -185,7 +185,7 @@ public void removeRunActions(MatrixBuild build) {
* @throws InterruptedException if so
* @throws IOException if so
*/
public void doPerformScan(StaplerRequest request, StaplerResponse response)
public void doPerformScan(StaplerRequest2 request, StaplerResponse2 response)
throws ServletException, InterruptedException, IOException {
getDefault().doPerformScan(this, request, response);
}
Expand All @@ -197,7 +197,7 @@ public void doPerformScan(StaplerRequest request, StaplerResponse response)
* @return the default mode.
*/
public ScanMode getDefault() {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request != null) {
String selected = (String)request.getSession(true).getAttribute(BFA_SOD_BUILD_TYPE);
if (!isBlank(selected)) {
Expand Down Expand Up @@ -314,7 +314,7 @@ public String getFullUrl() {
*/
@SuppressWarnings("unused") //Called by the view
public void setAsDefault() {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request == null) {
throw new IllegalStateException("setAsDefault() can only be called in request scope");
}
Expand All @@ -325,14 +325,14 @@ public void setAsDefault() {
* Finds the {@link ScanOnDemandBaseAction} in the ancestor path.
*
* Throws {@link IllegalStateException} if we are not in the request scope and
* {@link Stapler#getCurrentRequest()} returns null.
* {@link Stapler#getCurrentRequest2()} returns null.
*
* @return the ancestor action
*
*/
@NonNull
public ScanOnDemandBaseAction getParent() {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();
if (request == null) {
throw new IllegalStateException("getParent can only be called from request scope.");
}
Expand All @@ -352,15 +352,15 @@ public ScanOnDemandBaseAction getParent() {
* Submit method for running build scan.
*
* @param action the action we have as an ancestor
* @param request StaplerRequest
* @param response StaplerResponse
* @param request StaplerRequest2
* @param response StaplerResponse2
* @throws ServletException if something unfortunate happens.
* @throws IOException if something unfortunate happens.
* @throws InterruptedException if something unfortunate happens.
*/
@SuppressWarnings("unused") //Called by the view
public void doPerformScan(@AncestorInPath ScanOnDemandBaseAction action,
StaplerRequest request, StaplerResponse response)
StaplerRequest2 request, StaplerResponse2 response)
throws ServletException, IOException, InterruptedException {
action.checkPermission();
Iterator<Run> runIterator = getRuns(action.getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
package com.sonyericsson.jenkins.plugins.bfa.model;

import hudson.Functions;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.tasks.BatchFile;
import hudson.tasks.CommandInterpreter;
import hudson.tasks.Shell;

import org.junit.Test;
import org.jvnet.hudson.test.HudsonTestCase;

import static org.junit.Assume.assumeFalse;
/**
* Test Failure Cause project action.
*/
Expand All @@ -43,16 +46,22 @@ public class FailureCauseProjectActionHudsonTest extends HudsonTestCase {
*/
@Test
public void testShowLastFailureOnProjectPage() throws Exception {
assumeFalse(Functions.isWindows());
FreeStyleProject project = createFreeStyleProject();
project.getBuildersList().add(new Shell("test $BUILD_NUMBER -eq 2"));
project.scheduleBuild2(0).get();
CommandInterpreter commandInterpreter;
if (Functions.isWindows()) {
commandInterpreter = new BatchFile("@if %BUILD_NUMBER% == 1 exit /b 1");
} else {
commandInterpreter = new Shell("test $BUILD_NUMBER -ne 1");
}
project.getBuildersList().add(commandInterpreter);
FreeStyleBuild build = project.scheduleBuild2(0).get();
assertBuildStatus(Result.FAILURE, build);

FailureCauseProjectAction action = project.getAction(FailureCauseProjectAction.class);
assertNotNull(action.getAction());
assertEquals(project.getLastBuild().getAction(FailureCauseBuildAction.class), action.getAction());
assertEquals(build.getAction(FailureCauseBuildAction.class), action.getAction());

project.scheduleBuild2(0).get();
buildAndAssertSuccess(project);
assertNull(project.getAction(FailureCauseProjectAction.class).getAction());
}
}

0 comments on commit ae68af2

Please sign in to comment.