类hudson.model.RootAction源码实例Demo

下面列出了怎么用hudson.model.RootAction的API类实例代码及写法,或者点击链接到github查看源代码。

/**
 * Builds the URL for the cached avatar image of the required size.
 *
 * @param url  the URL of the source avatar image.
 * @param size the size of the image.
 * @return the URL of the cached image.
 */
public static String buildUrl(String url, String size) {
    Jenkins j = Jenkins.get();
    GitLabAvatarCache instance = j.getExtensionList(RootAction.class).get(GitLabAvatarCache.class);
    if (instance == null) {
        throw new AssertionError();
    }
    String key = Util.getDigestOf(GitLabAvatarCache.class.getName() + url);
    // seed the cache
    instance.getCacheEntry(key, url);
    return UriTemplate.buildFromTemplate(j.getRootUrlFromRequest())
        .literal(instance.getUrlName())
        .path("key")
        .query("size")
        .build()
        .set("key", key)
        .set("size", size)
        .expand();
}
 
源代码2 项目: jenkins-test-harness   文件: JenkinsRule.java
/**
 * Executes the given closure on the server, by the servlet request handling thread,
 * in the context of an HTTP request.
 *
 * <p>
 * In {@link JenkinsRule}, a thread that's executing the test code is different from the thread
 * that carries out HTTP requests made through {@link WebClient}. But sometimes you want to
 * make assertions and other calls with side-effect from within the request handling thread.
 *
 * <p>
 * This method allows you to do just that. It is useful for testing some methods that
 * require {@link org.kohsuke.stapler.StaplerRequest} and {@link org.kohsuke.stapler.StaplerResponse}, or getting the credential
 * of the current user (via {@link jenkins.model.Jenkins#getAuthentication()}, and so on.
 *
 * @param c
 *      The closure to be executed on the server.
 * @return
 *      The return value from the closure.
 * @throws Exception
 *      If a closure throws any exception, that exception will be carried forward.
 */
public <V> V executeOnServer(final Callable<V> c) throws Exception {
    final Exception[] t = new Exception[1];
    final List<V> r = new ArrayList<V>(1);  // size 1 list

    ClosureExecuterAction cea = jenkins.getExtensionList(RootAction.class).get(ClosureExecuterAction.class);
    UUID id = UUID.randomUUID();
    cea.add(id,new Runnable() {
        public void run() {
            try {
                StaplerResponse rsp = Stapler.getCurrentResponse();
                rsp.setStatus(200);
                rsp.setContentType("text/html");
                r.add(c.call());
            } catch (Exception e) {
                t[0] = e;
            }
        }
    });
    goTo("closures/?uuid="+id);

    if (t[0]!=null)
        throw t[0];
    return r.get(0);
}
 
源代码3 项目: jenkins-test-harness   文件: JenkinsRule.java
/**
 * Makes an HTTP request, process it with the given request handler, and returns the response.
 */
public HtmlPage eval(final Runnable requestHandler) throws IOException, SAXException {
    ClosureExecuterAction cea = jenkins.getExtensionList(RootAction.class).get(ClosureExecuterAction.class);
    UUID id = UUID.randomUUID();
    cea.add(id,requestHandler);
    return goTo("closures/?uuid="+id);
}
 
源代码4 项目: gerrit-code-review-plugin   文件: GerritWebHook.java
public static GerritWebHook get() {
  return Jenkins.getInstance().getExtensionList(RootAction.class).get(GerritWebHook.class);
}
 
public static GitLabSCMWebHook get() {
    return Jenkins.getInstance().getExtensionList(RootAction.class).get(GitLabSCMWebHook.class);
}
 
 类所在包
 同包方法