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());
}
Aggregations