Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(java): Upgrade to java 11 #242

Merged
merged 7 commits into from
Oct 30, 2023
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
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,31 @@ For example:
<dependency>
<groupId>software.amazon.nio.s3</groupId>
<artifactId>aws-java-nio-spi-for-s3</artifactId>
<version>1.2.4</version>
<version>2.0.0-dev</version>
</dependency>
```

```groovy
implementation("software.amazon.nio.s3:aws-java-nio-spi-for-s3:2.0.0-dev")
```

### Java compatibility
| Library version | Java |
|-----------------|--------|
| <= 1.2.1 | \>= 8 |
| \>= 2.x.x | \>= 11 |

Versions 1.2.2 until 2.x.x are compatible with java 8 and above,
but will need to exclude logback dependency if using with java 8:
```groovy
implementation("software.amazon.nio.s3:aws-java-nio-spi-for-s3:1.2.2") {
exclude group: 'ch.qos.logback', module: 'logback-core'
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
implementation("ch.qos.logback:logback-classic:1.3.11") // 1.3.x is still compatible with java 8
implementation("ch.qos.logback:logback-core:1.3.11")
```

## AWS Credentials

This library will perform all actions using credentials according to the AWS SDK for Java [default credential provider
Expand Down Expand Up @@ -286,14 +307,14 @@ to `/foo/baa`.

## Building this library

The library uses the gradle build system and targets Java 1.8 to allow it to be used in many contexts. To build you can simply run:
The library uses the gradle build system and targets Java 11 to allow it to be used in many contexts. To build you can simply run:

```shell
./gradlew build
```

This will run all unit tests and then generate a jar file in `libs` with the name `s3fs-spi-<version>.jar`. Note that
although the compiled JAR targets Java 1.8 a later version of the JDK may be needed to run Gradle itself.
although the compiled JAR targets Java 11 a later version of the JDK may be needed to run Gradle itself.

### Shadowed Jar with dependencies

Expand Down Expand Up @@ -322,7 +343,7 @@ found at `build/reports/jacoco/test/html/index.html`
We encourage community contributions via pull requests. Please refer to our [code of conduct](./CODE_OF_CONDUCT.md) and
[contributing](./CONTRIBUTING.md) for guidance.

Code must compile to JDK 1.8 compatible bytecode. Matching unit tests are required for new features and fixes.
Code must compile to JDK 11 compatible bytecode. Matching unit tests are required for new features and fixes.

### Contributing Unit Tests

Expand Down
19 changes: 9 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ group = 'software.amazon.nio.s3'
archivesBaseName = 'nio-spi-for-s3'
version = '2.0.0-dev'

apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8


java {
withSourcesJar()
withJavadocJar()
}

compileJava {
// see https://docs.gradle.org/6.6/userguide/building_java_projects.html#sec:java_cross_compilation
options.release = 8
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(JavaCompile).configureEach {
options.release.set(11)
}

sourceSets {
Expand All @@ -58,8 +58,7 @@ dependencies {
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'ch.qos.logback:logback-classic:1.4.11'
implementation 'ch.qos.logback:logback-core:1.4.11'
// cannot use caffeine v3 because that requires java 11
implementation('com.github.ben-manes.caffeine:caffeine:2.9.3')
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'

examplesImplementation project
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import software.amazon.awssdk.services.s3.model.HeadBucketResponse;
import software.amazon.awssdk.services.s3.model.S3Exception;
import software.amazon.nio.spi.s3.config.S3NioSpiConfiguration;
import static software.amazon.nio.spi.s3.util.StringUtils.isBlank;

/**
* Factory/builder class that creates sync and async S3 clients. It also provides
Expand Down Expand Up @@ -179,7 +178,7 @@ protected S3Client generateClient (String bucketName, S3Client locationClient) {
logger.debug("generating client for bucket: '{}'", bucketName);
S3Client bucketSpecificClient = null;

if ((configuration.getEndpoint() == null) || isBlank(configuration.getEndpoint())) {
if ((configuration.getEndpoint() == null) || configuration.getEndpoint().isBlank()) {
//
// we try to locate a bucket only if no endpoint is provided, which
// means we are dealing with AWS S3 buckets
Expand Down Expand Up @@ -239,7 +238,7 @@ protected S3AsyncClient generateAsyncClient (String bucketName, S3Client locatio
logger.debug("generating asynchronous client for bucket: '{}'", bucketName);
S3AsyncClient bucketSpecificClient = null;

if ((configuration.getEndpoint() == null) || isBlank(configuration.getEndpoint())) {
if ((configuration.getEndpoint() == null) || configuration.getEndpoint().isBlank()) {
//
// we try to locate a bucket only if no endpoint is provided, which
// means we are dealing with AWS S3 buckets
Expand Down Expand Up @@ -302,7 +301,7 @@ private S3Client clientForRegion(String regionName) {
)
);

if (!isBlank(endpoint)) {
if (!endpoint.isBlank()) {
clientBuilder.endpointOverride(URI.create(configuration.getEndpointProtocol() + "://" + endpoint));
}

Expand All @@ -321,7 +320,7 @@ private S3AsyncClient asyncClientForRegion(String regionName) {

logger.debug("bucket region is: '{}'", region.id());

if (!isBlank(endpoint)) {
if (!endpoint.isBlank()) {
asyncClientBuilder.endpointOverride(URI.create(configuration.getEndpointProtocol() + "://" + endpoint));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public S3NioSpiConfiguration withEndpoint(String endpoint) {
}
endpoint = endpoint.trim();

if ((endpoint.length() > 0) && !ENDPOINT_REGEXP.matcher(endpoint).matches()) {
if (!endpoint.isEmpty() && !ENDPOINT_REGEXP.matcher(endpoint).matches()) {
throw new IllegalArgumentException(
String.format("endpoint '%s' does not match format host:port where port is a number", endpoint)
);
Expand Down Expand Up @@ -211,7 +211,7 @@ public S3NioSpiConfiguration withEndpointProtocol(String protocol) {
* @return this instance
*/
public S3NioSpiConfiguration withRegion(String region) {
if ((region == null) || StringUtils.isBlank(region)) {
if ((region == null) || region.isBlank()) {
remove(AWS_REGION_PROPERTY);
} else {
put(AWS_REGION_PROPERTY, region.trim());
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/software/amazon/nio/spi/s3/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,4 @@ public static String joinFrom(String separator, String[] elements, int startAt)
return sj.toString();
}

/**
* Like Java 11's String.isBlank(): it returns true if the string is empty or
* contains only white space codepoints, otherwise false.
*
* @param s the string to check
*
* @return true if the string is empty or contains only white space codepoints, otherwise false
*
* TODO: to replace with Java11's isBlank when moving away from Java8
*/
public static boolean isBlank(final String s) {
for (int i=0; i<s.length(); ++i) {
if (!Character.isWhitespace(s.charAt(i))) {
return false;
}
}
return true;
}
}