Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,10 @@ public FileManager createFileManager(String effectiveRelease) throws IOException
locations.forEach((location, paths) ->
paths.forEach(path -> fileManager.addPath(location, path)));

return fileManager;
return fileManagerLoggingMode == LoggingMode.DISABLED
? fileManager
: LoggingFileManagerProxy.wrap(fileManager,
fileManagerLoggingMode == LoggingMode.STACKTRACES);
}

private Lazy<RamFileSystem> newFallbackFs(FileManagerImpl fileManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Locale;
import java.util.Objects;
import java.util.StringJoiner;
import org.apiguardian.api.API;
import org.apiguardian.api.API.Status;
import org.slf4j.Logger;
Expand Down Expand Up @@ -76,6 +77,8 @@
@API(since = "0.0.1", status = Status.EXPERIMENTAL)
public final class RamFileSystem implements PathWrapper {

private static final String SEPARATOR = "/";

private static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8;
private static final Logger LOGGER = LoggerFactory.getLogger(RamFileSystem.class);

Expand All @@ -97,8 +100,8 @@ private RamFileSystem(String name, boolean closeOnGarbageCollection) {
.builder(PathType.unix())
.setSupportedFeatures(Feature.LINKS, Feature.SYMBOLIC_LINKS, Feature.FILE_CHANNEL)
.setAttributeViews("basic", "posix")
.setRoots("/")
.setWorkingDirectory("/")
.setRoots(SEPARATOR)
.setWorkingDirectory(SEPARATOR)
.setPathEqualityUsesCanonicalForm(true)
.build();

Expand Down Expand Up @@ -330,6 +333,23 @@ private static ClassLoader currentCallerClassLoader() {
return Thread.currentThread().getContextClassLoader();
}

private static String collapsePath(String first, String... rest) {
var joiner = new StringJoiner(SEPARATOR);
joiner.add(first);
for (var part : rest) {
joiner.add(part);
}
return joiner.toString();
}

private static String collapsePath(Path path) {
var joiner = new StringJoiner(SEPARATOR);
for (var part : path) {
joiner.add(part.toString());
}
return joiner.toString();
}

/**
* Chainable builder for creating individual files.
*
Expand All @@ -342,7 +362,7 @@ public final class FileBuilder {
private final Path targetPath;

private FileBuilder(String first, String... rest) {
this(path.resolve(first).resolve(String.join("/", rest)));
this(path.resolve(collapsePath(first, rest)));
}

private FileBuilder(Path targetPath) {
Expand Down Expand Up @@ -490,10 +510,11 @@ private RamFileSystem createFile(InputStream input) throws IOException {
*/
@API(since = "0.0.1", status = Status.EXPERIMENTAL)
public final class DirectoryBuilder {

private final Path targetPath;

private DirectoryBuilder(String first, String... rest) {
this(path.resolve(first).resolve(String.join("/", rest)));
this(path.resolve(collapsePath(first, rest)));
}

private DirectoryBuilder(Path targetPath) {
Expand Down Expand Up @@ -539,7 +560,8 @@ public FileVisitResult preVisitDirectory(
Path dir,
BasicFileAttributes attrs
) throws IOException {
var targetChildDirectory = targetPath.resolve(rootDir.relativize(dir).toString());
// Fix windows-style separators if needed.
var targetChildDirectory = targetPath.resolve(collapsePath(rootDir.relativize(dir)));

LOGGER.trace("making directory {} (existing {})", targetChildDirectory, dir);

Expand All @@ -553,7 +575,8 @@ public FileVisitResult visitFile(
Path file,
BasicFileAttributes attrs
) throws IOException {
var targetFile = targetPath.resolve(rootDir.relativize(file).toString());
// Fix windows-style separators if needed.
var targetFile = targetPath.resolve(collapsePath(rootDir.relativize(file)));

LOGGER.trace("copying {} to {}", file, targetFile);

Expand Down