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

项目:gerrit-plugin    文件:GerritWebHook.java   
@SuppressWarnings("unused")
public void doIndex() throws IOException {
  HttpServletRequest req = Stapler.getCurrentRequest();
  GerritProjectEvent projectEvent = getBody(req);

  log.info("GerritWebHook invoked for event " + projectEvent);

  List<Item> jenkinsItems = Jenkins.getActiveInstance().getAllItems();
  for (Item item : jenkinsItems) {
    if (item instanceof SCMSourceOwner) {
      SCMSourceOwner scmJob = (SCMSourceOwner) item;
      log.info("Found SCM job " + scmJob);
      List<SCMSource> scmSources = scmJob.getSCMSources();
      for (SCMSource scmSource : scmSources) {
        if (scmSource instanceof GerritSCMSource) {
          GerritSCMSource gerritSCMSource = (GerritSCMSource) scmSource;
          if (projectEvent.matches(gerritSCMSource.getRemote())) {
            log.info(
                "Triggering SCM event for source " + scmSources.get(0) + " on job " + scmJob);
            scmJob.onSCMSourceUpdated(scmSource);
          }
        }
      }
    }
  }
}
项目:compuware-scm-downloader-plugin    文件:ScmTestUtils.java   
/**
 * Setup the global configuration.
 * 
 * @throws IOException
 */
public static void setupGlobalConfiguration() throws IOException
{
    JSONObject hostConnection = new JSONObject();
    hostConnection.put(TestConstants.DESCRIPTION, "TestConnection");
    hostConnection.put(TestConstants.HOST_PORT, TestConstants.EXPECTED_HOST + ':' + TestConstants.EXPECTED_PORT);
    hostConnection.put(TestConstants.CODE_PAGE, TestConstants.EXPECTED_CODE_PAGE);
    hostConnection.put(TestConstants.TIMEOUT, TestConstants.EXPECTED_TIMEOUT);
    hostConnection.put(TestConstants.CONNECTION_ID, TestConstants.EXPECTED_CONNECTION_ID);
    hostConnection.put(TestConstants.CES_URL, TestConstants.EXPECTED_CES_URL);

    JSONArray hostConnections = new JSONArray();
    hostConnections.add(hostConnection);

    JSONObject json = new JSONObject();
    json.put("hostConn", hostConnections);
    json.put(TestConstants.TOPAZ_CLI_LOCATION_LINUX, "/opt/Compuware/TopazCLI");
    json.put(TestConstants.TOPAZ_CLI_LOCATION_WINDOWS, "C:\\Program Files\\Compuware\\Topaz Workbench CLI");

    CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
    globalConfig.configure(Stapler.getCurrentRequest(), json);

    SystemCredentialsProvider.getInstance().getCredentials().add(new UsernamePasswordCredentialsImpl(CredentialsScope.USER,
            TestConstants.EXPECTED_CREDENTIALS_ID, null, TestConstants.EXPECTED_USER_ID, TestConstants.EXPECTED_PASSWORD));
    SystemCredentialsProvider.getInstance().save();
}
项目:compuware-scm-downloader-plugin    文件:ScmTestUtils.java   
/**
 * Setup the global configuration.
 * 
 * @throws IOException
 */
public static void setupGlobalConfiguration() throws IOException
{
    JSONObject hostConnection = new JSONObject();
    hostConnection.put(TestConstants.DESCRIPTION, "TestConnection");
    hostConnection.put(TestConstants.HOST_PORT, TestConstants.EXPECTED_HOST + ':' + TestConstants.EXPECTED_PORT);
    hostConnection.put(TestConstants.CODE_PAGE, TestConstants.EXPECTED_CODE_PAGE);
    hostConnection.put(TestConstants.TIMEOUT, TestConstants.EXPECTED_TIMEOUT);
    hostConnection.put(TestConstants.CONNECTION_ID, TestConstants.EXPECTED_CONNECTION_ID);
    hostConnection.put(TestConstants.CES_URL, TestConstants.EXPECTED_CES_URL);

    JSONArray hostConnections = new JSONArray();
    hostConnections.add(hostConnection);

    JSONObject json = new JSONObject();
    json.put("hostConn", hostConnections);
    json.put(TestConstants.TOPAZ_CLI_LOCATION_LINUX, "/opt/Compuware/TopazCLI");
    json.put(TestConstants.TOPAZ_CLI_LOCATION_WINDOWS, "C:\\Program Files\\Compuware\\Topaz Workbench CLI");

    CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
    globalConfig.configure(Stapler.getCurrentRequest(), json);

    SystemCredentialsProvider.getInstance().getCredentials().add(new UsernamePasswordCredentialsImpl(CredentialsScope.USER,
            TestConstants.EXPECTED_CREDENTIALS_ID, null, TestConstants.EXPECTED_USER_ID, TestConstants.EXPECTED_PASSWORD));
    SystemCredentialsProvider.getInstance().save();
}
项目:fabric8-jenkins-workflow-steps    文件:AnnotatedLargeText.java   
@Override
public long writeLogTo(long start, int size, Writer w) throws IOException {
    if (isHtml()) {
        ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.charset);
        long r = super.writeLogTo(start, size, caw);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Cipher sym = PASSING_ANNOTATOR.encrypt();
        ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
        oos.writeLong(System.currentTimeMillis());
        oos.writeObject(caw.getConsoleAnnotator());
        oos.close();
        StaplerResponse rsp = Stapler.getCurrentResponse();
        if(rsp != null) {
            rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
        }
        return r;
    } else {
        return super.writeLogTo(start, size, w);
    }
}
项目:yaml-project-plugin    文件:Binder.java   
/** {@inheritDoc} */
@Override
public <T extends Describable> T bind(JSONObject json)
    throws IOException, FormException {
  final String clazz = checkNotNull(json.optString("$class", null));

  final Descriptor descriptor = getDescriptor(clazz);

  final Stapler stapler = getStapler();
  final StaplerRequest request = getRequest(stapler, json);

  // We do this instead of 'request.bindJson' because this doesn't
  // require a DataBoundConstructor.
  // TODO(mattmoor): Should we do the rewrite of describable lists
  // here as well?
  return (T) descriptor.newInstance(request, json);
}
项目: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();
}
项目:Parameterized-Remote-Trigger-Plugin    文件:Auth.java   
public static ListBoxModel doFillCredsItems() {
    StandardUsernameListBoxModel model = new StandardUsernameListBoxModel();

    Item item = Stapler.getCurrentRequest().findAncestorObject(Item.class);

    List<StandardUsernameCredentials> listOfAllCredentails = CredentialsProvider.lookupCredentials(
            StandardUsernameCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());

    List<StandardUsernameCredentials> listOfSandardUsernameCredentials = new ArrayList<StandardUsernameCredentials>();

    // since we only care about 'UsernamePasswordCredentials' objects, lets seek those out and ignore the rest.
    for (StandardUsernameCredentials c : listOfAllCredentails) {
        if (c instanceof UsernamePasswordCredentials) {
            listOfSandardUsernameCredentials.add(c);
        }
    }
    model.withAll(listOfSandardUsernameCredentials);

    return model;
}
项目:gitea-plugin    文件:GiteaLink.java   
/**
 * {@inheritDoc}
 */
@Override
public String getIconFileName() {
    String iconClassName = getIconClassName();
    if (iconClassName != null) {
        Icon icon = IconSet.icons.getIconByClassSpec(iconClassName + " icon-md");
        if (icon != null) {
            JellyContext ctx = new JellyContext();
            ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
            return icon.getQualifiedUrl(ctx);
        }
    }
    return null;
}
项目:jira-steps    文件:Config.java   
@Override
public boolean configure(StaplerRequest req, JSONObject formData) {
    Stapler.CONVERT_UTILS.deregister(java.net.URL.class);
    Stapler.CONVERT_UTILS.register(new EmptyFriendlyURLConverter(), java.net.URL.class);
    sites.replaceBy(req.bindJSONToList(Site.class, formData.get("sites")));
    save();
    return true;
}
项目:apache-httpcomponents-client-4-api-plugin    文件:Client4JDKInstaller.java   
public FormValidation doCheckAcceptLicense(@QueryParameter boolean value) {
    if (username==null || password==null)
        return FormValidation.errorWithMarkup(Messages.JDKInstaller_RequireOracleAccount(Stapler.getCurrentRequest().getContextPath()+'/'+getDescriptorUrl()+"/enterCredential"));
    if (value) {
        return FormValidation.ok();
    } else {
        return FormValidation.error(Messages.JDKInstaller_DescriptorImpl_doCheckAcceptLicense());
    }
}
项目:jira-steps-plugin    文件:Config.java   
@Override
public boolean configure(StaplerRequest req, JSONObject formData) {
  Stapler.CONVERT_UTILS.deregister(java.net.URL.class);
  Stapler.CONVERT_UTILS.register(new EmptyFriendlyURLConverter(), java.net.URL.class);
  sites.replaceBy(req.bindJSONToList(Site.class, formData.get("sites")));
  save();
  return true;
}
项目:gitlab-branch-source-plugin    文件:GitLabSCMIcons.java   
public static String iconFileName(String name, Size size) {
    Icon icon = icons.getIconByClassSpec(classSpec(name, size));
    if (icon == null) {
        return null;
    }

    JellyContext ctx = new JellyContext();
    ctx.setVariable("resURL", Stapler.getCurrentRequest().getContextPath() + Jenkins.RESOURCE_PATH);
    return icon.getQualifiedUrl(ctx);
}
项目:restricted-register-plugin    文件:HudsonSecurityRealmRegistration.java   
@SuppressWarnings("unused")
public String getUsernameFromAuthCode() {
    final StaplerRequest request = Stapler.getCurrentRequest();
    if (request.hasParameter(getCodeParamKey())) {
        final User user = getUserForActivationCode(request.getParameter(getCodeParamKey()));
        if (user != null) {
            return user.getId();
        }
    }
    return "";
}
项目:restricted-register-plugin    文件:SecretKeyChecker.java   
public static boolean isGetParamSecretValid() {
    String secret = null;
    final StaplerRequest request = Stapler.getCurrentRequest();
    if (request.hasParameter(BaseFormField.SECRET.getFieldName())) {
        secret = request.getParameter(BaseFormField.SECRET.getFieldName());
    }
    return isSecretKeyValid(secret);
}
项目:display-url-api-plugin    文件:RunDisplayAction.java   
@Override
protected String getRedirectURL(DisplayURLProvider provider) {
    StaplerRequest req = Stapler.getCurrentRequest();
    String page = req.getParameter("page");
    String url;
    if ("changes".equals(page)) {
        url = provider.getChangesURL(run);
    } else {
        url = provider.getRunURL(run);
    }
    return url;
}
项目:gitlab-build-plugin    文件:GitlabWebhookAction.java   
/**
 * Method will return current project.
 *
 * @return currentProject.
 */
public Project getProject() {
    Project currentProject = null;
    StaplerRequest request = Stapler.getCurrentRequest();
    if (request != null) {
        currentProject = request.findAncestorObject(Project.class);
    }
    return currentProject;
}
项目:fabric8-jenkins-workflow-steps    文件:AnnotatedLargeText.java   
public long writeHtmlTo(long start, Writer w) throws IOException {
    ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.charset);
    long r = super.writeLogTo(start, caw);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Cipher sym = PASSING_ANNOTATOR.encrypt();
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym)));
    oos.writeLong(System.currentTimeMillis());
    oos.writeObject(caw.getConsoleAnnotator());
    oos.close();
    StaplerResponse rsp = Stapler.getCurrentResponse();
    if(rsp != null) {
        rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray())));
    }
    return r;
}
项目:fabric8-jenkins-workflow-steps    文件:FlowNodeAction.java   
public static String getUrl(FlowNode node) {
    StaplerRequest currentRequest = Stapler.getCurrentRequest();
    String path = currentRequest.getContextPath();
    if (!path.endsWith("/")) {
        path += "/";
    }
    return path + "fabric8/";
}
项目:fabric8-jenkins-workflow-steps    文件:WorkflowRunAction.java   
public static String getUrl(WorkflowRun node) {
    StaplerRequest currentRequest = Stapler.getCurrentRequest();
    String path = currentRequest.getContextPath();
    if (!path.endsWith("/")) {
        path += "/";
    }
    return path + "fabric8/";
}
项目:fabric8-jenkins-workflow-steps    文件:WorkflowJobAction.java   
public static String getUrl(WorkflowJob node) {
    StaplerRequest currentRequest = Stapler.getCurrentRequest();
    String path = currentRequest.getContextPath();
    if (!path.endsWith("/")) {
        path += "/";
    }
    return path + "fabric8";
}
项目:deployer-framework-plugin    文件:DeployNowJobProperty.java   
public Set<DeploySourceOrigin> getSources() {
    AbstractProject project = Stapler.getCurrentRequest().findAncestorObject(AbstractProject.class);
    if (project != null) {
        return CapabilitiesResolver.of(project).getInstantSources(project);
    }
    return Collections.singleton(DeploySourceOrigin.RUN);
}
项目: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;
}
项目:yaml-project-plugin    文件:Binder.java   
/** @return a response to use with {@link Stapler} binding utilities */
@VisibleForTesting
StaplerResponse getResponse(Stapler stapler) {
  return new ResponseImpl(stapler,
      new FakeHttpServletResponse()) {
    @Override
    public void sendRedirect(String url) throws IOException {
      ;
    }
  };
}
项目:yaml-project-plugin    文件:Binder.java   
/**
 * A request to use with {@link Stapler} that pretends the given
 * json block is submitted form data, to allow it to be sent through
 * the object creation process.
 */
@VisibleForTesting
StaplerRequest getRequest(Stapler stapler, final JSONObject json) {
  return new RequestImpl(stapler,
      new FakeHttpServletRequest() {
        @Override
        public String getRequestURI() {
          return "/";
        }
      }, Collections.EMPTY_LIST, null) {

    @Override
    public JSONObject getSubmittedForm() {
      return json;
    }

    @Override
    public String getParameter(String name) {
      Object o = getSubmittedForm().opt(name);
      if (o instanceof JSONObject) {
        return ((JSONObject) o).optString("value");
      } else if (o != null) {
        return o.toString();
      }
      return null;
    }
  };
}
项目:yaml-project-plugin    文件:Binder.java   
/** Gets an instance of stapler for use in lazy json binding. */
@VisibleForTesting
Stapler getStapler() {
  final WebApp webapp = new WebApp(null /* context */);
  webapp.setClassLoader(getClassLoader());

  Stapler stapler = new Stapler() {
      @Override
      public WebApp getWebApp() {
        return webapp;
      }
    };
  return stapler;
}
项目: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;
}
项目:p4-jenkins    文件:PerforceScm.java   
public static P4Browser findBrowser(String scmCredential) {
    // Retrieve item from request
    StaplerRequest req = Stapler.getCurrentRequest();
    Job job = req == null ? null : req.findAncestorObject(Job.class);

    // If cannot retrieve item, check from root
    P4BaseCredentials credentials = job == null
            ? ConnectionHelper.findCredential(scmCredential, Jenkins.getActiveInstance())
            : ConnectionHelper.findCredential(scmCredential, job);

    if (credentials == null) {
        logger.fine("Could not retrieve credentials from id: '${scmCredential}");
        return null;
    }
    try {
        ConnectionHelper connection = new ConnectionHelper(credentials, null);
        String url = connection.getSwarm();
        if (url != null) {
            return new SwarmBrowser(url);
        } else {
            return null;
        }
    } catch (P4JavaException e) {
        logger.info("Unable to access Perforce Property.");
        return null;
    }
}
项目:DotCi    文件:GithubReposController.java   
@Override
public Object getTarget() {
    final StaplerRequest currentRequest = Stapler.getCurrentRequest();
    if (getAccessToken(currentRequest) == null)
        return new GithubOauthLoginAction();
    return this;
}
项目:DotCi    文件:OrganizationContainer.java   
@Override
public Object getTarget() {
    final StaplerRequest currentRequest = Stapler.getCurrentRequest();
    //@formatter:off
    if (!currentRequest.getRequestURI().matches(".*(api/(json|xml)).*")
        && !currentRequest.getRequestURI().contains("buildWithParameters")
        && !currentRequest.getRequestURI().contains("logTail")
        && !currentRequest.getRequestURI().contains("artifact")) {
        //@formatter:on
        authenticate();
    }

    return this;
}
项目:DotCi    文件:JobInfo.java   
@Exported
public List<Build> getBuilds() {
    final StaplerRequest req = Stapler.getCurrent().getCurrentRequest();
    final String branchTab = req.getParameter("branchTab");
    final String buildCount = req.getParameter("count");
    return Lists.newArrayList(new BuildHistory(this.dynamicProject).getBuilds(branchTab, Integer.parseInt(buildCount)));
}
项目:DotCi    文件:JobInfo.java   
@Exported
public List<JobMetric> getMetrics() {
    final StaplerRequest req = Stapler.getCurrent().getCurrentRequest();
    final String branchTab = req.getParameter("branchTab");
    final String buildCount = req.getParameter("count");
    return JobMetric.getApplicableJobMetrics(this.dynamicProject, branchTab, Integer.parseInt(buildCount));
}
项目:DotCi    文件:DynamicRunPtr.java   
public String getNearestRunUrl() {
    final
    Build r = getRun();
    if (r == null) {
        return null;
    }
    if (this.dynamicBuild.getNumber() == r.getNumber()) {
        return getShortUrl() + "/console";
    }
    return Stapler.getCurrentRequest().getContextPath() + '/' + r.getUrl();
}
项目:DotCi    文件:DbBackedProject.java   
@Override
public B getLastBuild() {
    String branch = "master";
    final StaplerRequest currentRequest = Stapler.getCurrentRequest();
    if (currentRequest != null && StringUtils.isNotEmpty(currentRequest.getParameter("branch"))) {
        branch = currentRequest.getParameter("branch");
    }
    return this.dynamicBuildRepository.<B>getLastBuild(this, branch);
}
项目: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);
}
项目:jenkins-inheritance-plugin    文件:InheritanceProject.java   
/**
 * {@inheritDoc}
 */
@Exported @Override
public boolean isConcurrentBuild() {
    //Check if we're called from a configure page; if so, do not inherit
    //In all other cases, do full inheritance
    StaplerRequest req = Stapler.getCurrentRequest();
    if (req != null && req.getRequestURI().endsWith("/configure")) {
        return this.isConcurrentBuildFast(false);
    }
    return this.isConcurrentBuildFast(true);
}
项目:jenkins-inheritance-plugin    文件:InheritanceViewAction.java   
public InheritanceBuild getBuild() {
    if (this.build == null) {
        StaplerRequest req = Stapler.getCurrentRequest();
        return this.getBuild(req);
    }
    return build;
}
项目:jenkins-inheritance-plugin    文件:VersionHandler.java   
/**
 * This method loads the map of versions from the parameters passed in
 * via the current StaperRequest's URL.
 * @return
 */
private static Map<String, Long> getFromUrlParameter() {
    StaplerRequest req = Stapler.getCurrentRequest();
    if (req == null) { return null; }

    Map<String, Long> out = new HashMap<String, Long>();

    //Check for "other jobs" version key
    String param = req.getParameter(VERSIONING_KEY);
    if (param != null && !(param.isEmpty())) {
        out.putAll(decodeUrlParameter(param));
    }

    //Check for "current job" version key
    param = req.getParameter(SINGLE_VERSION_KEY);
    if (param != null && !(param.isEmpty())) {
        InheritanceProject ip = InheritanceProject.getProjectFromRequest(req);
        if (ip != null) {
            try {
                out.put(ip.getFullName(), Long.valueOf(param));
            } catch (NumberFormatException ex) {
                //Invalid value for "versions" field
            }
        }
    }

    if (out.isEmpty()) {
        return null;
    } else {
        return out;
    }
}
项目:jenkins-inheritance-plugin    文件:VersionHandler.java   
private static Map<String, Long> getFromRequest() {
    //Checking if we were invoked through an HTTP URL request
    StaplerRequest req = Stapler.getCurrentRequest();
    if (req == null) {
        return null;
    }

    //FIXME: This method should allow using the ?version=<num> everywhere,
    //not just in structured form submissions.

    Object verObj = req.getAttribute("versions");
    if (verObj == null) {
        //Fallback, use explicit parameters in form content
        if (StringUtils.isEmpty(req.getParameter("project"))
                || StringUtils.isEmpty(req.getParameter("version"))
        ) {
            return null;
        }
        Map<String, Long> versionMap = getFromFormRequest(req);
        if (versionMap == null || versionMap.isEmpty()) {
            return null;
        }
        return versionMap;
    }
    try {
        @SuppressWarnings("unchecked")
        Map<String, Long> verMap =
                (Map<String, Long>) verObj;
        return verMap;
    } catch (ClassCastException ex) {
        log.warning(
            "ClassCaseException when attempting to decode 'versions' attribute of HTTP-Request"
        );
    }
    return null;
}