jenkins.model.lazy.LazyBuildMixIn Java Examples

The following examples show how to use jenkins.model.lazy.LazyBuildMixIn. 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: RunSearch.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Iterable<BlueRun> findRuns(Job job, final Link parent, int start, int limit){
    final List<BlueRun> runs = new ArrayList<>();
    Iterable<Job> pipelines;
    if(job != null){
        pipelines = ImmutableList.of(job);
    }else{
        pipelines = Jenkins.getInstance().getItems(Job.class);
    }

    for (Job p : pipelines) {
        Iterator<? extends Run> runIterator;
        if (job instanceof LazyBuildMixIn.LazyLoadingJob) {
            final LazyBuildMixIn lazyLoadMixin = ((LazyBuildMixIn.LazyLoadingJob) job).getLazyBuildMixIn();
            runIterator = lazyLoadMixin.getRunMap().iterator();

        }else{
            runIterator = p.getBuilds().iterator();

        }
        runs.addAll(collectRuns(runIterator, parent, start, limit));
    }

    return runs;
}
 
Example #2
Source File: AbstractTestResultAction.java    From junit-plugin with MIT License 6 votes vote down vote up
private <U extends AbstractTestResultAction> U getPreviousResult(Class<U> type, boolean eager) {
    Run<?,?> b = run;
    Set<Integer> loadedBuilds;
    if (!eager && run.getParent() instanceof LazyBuildMixIn.LazyLoadingJob) {
        loadedBuilds = ((LazyBuildMixIn.LazyLoadingJob<?,?>) run.getParent()).getLazyBuildMixIn()._getRuns().getLoadedBuilds().keySet();
    } else {
        loadedBuilds = null;
    }
    while(true) {
        b = loadedBuilds == null || loadedBuilds.contains(b.number - /* assuming there are no gaps */1) ? b.getPreviousBuild() : null;
        if(b==null)
            return null;
        U r = b.getAction(type);
        if (r != null) {
            if (r == this) {
                throw new IllegalStateException(this + " was attached to both " + b + " and " + run);
            }
            if (r.run.number != b.number) {
                throw new IllegalStateException(r + " was attached to both " + b + " and " + r.run);
            }
            return r;
        }
    }
}
 
Example #3
Source File: RunLoadCounter.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Prepares a new project to be measured.
 * Usually called before starting builds, but may also be called retroactively.
 * @param project a project of any kind
 * @throws IOException if preparations fail
 */
public static void prepare(LazyBuildMixIn.LazyLoadingJob<?, ?> project) throws IOException {
    ExtensionList.lookup(RunListener.class).get(MarkerAdder.class).register((Job) project);
    for (Run<?, ?> build : project.getLazyBuildMixIn()._getRuns()) {
        Marker.add(build);
        build.save();
    }
}
 
Example #4
Source File: RunLoadCounter.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Counts how many build records are loaded as a result of some task.
 * @param project a project on which {@link #prepare} was called prior to creating builds
 * @param thunk a task which is expected to load some build records
 * @return how many build records were actually {@linkplain Run#onLoad loaded} as a result
 */
public static int countLoads(LazyBuildMixIn.LazyLoadingJob<?, ?> project, Runnable thunk) {
    project.getLazyBuildMixIn()._getRuns().purgeCache();
    currProject.set(((Job) project).getFullName());
    currCount.set(new AtomicInteger());
    thunk.run();
    return currCount.get().get();
}
 
Example #5
Source File: RunLoadCounter.java    From jenkins-test-harness with MIT License 3 votes vote down vote up
/**
 * Asserts that at most a certain number of build records are loaded as a result of some task.
 * @param project a project on which {@link #prepare} was called prior to creating builds
 * @param max the maximum number of build records we expect to load
 * @param thunk a task which is expected to load some build records
 * @return the result of the task, if any
 * @throws Exception if the task failed
 * @throws AssertionError if one more than max build record is loaded
 * @param <T> the return value type
 */
public static <T> T assertMaxLoads(LazyBuildMixIn.LazyLoadingJob<?, ?> project, int max, Callable<T> thunk) throws Exception {
    project.getLazyBuildMixIn()._getRuns().purgeCache();
    currProject.set(((Job) project).getFullName());
    currCount.set(new AtomicInteger(-(max + 1)));
    return thunk.call();
}