For IntelliJ IDEA and
Android Studio


@NonNull @Override public Iterable<SCMFile> children() throws IOException, InterruptedException { if (parent().isRoot()) { switch (hash) { case "6769413a79793e242c73d7377f0006c6aea95480": return Collections.singleton(newChild("Jenkinsfile", false)); case "3f0b897057d8b43d3b9ff55e3fdefbb021493470": return Arrays.asList(newChild("Jenkinsfile", false), newChild("README.md", false)); case "a94782d8d90b56b7e0d277c04589bd2e6f70d2cc": return Collections.singleton(newChild("README.md", false)); case "315fd8b5cae3363b29050f1aabfc27c985e22f7e": return Collections.singleton(newChild("Jenkinsfile", false)); } } return Collections.emptySet(); }
@Issue("JENKINS-42817") @Test public void slashyBranches() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "bug/JENKINS-42817"); sampleRepo.write("file", "modified"); sampleRepo.git("commit", "--all", "--message=dev"); SCMFileSystem fs = SCMFileSystem.of(r.createFreeStyleProject(), new GitSCM(GitSCM.createRepoList(sampleRepo.toString(), null), Collections.singletonList(new BranchSpec("*/bug/JENKINS-42817")), false, Collections.<SubmoduleConfig>emptyList(), null, null, Collections.<GitSCMExtension>emptyList())); assertThat(fs, notNullValue()); SCMFile root = fs.getRoot(); assertThat(root, notNullValue()); assertTrue(root.isRoot()); Iterable<SCMFile> children = root.children(); Iterator<SCMFile> iterator = children.iterator(); assertThat(iterator.hasNext(), is(true)); SCMFile file = iterator.next(); assertThat(iterator.hasNext(), is(false)); assertThat(file.getName(), is("file")); assertThat(file.contentAsString(), is("modified")); }
/** * Gets the file name including the path portion, such as "foo/bar/manchu.txt". Will never end in {@code /}. * * @return the pathname of this file. * @since 2.0 */ @NonNull public String getPath() { if (parent == null) { // root node return ""; } List<String> names = new ArrayList<String>(); SCMFile ptr = this; while (ptr != null && !ptr.isRoot()) { names.add(ptr.getName()); ptr = ptr.parent(); } Collections.reverse(names); return StringUtils.join(names, "/"); }
@Test public void ofSource_Smokes() throws Exception { sampleRepo.init(); sampleRepo.git("checkout", "-b", "dev"); sampleRepo.write("file", "modified"); sampleRepo.git("commit", "--all", "--message=dev"); SCMSource source = new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true); SCMFileSystem fs = SCMFileSystem.of(source, new SCMHead("dev")); assertThat(fs, notNullValue()); SCMFile root = fs.getRoot(); assertThat(root, notNullValue()); assertTrue(root.isRoot()); // assertTrue(root.isDirectory()); // IllegalArgumentException // assertTrue(root.exists()); // IllegalArgumentException // assertFalse(root.isFile()); // IllegalArgumentException Iterable<SCMFile> children = root.children(); Iterator<SCMFile> iterator = children.iterator(); assertThat(iterator.hasNext(), is(true)); SCMFile file = iterator.next(); assertThat(iterator.hasNext(), is(false)); assertThat(file.getName(), is("file")); assertThat(file.contentAsString(), is("modified")); }
@NonNull @Override public Iterable<SCMFile> children() throws IOException, InterruptedException { if (parent().isRoot()) { switch (hash) { case "6769413a79793e242c73d7377f0006c6aea95480": return Collections.singleton(newChild("Jenkinsfile", false)); case "3f0b897057d8b43d3b9ff55e3fdefbb021493470": return Arrays.asList(newChild("Jenkinsfile", false), newChild("README.md", false)); case "a94782d8d90b56b7e0d277c04589bd2e6f70d2cc": return Collections.singleton(newChild("README.md", false)); case "315fd8b5cae3363b29050f1aabfc27c985e22f7e": return Collections.singleton(newChild("Jenkinsfile", false)); } } return Collections.emptySet(); }
/** * Gets the file name including the path portion, such as "foo/bar/manchu.txt". Will never end in {@code /}. * * @return the pathname of this file. * @since 2.0 */ @NonNull public String getPath() { if (parent == null) { // root node return ""; } List<String> names = new ArrayList<String>(); SCMFile ptr = this; while (ptr != null && !ptr.isRoot()) { names.add(ptr.getName()); ptr = ptr.parent(); } Collections.reverse(names); return StringUtils.join(names, "/"); }