Skip to content

Commit

Permalink
Revert os specific bundlesParser changes and only prefix **
Browse files Browse the repository at this point in the history
  • Loading branch information
eschleb committed Jan 19, 2024
1 parent 597b043 commit ccc310f
Showing 1 changed file with 3 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;

Expand All @@ -23,8 +22,6 @@

public class BundlesParser {
private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private static final String OS_NAME = System.getProperty("os.name");
private static final String WINDOWS = "Windows";

Stream<Bundle> parse(final String bundlesConfigFilePath) {
return getBundleConfig(bundlesConfigFilePath)
Expand Down Expand Up @@ -53,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 @@ -76,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 (isWindows()) {
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 @@ -107,22 +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();
}
}
}

private boolean isWindows() {
return OS_NAME.startsWith(WINDOWS);
}

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

0 comments on commit ccc310f

Please sign in to comment.