コード例 #1
0
  private Term runSubmitFilters(
      Term results,
      PrologEnvironment env,
      String filterRuleLocatorName,
      String filterRuleWrapperName)
      throws RuleEvalException {
    ProjectState projectState = control.getProjectControl().getProjectState();
    PrologEnvironment childEnv = env;
    for (ProjectState parentState : projectState.parents()) {
      PrologEnvironment parentEnv;
      try {
        parentEnv = parentState.newPrologEnvironment();
      } catch (CompileException err) {
        throw new RuleEvalException(
            "Cannot consult rules.pl for " + parentState.getProject().getName(), err);
      }

      parentEnv.copyStoredValues(childEnv);
      Term filterRule = parentEnv.once("gerrit", filterRuleLocatorName, new VariableTerm());
      try {
        if (fastEvalLabels) {
          env.once("gerrit", "assume_range_from_label");
        }

        Term[] template =
            parentEnv.once(
                "gerrit", filterRuleWrapperName, filterRule, results, new VariableTerm());
        results = template[2];
      } catch (ReductionLimitException err) {
        throw new RuleEvalException(
            String.format(
                "%s on change %d of %s",
                err.getMessage(), cd.getId().get(), parentState.getProject().getName()));
      } catch (RuntimeException err) {
        throw new RuleEvalException(
            String.format(
                "Exception calling %s on change %d of %s",
                filterRule, cd.getId().get(), parentState.getProject().getName()),
            err);
      } finally {
        reductionsConsumed += env.getReductions();
      }
      childEnv = parentEnv;
    }
    return results;
  }
コード例 #2
0
 private Map<String, Map<String, ConfigParameterInfo>> getPluginConfig(
     ProjectState project,
     DynamicMap<ProjectConfigEntry> pluginConfigEntries,
     PluginConfigFactory cfgFactory,
     AllProjectsName allProjects) {
   TreeMap<String, Map<String, ConfigParameterInfo>> pluginConfig = new TreeMap<>();
   for (Entry<ProjectConfigEntry> e : pluginConfigEntries) {
     ProjectConfigEntry configEntry = e.getProvider().get();
     PluginConfig cfg = cfgFactory.getFromProjectConfig(project, e.getPluginName());
     String configuredValue = cfg.getString(e.getExportName());
     ConfigParameterInfo p = new ConfigParameterInfo();
     p.displayName = configEntry.getDisplayName();
     p.description = configEntry.getDescription();
     p.warning = configEntry.getWarning(project);
     p.type = configEntry.getType();
     p.permittedValues = configEntry.getPermittedValues();
     p.editable = configEntry.isEditable(project) ? true : null;
     if (configEntry.isInheritable() && !allProjects.equals(project.getProject().getNameKey())) {
       PluginConfig cfgWithInheritance =
           cfgFactory.getFromProjectConfigWithInheritance(project, e.getPluginName());
       p.inheritable = true;
       p.value =
           configEntry.onRead(
               project,
               cfgWithInheritance.getString(e.getExportName(), configEntry.getDefaultValue()));
       p.configuredValue = configuredValue;
       p.inheritedValue = getInheritedValue(project, cfgFactory, e);
     } else {
       if (configEntry.getType() == ProjectConfigEntryType.ARRAY) {
         p.values =
             configEntry.onRead(project, Arrays.asList(cfg.getStringList(e.getExportName())));
       } else {
         p.value =
             configEntry.onRead(
                 project,
                 configuredValue != null ? configuredValue : configEntry.getDefaultValue());
       }
     }
     Map<String, ConfigParameterInfo> pc = pluginConfig.get(e.getPluginName());
     if (pc == null) {
       pc = new TreeMap<>();
       pluginConfig.put(e.getPluginName(), pc);
     }
     pc.put(e.getExportName(), p);
   }
   return !pluginConfig.isEmpty() ? pluginConfig : null;
 }