Java 类org.kohsuke.stapler.Ancestor 实例源码

项目:lucene-search-plugin    文件:FreeTextSearch.java   
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;
}
项目:uno-choice-plugin    文件:DynamicReferenceParameter.java   
@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);
}
项目:uno-choice-plugin    文件:AbstractScriptableParameter.java   
/**
 * 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;
}
项目:DotCi    文件:DynamicSubBuild.java   
@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();
}
项目:deployer-framework-plugin    文件:DeploySourceDescriptor.java   
/**
 * 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;
}
项目:deployer-framework-plugin    文件:DeploySourceDescriptor.java   
/**
 * 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;
}
项目:gitlab-plugin    文件:GitLabPushTrigger.java   
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;
}
项目:jenkins-build-monitor-plugin    文件:RelativeLocation.java   
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);
}
项目:ez-templates    文件:ProjectUtils.java   
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();
}
项目:parameterized-scheduler    文件:ParameterizedStaplerRequest.java   
@Override
public List<Ancestor> getAncestors() {
    return null;
}
项目:parameterized-scheduler    文件:ParameterizedStaplerRequest.java   
@SuppressWarnings("rawtypes")
@Override
public Ancestor findAncestor(Class type) {
    return null;
}
项目:parameterized-scheduler    文件:ParameterizedStaplerRequest.java   
@Override
public Ancestor findAncestor(Object o) {
    return null;
}