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 or newer and Jakarta EE 9 #314

Merged
merged 2 commits into from
Mar 13, 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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@

<properties>
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
<jenkins.baseline>2.426</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.1</jenkins.version>
<jenkins.baseline>2.479</jenkins.baseline>
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
<hpi.compatibleSinceVersion>2.0.0</hpi.compatibleSinceVersion>
<spotless.check.skip>false</spotless.check.skip>
</properties>
Expand All @@ -58,7 +58,7 @@
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-${jenkins.baseline}.x</artifactId>
<version>2884.vc36b_64ce114a_</version>
<version>4228.v0a_71308d905b_</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/jenkins/plugins/DingTalkGlobalConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

/**
* 全局配置
Expand Down Expand Up @@ -106,7 +106,7 @@ public DingTalkGlobalConfig() {
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
public boolean configure(StaplerRequest2 req, JSONObject json) throws FormException {
Object robotConfigObj = json.get("robotConfigs");

if (robotConfigObj == null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/jenkins/plugins/DingTalkManagementLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import hudson.model.ManagementLink;
import hudson.util.FormApply;
import java.io.IOException;
import javax.servlet.ServletException;
import jakarta.servlet.ServletException;
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.verb.POST;

@Extension(ordinal = Double.MAX_VALUE)
Expand Down Expand Up @@ -37,7 +37,7 @@ public String getDescription() {
}

@POST
public void doConfigure(StaplerRequest req, StaplerResponse res)
public void doConfigure(StaplerRequest2 req, StaplerResponse2 res)
throws ServletException, FormException, IOException {
getDingTalkGlobalConfigDescriptor().configure(req, req.getSubmittedForm());
FormApply.success(req.getContextPath() + "/manage").generateResponse(req, res, null);
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/io/jenkins/plugins/DingTalkRunListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,14 @@
}

private BuildStatusEnum getBuildStatus(NoticeOccasionEnum noticeOccasion) {
switch (noticeOccasion) {
case START:
return BuildStatusEnum.START;
case SUCCESS:
return BuildStatusEnum.SUCCESS;
case FAILURE:
return BuildStatusEnum.FAILURE;
case ABORTED:
return BuildStatusEnum.ABORTED;
case UNSTABLE:
return BuildStatusEnum.UNSTABLE;
case NOT_BUILT:
return BuildStatusEnum.NOT_BUILT;
default:
return BuildStatusEnum.UNKNOWN;
}
return switch (noticeOccasion) {
case START -> BuildStatusEnum.START;
case SUCCESS -> BuildStatusEnum.SUCCESS;
case FAILURE -> BuildStatusEnum.FAILURE;
case ABORTED -> BuildStatusEnum.ABORTED;
case UNSTABLE -> BuildStatusEnum.UNSTABLE;
case NOT_BUILT -> BuildStatusEnum.NOT_BUILT;

Check warning on line 94 in src/main/java/io/jenkins/plugins/DingTalkRunListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 88-94 are not covered by tests
};
}

private BuildExecutor getExecutorFromUser(Run<?, ?> run, TaskListener listener) {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/jenkins/plugins/DingTalkStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import io.jenkins.plugins.service.DingTalkService;
import io.jenkins.plugins.tools.DingTalkUtils;
import io.jenkins.plugins.tools.Utils;

import java.io.Serial;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -207,6 +209,7 @@

private static class DingTalkStepExecution extends StepExecution {

@Serial
private static final long serialVersionUID = 1L;
private final transient DingTalkStep step;

Expand Down Expand Up @@ -242,9 +245,9 @@

@Override
public Set<? extends Class<?>> getRequiredContext() {
return new HashSet<Class<?>>() {{
add(Run.class);
add(TaskListener.class);
return new HashSet<>() {{

Check warning on line 248 in src/main/java/io/jenkins/plugins/DingTalkStep.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 248 is not covered by tests
add(Run.class);
add(TaskListener.class);
}};
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/jenkins/plugins/DingTalkUserProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import hudson.model.UserPropertyDescriptor;
import lombok.Getter;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;

@Getter
public class DingTalkUserProperty extends UserProperty {

@Getter
private String mobile;

public DingTalkUserProperty(String mobile) {
Expand All @@ -34,7 +34,7 @@ public UserProperty newInstance(User user) {
}

@Override
public UserProperty newInstance(@Nullable StaplerRequest req, @NonNull JSONObject formData) {
public UserProperty newInstance(@Nullable StaplerRequest2 req, @NonNull JSONObject formData) {
return new DingTalkUserProperty(formData.optString("mobile"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
* @author liuwei
*/
@Getter
public enum NoticeOccasionEnum {
/**
* 在启动构建时通知
Expand Down Expand Up @@ -39,7 +40,6 @@ public enum NoticeOccasionEnum {
*/
NOT_BUILT(Messages.NoticeOccasion_not_built());

@Getter
private final String desc;

NoticeOccasionEnum(String desc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
*
* @author liuwei
*/
@Getter
@ToString
public enum SecurityPolicyEnum {

/** 关键字 */
KEY(Messages.SecurityPolicyType_key()),

/** 加签 */
SECRET(Messages.SecurityPolicyType_secret());

@Getter private final String desc;
private final String desc;

Check warning on line 22 in src/main/java/io/jenkins/plugins/enums/SecurityPolicyEnum.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 12-22 are not covered by tests

SecurityPolicyEnum(String desc) {
this.desc = desc;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/io/jenkins/plugins/model/ButtonModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
* @author liuwei
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/jenkins/plugins/model/RobotConfigModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.jenkins.plugins.DingTalkRobotConfig;
import io.jenkins.plugins.DingTalkSecurityPolicyConfig;
import io.jenkins.plugins.enums.SecurityPolicyEnum;
import java.io.UnsupportedEncodingException;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
Expand Down Expand Up @@ -69,29 +69,29 @@
meta.setSign(config.getValue());
break;
default:
log.error("对应的安全策略不存在:" + type);
log.error("对应的安全策略不存在:{}", type);
}
});
return meta;
}

/**
* 签名方法
*
* @return 签名
*/
private static String createSign(long timestamp, String secret) {
String result = "";
try {
String seed = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] signData = mac.doFinal(seed.getBytes(StandardCharsets.UTF_8));
result =
URLEncoder.encode(
new String(Base64.encodeBase64(signData), StandardCharsets.UTF_8.name()),
StandardCharsets.UTF_8.name());
} catch (NoSuchAlgorithmException | UnsupportedEncodingException | InvalidKeyException e) {
new String(Base64.encodeBase64(signData), StandardCharsets.UTF_8),
StandardCharsets.UTF_8);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {

Check warning on line 94 in src/main/java/io/jenkins/plugins/model/RobotConfigModel.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 72-94 are not covered by tests
log.error("钉钉插件设置签名失败:", e);
}
return result;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/io/jenkins/plugins/sdk/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@
} else {
conn = (HttpURLConnection) url.openConnection(proxy);
}
if (conn instanceof HttpsURLConnection) {
HttpsURLConnection connHttps = (HttpsURLConnection) conn;
if (IGNORE_SSL_CHECK) {
if (conn instanceof HttpsURLConnection connHttps) {

Check warning on line 109 in src/main/java/io/jenkins/plugins/sdk/HttpRequest.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 109 is not covered by tests
if (IGNORE_SSL_CHECK) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[]{new TrustAllTrustManager()}, new SecureRandom());
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/io/jenkins/plugins/service/DingTalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,11 @@
if (type == null) {
return "消息类型【type】不能为空";
}
switch (type) {
case TEXT:
return sender.sendText(msg);
case LINK:
return sender.sendLink(msg);
case MARKDOWN:
return sender.sendMarkdown(msg);
case ACTION_CARD:
return sender.sendActionCard(msg);
default:
return String.format("错误的消息类型:%s", type.name());
}
return switch (type) {
case TEXT -> sender.sendText(msg);
case LINK -> sender.sendLink(msg);
case MARKDOWN -> sender.sendMarkdown(msg);
case ACTION_CARD -> sender.sendActionCard(msg);

Check warning on line 75 in src/main/java/io/jenkins/plugins/service/DingTalkService.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 71-75 are not covered by tests
};
}
}
31 changes: 13 additions & 18 deletions src/main/java/io/jenkins/plugins/tools/JavaFxColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,153 +145,148 @@
float c = ((type == PARSE_COMPONENT)
? Integer.parseInt(color)
: Float.parseFloat(color));
switch (type) {
case PARSE_ALPHA:
return (c < 0.0f) ? 0.0f : (Math.min(c, 1.0f));
case PARSE_PERCENT:
return (c <= 0.0f) ? 0.0f : ((c >= 100.0f) ? 1.0f : (c / 100.0f));
case PARSE_COMPONENT:
return (c <= 0.0f) ? 0.0f : ((c >= 255.0f) ? 1.0f : (c / 255.0f));
case PARSE_ANGLE:
return ((c < 0.0f)
? ((c % 360.0f) + 360.0f)
: ((c > 360.0f)
? (c % 360.0f)
: c));
}

throw new IllegalArgumentException("Invalid color specification");
return switch (type) {
case PARSE_ALPHA -> (c < 0.0f) ? 0.0f : (Math.min(c, 1.0f));
case PARSE_PERCENT -> (c <= 0.0f) ? 0.0f : ((c >= 100.0f) ? 1.0f : (c / 100.0f));
case PARSE_COMPONENT -> (c <= 0.0f) ? 0.0f : ((c >= 255.0f) ? 1.0f : (c / 255.0f));
case PARSE_ANGLE -> ((c < 0.0f)
? ((c % 360.0f) + 360.0f)
: ((c > 360.0f)
? (c % 360.0f)
: c));
default -> throw new IllegalArgumentException("Invalid color specification");
};
}

private static Color parseHSLColor(String color, int hoff,
boolean hasAlpha, float a) {
try {
int hend = color.indexOf(',', hoff);
int send = hend < 0 ? -1 : color.indexOf(',', hend + 1);
int lend = send < 0 ? -1 : color.indexOf(hasAlpha ? ',' : ')', send + 1);
int aend = hasAlpha ? (lend < 0 ? -1 : color.indexOf(')', lend + 1)) : lend;
if (aend >= 0) {
float h = parseComponent(color, hoff, hend, PARSE_ANGLE);
float s = parseComponent(color, hend + 1, send, PARSE_PERCENT);
float l = parseComponent(color, send + 1, lend, PARSE_PERCENT);
if (hasAlpha) {
a *= parseComponent(color, lend + 1, aend, PARSE_ALPHA);
}
return hsb(h, s, l, a);
}
} catch (NumberFormatException ignored) {
}

throw new IllegalArgumentException("Invalid color specification");
}

public static Color hsb(float hue, float saturation, float brightness) {
return hsb(hue, saturation, brightness, 1.0f);
}

public static Color hsb(float hue, float saturation, float brightness, float opacity) {
checkSB(saturation, brightness);
float[] rgb = hsb2Rgb(hue, saturation, brightness);
return color(rgb[0], rgb[1], rgb[2], opacity);
}

public static float[] getHsb(Color color) {
return rgb2Hsb(
color.getRed() / 255.0f,
color.getGreen() / 255.0f,
color.getBlue() / 255.0f
);
}

public static float[] getRgb(Color color) {
return color.getColorComponents(null);
}

public static String getHex(Color color) {
return "#" +
decimal2Hex(
color.getRed()
) +
decimal2Hex(
color.getGreen()
)
+
decimal2Hex(
color.getBlue()
);
}

private static String decimal2Hex(int value) {
return StringUtils.leftPad(
Integer.toHexString(value),
2,
"0"
);
}

private static float[] hsb2Rgb(float hue, float saturation, float brightness) {
// normalize the hue
float normalizedHue = ((hue % 360) + 360) % 360;
hue = normalizedHue / 360f;

float r = 0, g = 0, b = 0;
if (saturation == 0) {
r = g = b = brightness;
} else {
float h = (float) ((hue - Math.floor(hue)) * 6.0);
float f = (float) (h - Math.floor(h));
float p = brightness * (1.0f - saturation);
float q = brightness * (1.0f - saturation * f);
float t = brightness * (1.0f - (saturation * (1.0f - f)));
switch ((int) h) {
case 0:
r = brightness;
g = t;
b = p;
break;
case 1:
r = q;
g = brightness;
b = p;
break;
case 2:
r = p;
g = brightness;
b = t;
break;
case 3:
r = p;
g = q;
b = brightness;
break;
case 4:
r = t;
g = p;
b = brightness;
break;
case 5:
r = brightness;
g = p;
b = q;
break;
default:
}
}
float[] f = new float[3];
f[0] = r;
f[1] = g;
f[2] = b;
return f;
}

private static float[] rgb2Hsb(float r, float g, float b) {
float hue, saturation, brightness;
float[] hsbvals = new float[3];
float cmax = (r > g) ? r : g;
float cmax = Math.max(r, g);
if (b > cmax) {
cmax = b;
}
float cmin = (r < g) ? r : g;
float cmin = Math.min(r, g);

Check warning on line 289 in src/main/java/io/jenkins/plugins/tools/JavaFxColor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 148-289 are not covered by tests
if (b < cmin) {
cmin = b;
}
Expand Down
Loading