hudson.model.RootAction Java Examples

The following examples show how to use hudson.model.RootAction. 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: GitLabAvatarCache.java    From gitlab-branch-source-plugin with MIT License 6 votes vote down vote up
/**
 * 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();
}
 
Example #2
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
/**
 * 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);
}
 
Example #3
Source File: JenkinsRule.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * 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);
}
 
Example #4
Source File: GerritWebHook.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
public static GerritWebHook get() {
  return Jenkins.getInstance().getExtensionList(RootAction.class).get(GerritWebHook.class);
}
 
Example #5
Source File: GitLabSCMWebHook.java    From gitlab-branch-source-plugin with GNU General Public License v2.0 4 votes vote down vote up
public static GitLabSCMWebHook get() {
    return Jenkins.getInstance().getExtensionList(RootAction.class).get(GitLabSCMWebHook.class);
}