下面列出了hudson.model.listeners.RunListener#jenkins.model.lazy.LazyBuildMixIn 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
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;
}
}
}
/**
* 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();
}
}
/**
* 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();
}
/**
* 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();
}