Skip to content

Commit

Permalink
Merge pull request #2 from merkle-open/bugfix/bundlesParser_windows_s…
Browse files Browse the repository at this point in the history
…pecialtreatment

revert os specific changes
  • Loading branch information
bjoern42 authored Jan 19, 2024
2 parents 27fd9dc + ccc310f commit e0abb10
Showing 1 changed file with 3 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import com.google.gson.Gson;
import com.google.gson.JsonIOException;
import com.google.gson.JsonSyntaxException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.invoke.MethodHandles;
Expand Down Expand Up @@ -52,16 +50,15 @@ private Stream<Bundle> create(final BundlesConfig bundlesConfig) {

private Stream<Bundle> create(final String bundlesDirName, final String path) {
try {
final URI uri = getClass().getClassLoader().getResource(path).toURI();
final FileSystem fileSystem = getFileSystem(uri);
final String filePattern = getFilePattern(fileSystem, bundlesDirName, path);
final String filePattern = "**" + path + "/**/" + bundlesDirName + "/*.json";
LOG.info("Load image bundle definitions which match pattern '{}'", filePattern);
final PathMatcher matcher = fileSystem.getPathMatcher("glob:" + filePattern);
final Stream.Builder<Stream<Bundle>> bundles = Stream.builder();

final URI uri = getClass().getClassLoader().getResource(path).toURI();
processResource(uri, p -> Files.walkFileTree(p, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) {
final PathMatcher matcher = file.getFileSystem().getPathMatcher("glob:" + filePattern);
if (matcher.matches(file)) {
bundles.accept(create(file));
}
Expand All @@ -75,14 +72,6 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr
}
}

private String getFilePattern(final FileSystem fileSystem, final String bundlesDirName, final String path) {
String filePattern = path + "/**/" + bundlesDirName + "/*.json";
if (fileSystem.getSeparator().equals(File.separator)) {
return StringUtils.removeStart(filePattern, '/');
}
return filePattern;
}

private void processResource(final URI uri, final IOConsumer<Path> consumer) throws IOException {
try {
consumer.accept(Paths.get(uri));
Expand All @@ -106,18 +95,6 @@ private Stream<Bundle> create(final Path bundleJson) {
}
}

private FileSystem getFileSystem(final URI uri) {
try {
return FileSystems.getFileSystem(uri);
} catch (Exception e) {
try {
return FileSystems.newFileSystem(uri, Collections.emptyMap());
} catch (Exception i) {
return FileSystems.getDefault();
}
}
}

interface IOConsumer<T> {
void accept(T t) throws IOException;
}
Expand Down

0 comments on commit e0abb10

Please sign in to comment.