Skip to content

Commit

Permalink
Remove guava dependency (#17)
Browse files Browse the repository at this point in the history
* Remove guava dependency

* Add extra test for dir path

* Update version

---------

Co-authored-by: Bartosz Litwiniuk <>
  • Loading branch information
BartoszLitwiniuk authored Jul 5, 2023
1 parent 37205f6 commit 78dd31b
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 1 addition & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
apply from: 'publish.gradle'

group = 'com.github.backtrace.io'
version = '0.9.6'
version = '0.9.7'

repositories {
mavenCentral()
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=0.9.6
VERSION_NAME=0.9.7

GROUP=com.github.backtrace-labs.backtrace-java

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/backtrace/io/database/BacktraceDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -124,7 +123,7 @@ private List<File> getDatabaseFiles() {
List<File> 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));
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/backtrace/io/helpers/FileHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;

/**
* Helper class for access to files
*/
Expand Down Expand Up @@ -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);
}

}
60 changes: 60 additions & 0 deletions src/test/java/backtrace/io/FileHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 78dd31b

Please sign in to comment.