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(style): Add Checkstyle plugin for Gradle #311

Merged
merged 40 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
df94fa3
build: Add checkstyle plugin
guicamest Nov 15, 2023
a9d3a9f
checkstyle: Copy config files from aws-sdk-v2
guicamest Nov 15, 2023
2203f9d
cleanup(checkstyle): Remove awssdk specific modules
guicamest Nov 15, 2023
31fca13
checkstyle(header): Configure and add missing license headers
guicamest Nov 15, 2023
b0b14b3
checkstyle(PosixLikePathRepresentation): static imports go first
guicamest Nov 15, 2023
ef254b8
checkstyle(TimeOutUtils): reorder imports
guicamest Nov 15, 2023
f1a41f9
checkstyle(S3XFileSystemInfo): reorder imports
guicamest Nov 15, 2023
0a50de2
checkstyle(S3FileSystemInfo): reorder imports
guicamest Nov 15, 2023
33b6c6f
checkstyle(S3NioSpiConfiguration): reorder imports
guicamest Nov 15, 2023
57c3dcd
checkstyle(S3XFileSystemProvider): reorder imports
guicamest Nov 15, 2023
367803c
checkstyle(S3WritableByteChannel): reorder imports
guicamest Nov 15, 2023
eef44b1
checkstyle(S3TransferUtil): Reformat
guicamest Nov 15, 2023
9407f38
checkstyle(S3SeekableByteChannel): Reformat
guicamest Nov 16, 2023
24600c0
checkstyl(S3ReadAheadByteChannel): Reformat
guicamest Nov 16, 2023
0d7c88d
checkstyle(S3Path): Reformat
guicamest Nov 16, 2023
d55f409
checkstyle(S3FileSystemProvider): Reformat
guicamest Nov 16, 2023
5a671c3
checkstyle(S3FileSystem): Reformat
guicamest Nov 16, 2023
c392a65
checkstyle(S3DirectoryStream): Reformat
guicamest Nov 16, 2023
3b60ea6
checkstyle(S3ClientProvider): Reformat
guicamest Nov 16, 2023
0ea6b1d
checkstyle(S3BasicFileAttributes): Reformat
guicamest Nov 16, 2023
e2eb47c
checkstyle(S3BasicFileAttributeView): Reformat
guicamest Nov 16, 2023
5aab550
checkstyle(reformat): S3NioSpiConfiguration, S3FileSystemInfo, S3XFil…
guicamest Nov 16, 2023
7670cee
checkstyle(PosixLikePathRepresentation): Reformat
guicamest Nov 16, 2023
cb2214d
checkstyle(examples): Reformat
guicamest Nov 16, 2023
0233a87
checkstyle(examples): Suppress HideUtilityClassConstructor
guicamest Nov 16, 2023
cd4689e
checkstyle(examples): Fix `Dont use System console for logging, use a…
guicamest Nov 16, 2023
dd096e5
checkstyle(main): Fix `Inner assignments should be avoided` in S3(X)F…
guicamest Nov 16, 2023
bc2e47e
checkstyle(LineLength): Fix
guicamest Nov 16, 2023
76c1e7e
checkstyle(Indentation): Fix
guicamest Nov 16, 2023
1d22712
checkstyle(DeclarationOrder): Fix
guicamest Nov 16, 2023
6ef86da
checkstyle(MethodTypeParameterName): Fix
guicamest Nov 16, 2023
d6806b2
checkstyle(ModifierOrder): Fix
guicamest Nov 16, 2023
669a130
checkstyle(ConstantName): Fix
guicamest Nov 16, 2023
6baa7dc
checkstyle(MemberName): Fix
guicamest Nov 16, 2023
9aaebaf
checkstyle(AbbreviationAsWordInName): Fix
guicamest Nov 16, 2023
f5d6b52
checkstyle: Remove Regexp check for SystemSetting; it is a SdkProtect…
guicamest Nov 16, 2023
16e16a9
checkstyle: Use Objects.hashCode instead of Objects.hash; suppress when
guicamest Nov 16, 2023
627ab57
checkstyle: Fix `Utility classes with public or default constructor`
guicamest Nov 16, 2023
e06de34
cleanup(checkstyle): Remove unrelated configuration
guicamest Nov 16, 2023
7299fc4
checkstyle: Require header for test files
guicamest Nov 16, 2023
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
350 changes: 350 additions & 0 deletions .checkstyle/checkstyle.xml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .checkstyle/java.header
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
29 changes: 29 additions & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>

<!--
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License").
~ You may not use this file except in compliance with the License.
~ A copy of the License is located at
~
~ http://aws.amazon.com/apache2.0
~
~ or in the "license" file accompanying this file. This file is distributed
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
~ express or implied. See the License for the specific language governing
~ permissions and limitations under the License.
-->

<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.2//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_2.dtd">
<suppressions>
<!-- ignore all checks for test classes except for the Header -->
<suppress checks="^((?!Header).)*$"
files=".*[\\/](test|integrationTest)[\\/]java[\\/].+\.java$"/>

<suppress checks="HideUtilityClassConstructor"
files=".*[\\/](examples)[\\/]java[\\/].+\.java$"/>

</suppressions>
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
id 'jacoco'
id 'jvm-test-suite'
id 'jacoco-report-aggregation'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.palantir.revapi' version '1.7.0'
}
Expand Down Expand Up @@ -64,6 +65,7 @@ dependencies {
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'

examplesImplementation project
examplesImplementation 'org.slf4j:slf4j-api:2.0.9'
}

publishing {
Expand Down Expand Up @@ -165,3 +167,8 @@ jacocoTestReport {
xml.outputLocation = file("build/reports/coverage.xml")
}
}

checkstyle {
toolVersion = '10.12.5'
configDirectory.set(new File(projectDir, ".checkstyle"))
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.examples;

import java.io.FileWriter;
Expand All @@ -10,6 +15,7 @@
public class CopyToS3 {
/**
* Demonstrates a cross filesystem operation by copying a local (temp) file into an S3 bucket.
*
* @param args the s3 path (URI) to copy to
* @throws IOException if the temp file cannot be created or a communication problem happens with the S3 service.
*/
Expand Down
22 changes: 18 additions & 4 deletions src/examples/java/software/amazon/nio/spi/examples/ListPrefix.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.examples;

import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ListPrefix {

private static final Logger logger = LoggerFactory.getLogger(ListPrefix.class);

public static void main(String[] args) throws IOException {
if (args.length == 0) {
System.err.println("Provide an s3 prefix to list.");
logger.error("Provide an s3 prefix to list.");
System.exit(1);
}

var s3Path = Paths.get(URI.create(args[0]));

// if the prefix doesn't exist you won't get any listings
System.err.println("Files.exists(s3Path) = " + Files.exists(s3Path));
if (!Files.exists(s3Path)) {
logger.error("the prefix {} doesn't exist, you won't get any listings", s3Path);
}

//if it's not a directory you won't get any listings.
System.err.println("Files.isDirectory(s3Path) = " + Files.isDirectory(s3Path));
if (!Files.isDirectory(s3Path)) {
logger.error("the path {} is not a directory, you won't get any listings", s3Path);
}

try (var listed = Files.list(s3Path)) {
listed.forEach(System.out::println);
listed.forEach((p) -> logger.info(p.toString()));
}
}
}
16 changes: 11 additions & 5 deletions src/examples/java/software/amazon/nio/spi/examples/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Demo class that will read text from S3 URIs that you provide on the command line. Your standard AWS credential chain
* is used for permissions.
*/
public class Main {

private static final Logger logger = LoggerFactory.getLogger(Main.class);

/**
* Demo main method
*
* @param args one or more S3 URIs to read
* @throws IOException if something goes wrong
*/
public static void main(String[] args) throws IOException {

if(args.length == 0){
System.err.println("Provide one or more S3 URIs to read from.");
if (args.length == 0) {
logger.error("Provide one or more S3 URIs to read from.");
System.exit(1);
}

Expand All @@ -35,10 +41,10 @@ public static void main(String[] args) throws IOException {
// proves that the correct path type is being used
assert path.getClass().getName().contains("S3Path");

System.err.println("*** READING FROM "+path.toUri()+" ***");
logger.info("*** READING FROM {} ***", path.toUri());
Files.readAllLines(path)
.forEach(System.out::println);
System.err.println("*** FINISHED READING OBJECT ***\n");
.forEach(logger::info);
markjschreiber marked this conversation as resolved.
Show resolved Hide resolved
logger.info("*** FINISHED READING OBJECT ***");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.examples;

import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReadAllBytes {

private static final Logger logger = LoggerFactory.getLogger(ReadAllBytes.class);

public static void main(String[] args) throws IOException {
var filePath = Paths.get(URI.create(args[0]));

final var bytes = Files.readAllBytes(filePath);
// assumes this is a text file
final var data = new String(bytes, StandardCharsets.UTF_8);
System.out.println(data);
logger.info(data);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.examples;


import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class WalkFromRoot {

private static final Logger logger = LoggerFactory.getLogger(WalkFromRoot.class);

/**
* Walks a bucket from the root listing all directories and files. Internally uses the {@code S3FileSystemProvider}'s
* {@code newDirectoryStream()} method which uses asynchronous paginated calls to S3.
Expand All @@ -17,8 +26,8 @@ public class WalkFromRoot {
*/
public static void main(String[] args) throws IOException {

if (args.length < 1){
System.err.println("Provide a bucket name to walk");
if (args.length < 1) {
logger.error("Provide a bucket name to walk");
System.exit(1);
}

Expand All @@ -29,13 +38,13 @@ public static void main(String[] args) throws IOException {


var root = Paths.get(URI.create(bucketName));
System.err.println("root.getClass() = " + root.getClass());
logger.info("root.getClass() = {}", root.getClass());

var s3 = root.getFileSystem();

for (var rootDir : s3.getRootDirectories()) {
try (var pathStream = Files.walk(rootDir)) {
pathStream.forEach(System.out::println);
pathStream.forEach((p) -> logger.info(p.toString()));
markjschreiber marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.testcontainers.containers.localstack.LocalStackContainer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.junit.jupiter.api.DisplayName;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.junit.jupiter.api.BeforeAll;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

import org.junit.jupiter.api.BeforeAll;
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/software/amazon/nio/spi/s3/Constants.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

public class Constants {
class Constants {
public static final String PATH_SEPARATOR = "/";

private Constants() {
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.nio.spi.s3;

public class NotYetImplementedException extends RuntimeException {
Expand Down
Loading