Ejemplo n.º 1
0
 @Override
 public BuildType fromShownString(final String s) {
   for (BuildType l : BuildType.values()) {
     if (l.getShownName().equals(s)) {
       return l;
     }
   }
   return null;
 }
Ejemplo n.º 2
0
  private void deserializeRule(DeserializationContext context, Build.Rule rulePb)
      throws PackageDeserializationException, InterruptedException {
    Location ruleLocation = EmptyLocation.INSTANCE;
    RuleClass ruleClass = packageDeserializationEnvironment.getRuleClass(rulePb, ruleLocation);
    Map<String, ParsedAttributeValue> attributeValues = new HashMap<>();
    AttributesToDeserialize attrToDeserialize =
        packageDeserializationEnvironment.attributesToDeserialize();

    Hasher hasher = Hashing.md5().newHasher();
    for (Build.Attribute attrPb : rulePb.getAttributeList()) {
      Type<?> type = ruleClass.getAttributeByName(attrPb.getName()).getType();
      attributeValues.put(attrPb.getName(), deserializeAttribute(type, attrPb));
      if (attrToDeserialize.addSyntheticAttributeHash) {
        // TODO(bazel-team): This might give false positives because of explicit vs implicit.
        hasher.putBytes(attrPb.toByteArray());
      }
    }
    AttributeContainerWithoutLocation attributeContainer =
        new AttributeContainerWithoutLocation(ruleClass, hasher.hash());

    Label ruleLabel = deserializeLabel(rulePb.getName());
    try {
      Rule rule =
          createRuleWithParsedAttributeValues(
              ruleClass,
              ruleLabel,
              context.packageBuilder,
              ruleLocation,
              attributeValues,
              NullEventHandler.INSTANCE,
              attributeContainer);
      context.packageBuilder.addRule(rule);

      // Remove the attribute after it is added to package in order to pass the validations
      // and be able to compute all the outputs.
      if (attrToDeserialize != DESERIALIZE_ALL_ATTRS) {
        for (String attrName : attributeValues.keySet()) {
          Attribute attribute = ruleClass.getAttributeByName(attrName);
          if (!(attrToDeserialize.shouldKeepAttributeWithName.apply(attrName)
              || BuildType.isLabelType(attribute.getType()))) {
            attributeContainer.clearIfNotLabel(attrName);
          }
        }
      }

      Preconditions.checkState(!rule.containsErrors());
    } catch (NameConflictException | LabelSyntaxException e) {
      throw new PackageDeserializationException(e);
    }
  }
  public final void doBuild(StaplerRequest req, StaplerResponse rsp)
      throws ServletException, IOException {
    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.log(Level.FINE, "doBuild action called");
    }

    String buildAction = req.getParameter("action");
    if (buildAction == null) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    String buildType = req.getParameter("build");
    if (buildType == null) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    BuildAction action;
    BuildType type;

    try {
      action = BuildAction.valueOf(buildAction.toUpperCase());
      type = BuildType.valueOf(buildType.toUpperCase());
    } catch (IllegalArgumentException e) {
      rsp.forwardToPreviousPage(req);
      return;
    }

    Builder builder = new Builder(action);

    String params = req.getParameter("params");
    BulkParamProcessor processor = new BulkParamProcessor(params);
    Map<String, String> projectParams = processor.getProjectParams();

    String paramBuild = req.getParameter("paramBuild");
    if (paramBuild != null && !paramBuild.isEmpty() && !projectParams.isEmpty()) {
      builder.setUserParams(projectParams);
    }

    String pattern = req.getParameter("pattern");
    if (pattern != null && !pattern.isEmpty()) {
      builder.setPattern(pattern);
      BuildHistory history = Jenkins.getInstance().getPlugin(BuildHistory.class);
      history.add(new BuildHistoryItem(pattern));
    }

    String view = req.getParameter("view");
    if (view != null && !view.isEmpty()) {
      builder.setView(view);
    }

    switch (type) {
      case ABORTED:
        builder.buildAborted();
        break;
      case ALL:
        builder.buildAll();
        break;
      case FAILED:
        builder.buildFailed();
        break;
      case FAILED_ONLY:
        builder.buildFailedOnly();
        break;
      case NOT_BUILD_ONLY:
        builder.buildNotBuildOnly();
        break;
      case NOT_BUILT:
        builder.buildNotBuilt();
        break;
      case UNSTABLE:
        builder.buildUnstable();
        break;
      case UNSTABLE_ONLY:
        builder.buildUnstableOnly();
        break;
    }

    rsp.forwardToPreviousPage(req);
  }
Ejemplo n.º 4
0
 @Override
 public String toShownString(final BuildType o) {
   return o.getShownName();
 }
Ejemplo n.º 5
0
 @Override
 public String toCabalString(final BuildType o) {
   return o.getCabalName();
 }
Ejemplo n.º 6
0
 @Override
 public BuildType[] getValues() {
   return BuildType.values();
 }
Ejemplo n.º 7
0
 /** 生成索引 */
 @RequestMapping(value = "/build", method = RequestMethod.GET)
 public String build(ModelMap model) {
   model.addAttribute("buildTypes", BuildType.values());
   return "/admin/index/build";
 }