private List<FreeTextSearchItem> normalSearch(StaplerRequest req, String query) { List<FreeTextSearchItem> searchResults = new ArrayList<FreeTextSearchItem>(); List<Ancestor> l = req.getAncestors(); for (int i = l.size() - 1; i >= 0; i--) { Ancestor a = l.get(i); if (a.getObject() instanceof SearchableModelObject) { SearchableModelObject smo = (SearchableModelObject) a.getObject(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine(String.format("smo.displayName=%s, searchName=%s", smo.getDisplayName(), smo.getSearchName())); } SearchIndex index = smo.getSearchIndex(); SuggestedItem target = find(index, query, smo); if (target != null) { searchResults.add(new SearchItemWrapper(target.item)); } } } return searchResults; }
@Override public ParameterDefinition newInstance(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException { if (req != null) { List<Ancestor> ancestors = req.getAncestors(); AbstractProject<?, ?> project = null; for (Ancestor ancestor : ancestors) { Object object = ancestor.getObject(); if (object instanceof AbstractProject<?, ?>) { project = (AbstractProject<?, ?>) object; break; } } this.project = project; } return super.newInstance(req, formData); }
/** * Inherited constructor. * * {@inheritDoc} * * @param name name * @param description description * @param randomName parameter random generated name (uuid) * @param script script used to generate the list of parameter values */ protected AbstractScriptableParameter(String name, String description, String randomName, Script script) { super(name, description, randomName); this.script = script; // Try to get the project name from the current request. In case of being called in some other non-web way, // the name will be fetched later via Jenkins.getInstance() and iterating through all items. This is for a // performance wise approach first. final StaplerRequest currentRequest = Stapler.getCurrentRequest(); String projectName = null; if (currentRequest != null) { final Ancestor ancestor = currentRequest.findAncestor(AbstractItem.class); if (ancestor != null) { final Object o = ancestor.getObject(); if (o instanceof AbstractItem) { final AbstractItem parentItem = (AbstractItem) o; projectName = parentItem.getName(); } } } this.projectName = projectName; }
@Override public String getUpUrl() { final StaplerRequest req = Stapler.getCurrentRequest(); if (req != null) { final List<Ancestor> ancs = req.getAncestors(); for (int i = 1; i < ancs.size(); i++) { if (ancs.get(i).getObject() == this) { final Object parentObj = ancs.get(i - 1).getObject(); if (parentObj instanceof DynamicBuild || parentObj instanceof DynamicSubProject) { return ancs.get(i - 1).getUrl() + '/'; } } } } return super.getDisplayName(); }
/** * If the stapler request ancestor is a Run or one of the deploy now actions, will return {@code null}, * otherwise returns the run. * * @return the run ancestor of the stapler request or {@code null} if there is none. */ @CheckForNull protected Run findRun() { StaplerRequest request = Stapler.getCurrentRequest(); if (request == null) { return null; } List<Ancestor> ancestors = request.getAncestors(); for (int i = ancestors.size() - 1; i >= 0; i--) { Ancestor a = ancestors.get(i); Object object = a.getObject(); if (object instanceof DeployNowRunAction) { return ((DeployNowRunAction) object).getOwner(); } if (object instanceof DeployNowProjectAction) { return CapabilitiesResolver.getLastDeployableBuild((((DeployNowProjectAction) object).getOwner())); } if (object instanceof Run) { return (Run) object; } if (object instanceof Job) { return CapabilitiesResolver.getLastDeployableBuild((Job) object); } } return null; }
/** * If the stapler request ancestor is a Run or one of the deploy now actions, will return {@code null}, * otherwise returns the job. * * @return the job ancestor of the stapler request or {@code null} if there is none. */ @CheckForNull protected Job findJob() { StaplerRequest request = Stapler.getCurrentRequest(); if (request == null) { return null; } List<Ancestor> ancestors = request.getAncestors(); for (int i = ancestors.size() - 1; i >= 0; i--) { Ancestor a = ancestors.get(i); Object object = a.getObject(); if (object instanceof DeployNowRunAction) { return null; } if (object instanceof DeployNowProjectAction) { return null; } if (object instanceof Run) { return null; } if (object instanceof Job) { return ((Job) object); } } return null; }
private Job<?, ?> retrieveCurrentJob() { StaplerRequest request = Stapler.getCurrentRequest(); if (request != null) { Ancestor ancestor = request.findAncestor(Job.class); return ancestor == null ? null : (Job<?, ?>) ancestor.getObject(); } return null; }
public String name() { ItemGroup ig = null; StaplerRequest request = Stapler.getCurrentRequest(); for( Ancestor a : request.getAncestors() ) { if(a.getObject() instanceof BuildMonitorView) { ig = ((View) a.getObject()).getOwnerItemGroup(); } } return Functions.getRelativeDisplayNameFrom(job, ig); }
public static AbstractProject findProject(StaplerRequest request) { Ancestor ancestor = request.getAncestors().get(request.getAncestors().size() - 1); while (ancestor != null && !(ancestor.getObject() instanceof AbstractProject)) { ancestor = ancestor.getPrev(); } if (ancestor == null) { return null; } return (AbstractProject) ancestor.getObject(); }
@Override public List<Ancestor> getAncestors() { return null; }
@SuppressWarnings("rawtypes") @Override public Ancestor findAncestor(Class type) { return null; }
@Override public Ancestor findAncestor(Object o) { return null; }