jenkins.scm.api.SCMProbeStat Java Examples

The following examples show how to use jenkins.scm.api.SCMProbeStat. 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: 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 #2
Source File: ConfigDrivenWorkflowBranchProjectFactory.java    From config-driven-pipeline-plugin with MIT License 5 votes vote down vote up
@Override protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return new SCMSourceCriteria() {
        @Override public boolean isHead(@NonNull SCMSourceCriteria.Probe probe, @NonNull TaskListener listener) throws IOException {
            SCMProbeStat stat = probe.stat(scriptPath);
            switch (stat.getType()) {
                case NONEXISTENT:
                    if (stat.getAlternativePath() != null) {
                        listener.getLogger().format("      ‘%s’ not found (but found ‘%s’, search is case sensitive)%n", scriptPath, stat.getAlternativePath());
                    } else {
                        listener.getLogger().format("      ‘%s’ not found%n", scriptPath);
                    }
                    return false;
                case DIRECTORY:
                    listener.getLogger().format("      ‘%s’ found but is a directory not a file%n", scriptPath);
                    return false;
                default:
                    listener.getLogger().format("      ‘%s’ found%n", scriptPath);
                    return true;

            }
        }

        @Override
        public int hashCode() {
            return getClass().hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return getClass().isInstance(obj);
        }
    };
}
 
Example #3
Source File: YamlBranchProjectFactory.java    From simple-pull-request-job-plugin with Apache License 2.0 5 votes vote down vote up
@Override
protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return new SCMSourceCriteria() {
        @Override
        public boolean isHead(SCMSourceCriteria.Probe probe, TaskListener listener) throws IOException {
            while (true) {
                SCMProbeStat stat = probe.stat(scriptPath);
                switch (stat.getType()) {
                    case NONEXISTENT:
                        // Handle default yml case.
                        if (scriptPath.equals(YAML_SCRIPT)) {
                            scriptPath = YML_SCRIPT;
                        }
                        if (stat.getAlternativePath() != null) {
                            listener.getLogger().format("‘%s’ not found (but found ‘%s’, search is case sensitive)%n", scriptPath, stat.getAlternativePath());
                        } else {
                            listener.getLogger().format("‘%s’ not found%n", scriptPath);
                        }
                        return false;
                    case DIRECTORY:
                        listener.getLogger().format("‘%s’ found but is a directory not a file%n", scriptPath);
                        return false;
                    default:
                        listener.getLogger().format("‘%s’ found%n", scriptPath);
                        return isCorrectYAMLFile(scriptPath);
                }
            }
        }

        @Override
        public int hashCode() {
            return getClass().hashCode();
        }

        @Override
        public boolean equals(Object obj) {
            return getClass().isInstance(obj);
        }
    };
}
 
Example #4
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 #5
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 #6
Source File: GitHubSCMProbe.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Override
public SCMProbeStat stat(String path) throws IOException {
    TreeCache.Entry e = tree().entry(path);
    return SCMProbeStat.fromType(e.getType());
}