diff --git a/CHANGELOG.md b/CHANGELOG.md index ecf3b5e..8dd580d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Backtrace Java Release Notes +## Version 0.9.7 - 05.07.2023 +- Remove 'com.google.guava:guava' library + ## Version 0.9.6 - 24.05.2023 - Update dependencies (GSON and slf4j-api) diff --git a/build.gradle b/build.gradle index 0537fcf..4cfc22f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ plugins { apply from: 'publish.gradle' group = 'com.github.backtrace.io' -version = '0.9.6' +version = '0.9.7' repositories { mavenCentral() @@ -18,8 +18,6 @@ test { dependencies { implementation 'com.google.code.gson:gson:2.10.1' - // This dependency is used internally, and not exposed to consumers on their own compile classpath. - implementation 'com.google.guava:guava:31.1-jre' implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.7' // Use JUnit test framework testImplementation 'junit:junit:4.13.2' diff --git a/gradle.properties b/gradle.properties index 18e73d6..80e09b1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=0.9.6 +VERSION_NAME=0.9.7 GROUP=com.github.backtrace-labs.backtrace-java diff --git a/src/main/java/backtrace/io/database/BacktraceDatabase.java b/src/main/java/backtrace/io/database/BacktraceDatabase.java index 3317fee..5ea8bbd 100644 --- a/src/main/java/backtrace/io/database/BacktraceDatabase.java +++ b/src/main/java/backtrace/io/database/BacktraceDatabase.java @@ -5,7 +5,6 @@ import backtrace.io.data.BacktraceData; import backtrace.io.data.BacktraceReport; import backtrace.io.helpers.FileHelper; -import com.google.common.io.Files; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -124,7 +123,7 @@ private List getDatabaseFiles() { List databaseFiles = new ArrayList<>(); for (final File f : files) { - String extension = Files.getFileExtension(f.getAbsolutePath()); + String extension = FileHelper.getFileExtension(f); if (!fileExtension.equals(extension)) { LOGGER.warn(String.format("File extension (%s) in database directory does not match to database files extension (%s)", fileExtension, extension)); diff --git a/src/main/java/backtrace/io/helpers/FileHelper.java b/src/main/java/backtrace/io/helpers/FileHelper.java index 202702f..5c3f50c 100644 --- a/src/main/java/backtrace/io/helpers/FileHelper.java +++ b/src/main/java/backtrace/io/helpers/FileHelper.java @@ -8,7 +8,6 @@ import java.util.Comparator; import java.util.HashSet; import java.util.List; - /** * Helper class for access to files */ @@ -95,4 +94,13 @@ public int compare(File o1, File o2) { }; } + public static String getFileExtension(File file) { + final String name = file.getName(); + final int lastIndexOf = name.lastIndexOf("."); + if (lastIndexOf == -1) { + return ""; // empty extension + } + return name.substring(lastIndexOf + 1); + } + } diff --git a/src/test/java/backtrace/io/FileHelperTest.java b/src/test/java/backtrace/io/FileHelperTest.java index e741295..7d30d37 100644 --- a/src/test/java/backtrace/io/FileHelperTest.java +++ b/src/test/java/backtrace/io/FileHelperTest.java @@ -63,4 +63,64 @@ public void removeIncorrectPaths() { Assert.assertEquals(1, attachments.size()); Assert.assertEquals(this.absolutePath, attachments.get(0)); } + + @Test + public void verifyCorrectPathExtension() { + // GIVEN + File sampleFile = new File("./test-dir/file.txt"); + + // WHEN + String result = FileHelper.getFileExtension(sampleFile); + + // THEN + Assert.assertEquals("txt", result); + } + + @Test + public void verifyCorrectPathMultipleDotsExtension() { + // GIVEN + File sampleFile = new File("./test-dir/file.test.txt.pdf"); + + // WHEN + String result = FileHelper.getFileExtension(sampleFile); + + // THEN + Assert.assertEquals("pdf", result); + } + + @Test + public void verifyEmptyExtension() { + // GIVEN + File sampleFile = new File("./test-dir/file"); + + // WHEN + String result = FileHelper.getFileExtension(sampleFile); + + // THEN + Assert.assertEquals("", result); + } + + @Test + public void verifyDirPath() { + // GIVEN + File sampleFile = new File("./test-dir"); + + // WHEN + String result = FileHelper.getFileExtension(sampleFile); + + // THEN + Assert.assertEquals("", result); + } + + @Test + public void verifyEmptyString() { + // GIVEN + File sampleFile = new File(""); + + // WHEN + String result = FileHelper.getFileExtension(sampleFile); + + // THEN + Assert.assertEquals("", result); + } }