jenkins.scm.api.SCMSourceCriteria Java Examples

The following examples show how to use jenkins.scm.api.SCMSourceCriteria. 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: GitHubSourceContext.java    From github-integration-plugin with MIT License 5 votes vote down vote up
public GitHubSourceContext(@Nonnull GitHubSCMSource source,
                           @Nonnull SCMHeadObserver observer,
                           @Nonnull SCMSourceCriteria criteria,
                           @Nullable SCMHeadEvent<?> scmHeadEvent,
                           @Nonnull GitHubRepo localRepo,
                           @Nonnull GHRepository remoteRepo,
                           @Nonnull TaskListener listener) {
    this.source = source;
    this.observer = observer;
    this.criteria = criteria;
    this.scmHeadEvent = scmHeadEvent;
    this.localRepo = localRepo;
    this.remoteRepo = remoteRepo;
    this.listener = listener;
}
 
Example #3
Source File: GitHubSCMSource.java    From github-integration-plugin with MIT License 5 votes vote down vote up
@Override
protected void retrieve(SCMSourceCriteria scmSourceCriteria, @Nonnull SCMHeadObserver scmHeadObserver,
                        SCMHeadEvent<?> scmHeadEvent, // null for manual run
                        @Nonnull TaskListener taskListener) throws IOException, InterruptedException {

    try (BulkChange bc = new BulkChange(getLocalStorage());
         TreeCache.Context ctx = TreeCache.createContext()) {
        GitHubRepo localRepo = getLocalRepo();

        // latch onto local repo state
        synchronized (localRepo) {
            localRepo.actualize(getRemoteRepo());

            GitHubSourceContext context = new GitHubSourceContext(this, scmHeadObserver, scmSourceCriteria,
                    scmHeadEvent, localRepo, getRemoteRepo(), taskListener);

            getHandlers().forEach(handler -> {
                try {
                    handler.handle(context);
                } catch (Throwable e) {
                    LOG.error("Can't process handler", e);
                    e.printStackTrace(taskListener.getLogger());
                }
            });
        }

        bc.commit();
    }
}
 
Example #4
Source File: PipelineBranchDefaultsProjectFactory.java    From pipeline-multibranch-defaults-plugin with MIT License 5 votes vote down vote up
@Override
protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return new SCMSourceCriteria() {
        @Override
        public boolean isHead(Probe probe, TaskListener listener) throws IOException {
            return true;
        }
    };
}
 
Example #5
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 #6
Source File: YamlMultiBranchProjectFactory.java    From simple-pull-request-job-plugin with Apache License 2.0 4 votes vote down vote up
@Override
protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return newProjectFactorySCMSourceCriteria(source);
}
 
Example #7
Source File: YamlMultiBranchProjectFactory.java    From simple-pull-request-job-plugin with Apache License 2.0 4 votes vote down vote up
private SCMSourceCriteria newProjectFactorySCMSourceCriteria(SCMSource source) {
    YamlBranchProjectFactory workflowBranchProjectFactory = new YamlBranchProjectFactory();
    workflowBranchProjectFactory.setScriptPath(scriptPath);
    return workflowBranchProjectFactory.getSCMSourceCriteria(source);
}
 
Example #8
Source File: BasicMultiBranchProject.java    From basic-branch-build-strategies-plugin with MIT License 4 votes vote down vote up
@Override
public SCMSourceCriteria getSCMSourceCriteria(@NonNull SCMSource source) {
    return criteria;
}
 
Example #9
Source File: BasicMultiBranchProject.java    From basic-branch-build-strategies-plugin with MIT License 4 votes vote down vote up
public void setCriteria(SCMSourceCriteria criteria) {
    this.criteria = criteria;
}
 
Example #10
Source File: BasicMultiBranchProject.java    From basic-branch-build-strategies-plugin with MIT License 4 votes vote down vote up
public SCMSourceCriteria getCriteria() {
    return criteria;
}
 
Example #11
Source File: GerritSCMSourceContext.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
public GerritSCMSourceContext(SCMSourceCriteria criteria, SCMHeadObserver observer) {
  super(criteria, observer);
}
 
Example #12
Source File: GiteaSCMSourceContext.java    From gitea-plugin with MIT License 4 votes vote down vote up
public GiteaSCMSourceContext(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer) {
    super(criteria, observer);
}
 
Example #13
Source File: GitLabSCMSource.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void retrieve(@CheckForNull SCMSourceCriteria criteria, @Nonnull SCMHeadObserver observer, @CheckForNull SCMHeadEvent<?> event, @Nonnull TaskListener listener) throws IOException, InterruptedException {
    listener.getLogger().format(Messages.GitLabSCMSource_retrievingHeadsForProject(project.getPathWithNamespace()) + "\n");
    heads.retrieve(criteria, observer, event, listener);
}
 
Example #14
Source File: GitLabSCMSourceContext.java    From gitlab-branch-source-plugin with MIT License 4 votes vote down vote up
public GitLabSCMSourceContext(@CheckForNull SCMSourceCriteria criteria,
    @NonNull SCMHeadObserver observer) {
    super(criteria, observer);
}
 
Example #15
Source File: GitHubSCMSource.java    From github-integration-plugin with MIT License 4 votes vote down vote up
@Nonnull
@Override
protected Set<SCMHead> retrieve(@CheckForNull SCMSourceCriteria criteria, @Nonnull TaskListener listener)
        throws IOException, InterruptedException {
    return super.retrieve(criteria, listener);
}
 
Example #16
Source File: ConfigDrivenWorkflowMultiBranchProjectFactory.java    From config-driven-pipeline-plugin with MIT License 4 votes vote down vote up
@Override protected SCMSourceCriteria getSCMSourceCriteria(SCMSource source) {
    return newProjectFactory().getSCMSourceCriteria(source);
}
 
Example #17
Source File: GitHubSCMSourceContext.java    From github-branch-source-plugin with MIT License 2 votes vote down vote up
/**
 * Constructor.
 *
 * @param criteria (optional) criteria.
 * @param observer the {@link SCMHeadObserver}.
 */
public GitHubSCMSourceContext(@CheckForNull SCMSourceCriteria criteria, @NonNull SCMHeadObserver observer) {
    super(criteria, observer);
}