Java Code Examples for jenkins.scm.api.SCMSourceCriteria#Probe

The following examples show how to use jenkins.scm.api.SCMSourceCriteria#Probe . 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: 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 2
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);
        }
    };
}