Skip to content

Commit

Permalink
Resolve deprecations and recommendations (#172)
Browse files Browse the repository at this point in the history
* Resolve Java deprecated API usage

* Resolve fields can be final code style issue

* Resolve unnecessary cast to string

* Resolve unnecessary semicolon code style issue

* Remove obsolete exception redundant declaration

* Remove redundant throw exception

* Unused imports

* Resolve Method identical to super method

* Remove explicit type

* Missing description

* Resolve memory recommendations => static class

* Naming conventions

* Performance enhancement

* Variable already assigned to same value

* Null pointer exceptions protection

* Simplify assertion

* Redundant arguments

* Replace stringBuilder with string

* Inefficient string conversion

* Unused imports

* Unnecessary cast

* Avoid unnecessary config using best practices

* Fix publish script
  • Loading branch information
AnasNaouchi authored May 21, 2024
1 parent d08ca37 commit 4311725
Show file tree
Hide file tree
Showing 55 changed files with 136 additions and 425 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: ./gradlew test

- name: Publish package
run: ./gradlew uploadArchives
run: ./gradlew publish
env:
PGP_SIGNING_KEY: ${{ secrets.PGP_SIGNING_KEY }}
PGP_SIGNING_PASSWORD: ${{ secrets.PGP_SIGNING_PASSWORD }}
Expand Down
26 changes: 13 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@ buildscript {
}
}

task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
java {
withJavadocJar()
withSourcesJar()
}

distributions {
Expand All @@ -56,16 +51,21 @@ signing {
sign configurations.archives
}

artifacts {
archives javadocJar, sourcesJar
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}

// REF: https://docs.gradle.org/current/userguide/publishing_maven.html
publishing {
publications {
mavenJava(MavenPublication) {
artifactId = 'omise-java'

shadow(MavenPublication) {
publication ->
project.shadow.component(publication)
artifactId = 'omise-java'
artifact sourcesJar
artifact javadocJar
pom {
name = 'Omise Java'
description = 'Java bindings for the Omise API'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class Client {

private final OkHttpClient httpClient;
private Requester requester;
private final Requester requester;

/**
* Creates a Client that sends the specified API version string in the header to access an earlier version
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void reverseCharge() throws IOException, OmiseException, ClientException {
new Charge.ReverseRequestBuilder("chrg_test_4xso2s8ivdej29pqnhz").build();
Charge charge = client().sendRequest(reverseChargeRequest);

System.out.printf("charge reversal: %s", Boolean.toString(charge.isReversed()));
System.out.printf("charge reversal: %s", charge.isReversed());
}

void updateCharge() throws IOException, OmiseException, ClientException {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/co/omise/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ private Serializer() {

.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE, true)
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); // TODO: Deprecate in vNext
.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
}

/**
Expand Down Expand Up @@ -197,7 +196,7 @@ public <T extends OmiseObject> Map<String, Object> serializeToMap(T model) {
* @return The string value for using as query parameters.
*/
public <T extends Enum<T>> String serializeToQueryParams(T value) {
return (String) objectMapper.convertValue(value, String.class);
return objectMapper.convertValue(value, String.class);
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/co/omise/models/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,6 @@ public void setZeroInterestInstallments(boolean zeroInterestInstallments) {

public static class GetRequestBuilder extends RequestBuilder<Account> {

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "account");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/models/AuthorizationType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public enum AuthorizationType {
@JsonProperty("pre_auth")
PreAuth,
@JsonProperty("final_auth")
FinalAuth;
FinalAuth
}
9 changes: 0 additions & 9 deletions src/main/java/co/omise/models/Balance.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import co.omise.Endpoint;
import co.omise.requests.RequestBuilder;
import co.omise.requests.ResponseType;
import com.fasterxml.jackson.annotation.JsonProperty;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;

import java.io.IOException;

/**
* Balance object
Expand Down Expand Up @@ -63,11 +59,6 @@ public void setTransferable(long transferable) {

public static class GetRequestBuilder extends RequestBuilder<Balance> {

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "balance");
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/co/omise/models/Capability.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import co.omise.requests.ResponseType;
import com.fasterxml.jackson.annotation.JsonProperty;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;

import java.io.IOException;
import java.util.List;

/**
Expand Down Expand Up @@ -66,11 +64,6 @@ public void setZeroInterestInstallments(boolean zeroInterestInstallments) {

public static class GetRequestBuilder extends RequestBuilder<Capability> {

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "capability");
Expand Down
24 changes: 7 additions & 17 deletions src/main/java/co/omise/models/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ public Create expiration(int month, int year) {
}

public static class DeleteRequestBuilder extends RequestBuilder<Card> {
private String customerId;
private String cardId;
private final String customerId;
private final String cardId;
public DeleteRequestBuilder(String customerId, String cardId) {
this.customerId = customerId;
this.cardId = cardId;
Expand All @@ -326,18 +326,13 @@ protected ResponseType<Card> type() {
}

public static class GetRequestBuilder extends RequestBuilder<Card> {
private String customerId;
private String cardId;
private final String customerId;
private final String cardId;
public GetRequestBuilder(String customerId, String cardId) {
this.customerId = customerId;
this.cardId = cardId;
}

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "customers", customerId, "cards", cardId);
Expand All @@ -350,8 +345,8 @@ protected ResponseType<Card> type() {
}

public static class UpdateRequestBuilder extends RequestBuilder<Card> {
private String customerId;
private String cardId;
private final String customerId;
private final String cardId;

@JsonProperty
private String city;
Expand Down Expand Up @@ -425,17 +420,12 @@ protected RequestBody payload() throws IOException {
}

public static class ListRequestBuilder extends RequestBuilder<ScopedList<Card>> {
private String customerId;
private final String customerId;
private ScopedList.Options options;
public ListRequestBuilder(String customerId) {
this.customerId = customerId;
}

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
if (options == null) {
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/co/omise/models/Chain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import co.omise.Endpoint;
import co.omise.requests.RequestBuilder;
import co.omise.requests.ResponseType;
import com.fasterxml.jackson.annotation.JsonProperty;

import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.RequestBody;

import java.io.IOException;

/**
* Chain object
Expand Down Expand Up @@ -56,11 +53,6 @@ public void setRevoked(boolean revoked) {
public static class ListRequestBuilder extends RequestBuilder<ScopedList<Chain>> {
private ScopedList.Options options;

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
if (options == null) {
Expand All @@ -84,16 +76,11 @@ public ListRequestBuilder options(ScopedList.Options options) {
}

public static class GetRequestBuilder extends RequestBuilder<Chain> {
private String chainId;
private final String chainId;
public GetRequestBuilder(String chainId) {
this.chainId = chainId;
}

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "chains", chainId);
Expand All @@ -106,7 +93,7 @@ protected ResponseType<Chain> type() {
}

public static class RevokeRequestBuilder extends RequestBuilder<Chain> {
private String chainId;
private final String chainId;
public RevokeRequestBuilder(String chainId) {
this.chainId = chainId;
}
Expand Down
36 changes: 8 additions & 28 deletions src/main/java/co/omise/models/Charge.java
Original file line number Diff line number Diff line change
Expand Up @@ -514,11 +514,6 @@ public void setMerchantAdvice(String merchantAdvice) {
public static class ListRequestBuilder extends RequestBuilder<ScopedList<Charge>> {
private ScopedList.Options options;

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
if (options == null) {
Expand Down Expand Up @@ -689,17 +684,12 @@ public CreateRequestBuilder metadata(String key, Object value) {
}

public static class ListEventsRequestBuilder extends RequestBuilder<ScopedList<Event>> {
private String chargeId;
private final String chargeId;
private ScopedList.Options options;
public ListEventsRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
if (options == null) {
Expand All @@ -725,11 +715,6 @@ public ListEventsRequestBuilder options(ScopedList.Options options) {
public static class ListSchedulesRequestBuilder extends RequestBuilder<ScopedList<Schedule>> {
private ScopedList.Options options;

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
if (options == null) {
Expand All @@ -753,16 +738,11 @@ public ListSchedulesRequestBuilder options(ScopedList.Options options) {
}

public static class GetRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;
public GetRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}

@Override
protected String method() {
return GET;
}

@Override
protected HttpUrl path() {
return buildUrl(Endpoint.API, "charges", chargeId);
Expand All @@ -775,7 +755,7 @@ protected ResponseType<Charge> type() {
}

public static class UpdateRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;

@JsonProperty
private String description;
Expand Down Expand Up @@ -828,7 +808,7 @@ public UpdateRequestBuilder metadata(String key, Object value) {
}

public static class CaptureRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;

@JsonProperty("capture_amount")
private long captureAmount;
Expand Down Expand Up @@ -864,7 +844,7 @@ protected RequestBody payload() throws IOException {
}

public static class ExpireRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;
public ExpireRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}
Expand All @@ -886,7 +866,7 @@ protected ResponseType<Charge> type() {
}

public static class MarkAsFailedRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;
public MarkAsFailedRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}
Expand All @@ -908,7 +888,7 @@ protected ResponseType<Charge> type() {
}

public static class MarkAsPaidRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;
public MarkAsPaidRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}
Expand All @@ -930,7 +910,7 @@ protected ResponseType<Charge> type() {
}

public static class ReverseRequestBuilder extends RequestBuilder<Charge> {
private String chargeId;
private final String chargeId;
public ReverseRequestBuilder(String chargeId) {
this.chargeId = chargeId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/co/omise/models/ChargeStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public enum ChargeStatus {
@JsonProperty("successful")
Successful,
@JsonProperty("unknown")
Unknown;
Unknown
}
Loading

0 comments on commit 4311725

Please sign in to comment.