Skip to content

Commit

Permalink
Minor comments and simplifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Feb 21, 2018
1 parent 9ccffba commit 7131067
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions core/src/test/java/jenkins/util/VirtualFileTest.java
Expand Up @@ -87,7 +87,7 @@ public class VirtualFileTest {
VirtualFile vfp = VirtualFile.forFilePath(fp);
assertEquals(modeString(hudson.util.IOUtils.mode(f)), modeString(vf.mode()));
assertEquals(modeString(hudson.util.IOUtils.mode(f)), modeString(vfp.mode()));
fp.chmod(0755);
fp.chmod(0755); // no-op on Windows, but harmless
assertEquals(modeString(hudson.util.IOUtils.mode(f)), modeString(vf.mode()));
assertEquals(modeString(hudson.util.IOUtils.mode(f)), modeString(vfp.mode()));
}
Expand Down Expand Up @@ -119,6 +119,7 @@ private static String modeString(int mode) throws IOException {
assertEquals("[sub/subsub/lowest.txt, top.txt, very/deep/path/here]", new TreeSet<>(vf.list("**", "**/mid*,**/conf*", false)).toString());
}
}
/** Roughly analogous to {@code org.jenkinsci.plugins.compress_artifacts.ZipStorage}. */
private static final class Ram extends VirtualFile {
private final Set<String> paths; // e.g., [/very/deep/path/here]
private final String path; // e.g., empty string or /very or /very/deep/path/here
Expand Down Expand Up @@ -152,7 +153,7 @@ public boolean exists() throws IOException {
}
@Override
public VirtualFile[] list() throws IOException {
return paths.stream().filter(p -> p.startsWith(path + "/")).map(p -> new Ram(paths, p.replaceFirst("(\\Q" + path + "\\E/[^/]+)/.+", "$1"))).collect(Collectors.toSet()).toArray(new VirtualFile[0]);
return paths.stream().filter(p -> p.startsWith(path + "/")).map(p -> new Ram(paths, p.replaceFirst("(\\Q" + path + "\\E/[^/]+)/.+", "$1"))).toArray(VirtualFile[]::new);
}
@Override
public VirtualFile child(String name) {
Expand Down Expand Up @@ -190,6 +191,7 @@ public InputStream open() throws IOException {
assertEquals("physical", link.readLink());
assertFalse(link.isFile());
assertFalse(link.isDirectory());
// not checking .exists() for now
}
}

Expand Down
Expand Up @@ -251,6 +251,7 @@ public void externalURLDownload() throws Exception {
throw x;
}
}
/** Simulation of a storage service with URLs unrelated to {@link Run#doArtifact}. */
@TestExtension("externalURLDownload")
public static final class ContentAddressableStore implements UnprotectedRootAction {
final List<byte[]> files = new ArrayList<>();
Expand Down Expand Up @@ -301,7 +302,7 @@ public void archive(FilePath workspace, Launcher launcher, BuildListener listene
}
@Override
public VirtualFile root() {
final VirtualFile file = new VirtualFile() {
final VirtualFile file = new VirtualFile() { // the file inside the root
@Override
public String getName() {
return "f";
Expand Down Expand Up @@ -359,7 +360,7 @@ public URL toExternalURL() throws IOException {
return new URL(Jenkins.get().getRootUrl() + "files/" + hash);
}
};
return new VirtualFile() {
return new VirtualFile() { // the root
@Override
public String getName() {
return "";
Expand Down

0 comments on commit 7131067

Please sign in to comment.