Search in sources :

Example 6 with Ancestor

use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.

the class Functions method decompose.

public static RunUrl decompose(StaplerRequest req) {
    List<Ancestor> ancestors = req.getAncestors();
    // find the first and last Run instances
    Ancestor f = null, l = null;
    for (Ancestor anc : ancestors) {
        if (anc.getObject() instanceof Run) {
            if (f == null)
                f = anc;
            l = anc;
        }
    }
    // there was no Run object
    if (l == null)
        return null;
    String head = f.getPrev().getUrl() + '/';
    String base = l.getUrl();
    String reqUri = req.getOriginalRequestURI();
    // Find "rest" or URI by removing N path components.
    // Not using reqUri.substring(f.getUrl().length()) to avoid mismatches due to
    // url-encoding or extra slashes.  Former may occur in Tomcat (despite the spec saying
    // this string is not decoded, Tomcat apparently decodes this string. You see ' '
    // instead of '%20', which is what the browser has sent), latter may occur in some
    // proxy or URL-rewriting setups where extra slashes are inadvertently added.
    String furl = f.getUrl();
    int slashCount = 0;
    // Count components in ancestor URL
    for (int i = furl.indexOf('/'); i >= 0; i = furl.indexOf('/', i + 1)) slashCount++;
    // Remove that many from request URL, ignoring extra slashes
    String rest = reqUri.replaceFirst("(?:/+[^/]*){" + slashCount + "}", "");
    return new RunUrl((Run) f.getObject(), head, base, rest);
}
Also used : Run(hudson.model.Run) Ancestor(org.kohsuke.stapler.Ancestor)

Example 7 with Ancestor

use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.

the class TestResultProjectAction method doFlipTrend.

/**
     * Changes the test result report display mode.
     */
public void doFlipTrend(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    boolean failureOnly = false;
    // check the current preference value
    Cookie[] cookies = req.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(FAILURE_ONLY_COOKIE))
                failureOnly = Boolean.parseBoolean(cookie.getValue());
        }
    }
    // flip!
    failureOnly = !failureOnly;
    // set the updated value
    Cookie cookie = new Cookie(FAILURE_ONLY_COOKIE, String.valueOf(failureOnly));
    List anc = req.getAncestors();
    Ancestor a = (Ancestor) anc.get(anc.size() - 2);
    // just for this project
    cookie.setPath(a.getUrl());
    // 1 year
    cookie.setMaxAge(60 * 60 * 24 * 365);
    rsp.addCookie(cookie);
    // back to the project page
    rsp.sendRedirect("..");
}
Also used : Cookie(javax.servlet.http.Cookie) List(java.util.List) Ancestor(org.kohsuke.stapler.Ancestor)

Example 8 with Ancestor

use of org.kohsuke.stapler.Ancestor in project hudson-2.x by hudson.

the class Search method makeSuggestIndex.

/**
     * Creates merged search index for suggestion.
     */
private SearchIndex makeSuggestIndex(StaplerRequest req) {
    SearchIndexBuilder builder = new SearchIndexBuilder();
    for (Ancestor a : req.getAncestors()) {
        if (a.getObject() instanceof SearchableModelObject) {
            SearchableModelObject smo = (SearchableModelObject) a.getObject();
            builder.add(smo.getSearchIndex());
        }
    }
    return builder.make();
}
Also used : Ancestor(org.kohsuke.stapler.Ancestor)

Aggregations

Ancestor (org.kohsuke.stapler.Ancestor)8 ModelObject (hudson.model.ModelObject)3 Item (hudson.model.Item)2 Run (hudson.model.Run)2 SearchableModelObject (hudson.search.SearchableModelObject)2 StaplerRequest (org.kohsuke.stapler.StaplerRequest)2 ItemGroup (hudson.model.ItemGroup)1 TopLevelItem (hudson.model.TopLevelItem)1 View (hudson.model.View)1 AccessControlled (hudson.security.AccessControlled)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Cookie (javax.servlet.http.Cookie)1