Skip to content

Commit

Permalink
chore: remove logback (#370)
Browse files Browse the repository at this point in the history
* chore: changes log statements to stderr and stdout ahead of removal of logback dependency

* chore: remove packaging of 'logback' SLF4J provider so that it is easier for users to bring their own SLF4J provider as needed
  • Loading branch information
markjschreiber authored Jan 30, 2024
1 parent fbdf836 commit 50713b2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .checkstyle/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@
<suppress checks="HideUtilityClassConstructor"
files=".*[\\/](examples)[\\/]java[\\/].+\.java$"/>

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

</suppressions>
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ dependencies {
implementation 'software.amazon.awssdk:s3-transfer-manager'
implementation 'software.amazon.awssdk.crt:aws-crt:0.29.7'
implementation 'org.slf4j:slf4j-api:2.0.11'
implementation 'ch.qos.logback:logback-classic:1.4.14'
implementation 'ch.qos.logback:logback-core:1.4.14'
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 @@ -9,33 +9,31 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("CheckStyle")
public class ListPrefix {

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

public static void main(String[] args) throws IOException {
if (args.length == 0) {
logger.error("Provide an s3 prefix to list.");
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
if (!Files.exists(s3Path)) {
logger.error("the prefix {} doesn't exist, you won't get any listings", s3Path);
System.err.printf("the prefix %s doesn't exist, you won't get any listings%n", s3Path);
}

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

try (var listed = Files.list(s3Path)) {
listed.forEach((p) -> logger.info(p.toString()));
listed.forEach(System.out::println);
}
}
}
20 changes: 5 additions & 15 deletions src/examples/java/software/amazon/nio/spi/examples/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,17 @@
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.
*/
@SuppressWarnings("CheckStyle")
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) {
logger.error("Provide one or more S3 URIs to read from.");
System.err.println("Provide one or more S3 URIs to read from.");
System.exit(1);
}

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

logger.info("*** READING FROM {} ***", path.toUri());
System.err.printf("*** READING FROM %s ***%n", path.toUri());
Files.readAllLines(path)
.forEach(logger::info);
logger.info("*** FINISHED READING OBJECT ***");
.forEach(System.out::println);
System.err.println("*** FINISHED READING OBJECT ***");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Demonstrates a move operation using the `Files` class
*/
@SuppressWarnings("CheckStyle")
public class MoveObject {

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

public static void main(String[] args) throws IOException {

if (args.length != 2) {
logger.error("Usage: java MoveObject <source> <destination>");
System.err.println("Usage: java MoveObject <source> <destination>");
System.exit(1);
}

logger.info("Moving {} to {}", args[0], args[1]);
System.err.printf("Moving %s to %s%n", args[0], args[1]);

URI source = URI.create(args[0]);
URI destination = URI.create(args[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("CheckStyle")
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);
logger.info(data);
System.out.println(data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("CheckStyle")
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 @@ -27,7 +24,7 @@ public class WalkFromRoot {
public static void main(String[] args) throws IOException {

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

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


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

var s3 = root.getFileSystem();

for (var rootDir : s3.getRootDirectories()) {
try (var pathStream = Files.walk(rootDir)) {
pathStream.forEach((p) -> logger.info(p.toString()));
pathStream.forEach(System.out::println);
}
}

Expand Down

0 comments on commit 50713b2

Please sign in to comment.