Skip to content

Commit

Permalink
Use EFS.getNullFileSystem() instead of new NullFileSystem()
Browse files Browse the repository at this point in the history
---
 Signed-off-by: Peter Kriens <[email protected]>

Signed-off-by: Peter Kriens <[email protected]>
  • Loading branch information
pkriens committed Jan 24, 2024
1 parent 98e3200 commit 25d3f0f
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import org.eclipse.core.filesystem.provider.FileInfo;
import org.eclipse.core.filesystem.provider.FileStore;
import org.eclipse.core.filesystem.provider.FileSystem;
import org.eclipse.core.internal.filesystem.NullFileStore;
import org.eclipse.core.internal.filesystem.NullFileSystem;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
Expand All @@ -51,12 +49,10 @@
* jarfileuri ::= <any uri including jarf>
* </pre>
*
* @author aqute
*/
public class JarFileSystem extends FileSystem {
private static final ILogger logger = Logger.getLogger(JarFileSystem.class);
@SuppressWarnings("unused")
private static final NullFileSystem INIT = new NullFileSystem();
private static final String SCHEME_JARF = "jarf";
private final ConcurrentMap<IFileStore, Reference<JarRootNode>> roots = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -100,10 +96,10 @@ public String[] childNames(int options, IProgressMonitor monitor) throws CoreExc

@Override
public IFileStore getChild(String name) {
new NullFileSystem();
return new NullFileStore(new Path(getPath()).append(name));
return nullFileStore(new Path(getPath()).append(name));
}


@Override
public InputStream openInputStream(int options, IProgressMonitor monitor) throws CoreException {
return new ByteArrayInputStream(new byte[0]);
Expand Down Expand Up @@ -215,7 +211,7 @@ public InputStream openInputStream(int options, IProgressMonitor monitor) throws
public IFileStore getStore(URI uri) {
if (!SCHEME_JARF.equals(uri.getScheme())) {
logger.logError("No file system for : " + uri, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(new Path(uri.getPath()));
}
return jarf(uri).map(pair -> {
URI fileuri = pair.getFirst();
Expand All @@ -224,14 +220,14 @@ public IFileStore getStore(URI uri) {
store = EFS.getStore(fileuri);
} catch (CoreException e) {
logger.logError("Cannot locate filestore for the JAR file: " + fileuri, e);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
}

JarRootNode root = roots.compute(store, this::computeRootNode)
.get();
if (root == null) {
logger.logError("Failed to load jar for: " + fileuri, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
}

IPath path = pair.getSecond();
Expand All @@ -243,7 +239,7 @@ public IFileStore getStore(URI uri) {
})
.recover(err -> {
logger.logError(err, null);
return new NullFileStore(Path.EMPTY);
return nullFileStore(Path.EMPTY);
})
.unwrap();
}
Expand Down Expand Up @@ -333,4 +329,9 @@ static Result<InputStream> openInputStream(URI uri, String path, IProgressMonito
return Result.err("Failed to open resource %s from %s : %s", path, uri, e);
}
}

static IFileStore nullFileStore(IPath path) {
return EFS.getNullFileSystem()
.getStore(path);
}
}

0 comments on commit 25d3f0f

Please sign in to comment.