Skip to content

Commit 30afdcb

Browse files
committed
Remove runtime dependency on maven-artifact
This was primarily being used to check the Java version to handle < Java 7 in a different way for date formatting, but since Java 8 is the minimum version at this point it is no longer necessary. Also ends up removing the transitive dependency on commons lang which had minimal usage but replaced with an internal StringUtils equivalent.
1 parent ec2826c commit 30afdcb

File tree

5 files changed

+28
-30
lines changed

5 files changed

+28
-30
lines changed

api/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@
9292
<artifactId>java-jwt</artifactId>
9393
<version>4.4.0</version>
9494
</dependency>
95-
<dependency>
96-
<groupId>org.apache.maven</groupId>
97-
<artifactId>maven-artifact</artifactId>
98-
<version>3.9.6</version>
99-
</dependency>
10095
<dependency>
10196
<groupId>junit</groupId>
10297
<artifactId>junit</artifactId>

api/src/main/java/com/messagebird/MessageBirdServiceImpl.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.messagebird.exceptions.UnauthorizedException;
99
import com.messagebird.objects.ErrorReport;
1010
import com.messagebird.objects.PagedPaging;
11-
import org.apache.maven.artifact.versioning.ComparableVersion;
1211

1312
import java.io.File;
1413
import java.io.FileOutputStream;
@@ -62,7 +61,7 @@ public class MessageBirdServiceImpl implements MessageBirdService {
6261
private static final String[] PROTOCOL_LISTS = new String[]{"http://", "https://"};
6362
private static final List<String> PROTOCOLS = Arrays.asList(PROTOCOL_LISTS);
6463

65-
private static final ComparableVersion JAVA_VERSION = getJavaVersion();
64+
private static final String JAVA_VERSION = getJavaVersion();
6665

6766
// Indicates whether we've overridden HttpURLConnection's behaviour to
6867
// allow PATCH requests yet. Also see docs on allowPatchRequestsIfNeeded().
@@ -89,13 +88,9 @@ public MessageBirdServiceImpl(final String accessKey, final String serviceUrl) {
8988

9089
}
9190

92-
private static ComparableVersion getJavaVersion() {
93-
try {
94-
String version = System.getProperty("java.version");
95-
return new ComparableVersion(version);
96-
} catch (IllegalArgumentException e) {
97-
return new ComparableVersion("0.0");
98-
}
91+
private static String getJavaVersion() {
92+
String version = System.getProperty("java.version");
93+
return version != null ? version : "0.0";
9994
}
10095

10196
private String determineUserAgentString() {
@@ -113,7 +108,7 @@ public MessageBirdServiceImpl(final String accessKey) {
113108

114109
@Override
115110
public <R> R request(String request, Class<R> clazz)
116-
throws UnauthorizedException, GeneralException, NotFoundException {
111+
throws UnauthorizedException, GeneralException, NotFoundException {
117112
return getJsonData(request, null, "GET", clazz);
118113
}
119114

@@ -142,7 +137,7 @@ public <R> R requestByID(String request, String id, Map<String, Object> params,
142137

143138
@Override
144139
public <E> List<E> requestByIdAsList(String request, String id, Class<E> elementClass)
145-
throws UnauthorizedException, GeneralException, NotFoundException {
140+
throws UnauthorizedException, GeneralException, NotFoundException {
146141
String path = "";
147142
if (id != null) {
148143
path = "/" + id;
@@ -276,8 +271,8 @@ public <T, P> T getJsonData(final String request, final P payload, final String
276271

277272
// Prevents mismatched exception when clazz is null
278273
return clazz == null
279-
? null
280-
: this.readValue(mapper, body, clazz);
274+
? null
275+
: this.readValue(mapper, body, clazz);
281276
} catch (IOException ioe) {
282277
throw new GeneralException(ioe);
283278
}
@@ -290,8 +285,8 @@ public <T, P> T getJsonData(final String request, final P payload, final String
290285

291286
// todo: need to refactor for duplicated code.
292287
public <P, E> List<E> getJsonDataAsList(final String request,
293-
final P payload, final String requestType, final Map<String, String> headers, final Class<E> elementClass)
294-
throws UnauthorizedException, GeneralException, NotFoundException {
288+
final P payload, final String requestType, final Map<String, String> headers, final Class<E> elementClass)
289+
throws UnauthorizedException, GeneralException, NotFoundException {
295290
if (request == null) {
296291
throw new IllegalArgumentException(REQUEST_VALUE_MUST_BE_SPECIFIED);
297292
}
@@ -327,12 +322,12 @@ public <P, E> List<E> getJsonDataAsList(final String request,
327322
}
328323

329324
private <T> T readValue(ObjectMapper mapper, String content, Class<T> clazz)
330-
throws JsonProcessingException {
325+
throws JsonProcessingException {
331326
return mapper.readValue(content, clazz);
332327
}
333328

334329
private <E> List<E> readValueAsList(ObjectMapper mapper, String content, final Class<E> elementClass)
335-
throws JsonProcessingException {
330+
throws JsonProcessingException {
336331
return mapper.readValue(content, mapper.getTypeFactory().constructCollectionType(List.class, elementClass));
337332
}
338333

@@ -637,11 +632,7 @@ private void setAdditionalHeaders(HttpURLConnection connection, Map<String, Stri
637632
}
638633

639634
private DateFormat getDateFormat() {
640-
ComparableVersion java6 = new ComparableVersion("1.6");
641-
if (JAVA_VERSION.compareTo(java6) > 0) {
642-
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
643-
}
644-
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
635+
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
645636
}
646637

647638
/**
@@ -798,4 +789,4 @@ private String getPathVariables(final Map<String, Object> map) {
798789
}
799790
return bpath.toString();
800791
}
801-
}
792+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.messagebird.common;
2+
3+
public class StringUtils {
4+
5+
private StringUtils() {
6+
// static utility
7+
}
8+
9+
public static boolean isBlank(String text) {
10+
return text == null || text.trim().isEmpty();
11+
}
12+
}

api/src/main/java/com/messagebird/objects/conversations/MessageParam.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.messagebird.objects.conversations;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import org.apache.commons.lang3.StringUtils;
4+
import com.messagebird.common.StringUtils;
55

66
public class MessageParam {
77

api/src/main/java/com/messagebird/objects/integrations/HSMComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.messagebird.objects.integrations;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4-
import org.apache.commons.lang3.StringUtils;
4+
import com.messagebird.common.StringUtils;
55

66
import java.util.List;
77

0 commit comments

Comments
 (0)