Search in sources :

Example 1 with ModelObject

use of hudson.model.ModelObject in project blueocean-plugin by jenkinsci.

the class BlueOceanWebURLBuilder method getTryBlueOceanURLs.

/**
     * Get the {@link TryBlueOceanURLs} instance for the {@link ModelObject}
     * associated with the current Stapler request.
     *
     * @return The {@link TryBlueOceanURLs} instance for the current classic
     * Jenkins page. The URL to the Blue Ocean homepage is returned if a more
     * appropriate URL is not found.
     */
@Nonnull
public static TryBlueOceanURLs getTryBlueOceanURLs() {
    StaplerRequest staplerRequest = Stapler.getCurrentRequest();
    List<Ancestor> list = staplerRequest.getAncestors();
    // Blue Ocean page we can link onto.
    for (int i = list.size() - 1; i >= 0; i--) {
        Ancestor ancestor = list.get(i);
        Object object = ancestor.getObject();
        if (object instanceof ModelObject) {
            String blueUrl = toBlueOceanURL((ModelObject) object);
            if (blueUrl != null) {
                if (object instanceof Item) {
                    return new TryBlueOceanURLs(blueUrl, ((Item) object).getUrl());
                } else if (object instanceof Run) {
                    return new TryBlueOceanURLs(blueUrl, ((Run) object).getUrl());
                } else {
                    return new TryBlueOceanURLs(blueUrl);
                }
            } else if (object instanceof Item) {
                return new TryBlueOceanURLs(getBlueHome(), ((Item) object).getUrl());
            }
        }
    }
    // Otherwise just return Blue Ocean home.
    return new TryBlueOceanURLs(getBlueHome());
}
Also used : Item(hudson.model.Item) ModelObject(hudson.model.ModelObject) StaplerRequest(org.kohsuke.stapler.StaplerRequest) ModelObject(hudson.model.ModelObject) Run(hudson.model.Run) Ancestor(org.kohsuke.stapler.Ancestor) Nonnull(javax.annotation.Nonnull)

Aggregations

Item (hudson.model.Item)1 ModelObject (hudson.model.ModelObject)1 Run (hudson.model.Run)1 Nonnull (javax.annotation.Nonnull)1 Ancestor (org.kohsuke.stapler.Ancestor)1 StaplerRequest (org.kohsuke.stapler.StaplerRequest)1