jenkins.scm.api.SCMFile Java Examples

The following examples show how to use jenkins.scm.api.SCMFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitLabSCMFile.java    From gitlab-branch-source-plugin with MIT License 7 votes vote down vote up
@NonNull
@Override
public Iterable<SCMFile> children() throws IOException, InterruptedException {
    if (!this.isDirectory()) {
        throw new IOException("Cannot get children from a regular file");
    }
    List<TreeItem> treeItems = fetchTree();
    List<SCMFile> result = new ArrayList<>(treeItems.size());
    for (TreeItem c : treeItems) {
        Type t;
        if (c.getType() == TreeItem.Type.TREE) {
            t = Type.DIRECTORY;
        } else if (c.getType() == TreeItem.Type.BLOB) {
            if ("120000".equals(c.getMode())) {
                // File Mode 120000 is a symlink
                t = Type.LINK;
            } else {
                t = Type.REGULAR_FILE;
            }
        } else {
            t = Type.OTHER;
        }
        result.add(new GitLabSCMFile(this, c.getName(), t));
    }
    return result;
}
 
Example #2
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
public void resolveDirPRHead() throws Exception {
    assumeThat(revision, nullValue());

    assertThat(prHeadRevision.isMerge(), is(false));

    SCMFileSystem fs = SCMFileSystem.of(source, prHead, prHeadRevision);
    assertThat(fs, instanceOf(GitHubSCMFileSystem.class));

    // We can't check the sha, but we can check last modified
    // which are different for head or merge
    assertThat(((GitHubSCMFileSystem)fs).lastModified(),
        is(1480691047000L));

    assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY));
}
 
Example #3
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Test
public void resolveDirPRMerge() throws Exception {
    assumeThat(revision, nullValue());

    assertThat(prMergeRevision.isMerge(), is(true));

    SCMFileSystem fs = SCMFileSystem.of(source, prMerge, prMergeRevision);
    assertThat(fs, instanceOf(GitHubSCMFileSystem.class));

    // We can't check the sha, but we can check last modified
    // which are different for head or merge
    assertThat(((GitHubSCMFileSystem)fs).lastModified(),
        is(1480777447000L));

    assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY));
}
 
Example #4
Source File: GitHubSCMProbe.java    From github-branch-source-plugin with MIT License 6 votes vote down vote up
@Override
public SCMFile getRoot() {
    if (repo == null) {
        return null;
    }
    synchronized (this) {
        if (!open) {
            return null;
        }
    }
    String ref;
    if (revision != null) {
        if (revision.getHead() instanceof PullRequestSCMHead) {
            ref = this.ref;
        } else if (revision instanceof AbstractGitSCMSource.SCMRevisionImpl){
            ref = ((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash();
        } else {
            ref = this.ref;
        }
    } else {
        ref = this.ref;
    }
    return new GitHubSCMFile(this, repo, ref);
}
 
Example #5
Source File: GitLabSCMProbe.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Nonnull
private SCMProbeStat stat(String root, String name) throws GitLabAPIException, FileNotFoundException {
    for (GitlabRepositoryTree content : api().getTree(projectId, hash, root)) {
        if (content.getName().equals(name)) {
            if (TYPE_BLOB.equals(content.getType())) {
                return SCMProbeStat.fromType(SCMFile.Type.REGULAR_FILE);
            } else if (TYPE_DIRECTORY.equals(content.getType())) {
                return SCMProbeStat.fromType(SCMFile.Type.DIRECTORY);
            } else {
                return SCMProbeStat.fromType(SCMFile.Type.OTHER);
            }
        }
    }

    throw new FileNotFoundException(root + "/" + name);
}
 
Example #6
Source File: AbstractMultiBranchCreateRequest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Override
public boolean isHead(@Nonnull Probe probe, @Nonnull TaskListener listener) throws IOException {
    SCMProbeStat stat = probe.stat("Jenkinsfile");
    boolean foundJenkinsFile =  stat.getType() != SCMFile.Type.NONEXISTENT && stat.getType() != SCMFile.Type.DIRECTORY;
    if(foundJenkinsFile && !jenkinsFileFound.get()) {
        jenkinsFileFound.set(true);
    }
    return foundJenkinsFile;
}
 
Example #7
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
public void resolveDir() throws Exception {
    assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class));
    assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(),
            is("c0e024f89969b976da165eecaa71e09dc60c3da1"));
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY));
}
 
Example #8
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@Test
public void listDir() throws Exception {
    assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class));
    assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(),
            is("c0e024f89969b976da165eecaa71e09dc60c3da1"));
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().child("fu").children(),
            hasItem(Matchers.<SCMFile>hasProperty("name", is("manchu.txt"))));
}
 
Example #9
Source File: GitHubSCMFile.java    From github-branch-source-plugin with MIT License 5 votes vote down vote up
@NonNull
@Override
public Iterable<SCMFile> children() throws IOException {
    checkOpen();
    List<GHContent> content = repo.getDirectoryContent(getPath(), ref.indexOf('/') == -1 ? ref : Constants.R_REFS + ref);
    List<SCMFile> result = new ArrayList<>(content.size());
    for (GHContent c : content) {
        result.add(new GitHubSCMFile(this, c.getName(), c));
    }
    return result;
}
 
Example #10
Source File: TreeCache.java    From github-integration-plugin with MIT License 5 votes vote down vote up
Entry(String path, GHTreeEntry entry, boolean file) {
    this.path = path;
    this.entry = entry;
    this.file = file;

    if (entry != null) {
        type = SCMFile.Type.DIRECTORY;
    } else if (file) {
        type = SCMFile.Type.REGULAR_FILE;
    } else {
        type = SCMFile.Type.NONEXISTENT;
    }
}
 
Example #11
Source File: GitLabSCMProbe.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Nonnull
@Override
public SCMProbeStat stat(@Nonnull String path) throws IOException {
    try {
        int index = path.lastIndexOf('/') + 1;
        return stat(path.substring(0, index), path.substring(index));
    } catch (FileNotFoundException fnf) {
        return SCMProbeStat.fromType(SCMFile.Type.NONEXISTENT);
    }
}
 
Example #12
Source File: GitHubSCMFile.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Nonnull
@Override
public Iterable<SCMFile> children() throws IOException, InterruptedException {
    return getEntry().getSubEntryNames().stream()
            .map(this::newChild)
            .collect(Collectors.toList());
}
 
Example #13
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void rootIsADirectory() throws Exception {
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().getType(), is(SCMFile.Type.DIRECTORY));

}
 
Example #14
Source File: TreeCache.java    From github-integration-plugin with MIT License 4 votes vote down vote up
public SCMFile.Type getType() {
    return type;
}
 
Example #15
Source File: GitHubSCMFile.java    From github-integration-plugin with MIT License 4 votes vote down vote up
private SCMFile newChild(@Nonnull String child) {
    return new GitHubSCMFile(this, child);
}
 
Example #16
Source File: GitHubSCMFile.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
@Override
protected SCMFile newChild(@Nonnull String child, boolean assumeIsDirectory) {
    return newChild(child);
}
 
Example #17
Source File: GitHubSCMFileSystem.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
@Override
public SCMFile getRoot() {
    return new GitHubSCMFile(this);
}
 
Example #18
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void readmeIsAFile() throws Exception {
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().child("README.md").getType(), is(SCMFile.Type.REGULAR_FILE));
}
 
Example #19
Source File: GitHubSCMFileSystemTest.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@Test
public void listFilesInRoot() throws Exception {
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().children(), hasItem(Matchers.<SCMFile>hasProperty("name", is("README.md"))));
}
 
Example #20
Source File: GitLabSCMFileSystem.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public SCMFile getRoot() {
    return new GitLabSCMFile(gitLabApi, projectPath, ref);
}
 
Example #21
Source File: GitHubSCMFileSystem.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public SCMFile getRoot() {
    return new GitHubSCMFile(this, repo, ref);
}
 
Example #22
Source File: GitHubSCMFile.java    From github-branch-source-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
protected SCMFile newChild(String name, boolean assumeIsDirectory) {
    return new GitHubSCMFile(this, name, assumeIsDirectory ? TypeInfo.DIRECTORY_ASSUMED: TypeInfo.UNRESOLVED);
}
 
Example #23
Source File: GiteaSCMFileSystem.java    From gitea-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public SCMFile getRoot() {
    return new GiteaSCMFile(connection, repo, ref);
}
 
Example #24
Source File: GiteaSCMFile.java    From gitea-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
public Iterable<SCMFile> children() throws IOException {
    // TODO once https://github.com/go-gitea/gitea/issues/1978
    return Collections.emptyList();
}
 
Example #25
Source File: GiteaSCMFile.java    From gitea-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
protected SCMFile newChild(String name, boolean assumeIsDirectory) {
    return new GiteaSCMFile(this, name, assumeIsDirectory ? Boolean.FALSE : null);
}
 
Example #26
Source File: GitLabSCMFile.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
@NonNull
@Override
protected SCMFile newChild(@NonNull String name, boolean assumeIsDirectory) {
    return new GitLabSCMFile(this, name, assumeIsDirectory);
}