Skip to content

Commit bec10e5

Browse files
author
Stephan Krusche
committed
update dependencies
fix deprecations and code warnings remove old libraries
1 parent ddf6a85 commit bec10e5

7 files changed

Lines changed: 76 additions & 108 deletions

File tree

jenkins-client-it-docker/pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>com.offbytwo.jenkins</groupId>
1313
<artifactId>jenkins-client-parent</artifactId>
14-
<version>0.4.0-SNAPSHOT</version>
14+
<version>0.4.0</version>
1515
</parent>
1616

1717
<artifactId>jenkins-client-it-docker</artifactId>
@@ -41,17 +41,20 @@
4141
<dependency>
4242
<groupId>org.assertj</groupId>
4343
<artifactId>assertj-core</artifactId>
44+
<version>3.23.1</version>
4445
<scope>test</scope>
4546
</dependency>
4647
<dependency>
4748
<groupId>org.apache.httpcomponents</groupId>
4849
<artifactId>httpclient</artifactId>
50+
<version>4.5.14</version>
4951
<scope>test</scope>
5052
</dependency>
5153

5254
<dependency>
5355
<groupId>org.slf4j</groupId>
5456
<artifactId>slf4j-api</artifactId>
57+
<version>2.0.5</version>
5558
<scope>test</scope>
5659
</dependency>
5760
<dependency>

jenkins-client/pom.xml

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<parent>
1212
<groupId>com.offbytwo.jenkins</groupId>
1313
<artifactId>jenkins-client-parent</artifactId>
14-
<version>0.4.0-SNAPSHOT</version>
14+
<version>0.4.0</version>
1515
</parent>
1616

1717
<artifactId>jenkins-client</artifactId>
@@ -22,74 +22,77 @@
2222
<dependency>
2323
<groupId>com.fasterxml.jackson.core</groupId>
2424
<artifactId>jackson-annotations</artifactId>
25+
<version>2.14.0</version>
2526
</dependency>
2627
<dependency>
2728
<groupId>com.fasterxml.jackson.core</groupId>
2829
<artifactId>jackson-core</artifactId>
30+
<version>2.14.0</version>
2931
</dependency>
3032

3133
<dependency>
3234
<groupId>com.fasterxml.jackson.core</groupId>
3335
<artifactId>jackson-databind</artifactId>
36+
<version>2.14.0</version>
3437
</dependency>
3538

3639
<dependency>
37-
<groupId>org.dom4j</groupId>
38-
<artifactId>dom4j</artifactId>
39-
</dependency>
40-
41-
<dependency>
42-
<groupId>org.jvnet.hudson</groupId>
43-
<artifactId>xstream</artifactId>
44-
<scope>test</scope>
40+
<groupId>javax.xml.bind</groupId>
41+
<artifactId>jaxb-api</artifactId>
4542
</dependency>
4643

4744
<dependency>
48-
<groupId>net.sf.json-lib</groupId>
49-
<artifactId>json-lib</artifactId>
50-
<classifier>jdk15</classifier>
45+
<groupId>org.dom4j</groupId>
46+
<artifactId>dom4j</artifactId>
5147
</dependency>
5248

53-
<!-- Musties -->
5449
<dependency>
5550
<groupId>org.apache.commons</groupId>
5651
<artifactId>commons-lang3</artifactId>
52+
<version>3.12.0</version>
5753
</dependency>
5854

5955
<dependency>
6056
<groupId>commons-io</groupId>
6157
<artifactId>commons-io</artifactId>
58+
<version>2.11.0</version>
6259
</dependency>
6360

6461
<dependency>
6562
<groupId>org.apache.httpcomponents</groupId>
6663
<artifactId>httpclient</artifactId>
64+
<version>4.5.14</version>
6765
</dependency>
6866

6967
<dependency>
7068
<groupId>org.apache.httpcomponents</groupId>
7169
<artifactId>httpcore</artifactId>
70+
<version>4.4.15</version>
7271
</dependency>
7372

7473
<dependency>
7574
<groupId>org.apache.httpcomponents</groupId>
7675
<artifactId>httpmime</artifactId>
76+
<version>4.5.14</version>
7777
</dependency>
7878

79-
<dependency>
80-
<groupId>jaxen</groupId>
81-
<artifactId>jaxen</artifactId>
82-
</dependency>
79+
<!-- <dependency>-->
80+
<!-- <groupId>jaxen</groupId>-->
81+
<!-- <artifactId>jaxen</artifactId>-->
82+
<!-- <version>2.0.0</version>-->
83+
<!-- </dependency>-->
8384

8485
<dependency>
8586
<groupId>org.slf4j</groupId>
8687
<artifactId>slf4j-api</artifactId>
88+
<version>2.0.5</version>
8789
</dependency>
8890

8991
<!-- Testing -->
9092
<dependency>
9193
<groupId>junit</groupId>
9294
<artifactId>junit</artifactId>
95+
<version>4.13.2</version>
9396
<scope>test</scope>
9497
</dependency>
9598

@@ -107,62 +110,14 @@
107110
<dependency>
108111
<groupId>org.assertj</groupId>
109112
<artifactId>assertj-core</artifactId>
113+
<version>3.23.1</version>
110114
<scope>test</scope>
111115
</dependency>
112116
<dependency>
113117
<groupId>xerces</groupId>
114118
<artifactId>xmlParserAPIs</artifactId>
119+
<version>2.6.2</version>
115120
</dependency>
116121
</dependencies>
117122

118-
<build>
119-
<plugins>
120-
<plugin>
121-
<groupId>org.apache.maven.plugins</groupId>
122-
<artifactId>maven-shade-plugin</artifactId>
123-
<executions>
124-
<execution>
125-
<id>httpclient</id>
126-
<phase>package</phase>
127-
<goals>
128-
<goal>shade</goal>
129-
</goals>
130-
<configuration>
131-
<artifactSet>
132-
<includes>
133-
<include>org.apache.httpcomponents:httpclient</include>
134-
<include>org.apache.httpcomponents:httpcore</include>
135-
</includes>
136-
</artifactSet>
137-
<shadedArtifactAttached>true</shadedArtifactAttached>
138-
<shadedClassifierName>apachehttp</shadedClassifierName>
139-
</configuration>
140-
</execution>
141-
</executions>
142-
</plugin>
143-
</plugins>
144-
</build>
145-
146-
<profiles>
147-
<profile>
148-
<id>run-its</id>
149-
<build>
150-
<plugins>
151-
<plugin>
152-
<artifactId>maven-failsafe-plugin</artifactId>
153-
<executions>
154-
<execution>
155-
<id>integration-test</id>
156-
<goals>
157-
<goal>integration-test</goal>
158-
<goal>verify</goal>
159-
</goals>
160-
</execution>
161-
</executions>
162-
</plugin>
163-
</plugins>
164-
</build>
165-
</profile>
166-
</profiles>
167-
168123
</project>

jenkins-client/src/main/java/com/offbytwo/jenkins/client/JenkinsHttpClient.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
import com.offbytwo.jenkins.model.BaseModel;
1313
import com.offbytwo.jenkins.model.Crumb;
1414
import com.offbytwo.jenkins.model.ExtractHeader;
15-
import net.sf.json.JSONObject;
1615
import org.apache.commons.io.IOUtils;
17-
import org.apache.commons.lang.StringUtils;
16+
import org.apache.commons.lang3.StringUtils;
1817
import org.apache.http.HttpEntity;
1918
import org.apache.http.HttpResponse;
2019
import org.apache.http.NameValuePair;
@@ -45,27 +44,28 @@
4544
import java.io.IOException;
4645
import java.io.InputStream;
4746
import java.net.URI;
48-
import java.nio.ByteBuffer;
47+
import java.nio.charset.Charset;
4948
import java.util.ArrayList;
5049
import java.util.List;
5150
import java.util.Map;
5251

5352
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
53+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
54+
5455
import com.offbytwo.jenkins.client.util.ResponseUtils;
5556
import com.offbytwo.jenkins.client.util.UrlUtils;
56-
import static org.apache.commons.lang.StringUtils.isNotBlank;
5757

5858
public class JenkinsHttpClient implements JenkinsHttpConnection {
5959

6060
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
6161

62-
private URI uri;
63-
private CloseableHttpClient client;
62+
private final URI uri;
63+
private final CloseableHttpClient client;
6464
private HttpContext localContext;
65-
private HttpResponseValidator httpResponseValidator;
65+
private final HttpResponseValidator httpResponseValidator;
6666
// private HttpResponseContentExtractor contentExtractor;
6767

68-
private ObjectMapper mapper;
68+
private final ObjectMapper mapper;
6969
private String context;
7070

7171
private String jenkinsVersion;
@@ -89,7 +89,7 @@ public JenkinsHttpClient(URI uri, CloseableHttpClient client) {
8989
this.httpResponseValidator = new HttpResponseValidator();
9090
// this.contentExtractor = new HttpResponseContentExtractor();
9191
this.jenkinsVersion = EMPTY_VERSION;
92-
LOGGER.debug("uri={}", uri.toString());
92+
LOGGER.debug("uri={}", uri);
9393
}
9494

9595
/**
@@ -168,7 +168,7 @@ public String get(String path) throws IOException {
168168
response.getStatusLine().getStatusCode());
169169
try {
170170
httpResponseValidator.validateResponse(response);
171-
return IOUtils.toString(response.getEntity().getContent());
171+
return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset());
172172
} finally {
173173
EntityUtils.consume(response.getEntity());
174174
releaseConnection(getMethod);
@@ -296,7 +296,10 @@ public void post_form(String path, Map<String, String> data, boolean crumbFlag)
296296
queryParams.add(param + "=" + EncodingUtils.formParameter(data.get(param)));
297297
}
298298

299-
queryParams.add("json=" + EncodingUtils.formParameter(JSONObject.fromObject(data).toString()));
299+
ObjectMapper objectMapper = new ObjectMapper();
300+
String jsonPathPart = objectMapper.writeValueAsString(data);
301+
302+
queryParams.add("json=" + EncodingUtils.formParameter(jsonPathPart));
300303
String value = mapper.writeValueAsString(data);
301304
StringEntity stringEntity = new StringEntity(value, ContentType.APPLICATION_FORM_URLENCODED);
302305
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
361364
jenkinsVersion = ResponseUtils.getJenkinsVersion(response);
362365
try {
363366
httpResponseValidator.validateResponse(response);
364-
return IOUtils.toString(response.getEntity().getContent());
367+
return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset());
365368
} finally {
366369
EntityUtils.consume(response.getEntity());
367370
releaseConnection(request);
@@ -392,7 +395,7 @@ public String post_text(String path, String textData, ContentType contentType, b
392395
jenkinsVersion = ResponseUtils.getJenkinsVersion(response);
393396
try {
394397
httpResponseValidator.validateResponse(response);
395-
return IOUtils.toString(response.getEntity().getContent());
398+
return IOUtils.toString(response.getEntity().getContent(), Charset.defaultCharset());
396399
} finally {
397400
EntityUtils.consume(response.getEntity());
398401
releaseConnection(request);

jenkins-client/src/main/java/com/offbytwo/jenkins/client/PreemptiveAuth.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,20 @@
1515
import org.apache.http.auth.AuthState;
1616
import org.apache.http.auth.Credentials;
1717
import org.apache.http.client.CredentialsProvider;
18-
import org.apache.http.client.protocol.ClientContext;
19-
import org.apache.http.protocol.ExecutionContext;
18+
import org.apache.http.client.protocol.HttpClientContext;
2019
import org.apache.http.protocol.HttpContext;
2120

22-
import java.io.IOException;
23-
2421
public class PreemptiveAuth implements HttpRequestInterceptor {
2522

2623
@Override
27-
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
28-
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
24+
public void process(HttpRequest request, HttpContext context) throws HttpException {
25+
AuthState authState = (AuthState) context.getAttribute(HttpClientContext.TARGET_AUTH_STATE);
2926

3027
if (authState.getAuthScheme() == null) {
3128
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
3229
CredentialsProvider credsProvider = (CredentialsProvider) context
33-
.getAttribute(ClientContext.CREDS_PROVIDER);
34-
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
30+
.getAttribute(HttpClientContext.CREDS_PROVIDER);
31+
HttpHost targetHost = (HttpHost) context.getAttribute(HttpClientContext.HTTP_TARGET_HOST);
3532
if (authScheme != null) {
3633
Credentials creds = credsProvider
3734
.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));

jenkins-client/src/main/java/com/offbytwo/jenkins/helper/Range.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ private Range setFrom(int from) {
5151
if (from < 0) {
5252
throw new IllegalArgumentException("from value must be greater or equal null.");
5353
}
54-
this.from = new Integer(from);
54+
this.from = from;
5555
return this;
5656
}
5757

5858
private Range setTo(int to) {
5959
if (to < 0) {
6060
throw new IllegalArgumentException("to must be greater or equal null.");
6161
}
62-
this.to = new Integer(to);
62+
this.to = to;
6363
return this;
6464
}
6565

@@ -81,7 +81,7 @@ public String getRangeString() {
8181
}
8282

8383
public static final class FromBuilder {
84-
private Range range;
84+
private final Range range;
8585

8686
public FromBuilder(Range range) {
8787
this.range = range;
@@ -101,7 +101,7 @@ public Range build() {
101101
}
102102

103103
public static final class ToBuilder {
104-
private Range range;
104+
private final Range range;
105105

106106
public ToBuilder(Range range) {
107107
this.range = range;
@@ -113,9 +113,9 @@ public Range build() {
113113
}
114114

115115
public static final class Builder {
116-
private Range range;
116+
private final Range range;
117117

118-
protected Builder() {
118+
private Builder() {
119119
this.range = new Range();
120120
}
121121

@@ -130,13 +130,13 @@ public ToBuilder to(int t) {
130130
}
131131

132132
public Range only(int only) {
133-
this.range.from = new Integer(only);
134-
this.range.to = new Integer(only + 1);
133+
this.range.from = only;
134+
this.range.to = only + 1;
135135
return this.range;
136136
}
137137
}
138138

139139
public static Builder build() {
140140
return new Builder();
141141
}
142-
}
142+
}

jenkins-client/src/main/java/com/offbytwo/jenkins/model/BuildCause.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BuildCause {
1919
private String userName;
2020

2121
public BuildCause() {
22-
this.upstreamBuild = new Integer(0);
22+
this.upstreamBuild = 0;
2323
//TODO: Think about initialization of the other
2424
// attributes as well.
2525
// userId = StringConstant.EMPTY;

0 commit comments

Comments
 (0)