Skip to content
Open
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
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ jobs:
strategy:
matrix:
# https://en.wikipedia.org/wiki/Java_version_history
java: [ '8', '11' ] # LTS
# The tests use JUnit 6, which needs Java 17 or later. The library itself is compiled
# for Java 7 with the JDK 17 toolchain (see build.gradle.kts).
java: [ '17', '21' ] # LTS

steps:
- name: Checkout
Expand All @@ -47,7 +49,7 @@ jobs:
jdks

- name: Build and test
run: ./gradlew build --stacktrace
run: ./gradlew build -PtestJavaVersion=${{ matrix.java }} --stacktrace

publish-snapshot:
name: Publish snapshot to GitHub Packages
Expand Down Expand Up @@ -85,7 +87,7 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v5
with:
java-version: 8
java-version: 17
distribution: 'temurin'

- name: Setup Gradle
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-tagged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Setup JDK and Maven
uses: actions/setup-java@v5
with:
java-version: 8
java-version: 17
distribution: "temurin"

- name: Setup key
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Supported features:

The minimum requirements to build this project are:

1. Gradle 8.2 (you can use `./gradlew` or `.\gradlew.bat` which will download it for you).
2. JDK 1.8 (target is 1.7, so don't use much higher version).
1. Gradle 8.14.6 (you can use `./gradlew` or `.\gradlew.bat` which will download it for you).
2. JDK 17 or later to run Gradle. The library targets Java 7. JDK 20 and later cannot compile for Java 7, so Gradle compiles with a JDK 17 toolchain. Gradle downloads JDK 17 if it is not installed.
3. Running `./gradlew build` should run successfully.

## Maven
Expand Down
53 changes: 42 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,54 @@ group = "com.uploadcare"

val isReleaseVersion = !version.toString().lowercase().endsWith("snapshot")

// The library targets Java 7. JDK 17 is the newest LTS JDK that can still compile for Java 7,
// and JUnit 6 needs Java 17 to run the tests.
java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
}

// Run the tests on another JDK with -PtestJavaVersion=<version> (for example 21).
val testJavaVersion = (project.findProperty("testJavaVersion") ?: "17").toString()

// Mockito 5 attaches an agent to the test JVM. Load it at JVM start, as the Mockito
// documentation advises, so newer JDKs do not warn about dynamic agent loading.
val mockitoAgent = configurations.create("mockitoAgent")

dependencies {
implementation("org.apache.httpcomponents:httpclient:4.5.13")
implementation("org.apache.httpcomponents:httpmime:4.5.13")
implementation("com.fasterxml.jackson.core:jackson-databind:2.16.2")
implementation("commons-codec:commons-codec:1.10")
implementation("commons-io:commons-io:2.7")
implementation("com.sun.activation:javax.activation:1.2.0")

testImplementation("junit:junit:4.13.1")
testImplementation("org.mockito:mockito-all:1.10.19")
implementation("org.apache.httpcomponents:httpclient:4.5.14")
implementation("org.apache.httpcomponents:httpmime:4.5.14")
implementation("com.fasterxml.jackson.core:jackson-databind:2.21.8")
implementation("commons-codec:commons-codec:1.23.0")
implementation("commons-io:commons-io:2.22.0")

testImplementation(platform("org.junit:junit-bom:6.1.3"))
testImplementation("org.junit.jupiter:junit-jupiter")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.mockito:mockito-core:5.24.0")
testImplementation("org.mockito:mockito-junit-jupiter:5.24.0")
mockitoAgent("org.mockito:mockito-core:5.24.0") { isTransitive = false }
}

tasks {
compileJava {
options.release.set(7)
// JDK 17 warns that release 7 is obsolete.
options.compilerArgs.add("-Xlint:-options")
}
compileTestJava {
options.release.set(17)
}
test {
useJUnitPlatform()
jvmArgs("-javaagent:${mockitoAgent.asPath}")
javaLauncher.set(project.javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(testJavaVersion))
})
}
}

// Setup global publishing repository settings.
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
25 changes: 14 additions & 11 deletions gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ pluginManagement {
}
}

plugins {
// Downloads the JDK of the Java toolchain when it is not installed.
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

dependencyResolutionManagement {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/uploadcare/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.uploadcare.data.*;
import com.uploadcare.exceptions.UploadcareApiException;
import com.uploadcare.urls.*;
Expand Down Expand Up @@ -134,7 +134,7 @@ public Client(
.build();
}
this.objectMapper = new ObjectMapper();
this.objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
this.objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
this.objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/uploadcare/api/RequestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.activation.MimetypesFileTypeMap;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

Expand Down Expand Up @@ -77,8 +77,8 @@ public static String iso8601(Date date) {
}

public static String getMimeType(String fileName) {
MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
return fileTypeMap.getContentType(fileName);
String type = fileName == null ? null : URLConnection.getFileNameMap().getContentTypeFor(fileName);
return type != null ? type : "application/octet-stream";
}

public String makeSignature(HttpUriRequest request, String date, String requestBodyMD5)
Expand Down
7 changes: 4 additions & 3 deletions src/test/java/com/uploadcare/api/FileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class FileTest
{
Expand All @@ -20,7 +21,7 @@ public void enumFails() throws Exception {

Bug bug = mapper.readValue(json, Bug.class);

Assert.assertTrue("Color mode was not properly converted!", File.ColorMode.RGBa.equals(bug.colorMode));
assertEquals(File.ColorMode.RGBa, bug.colorMode, "Color mode was not properly converted!");
}

static class Bug {
Expand Down
18 changes: 14 additions & 4 deletions src/test/java/com/uploadcare/api/RequestHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

import com.uploadcare.urls.Urls;
import org.apache.http.client.methods.HttpGet;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.net.URI;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RequestHelperTest {

private static final String FILE_ID = "27c7846b-a019-4516-a5e4-de635f822161";
private static final String FORMATTED_DATE = "Fri, 17 Nov 1989 00:00:00 +0000";
private RequestHelper requestHelper;

@Before
@BeforeEach
public void setUp() {
Client client = Client.demoClient();
requestHelper = new RequestHelper(client);
Expand All @@ -41,4 +41,14 @@ public void test_makeSignature() throws InvalidKeyException, NoSuchAlgorithmExce
assertEquals("535e263808dd38599343f04aab3c9f34bb15573c", signature);
}

@Test
public void test_getMimeType() {
assertEquals("image/png", RequestHelper.getMimeType("olympia.png"));
assertEquals("image/jpeg", RequestHelper.getMimeType("olympia.jpg"));
assertEquals("text/plain", RequestHelper.getMimeType("notes.txt"));
assertEquals("application/octet-stream", RequestHelper.getMimeType("file.unknownext"));
assertEquals("application/octet-stream", RequestHelper.getMimeType("noextension"));
assertEquals("application/octet-stream", RequestHelper.getMimeType(null));
}

}
Loading
Loading