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

Require Jenkins 2.479.1 and Jakarta EE 9 #427

Merged
merged 1 commit into from
Feb 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

strategy:
matrix:
java: [11]
java: [17]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down
17 changes: 5 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.7</version>
<relativePath/>
</parent>

Expand All @@ -19,9 +19,8 @@
<properties>
<changelist>999999-SNAPSHOT</changelist>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.440</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<useBeta>true</useBeta>
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
</properties>

<licenses>
Expand All @@ -44,16 +43,10 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>3413.v0d896b_76a_30d</version>
<version>4051.v78dce3ce8b_d6</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<!-- TODO remove when available in bom-2.440.x -->
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>github-branch-source</artifactId>
<version>1807.v50351eb_7dd13</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -94,7 +87,7 @@
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>3.0.1</version>
<version>3.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
Expand Down Expand Up @@ -74,7 +73,7 @@ protected boolean isApplicable(@CheckForNull final Item item) {

@Override
protected Set<GHEvent> events() {
return Collections.unmodifiableSet(new HashSet<>(Collections.singletonList(GHEvent.CHECK_RUN)));
return Set.copyOf(Collections.singletonList(GHEvent.CHECK_RUN));
}

@Override
Expand All @@ -92,7 +91,7 @@ protected void onEvent(final GHSubscriberEvent event) {
JSONObject payloadJSON = new JSONObject(payload);

LOGGER.log(Level.INFO, "Received rerun request through GitHub checks API.");
try (ACLContext ignored = ACL.as(ACL.SYSTEM)) {
try (ACLContext ignored = ACL.as2(ACL.SYSTEM2)) {
String branchName = payloadJSON.getJSONObject("check_run").getJSONObject("check_suite").optString("head_branch");
scheduleRerun(checkRun, branchName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public Optional<Long> getId(final String name) {
protected abstract Optional<Run<?, ?>> getRun();

private Optional<GitHubChecksAction> getAction(final String name) {
if (!getRun().isPresent()) {
if (getRun().isEmpty()) {
return Optional.empty();
}
return getRun().get().getActions(GitHubChecksAction.class)
Expand All @@ -136,11 +136,11 @@ private Optional<GitHubChecksAction> getAction(final String name) {
}

void addActionIfMissing(final long id, final String name) {
if (!getRun().isPresent()) {
if (getRun().isEmpty()) {
return;
}
Optional<GitHubChecksAction> action = getAction(name);
if (!action.isPresent()) {
if (action.isEmpty()) {
getRun().get().addAction(new GitHubChecksAction(id, name));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,11 @@
* @throws IllegalArgumentException if the status of the {@code details} is not one of {@link ChecksStatus}
*/
public Status getStatus() {
switch (details.getStatus()) {
case NONE:
case QUEUED:
return Status.QUEUED;
case IN_PROGRESS:
return Status.IN_PROGRESS;
case COMPLETED:
return Status.COMPLETED;
default:
throw new IllegalArgumentException("Unsupported checks status: " + details.getStatus());
}
return switch (details.getStatus()) {

Check warning on line 77 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 77 is only partially covered, one branch is missing
case NONE, QUEUED -> Status.QUEUED;

Check warning on line 78 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 78 is not covered by tests

Check warning on line 78 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java#L78

Added line #L78 was not covered by tests
case IN_PROGRESS -> Status.IN_PROGRESS;
case COMPLETED -> Status.COMPLETED;
};
}

/**
Expand Down Expand Up @@ -128,24 +122,16 @@
*/
@SuppressWarnings("PMD.CyclomaticComplexity")
public Optional<Conclusion> getConclusion() {
switch (details.getConclusion()) {
case SKIPPED:
return Optional.of(Conclusion.SKIPPED);
case FAILURE:
case CANCELED: // TODO use CANCELLED if https://github.com/github/feedback/discussions/10255 is fixed
case TIME_OUT: // TODO TIMED_OUT as above
return Optional.of(Conclusion.FAILURE);
case NEUTRAL:
return Optional.of(Conclusion.NEUTRAL);
case SUCCESS:
return Optional.of(Conclusion.SUCCESS);
case ACTION_REQUIRED:
return Optional.of(Conclusion.ACTION_REQUIRED);
case NONE:
return Optional.empty();
default:
throw new IllegalArgumentException("Unsupported checks conclusion: " + details.getConclusion());
}
return switch (details.getConclusion()) {

Check warning on line 125 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 125 is only partially covered, 3 branches are missing
case SKIPPED ->
Optional.of(Conclusion.SKIPPED); // TODO use CANCELLED if https://github.com/github/feedback/discussions/10255 is fixed

Check warning on line 127 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 127 is not covered by tests

Check warning on line 127 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

Check warning on line 127 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java#L127

Added line #L127 was not covered by tests
case FAILURE, CANCELED, TIME_OUT -> // TODO TIMED_OUT as above

Check warning on line 128 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: TIMED_OUT as above
Optional.of(Conclusion.FAILURE);
case NEUTRAL -> Optional.of(Conclusion.NEUTRAL);

Check warning on line 130 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 130 is not covered by tests

Check warning on line 130 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java#L130

Added line #L130 was not covered by tests
case SUCCESS -> Optional.of(Conclusion.SUCCESS);
case ACTION_REQUIRED -> Optional.of(Conclusion.ACTION_REQUIRED);

Check warning on line 132 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 132 is not covered by tests

Check warning on line 132 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java#L132

Added line #L132 was not covered by tests
case NONE -> Optional.empty();
};
}

/**
Expand Down Expand Up @@ -235,17 +221,11 @@
}

private AnnotationLevel getAnnotationLevel(final ChecksAnnotationLevel checksLevel) {
switch (checksLevel) {
case NOTICE:
return AnnotationLevel.NOTICE;
case FAILURE:
return AnnotationLevel.FAILURE;
case WARNING:
return AnnotationLevel.WARNING;
case NONE:
throw new IllegalArgumentException("Annotation level is required but not set.");
default:
throw new IllegalArgumentException("Unsupported checks annotation level: " + checksLevel);
}
return switch (checksLevel) {
case NOTICE -> AnnotationLevel.NOTICE;
case FAILURE -> AnnotationLevel.FAILURE;
case WARNING -> AnnotationLevel.WARNING;
case NONE -> throw new IllegalArgumentException("Annotation level is required but not set.");

Check warning on line 228 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 224-228 are not covered by tests

Check warning on line 228 in src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/jenkins/plugins/checks/github/GitHubChecksDetails.java#L225-L228

Added lines #L225 - L228 were not covered by tests
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private GitSCM resolveGitSCM() {
public boolean isValid(final FilteredLog logger) {
logger.logError("Trying to resolve checks parameters from Git SCM...");

if (!getScmFacade().findGitSCM(run).isPresent()) {
if (getScmFacade().findGitSCM(run).isEmpty()) {
logger.logError("Job does not use Git SCM");

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ void shouldProcessCheckRunEventWithRerequestedAction() throws IOException {
@Test
void shouldThrowExceptionWhenCheckSuitesMissingFromPayload() throws IOException {
assertThatThrownBy(
() -> {
new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class))
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE));
})
() -> new CheckRunGHEventSubscriber(mock(JenkinsFacade.class), mock(SCMFacade.class))
.onEvent(createEventWithRerunRequest(RERUN_REQUEST_JSON_FOR_PR_MISSING_CHECKSUITE)))
.isInstanceOf(IllegalStateException.class)
.hasMessageContaining("Could not parse check run event:");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsScope;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import hudson.model.Action;
Expand Down Expand Up @@ -30,7 +31,6 @@
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.introspect.VisibilityChecker;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down Expand Up @@ -66,9 +66,6 @@

import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

/**
Expand Down Expand Up @@ -284,7 +281,7 @@ private GHCheckRun createStubCheckRun(final long id) throws JsonProcessingExcept
mapper.setVisibility(new VisibilityChecker.Std(NONE, NONE, NONE, NONE, ANY));
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true);
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);

InjectableValues.Std std = new InjectableValues.Std();
std.addValue("org.kohsuke.github.connector.GitHubConnectorResponse", null);
Expand Down Expand Up @@ -344,8 +341,7 @@ public void testChecksPublisherUpdatesCorrectly() throws Exception {
// Check that the owner is passed from context to credentials
if (context instanceof GitHubSCMSourceChecksContext) {
var credentials = publisher.getContext().getCredentials();
if (credentials instanceof GitHubAppCredentials) {
var gitHubAppCredentials = (GitHubAppCredentials) credentials;
if (credentials instanceof GitHubAppCredentials gitHubAppCredentials) {
assertThat(gitHubAppCredentials.getOwner()).isEqualTo("XiongKezhi");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public class GitSCMChecksContextITest {
@Test
public void shouldRetrieveContextFromFreeStyleBuild() throws Exception {
FreeStyleProject job = j.createFreeStyleProject();

BranchSpec branchSpec = new BranchSpec(EXISTING_HASH);
GitSCM scm = new GitSCM(GitSCM.createRepoList(HTTP_URL, CREDENTIALS_ID),
Collections.singletonList(branchSpec), false, Collections.emptyList(),
Collections.singletonList(branchSpec),
null, null, Collections.emptyList());
job.setScm(scm);

Expand All @@ -61,28 +61,28 @@ public void shouldRetrieveContextFromFreeStyleBuild() throws Exception {

/**
* Creates a pipeline that uses {@link hudson.plugins.git.GitSCM} and runs a successful build.
* Then this build is used to create a new {@link GitSCMChecksContext}.
* Then this build is used to create a new {@link GitSCMChecksContext}.
*/
@Test
@Test
public void shouldRetrieveContextFromPipeline() throws Exception {
WorkflowJob job = j.createProject(WorkflowJob.class);
job.setDefinition(new CpsFlowDefinition("node {\n"
+ " stage ('Checkout') {\n"

job.setDefinition(new CpsFlowDefinition("node {\n"
+ " stage ('Checkout') {\n"
+ " checkout scm: ([\n"
+ " $class: 'GitSCM',\n"
+ " userRemoteConfigs: [[credentialsId: '" + CREDENTIALS_ID + "', url: '" + HTTP_URL + "']],\n"
+ " branches: [[name: '" + EXISTING_HASH + "']]\n"
+ " ])"
+ " }\n"
+ " }\n"
+ "}\n", true));

Run<?, ?> run = buildSuccessfully(job);

GitSCMChecksContext gitSCMChecksContext = new GitSCMChecksContext(run, URL_NAME);

assertThat(gitSCMChecksContext.getRepository()).isEqualTo("jenkinsci/github-checks-plugin");
assertThat(gitSCMChecksContext.getCredentialsId()).isEqualTo(CREDENTIALS_ID);
assertThat(gitSCMChecksContext.getHeadSha()).isEqualTo(EXISTING_HASH);
assertThat(gitSCMChecksContext.getHeadSha()).isEqualTo(EXISTING_HASH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;

import org.jvnet.hudson.test.JenkinsRule;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -26,7 +28,7 @@ public class GitHubChecksConfigITest {
@Test
public void shouldUseDefaultConfigWhenNoSCM() throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
GitHubChecksPublisherFactory.fromJob(j.createFreeStyleProject(), new StreamTaskListener(os));
GitHubChecksPublisherFactory.fromJob(j.createFreeStyleProject(), new StreamTaskListener(os, StandardCharsets.UTF_8));

assertThat(os.toString()).doesNotContain("Causes for no suitable publisher found: ");
}
Expand Down
Loading