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

Minor code improvements #206

Merged
merged 1 commit into from
Nov 4, 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: 0 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ jobs:
runs-on: ubuntu-latest
name: Coverage on Ubuntu
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17 and Maven
uses: s4u/setup-maven-action@v1.16.0
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public String getUrlName() {
* Translates pre 2.0 build.xml to latest format for backwards compatibility.
* @return this instance
*/
@Serial
@Deprecated(since = "2.0", forRemoval = true)
protected Object readResolve() {
// field renamed - see AbstractBadgeAction
Expand Down Expand Up @@ -239,34 +240,24 @@ public static String getJenkinsColorStyle(@NonNull String color) {
primary = color.substring(5);
}
// https://github.com/jenkinsci/jenkins/blob/master/src/main/scss/abstracts/_theme.scss
switch (primary) {
return switch (primary) {
// palette
case "blue":
case "brown":
case "cyan":
case "green":
case "indigo":
case "orange":
case "pink":
case "purple":
case "red":
case "yellow":
case "white":
case "black":
return "var(--" + color + ")";
case "blue",
"brown",
"cyan",
"green",
"indigo",
"orange",
"pink",
"purple",
"red",
"yellow",
"white",
"black" -> "var(--" + color + ")";
// semantics
case "accent":
case "text":
case "error":
case "warning":
case "success":
case "destructive":
case "build":
case "danger":
case "info":
return "var(--" + color + "-color)";
default:
return color;
}
case "accent", "text", "error", "warning", "success", "destructive", "build", "danger", "info" -> "var(--"
+ color + "-color)";
default -> color;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
* Translates pre 2.0 build.xml to latest format for backwards compatibility.
* @return this instance
*/
@Serial
@Override
@Deprecated(since = "2.0", forRemoval = true)
protected Object readResolve() {

Check warning on line 98 in src/main/java/com/jenkinsci/plugins/badge/action/BadgeSummaryAction.java

View check run for this annotation

ci.jenkins.io / Java Compiler

compiler:compile

NORMAL: readResolve() in com.jenkinsci.plugins.badge.action.AbstractBadgeAction has been deprecated and marked for removal
super.readResolve();

// field renamed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
import hudson.model.Run;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -136,6 +137,7 @@ public String toString() {

abstract static class Execution extends SynchronousStepExecution<AbstractBadgeAction> {

@Serial
private static final long serialVersionUID = 1L;

private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.jenkinsci.plugins.badge.action.AbstractBadgeAction;
import hudson.model.Action;
import hudson.model.Run;
import java.io.Serial;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
Expand Down Expand Up @@ -75,6 +76,7 @@ public StepExecution start(StepContext context) {

public static class Execution extends SynchronousStepExecution<Void> {

@Serial
private static final long serialVersionUID = 1L;

private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.PrintStream;
import java.io.Serial;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
Expand Down Expand Up @@ -95,6 +96,7 @@ public boolean isAdvanced() {
@Deprecated(since = "2.0", forRemoval = true)
public static class Execution extends SynchronousStepExecution<Void> {

@Serial
private static final long serialVersionUID = 1L;

@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Only used when starting.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.PrintStream;
import java.io.Serial;
import java.io.Serializable;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down Expand Up @@ -132,6 +133,7 @@ public boolean isAdvanced() {
@Deprecated(since = "2.0", forRemoval = true)
private static class ShortText implements Serializable {

@Serial
private static final long serialVersionUID = 1L;

private final String text;
Expand Down Expand Up @@ -197,6 +199,7 @@ public void setLink(String link) {
@Deprecated(since = "2.0", forRemoval = true)
public static class Execution extends SynchronousStepExecution<Void> {

@Serial
private static final long serialVersionUID = 1L;

@SuppressFBWarnings(value = "SE_TRANSIENT_FIELD_NOT_RESTORED", justification = "Only used when starting.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.PrintStream;
import java.io.Serial;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
Expand Down Expand Up @@ -105,6 +106,7 @@ public boolean isAdvanced() {
@Deprecated(since = "2.0", forRemoval = true)
public static class Execution extends SynchronousStepExecution<BadgeSummaryAction> {

@Serial
private static final long serialVersionUID = 1L;

private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.PrintStream;
import java.io.Serial;
import org.jenkinsci.plugins.workflow.steps.Step;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
Expand Down Expand Up @@ -90,6 +91,7 @@ public StepExecution start(StepContext context) {

public static class Execution extends SynchronousStepExecution<Void> {

@Serial
private static final long serialVersionUID = 1L;

private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,20 @@ protected void runAddJob(JenkinsRule r, AbstractAddBadgeStep step, boolean inNod
}

if (declarativePipeline) {
script = "pipeline {\n" + " agent any\n"
+ " stages {\n"
+ " stage('Testing') {\n"
+ " steps {\n"
+ " " + script + "\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}\n";
script =
"""
pipeline {
agent any
stages {
stage('Testing') {
steps {
%s
}
}
}
}
"""
.formatted(script);
}

project.setDefinition(new CpsFlowDefinition(script, true));
Expand All @@ -160,25 +165,32 @@ protected void runModifyJob(JenkinsRule r, AbstractAddBadgeStep step, boolean in
step.setText(UUID.randomUUID().toString());
assertNotEquals(actualText, step.getText());

String script = "def badge = " + step + "\n";
script += "badge.setText('" + actualText + "')";
String script = """
def badge = %s
badge.setText('%s')
""".formatted(step, actualText);

if (inNode) {
script = "node() { " + script + " }";
}

if (declarativePipeline) {
script = "pipeline {\n" + " agent any\n"
+ " stages {\n"
+ " stage('Testing') {\n"
+ " steps {\n"
+ " script {\n"
+ " " + script + "\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}\n";
script =
"""
pipeline {
agent any
stages {
stage('Testing') {
steps {
script {
%s
}
}
}
}
}
"""
.formatted(script);
}

project.setDefinition(new CpsFlowDefinition(script, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ void createSummary_html_unescaped_remove_script(JenkinsRule r) throws Exception
String html = "<ul><li>" + text + "</li></ul><script>alert(\"exploit!\");</script>";
BadgeSummaryAction action = createSummary(r, "summary.appendText('" + html + "', false);");
assertEquals("<ul><li>" + text + "</li></ul>", action.getText());
// assertEquals(html, action.getRawText());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,21 @@ protected void runRemoveJob(
}

if (declarativePipeline) {
script = "pipeline {\n" + " agent any\n"
+ " stages {\n"
+ " stage('Testing') {\n"
+ " steps {\n"
+ " script {\n"
+ " " + script + "\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ " }\n"
+ "}\n";
script =
"""
pipeline {
agent any
stages {
stage('Testing') {
steps {
script {
%s
}
}
}
}
}"""
.formatted(script);
}

project.setDefinition(new CpsFlowDefinition(script, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void addShortText(JenkinsRule r) throws Exception {
String text = UUID.randomUUID().toString();
String color = UUID.randomUUID().toString();
String background = UUID.randomUUID().toString();
Integer border = new Random().nextInt();
int border = new Random().nextInt();
String borderColor = UUID.randomUUID().toString();
String link = "http://" + UUID.randomUUID();

Expand All @@ -133,7 +133,7 @@ void addShortText(JenkinsRule r) throws Exception {
void jenkinsColorStyle(JenkinsRule r) throws Exception {
String text = UUID.randomUUID().toString();
String color = "jenkins-!-color-red";
Integer border = 1;
int border = 1;

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
Expand All @@ -152,7 +152,7 @@ void jenkinsColorStyle(JenkinsRule r) throws Exception {
void jenkinsWarningStyle(JenkinsRule r) throws Exception {
String text = UUID.randomUUID().toString();
String color = "jenkins-!-warning-color";
Integer border = 1;
int border = 1;

WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition(
Expand Down
Loading