Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
Expand All @@ -30,11 +34,11 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -44,8 +48,15 @@ jobs:

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -59,4 +70,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
10 changes: 5 additions & 5 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: Java CI

on:
push:
Expand All @@ -16,16 +16,16 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check w/o SNAPSHOT when "bump version"
if: ${{ contains(github.event.head_commit.message, 'bump version') }}
run: grep "<version>" pom.xml | head -1 | grep -v SNAPSHOT

- name: Set up JDK 1.8
uses: actions/setup-java@v3
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '8'
java-version: '17'
distribution: 'temurin'
cache: maven

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[![Release](https://jitpack.io/v/umjammer/ACD-JAPI.svg)](https://jitpack.io/#umjammer/ACD-JAPI)
[![Java CI with Maven](https://github.com/umjammer/ACD-JAPI/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/ACD-JAPI/actions)
[![Java CI](https://github.com/umjammer/ACD-JAPI/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/ACD-JAPI/actions/workflows/maven.yml)
[![CodeQL](https://github.com/umjammer/ACD-JAPI/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/ACD-JAPI/actions/workflows/codeql-analysis.yml)
![Java](https://img.shields.io/badge/Java-8-b07219)
![Java](https://img.shields.io/badge/Java-17-b07219)
[![Parent](https://img.shields.io/badge/Parent-vavi--apps--fuse-pink)](https://github.com/umjammer/vavi-apps-fuse)

# ACD-JAPI
## Amazon Cloud Drive Java API (unofficial)
This project provide a Java version of Amazon Cloud Drive API from REST version.

## Maven Repository
## Install

Maven/Gradle

Expand Down
2 changes: 2 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jdk:
- openjdk17
51 changes: 10 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@

<groupId>org.yetiz</groupId>
<artifactId>ACD-JAPI</artifactId>
<version>1.1.6v</version>
<version>1.1.7v</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<version>3.12.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<release>17</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<version>3.2.5</version>
<configuration>
<argLine>-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties</argLine>
<trimStackTrace>false</trimStackTrace>
Expand All @@ -36,7 +34,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.9.2</version>
<version>5.13.4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -47,51 +45,22 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10</version>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<version>3.20.0</version>
</dependency>
<dependency>
<groupId>org.asynchttpclient</groupId>
<artifactId>async-http-client</artifactId>
<version>2.12.3</version>
<exclusions>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
</exclusion>
<exclusion>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
</exclusion>
</exclusions>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
<version>4.1.91.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec</artifactId>
<version>4.1.91.Final</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-codec-http</artifactId>
<version>4.1.91.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
<version>2.0.17</version>
</dependency>

<dependency>
Expand All @@ -113,7 +82,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.36</version>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/org/yetiz/lib/acd/ACDSession.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.yetiz.lib.acd;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Duration;
import java.util.Calendar;

import com.google.gson.JsonObject;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.AsyncHttpClientConfig;
Expand All @@ -16,9 +21,8 @@
import org.yetiz.lib.acd.exception.InvalidAuthTokenException;
import org.yetiz.lib.utils.Log;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Calendar;
import static java.util.concurrent.TimeUnit.MICROSECONDS;


/**
* Created by yeti on 2015/4/13.
Expand Down Expand Up @@ -47,10 +51,10 @@ private ACDSession(int timeoutMs) {
Log.d("Timeout set to " + timeoutMs);
AsyncHttpClientConfig asyncHttpClientConfig = new DefaultAsyncHttpClientConfig.Builder()
.setFollowRedirect(false)
.setConnectTimeout(timeoutMs)
.setReadTimeout(timeoutMs)
.setRequestTimeout(timeoutMs)
.setPooledConnectionIdleTimeout(timeoutMs)
.setConnectTimeout(Duration.of(timeoutMs, MICROSECONDS.toChronoUnit()))
.setReadTimeout(Duration.of(timeoutMs, MICROSECONDS.toChronoUnit()))
.setRequestTimeout(Duration.of(timeoutMs, MICROSECONDS.toChronoUnit()))
.setPooledConnectionIdleTimeout(Duration.of(timeoutMs, MICROSECONDS.toChronoUnit()))
.build();
this.asyncHttpClient = new DefaultAsyncHttpClient(asyncHttpClientConfig);
}
Expand Down Expand Up @@ -205,7 +209,7 @@ public Response execute(Request request) {
}

private Request setAuthHeader(Request request) {
return new RequestBuilder(request).setHeader("Authorization", acdToken.getAuthorizationString()).build();
return new RequestBuilder(request.getMethod()).setHeader("Authorization", acdToken.getAuthorizationString()).build();
}

private void updateTokenOfConfigureFile() {
Expand Down
42 changes: 31 additions & 11 deletions src/main/java/org/yetiz/lib/acd/DateAdapter.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
package org.yetiz.lib.acd;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.internal.bind.DateTypeAdapter;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

/**
* Created by yeti on 4/15/15.
*/
public final class DateAdapter extends TypeAdapter<Date> {
public static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
@SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> typeToken) {
return typeToken.getRawType() == Date.class ? (TypeAdapter<T>) new DateTypeAdapter() : null;
return typeToken.getRawType() == Date.class ? (TypeAdapter<T>) new MyDateAdapter() : null;
}
};

private final DateFormat enUsFormat
public static class MyDateAdapter extends TypeAdapter<Date> {
@Override
public void write(JsonWriter out, Date value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
out.value(value.getTime()); // emit as long (milliseconds since epoch)
}

@Override
public Date read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
}
long millis = in.nextLong();
return new Date(millis);
}
}

private final DateFormat enUsFormat
= DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.US);
private final DateFormat localFormat
= DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/example/WithRawAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static Configure getConfigure(String[] args) {

public static ACDSession getACDSession(String[] args, Configure configure) {
ACDSession acdSession = null;
if (configure.getAccessToken().equals("")) {
if (configure.getAccessToken().isEmpty()) {
if (args.length == 2)
acdSession = ACDSession.getACDSessionByCode(configure, args[1]);
else {
Expand Down
Loading