From bec10e5be7b06c8179a900788531837f92d07005 Mon Sep 17 00:00:00 2001 From: Stephan Krusche Date: Sat, 31 Dec 2022 13:10:39 +0100 Subject: [PATCH 1/4] update dependencies fix deprecations and code warnings remove old libraries --- jenkins-client-it-docker/pom.xml | 5 +- jenkins-client/pom.xml | 89 +++++-------------- .../jenkins/client/JenkinsHttpClient.java | 29 +++--- .../jenkins/client/PreemptiveAuth.java | 13 ++- .../com/offbytwo/jenkins/helper/Range.java | 18 ++-- .../offbytwo/jenkins/model/BuildCause.java | 2 +- pom.xml | 28 ++++-- 7 files changed, 76 insertions(+), 108 deletions(-) diff --git a/jenkins-client-it-docker/pom.xml b/jenkins-client-it-docker/pom.xml index 11e6b485..2fbe46d4 100644 --- a/jenkins-client-it-docker/pom.xml +++ b/jenkins-client-it-docker/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0-SNAPSHOT + 0.4.0 jenkins-client-it-docker @@ -41,17 +41,20 @@ org.assertj assertj-core + 3.23.1 test org.apache.httpcomponents httpclient + 4.5.14 test org.slf4j slf4j-api + 2.0.5 test diff --git a/jenkins-client/pom.xml b/jenkins-client/pom.xml index 2cbc3df9..d01b0a02 100644 --- a/jenkins-client/pom.xml +++ b/jenkins-client/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0-SNAPSHOT + 0.4.0 jenkins-client @@ -22,74 +22,77 @@ com.fasterxml.jackson.core jackson-annotations + 2.14.0 com.fasterxml.jackson.core jackson-core + 2.14.0 com.fasterxml.jackson.core jackson-databind + 2.14.0 - org.dom4j - dom4j - - - - org.jvnet.hudson - xstream - test + javax.xml.bind + jaxb-api - net.sf.json-lib - json-lib - jdk15 + org.dom4j + dom4j - org.apache.commons commons-lang3 + 3.12.0 commons-io commons-io + 2.11.0 org.apache.httpcomponents httpclient + 4.5.14 org.apache.httpcomponents httpcore + 4.4.15 org.apache.httpcomponents httpmime + 4.5.14 - - jaxen - jaxen - + + + + + org.slf4j slf4j-api + 2.0.5 junit junit + 4.13.2 test @@ -107,62 +110,14 @@ org.assertj assertj-core + 3.23.1 test xerces xmlParserAPIs + 2.6.2 - - - - org.apache.maven.plugins - maven-shade-plugin - - - httpclient - package - - shade - - - - - org.apache.httpcomponents:httpclient - org.apache.httpcomponents:httpcore - - - true - apachehttp - - - - - - - - - - run-its - - - - maven-failsafe-plugin - - - integration-test - - integration-test - verify - - - - - - - - - diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java index 4eadc5c9..d4d3b1ab 100755 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java @@ -12,9 +12,8 @@ import com.offbytwo.jenkins.model.BaseModel; import com.offbytwo.jenkins.model.Crumb; import com.offbytwo.jenkins.model.ExtractHeader; -import net.sf.json.JSONObject; import org.apache.commons.io.IOUtils; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; @@ -45,27 +44,28 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; -import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Map; import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES; +import static org.apache.commons.lang3.StringUtils.isNotBlank; + import com.offbytwo.jenkins.client.util.ResponseUtils; import com.offbytwo.jenkins.client.util.UrlUtils; -import static org.apache.commons.lang.StringUtils.isNotBlank; public class JenkinsHttpClient implements JenkinsHttpConnection { private final Logger LOGGER = LoggerFactory.getLogger(getClass()); - private URI uri; - private CloseableHttpClient client; + private final URI uri; + private final CloseableHttpClient client; private HttpContext localContext; - private HttpResponseValidator httpResponseValidator; + private final HttpResponseValidator httpResponseValidator; // private HttpResponseContentExtractor contentExtractor; - private ObjectMapper mapper; + private final ObjectMapper mapper; private String context; private String jenkinsVersion; @@ -89,7 +89,7 @@ public JenkinsHttpClient(URI uri, CloseableHttpClient client) { this.httpResponseValidator = new HttpResponseValidator(); // this.contentExtractor = new HttpResponseContentExtractor(); this.jenkinsVersion = EMPTY_VERSION; - LOGGER.debug("uri={}", uri.toString()); + LOGGER.debug("uri={}", uri); } /** @@ -168,7 +168,7 @@ public String get(String path) throws IOException { response.getStatusLine().getStatusCode()); try { httpResponseValidator.validateResponse(response); - return IOUtils.toString(response.getEntity().getContent()); + return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset()); } finally { EntityUtils.consume(response.getEntity()); releaseConnection(getMethod); @@ -296,7 +296,10 @@ public void post_form(String path, Map data, boolean crumbFlag) queryParams.add(param + "=" + EncodingUtils.formParameter(data.get(param))); } - queryParams.add("json=" + EncodingUtils.formParameter(JSONObject.fromObject(data).toString())); + ObjectMapper objectMapper = new ObjectMapper(); + String jsonPathPart = objectMapper.writeValueAsString(data); + + queryParams.add("json=" + EncodingUtils.formParameter(jsonPathPart)); String value = mapper.writeValueAsString(data); StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_FORM_URLENCODED); request = new HttpPost(UrlUtils.toNoApiUri(uri, context, path) + StringUtils.join(queryParams, "&")); @@ -361,7 +364,7 @@ public String post_xml(String path, String xml_data, boolean crumbFlag) throws I jenkinsVersion = ResponseUtils.getJenkinsVersion(response); try { httpResponseValidator.validateResponse(response); - return IOUtils.toString(response.getEntity().getContent()); + return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset()); } finally { EntityUtils.consume(response.getEntity()); releaseConnection(request); @@ -392,7 +395,7 @@ public String post_text(String path, String textData, ContentType contentType, b jenkinsVersion = ResponseUtils.getJenkinsVersion(response); try { httpResponseValidator.validateResponse(response); - return IOUtils.toString(response.getEntity().getContent()); + return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset()); } finally { EntityUtils.consume(response.getEntity()); releaseConnection(request); diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java index ce772ca9..803385e1 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java @@ -15,23 +15,20 @@ import org.apache.http.auth.AuthState; import org.apache.http.auth.Credentials; import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.protocol.ClientContext; -import org.apache.http.protocol.ExecutionContext; +import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.protocol.HttpContext; -import java.io.IOException; - public class PreemptiveAuth implements HttpRequestInterceptor { @Override - public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { - AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE); + public void process(HttpRequest request, HttpContext context) throws HttpException { + AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE); if (authState.getAuthScheme() == null) { AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth"); CredentialsProvider credsProvider = (CredentialsProvider) context - .getAttribute(ClientContext.CREDS_PROVIDER); - HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST); + .getAttribute(HttpClientContext.CREDS_PROVIDER); + HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST); if (authScheme != null) { Credentials creds = credsProvider .getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort())); diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java index cdbdc60a..7ef6f8be 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java @@ -51,7 +51,7 @@ private Range setFrom(int from) { if (from < 0) { throw new IllegalArgumentException("from value must be greater or equal null."); } - this.from = new Integer(from); + this.from = from; return this; } @@ -59,7 +59,7 @@ private Range setTo(int to) { if (to < 0) { throw new IllegalArgumentException("to must be greater or equal null."); } - this.to = new Integer(to); + this.to = to; return this; } @@ -81,7 +81,7 @@ public String getRangeString() { } public static final class FromBuilder { - private Range range; + private final Range range; public FromBuilder(Range range) { this.range = range; @@ -101,7 +101,7 @@ public Range build() { } public static final class ToBuilder { - private Range range; + private final Range range; public ToBuilder(Range range) { this.range = range; @@ -113,9 +113,9 @@ public Range build() { } public static final class Builder { - private Range range; + private final Range range; - protected Builder() { + private Builder() { this.range = new Range(); } @@ -130,8 +130,8 @@ public ToBuilder to(int t) { } public Range only(int only) { - this.range.from = new Integer(only); - this.range.to = new Integer(only + 1); + this.range.from = only; + this.range.to = only + 1; return this.range; } } @@ -139,4 +139,4 @@ public Range only(int only) { public static Builder build() { return new Builder(); } -} \ No newline at end of file +} diff --git a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java index 821a027f..46608bfc 100644 --- a/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java +++ b/jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java @@ -19,7 +19,7 @@ public class BuildCause { private String userName; public BuildCause() { - this.upstreamBuild = new Integer(0); + this.upstreamBuild = 0; //TODO: Think about initialization of the other // attributes as well. // userId = StringConstant.EMPTY; diff --git a/pom.xml b/pom.xml index f88539d9..35d64d36 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0-SNAPSHOT + 0.4.0 pom @@ -41,10 +41,13 @@ + 17 + 17 + 17 UTF-8 UTF-8 - 1.8 - 1.8 + 17 + 17 true true @@ -109,6 +112,13 @@ 2.1.3 + + + javax.xml.bind + jaxb-api + 2.3.1 + + org.jvnet.hudson xstream @@ -116,12 +126,12 @@ test - - net.sf.json-lib - json-lib - ${json-lib.version} - jdk15 - + + + + + + From 51cd47a199e50822063695db167540cb14e836a8 Mon Sep 17 00:00:00 2001 From: Stephan Krusche Date: Sat, 31 Dec 2022 13:22:18 +0100 Subject: [PATCH 2/4] small improvements --- jenkins-client/pom.xml | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/jenkins-client/pom.xml b/jenkins-client/pom.xml index d01b0a02..ac447cbd 100644 --- a/jenkins-client/pom.xml +++ b/jenkins-client/pom.xml @@ -18,12 +18,13 @@ Jenkins API client for Java :: The Client. - + com.fasterxml.jackson.core jackson-annotations 2.14.0 + com.fasterxml.jackson.core jackson-core @@ -67,7 +68,7 @@ org.apache.httpcomponents httpcore - 4.4.15 + 4.4.16 @@ -76,19 +77,12 @@ 4.5.14 - - - - - - org.slf4j slf4j-api - 2.0.5 + 2.0.6 - junit junit @@ -107,17 +101,14 @@ jenkins-test-harness test + org.assertj assertj-core 3.23.1 test - - xerces - xmlParserAPIs - 2.6.2 - + From 8dbbf00661576167c85261878ad511b2a47f14a9 Mon Sep 17 00:00:00 2001 From: Stephan Krusche Date: Sun, 12 Mar 2023 17:13:12 +0100 Subject: [PATCH 3/4] update dom4j --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 35d64d36..6b3155aa 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ org.dom4j dom4j - 2.1.3 + 2.1.4 From f6dd6adc490cb4c8609b32ea974780be1250605e Mon Sep 17 00:00:00 2001 From: Stephan Krusche Date: Sun, 16 Jun 2024 15:22:02 +0200 Subject: [PATCH 4/4] update dependencies --- jenkins-client-it-docker/pom.xml | 15 ++++-- jenkins-client/pom.xml | 2 +- pom.xml | 86 ++++++++++++-------------------- 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/jenkins-client-it-docker/pom.xml b/jenkins-client-it-docker/pom.xml index 2fbe46d4..e0d656f3 100644 --- a/jenkins-client-it-docker/pom.xml +++ b/jenkins-client-it-docker/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0 + 0.4.1 jenkins-client-it-docker @@ -41,7 +41,7 @@ org.assertj assertj-core - 3.23.1 + 3.26.0 test @@ -54,7 +54,7 @@ org.slf4j slf4j-api - 2.0.5 + 2.0.12 test @@ -100,7 +100,14 @@ - + + + maven_central + Maven Central + https://repo.maven.apache.org/maven2/ + + + run-docker-its diff --git a/jenkins-client/pom.xml b/jenkins-client/pom.xml index ac447cbd..4e528cfe 100644 --- a/jenkins-client/pom.xml +++ b/jenkins-client/pom.xml @@ -11,7 +11,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0 + 0.4.1 jenkins-client diff --git a/pom.xml b/pom.xml index 6b3155aa..86885d2b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.offbytwo.jenkins jenkins-client-parent - 0.4.0 + 0.4.1 pom @@ -41,13 +41,13 @@ - 17 - 17 - 17 + 21 + 21 + 21 UTF-8 UTF-8 - 17 - 17 + 21 + 21 true true @@ -57,14 +57,13 @@ 1.644 4.12 3.0.0 - 2.4 + 2.16.1 1.4.7-jenkins-1 - 3.9 - 2.4 - 4.5.8 - 4.4.11 - 4.5.8 - 2.10.3 + 3.14.0 + 4.5.14 + 4.4.16 + 4.5.14 + 2.17.1 @@ -74,18 +73,6 @@ - - - Cosmin Stejerean - cosmin@offbytwo.com - http://offbytwo.com - - - Karl Heinz Marbaise - khmarbaise@apache.org - - - @@ -126,13 +113,6 @@ test - - - - - - - org.apache.commons @@ -167,7 +147,7 @@ jaxen jaxen - 1.1.6 + 1.2.0 @@ -209,19 +189,19 @@ org.slf4j slf4j-api - 1.7.25 + 1.7.36 org.apache.logging.log4j log4j-bom - 2.12.1 + 2.23.1 import pom xerces xmlParserAPIs - 2.6.1 + 2.6.2 @@ -232,22 +212,22 @@ org.apache.maven.plugins maven-help-plugin - 3.2.0 + 3.9.7 org.apache.maven.plugins maven-clean-plugin - 3.1.0 + 3.3.2 org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.3.1 org.apache.maven.plugins maven-source-plugin - 3.1.0 + 3.3.1