Skip to content

Commit

Permalink
Remove runtime dependency on maven-artifact
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryanrupp committed Nov 22, 2024
1 parent ec2826c commit 30afdcb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 30 deletions.
5 changes: 0 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.9.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
37 changes: 14 additions & 23 deletions api/src/main/java/com/messagebird/MessageBirdServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.messagebird.exceptions.UnauthorizedException;
import com.messagebird.objects.ErrorReport;
import com.messagebird.objects.PagedPaging;
import org.apache.maven.artifact.versioning.ComparableVersion;

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

private static final ComparableVersion JAVA_VERSION = getJavaVersion();
private static final String JAVA_VERSION = getJavaVersion();

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

}

private static ComparableVersion getJavaVersion() {
try {
String version = System.getProperty("java.version");
return new ComparableVersion(version);
} catch (IllegalArgumentException e) {
return new ComparableVersion("0.0");
}
private static String getJavaVersion() {
String version = System.getProperty("java.version");
return version != null ? version : "0.0";
}

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

@Override
public <R> R request(String request, Class<R> clazz)
throws UnauthorizedException, GeneralException, NotFoundException {
throws UnauthorizedException, GeneralException, NotFoundException {
return getJsonData(request, null, "GET", clazz);
}

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

@Override
public <E> List<E> requestByIdAsList(String request, String id, Class<E> elementClass)
throws UnauthorizedException, GeneralException, NotFoundException {
throws UnauthorizedException, GeneralException, NotFoundException {
String path = "";
if (id != null) {
path = "/" + id;
Expand Down Expand Up @@ -276,8 +271,8 @@ public <T, P> T getJsonData(final String request, final P payload, final String

// Prevents mismatched exception when clazz is null
return clazz == null
? null
: this.readValue(mapper, body, clazz);
? null
: this.readValue(mapper, body, clazz);
} catch (IOException ioe) {
throw new GeneralException(ioe);
}
Expand All @@ -290,8 +285,8 @@ public <T, P> T getJsonData(final String request, final P payload, final String

// todo: need to refactor for duplicated code.
public <P, E> List<E> getJsonDataAsList(final String request,
final P payload, final String requestType, final Map<String, String> headers, final Class<E> elementClass)
throws UnauthorizedException, GeneralException, NotFoundException {
final P payload, final String requestType, final Map<String, String> headers, final Class<E> elementClass)
throws UnauthorizedException, GeneralException, NotFoundException {
if (request == null) {
throw new IllegalArgumentException(REQUEST_VALUE_MUST_BE_SPECIFIED);
}
Expand Down Expand Up @@ -327,12 +322,12 @@ public <P, E> List<E> getJsonDataAsList(final String request,
}

private <T> T readValue(ObjectMapper mapper, String content, Class<T> clazz)
throws JsonProcessingException {
throws JsonProcessingException {
return mapper.readValue(content, clazz);
}

private <E> List<E> readValueAsList(ObjectMapper mapper, String content, final Class<E> elementClass)
throws JsonProcessingException {
throws JsonProcessingException {
return mapper.readValue(content, mapper.getTypeFactory().constructCollectionType(List.class, elementClass));
}

Expand Down Expand Up @@ -637,11 +632,7 @@ private void setAdditionalHeaders(HttpURLConnection connection, Map<String, Stri
}

private DateFormat getDateFormat() {
ComparableVersion java6 = new ComparableVersion("1.6");
if (JAVA_VERSION.compareTo(java6) > 0) {
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
}
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZ");
return new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
}

/**
Expand Down Expand Up @@ -798,4 +789,4 @@ private String getPathVariables(final Map<String, Object> map) {
}
return bpath.toString();
}
}
}
12 changes: 12 additions & 0 deletions api/src/main/java/com/messagebird/common/StringUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.messagebird.common;

public class StringUtils {

private StringUtils() {
// static utility
}

public static boolean isBlank(String text) {
return text == null || text.trim().isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.messagebird.objects.conversations;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import com.messagebird.common.StringUtils;

public class MessageParam {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.messagebird.objects.integrations;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.StringUtils;
import com.messagebird.common.StringUtils;

import java.util.List;

Expand Down

0 comments on commit 30afdcb

Please sign in to comment.