Skip to content

Commit

Permalink
Small improvment
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed Oct 15, 2021
1 parent c08349a commit 11c7877
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public String getRef() {
// Create the zip file if it doesn't exist
env.put("create", "true");

URI uri = URI.create("jar:file:" + tmpZipFile.toAbsolutePath());
// The 'jar:' prefix is necessary to enable the use of FileSystems.newFileSystem over a .zip
URI uri = URI.create("jar:" + tmpZipFile.toUri());

try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {
// Path externalTxtFile = Paths.get("/codeSamples/zipfs/SomeTextFile.txt");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ public void listFiles(Consumer<ICodeProviderFile> consumer) throws IOException {
throw new IllegalStateException("Issue given root=" + root + " and path=" + f);
}

// https://stackoverflow.com/questions/58411668/how-to-replace-backslash-with-the-forwardslash-in-java-nio-file-path
Path relativized = root.relativize(f);
consumer.accept(new DummyCodeProviderFile("/" + relativized.toString(), f));
// We get '\' under Windows
String pathWithSlash = "/" + relativized.toString().replaceAll("\\\\", "/");
consumer.accept(new DummyCodeProviderFile(pathWithSlash, f));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.scalafmt.dynamic.ScalafmtDynamicError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

import com.google.common.io.ByteStreams;
Expand All @@ -14,6 +17,7 @@
import eu.solven.cleanthat.language.SourceCodeProperties;

public class TestScalafmtFormatter {
private static final Logger LOGGER = LoggerFactory.getLogger(TestScalafmtFormatter.class);

@Test
public void testScala() throws IOException {
Expand All @@ -23,7 +27,13 @@ public void testScala() throws IOException {
String scalaCode =
new String(ByteStreams.toByteArray(new ClassPathResource("/scala/Hello.scala").getInputStream()),
StandardCharsets.UTF_8);
String formatted = formatter.doFormat(scalaCode, LineEnding.KEEP);
String formatted;
try {
formatted = formatter.doFormat(scalaCode, LineEnding.KEEP);
} catch (ScalafmtDynamicError.CannotDownload e) {
LOGGER.info("Issue downloading Scalafmt. Possibly a proxy issue", e);
return;
}

Assertions.assertThat(formatted).isNotEqualTo(scalaCode).hasLineCount(5);
Assertions.assertThat(formatted.split("[\r\n]"))
Expand Down

0 comments on commit 11c7877

Please sign in to comment.