Java Code Examples for jenkins.scm.api.SCMFile

The following examples show how to use jenkins.scm.api.SCMFile. These examples are extracted from open source projects. 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 Project: gitlab-branch-source-plugin   Source File: GitLabSCMFile.java    License: MIT License 6 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
@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 3
Source Project: github-branch-source-plugin   Source File: GitHubSCMProbe.java    License: 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 4
@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 5
@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 6
@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 7
@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 8
Source Project: github-branch-source-plugin   Source File: GitHubSCMFile.java    License: 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 9
@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 10
@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 11
Source Project: github-integration-plugin   Source File: TreeCache.java    License: 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 12
Source Project: github-integration-plugin   Source File: GitHubSCMFile.java    License: 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 Project: gitlab-branch-source-plugin   Source File: GitLabSCMFileSystem.java    License: MIT License 4 votes vote down vote up
@NonNull
@Override
public SCMFile getRoot() {
    return new GitLabSCMFile(gitLabApi, projectPath, ref);
}
 
Example 14
Source Project: gitlab-branch-source-plugin   Source File: GitLabSCMFile.java    License: MIT License 4 votes vote down vote up
@NonNull
@Override
protected SCMFile newChild(@NonNull String name, boolean assumeIsDirectory) {
    return new GitLabSCMFile(this, name, assumeIsDirectory);
}
 
Example 15
Source Project: gitea-plugin   Source File: GiteaSCMFile.java    License: 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 16
Source Project: gitea-plugin   Source File: GiteaSCMFile.java    License: 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 17
Source Project: gitea-plugin   Source File: GiteaSCMFileSystem.java    License: MIT License 4 votes vote down vote up
@NonNull
@Override
public SCMFile getRoot() {
    return new GiteaSCMFile(connection, repo, ref);
}
 
Example 18
Source Project: github-branch-source-plugin   Source File: GitHubSCMFile.java    License: 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 19
Source Project: github-branch-source-plugin   Source File: GitHubSCMFileSystem.java    License: MIT License 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@NonNull
@Override
public SCMFile getRoot() {
    return new GitHubSCMFile(this, repo, ref);
}
 
Example 20
@Test
public void rootIsADirectory() throws Exception {
    SCMFileSystem fs = SCMFileSystem.of(source, master, revision);
    assertThat(fs.getRoot().getType(), is(SCMFile.Type.DIRECTORY));

}
 
Example 21
@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 22
@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 23
Source Project: github-integration-plugin   Source File: TreeCache.java    License: MIT License 4 votes vote down vote up
public SCMFile.Type getType() {
    return type;
}
 
Example 24
Source Project: github-integration-plugin   Source File: GitHubSCMFile.java    License: MIT License 4 votes vote down vote up
private SCMFile newChild(@Nonnull String child) {
    return new GitHubSCMFile(this, child);
}
 
Example 25
Source Project: github-integration-plugin   Source File: GitHubSCMFile.java    License: MIT License 4 votes vote down vote up
@Nonnull
@Override
protected SCMFile newChild(@Nonnull String child, boolean assumeIsDirectory) {
    return newChild(child);
}
 
Example 26
Source Project: github-integration-plugin   Source File: GitHubSCMFileSystem.java    License: MIT License 4 votes vote down vote up
@Nonnull
@Override
public SCMFile getRoot() {
    return new GitHubSCMFile(this);
}