Skip to content

Commit 91e55c4

Browse files
committed
Revert "Require Jenkins 2.479.3 and Jakarta EE 9 (jenkinsci#69)"
[JENKINS-75556] ClassCastException connecting to Gitee server https://issues.jenkins.io/browse/JENKINS-75556 reports the issue. Revert this change so that Gitee users are able to install and use the most recent release of the plugin. This reverts commit 437cb91.
1 parent 6cb10c9 commit 91e55c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+302
-317
lines changed

pom.xml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>5.9</version>
7+
<version>4.88</version>
88
<relativePath />
99
</parent>
1010

@@ -17,7 +17,7 @@
1717
<licenses>
1818
<license>
1919
<name>GPL v2.0 License</name>
20-
<url>https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html</url>
20+
<url>http://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html</url>
2121
</license>
2222
</licenses>
2323

@@ -52,8 +52,8 @@
5252
<properties>
5353
<changelist>999999-SNAPSHOT</changelist>
5454
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
55-
<jenkins.baseline>2.479</jenkins.baseline>
56-
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
55+
<jenkins.baseline>2.452</jenkins.baseline>
56+
<jenkins.version>${jenkins.baseline}.4</jenkins.version>
5757
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
5858
</properties>
5959

@@ -63,7 +63,7 @@
6363
<!-- Pick up common dependencies for the selected LTS line: https://github.com/jenkinsci/bom#usage -->
6464
<groupId>io.jenkins.tools.bom</groupId>
6565
<artifactId>bom-${jenkins.baseline}.x</artifactId>
66-
<version>4545.v56392b_7ca_7b_a_</version>
66+
<version>3944.v1a_e4f8b_452db_</version>
6767
<type>pom</type>
6868
<scope>import</scope>
6969
</dependency>
@@ -106,16 +106,15 @@
106106
</dependency>
107107

108108
<!-- REST client dependencies -->
109+
<dependency>
110+
<groupId>org.jboss.spec.javax.ws.rs</groupId>
111+
<artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
112+
<version>1.0.1.Final</version>
113+
</dependency>
109114
<dependency>
110115
<groupId>org.jboss.resteasy</groupId>
111116
<artifactId>resteasy-client</artifactId>
112-
<version>6.2.11.Final</version>
113-
<exclusions>
114-
<exclusion>
115-
<groupId>org.apache.httpcomponents</groupId>
116-
<artifactId>httpclient</artifactId>
117-
</exclusion>
118-
</exclusions>
117+
<version>3.0.23.Final</version>
119118
</dependency>
120119
<dependency>
121120
<groupId>io.jenkins.plugins</groupId>
@@ -130,8 +129,8 @@
130129
<artifactId>apache-httpcomponents-client-4-api</artifactId>
131130
</dependency>
132131
<dependency>
133-
<groupId>com.fasterxml.jackson.jakarta.rs</groupId>
134-
<artifactId>jackson-jakarta-rs-json-provider</artifactId>
132+
<groupId>com.fasterxml.jackson.jaxrs</groupId>
133+
<artifactId>jackson-jaxrs-json-provider</artifactId>
135134
<!-- Needs to match the jackson version from plugin BOM -->
136135
<version>2.17.0</version>
137136
</dependency>

src/main/java/com/gitee/jenkins/cause/CauseData.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.gitee.jenkins.cause;
22

33
import com.gitee.jenkins.gitee.api.model.PullRequest;
4-
import edu.umd.cs.findbugs.annotations.NonNull;
54
import hudson.markup.EscapedMarkupFormatter;
65
import jenkins.model.Jenkins;
76
import net.karneim.pojobuilder.GeneratePojoBuilder;
@@ -125,7 +124,7 @@ public final class CauseData {
125124
}
126125

127126
public Map<String, String> getBuildVariables() {
128-
MapWrapper<String, String> variables = new MapWrapper<>(new HashMap<>());
127+
MapWrapper<String, String> variables = new MapWrapper<>(new HashMap<String, String>());
129128
variables.put("giteeBranch", branch);
130129
variables.put("giteeSourceBranch", sourceBranch);
131130
variables.put("giteeActionType", actionType.name());
@@ -519,7 +518,7 @@ String getShortDescription(CauseData data) {
519518
@Override
520519
String getShortDescription(CauseData data) {
521520
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
522-
if (Jenkins.get().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
521+
if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
523522
return Messages.GiteeWebHookCause_ShortDescription_PullRequestHook_plain(String.valueOf(data.getPullRequestIid()),
524523
forkNamespace + data.getSourceBranch(),
525524
data.getTargetBranch());
@@ -535,7 +534,7 @@ String getShortDescription(CauseData data) {
535534
String getShortDescription(CauseData data) {
536535
String triggeredBy = data.getTriggeredByUser();
537536
String forkNamespace = StringUtils.equals(data.getSourceNamespace(), data.getTargetBranch()) ? "" : data.getSourceNamespace() + "/";
538-
if (Jenkins.get().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
537+
if (Jenkins.getActiveInstance().getMarkupFormatter() instanceof EscapedMarkupFormatter || data.getTargetProjectUrl() == null) {
539538
return Messages.GiteeWebHookCause_ShortDescription_NoteHook_plain(triggeredBy,
540539
String.valueOf(data.getPullRequestIid()),
541540
forkNamespace + data.getSourceBranch(),
@@ -590,7 +589,6 @@ public V put(K key, V value) {
590589
return map.put(key, value);
591590
}
592591

593-
@NonNull
594592
@Override
595593
public Set<Entry<K, V>> entrySet() {
596594
return map.entrySet();

src/main/java/com/gitee/jenkins/connection/GiteeApiToken.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.cloudbees.plugins.credentials.CredentialsNameProvider;
44
import com.cloudbees.plugins.credentials.NameWith;
55
import com.cloudbees.plugins.credentials.common.StandardCredentials;
6-
import edu.umd.cs.findbugs.annotations.NonNull;
76
import hudson.Util;
87
import hudson.util.Secret;
98

@@ -16,10 +15,8 @@ public interface GiteeApiToken extends StandardCredentials {
1615
Secret getApiToken();
1716

1817
class NameProvider extends CredentialsNameProvider<GiteeApiToken> {
19-
20-
@NonNull
2118
@Override
22-
public String getName(@NonNull GiteeApiToken c) {
19+
public String getName(GiteeApiToken c) {
2320
String description = Util.fixEmptyAndTrim(c.getDescription());
2421
return Messages.GiteeApiToken_name() + (description != null ? " (" + description + ")" : "");
2522
}

src/main/java/com/gitee/jenkins/connection/GiteeApiTokenImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.cloudbees.plugins.credentials.CredentialsScope;
44
import com.cloudbees.plugins.credentials.impl.BaseStandardCredentials;
5-
import edu.umd.cs.findbugs.annotations.NonNull;
65
import hudson.Extension;
76
import hudson.util.Secret;
87
import org.kohsuke.stapler.DataBoundConstructor;
@@ -27,8 +26,6 @@ public Secret getApiToken() {
2726

2827
@Extension
2928
public static class DescriptorImpl extends BaseStandardCredentialsDescriptor {
30-
31-
@NonNull
3229
@Override
3330
public String getDisplayName() {
3431
return Messages.GiteeApiToken_name();

src/main/java/com/gitee/jenkins/connection/GiteeConnection.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
import com.cloudbees.plugins.credentials.SystemCredentialsProvider;
99
import com.cloudbees.plugins.credentials.common.StandardCredentials;
1010
import com.cloudbees.plugins.credentials.domains.Domain;
11+
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
1112
import com.gitee.jenkins.gitee.api.GiteeClient;
1213
import com.gitee.jenkins.gitee.api.GiteeClientBuilder;
1314
import com.gitee.jenkins.gitee.api.impl.GiteeV5ClientBuilder;
1415
import hudson.init.InitMilestone;
1516
import hudson.init.Initializer;
17+
import hudson.model.Item;
1618
import hudson.security.ACL;
1719
import hudson.util.Secret;
1820
import jenkins.model.Jenkins;
@@ -26,7 +28,7 @@
2628
import java.util.List;
2729
import java.util.UUID;
2830

29-
import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentialsInItem;
31+
import static com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials;
3032
import static com.gitee.jenkins.gitee.api.GiteeClientBuilder.getGiteeClientBuilderById;
3133

3234

@@ -119,14 +121,14 @@ public GiteeClient getClient() {
119121

120122
private String getApiToken(String apiTokenId) {
121123
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
122-
lookupCredentialsInItem(StandardCredentials.class, null, ACL.SYSTEM2, new ArrayList<>()),
124+
lookupCredentials(StandardCredentials.class, (Item) null, ACL.SYSTEM, new ArrayList<DomainRequirement>()),
123125
CredentialsMatchers.withId(apiTokenId));
124126
if (credentials != null) {
125-
if (credentials instanceof GiteeApiToken token) {
126-
return token.getApiToken().getPlainText();
127+
if (credentials instanceof GiteeApiToken) {
128+
return ((GiteeApiToken) credentials).getApiToken().getPlainText();
127129
}
128-
if (credentials instanceof StringCredentials stringCredentials) {
129-
return stringCredentials.getSecret().getPlainText();
130+
if (credentials instanceof StringCredentials) {
131+
return ((StringCredentials) credentials).getSecret().getPlainText();
130132
}
131133
}
132134
throw new IllegalStateException("No credentials found for credentialsId: " + apiTokenId);
@@ -146,10 +148,10 @@ protected GiteeConnection readResolve() {
146148

147149
@Initializer(after = InitMilestone.PLUGINS_STARTED)
148150
public static void migrate() throws IOException {
149-
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.get().getDescriptor(GiteeConnectionConfig.class);
151+
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
150152
for (GiteeConnection connection : descriptor.getConnections()) {
151153
if (connection.apiTokenId == null && connection.apiToken != null) {
152-
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.get())) {
154+
for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
153155
if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
154156
List<Domain> domains = credentialsStore.getDomains();
155157
connection.apiTokenId = UUID.randomUUID().toString();

src/main/java/com/gitee/jenkins/connection/GiteeConnectionConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import org.eclipse.jgit.util.StringUtils;
2222
import org.jenkinsci.plugins.plaincredentials.StringCredentials;
2323
import org.kohsuke.stapler.QueryParameter;
24-
import org.kohsuke.stapler.StaplerRequest2;
24+
import org.kohsuke.stapler.StaplerRequest;
2525

26-
import jakarta.ws.rs.ProcessingException;
27-
import jakarta.ws.rs.WebApplicationException;
26+
import javax.ws.rs.ProcessingException;
27+
import javax.ws.rs.WebApplicationException;
2828
import java.util.ArrayList;
2929
import java.util.HashMap;
3030
import java.util.List;
@@ -49,7 +49,7 @@ public GiteeConnectionConfig() {
4949
}
5050

5151
@Override
52-
public boolean configure(StaplerRequest2 req, JSONObject json) throws FormException {
52+
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
5353
connections = req.bindJSONToList(GiteeConnection.class, json.get("connections"));
5454
// useAuthenticatedEndpoint = json.getBoolean("useAuthenticatedEndpoint");
5555
refreshConnectionMap();
@@ -152,11 +152,11 @@ public FormValidation doTestConnection(@QueryParameter String url,
152152
}
153153

154154
public ListBoxModel doFillApiTokenIdItems(@QueryParameter String name, @QueryParameter String url) {
155-
if (Jenkins.get().hasPermission(Item.CONFIGURE)) {
155+
if (Jenkins.getInstance().hasPermission(Item.CONFIGURE)) {
156156
AbstractIdCredentialsListBoxModel<StandardListBoxModel, StandardCredentials> options = new StandardListBoxModel()
157157
.includeEmptyValue()
158-
.includeMatchingAs(ACL.SYSTEM2,
159-
Jenkins.get(),
158+
.includeMatchingAs(ACL.SYSTEM,
159+
Jenkins.getActiveInstance(),
160160
StandardCredentials.class,
161161
URIRequirementBuilder.fromUri(url).build(),
162162
new GiteeCredentialMatcher());

src/main/java/com/gitee/jenkins/connection/GiteeConnectionProperty.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
import com.gitee.jenkins.gitee.api.GiteeClient;
5-
import edu.umd.cs.findbugs.annotations.NonNull;
65
import hudson.Extension;
76
import hudson.model.Job;
87
import hudson.model.JobProperty;
@@ -14,7 +13,7 @@
1413
import org.apache.commons.lang.StringUtils;
1514
import org.jenkinsci.Symbol;
1615
import org.kohsuke.stapler.DataBoundConstructor;
17-
import org.kohsuke.stapler.StaplerRequest2;
16+
import org.kohsuke.stapler.StaplerRequest;
1817

1918
/**
2019
* @author Robin Müller
@@ -34,7 +33,7 @@ public String getGiteeConnection() {
3433

3534
public GiteeClient getClient() {
3635
if (StringUtils.isNotEmpty(giteeConnection)) {
37-
GiteeConnectionConfig connectionConfig = (GiteeConnectionConfig) Jenkins.get().getDescriptor(GiteeConnectionConfig.class);
36+
GiteeConnectionConfig connectionConfig = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
3837
return connectionConfig != null ? connectionConfig.getClient(giteeConnection) : null;
3938
}
4039
return null;
@@ -61,7 +60,6 @@ public static GiteeClient getClient(Job<?, ?> job) {
6160
@Symbol("giteeConnection")
6261
public static class DescriptorImpl extends JobPropertyDescriptor {
6362

64-
@NonNull
6563
@Override
6664
public String getDisplayName() {
6765
return "Gitee connection";
@@ -73,13 +71,13 @@ public boolean isApplicable(Class<? extends Job> jobType) {
7371
}
7472

7573
@Override
76-
public JobProperty<?> newInstance(StaplerRequest2 req, JSONObject formData) throws FormException {
74+
public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException {
7775
return req.bindJSON(GiteeConnectionProperty.class, formData);
7876
}
7977

8078
public ListBoxModel doFillGiteeConnectionItems() {
8179
ListBoxModel options = new ListBoxModel();
82-
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.get().getDescriptor(GiteeConnectionConfig.class);
80+
GiteeConnectionConfig descriptor = (GiteeConnectionConfig) Jenkins.getInstance().getDescriptor(GiteeConnectionConfig.class);
8381
for (GiteeConnection connection : descriptor.getConnections()) {
8482
options.add(connection.getName(), connection.getName());
8583
}

src/main/java/com/gitee/jenkins/environment/GiteeEnvironmentContributor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ public class GiteeEnvironmentContributor extends EnvironmentContributor {
2020
@Override
2121
public void buildEnvironmentFor(@NonNull Run r, @NonNull EnvVars envs, @NonNull TaskListener listener) throws IOException, InterruptedException {
2222
GiteeWebHookCause cause = null;
23-
if (r instanceof MatrixRun run) {
24-
MatrixBuild parent = run.getParentBuild();
23+
if (r instanceof MatrixRun) {
24+
MatrixBuild parent = ((MatrixRun)r).getParentBuild();
2525
if (parent != null) {
26-
cause = parent.getCause(GiteeWebHookCause.class);
26+
cause = (GiteeWebHookCause) parent.getCause(GiteeWebHookCause.class);
2727
}
2828
} else {
2929
cause = (GiteeWebHookCause) r.getCause(GiteeWebHookCause.class);

src/main/java/com/gitee/jenkins/gitee/JacksonConfig.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import com.fasterxml.jackson.databind.DeserializationFeature;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
5+
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
66

7-
import jakarta.ws.rs.Consumes;
8-
import jakarta.ws.rs.Produces;
9-
import jakarta.ws.rs.core.MediaType;
10-
import jakarta.ws.rs.ext.ContextResolver;
11-
import jakarta.ws.rs.ext.Provider;
7+
import javax.ws.rs.Consumes;
8+
import javax.ws.rs.Produces;
9+
import javax.ws.rs.core.MediaType;
10+
import javax.ws.rs.ext.ContextResolver;
11+
import javax.ws.rs.ext.Provider;
1212

1313
/**
1414
* @author Robin Müller
@@ -19,7 +19,7 @@
1919
public class JacksonConfig implements ContextResolver<ObjectMapper> {
2020
public ObjectMapper getContext(Class<?> type) {
2121
return new ObjectMapper()
22-
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
22+
.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE)
2323
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
2424
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL, true);
2525
}

src/main/java/com/gitee/jenkins/gitee/api/GiteeClientBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static GiteeClientBuilder getGiteeClientBuilderById(String id) {
2727
}
2828

2929
public static List<GiteeClientBuilder> getAllGiteeClientBuilders() {
30-
List<GiteeClientBuilder> builders = new ArrayList<>(Jenkins.get().getExtensionList(GiteeClientBuilder.class));
30+
List<GiteeClientBuilder> builders = new ArrayList<>(Jenkins.getInstance().getExtensionList(GiteeClientBuilder.class));
3131
sort(builders);
3232
return builders;
3333
}

0 commit comments

Comments
 (0)