Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh plugin for October 2024 #183

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
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 @@

/**
* 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 @@
* @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,124 +197,124 @@
* @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)) {
ScanMode mode = getMode(selected);
if (mode != null) {
return mode;
}
}
}
return getMode(NonScanned.URL);
}

/**
* Stapler function to enable 'scan-on-demand/all' etc.
*
* @param url the scan mode
*
* @return most likely a {@link ScanMode}
*/
@SuppressWarnings("unused") //Stapler function
public Object getDynamic(String url) {
if (isBlank(url)) {
return getDefault();
} else {
return getMode(url);
}
}

/**
* Finds the mode with the provided url as returned by {@link ScanMode#getUrlName()}.
*
* @param url the url to match
*
* @return the scan mode or null if no matching scan mode is found.
*/
public ScanMode getMode(String url) {
for (ScanMode mode : ExtensionList.lookup(ScanMode.class)) {
if (mode.getUrlName().equals(url)) {
return mode;
}
}
return null;
}

/**
* Represents the different scan modes that can be used to re-scan the builds of a Job.
*
* @see NonScanned
* @see AllBuilds
*/
@Restricted(NoExternalUse.class)
public abstract static class ScanMode implements ExtensionPoint {

/**
* Session key used to store the default scan mode
*/
static final String BFA_SOD_BUILD_TYPE = "bfa-sod-buildType";

/**
* If there is any run in the job matching this scan mode's criteria.
* Default implementation is {@link #getRuns(Job)}{@code .hasNext()}
* @param job the job to check
*
* @return true if so.
*/
@SuppressWarnings("unused") //Called by the view
public boolean hasAnyRun(Job job) {
return getRuns(job).hasNext();
}

/**
* The short relative url name of this scan mode.
* Also used as a short identifier of the scan mode.
*
* @return the url name
*/
@NonNull
public abstract String getUrlName();

/**
* The full url from the root of Jenkins.
*
* @return the full url
* @see ScanOnDemandBaseAction#getFullUrl()
*/
@CheckForNull
public String getFullUrl() {
final String fullUrl = getParent().getFullUrl();
if (fullUrl == null) {
return null;
}
return Functions.joinPath(fullUrl, getUrlName());
}

/**
* Human readable name to display.
*
* @return the name
*/
@NonNull
public abstract String getDisplayName();

/**
* Provides an iterator of the {@link Run}s of the provided job that matches this scan mode.
*
* @param job the job to filter builds from
* @return an iterator of the matching builds
*/
@NonNull
abstract Iterator<Run> getRuns(Job job);

/**
* Sets this scan mode as the default for this user on future page visits.
*/
@SuppressWarnings("unused") //Called by the view
public void setAsDefault() {
StaplerRequest request = Stapler.getCurrentRequest();
StaplerRequest2 request = Stapler.getCurrentRequest2();

Check warning on line 317 in src/main/java/com/sonyericsson/jenkins/plugins/bfa/sod/ScanOnDemandBaseAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 200-317 are not covered by tests
if (request == null) {
throw new IllegalStateException("setAsDefault() can only be called in request scope");
}
Expand All @@ -325,14 +325,14 @@
* 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 @@
* 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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are running the test suite on Windows, fix this test so that it works on either Windows or Linux.

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());
}
}
Loading