Пример #1
0
 private PrologEnvironment getPrologEnvironment(CurrentUser user) throws RuleEvalException {
   ProjectState projectState = control.getProjectControl().getProjectState();
   PrologEnvironment env;
   try {
     if (rule == null) {
       env = projectState.newPrologEnvironment();
     } else {
       env = projectState.newPrologEnvironment("stdin", new StringReader(rule));
     }
   } catch (CompileException err) {
     String msg;
     if (rule == null && control.getProjectControl().isOwner()) {
       msg = String.format("Cannot load rules.pl for %s: %s", getProjectName(), err.getMessage());
     } else if (rule != null) {
       msg = err.getMessage();
     } else {
       msg = String.format("Cannot load rules.pl for %s", getProjectName());
     }
     throw new RuleEvalException(msg, err);
   }
   env.set(StoredValues.REVIEW_DB, cd.db());
   env.set(StoredValues.CHANGE_DATA, cd);
   env.set(StoredValues.CHANGE_CONTROL, control);
   if (user != null) {
     env.set(StoredValues.CURRENT_USER, user);
   }
   return env;
 }
Пример #2
0
 private ProjectState newProjectState() {
   ProjectCache projectCache = null;
   Project.NameKey wildProject = new Project.NameKey("-- All Projects --");
   ProjectControl.AssistedFactory projectControlFactory = null;
   ProjectState ps =
       new ProjectState(
           anonymousUser,
           projectCache,
           wildProject,
           projectControlFactory,
           new Project(parent),
           localRights);
   ps.setInheritedRights(inheritedRights);
   return ps;
 }
Пример #3
0
 private String getInheritedValue(
     ProjectState project, PluginConfigFactory cfgFactory, Entry<ProjectConfigEntry> e) {
   ProjectConfigEntry configEntry = e.getProvider().get();
   ProjectState parent = Iterables.getFirst(project.parents(), null);
   String inheritedValue = configEntry.getDefaultValue();
   if (parent != null) {
     PluginConfig parentCfgWithInheritance =
         cfgFactory.getFromProjectConfigWithInheritance(parent, e.getPluginName());
     inheritedValue =
         parentCfgWithInheritance.getString(e.getExportName(), configEntry.getDefaultValue());
   }
   return inheritedValue;
 }
Пример #4
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;
 }
Пример #5
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;
  }
Пример #6
0
  public ConfigInfoImpl(
      boolean serverEnableSignedPush,
      ProjectControl control,
      TransferConfig config,
      DynamicMap<ProjectConfigEntry> pluginConfigEntries,
      PluginConfigFactory cfgFactory,
      AllProjectsName allProjects,
      DynamicMap<RestView<ProjectResource>> views) {
    ProjectState projectState = control.getProjectState();
    Project p = control.getProject();
    this.description = Strings.emptyToNull(p.getDescription());

    InheritedBooleanInfo useContributorAgreements = new InheritedBooleanInfo();
    InheritedBooleanInfo useSignedOffBy = new InheritedBooleanInfo();
    InheritedBooleanInfo useContentMerge = new InheritedBooleanInfo();
    InheritedBooleanInfo requireChangeId = new InheritedBooleanInfo();
    InheritedBooleanInfo createNewChangeForAllNotInTarget = new InheritedBooleanInfo();
    InheritedBooleanInfo enableSignedPush = new InheritedBooleanInfo();
    InheritedBooleanInfo requireSignedPush = new InheritedBooleanInfo();
    InheritedBooleanInfo rejectImplicitMerges = new InheritedBooleanInfo();

    useContributorAgreements.value = projectState.isUseContributorAgreements();
    useSignedOffBy.value = projectState.isUseSignedOffBy();
    useContentMerge.value = projectState.isUseContentMerge();
    requireChangeId.value = projectState.isRequireChangeID();
    createNewChangeForAllNotInTarget.value = projectState.isCreateNewChangeForAllNotInTarget();

    useContributorAgreements.configuredValue = p.getUseContributorAgreements();
    useSignedOffBy.configuredValue = p.getUseSignedOffBy();
    useContentMerge.configuredValue = p.getUseContentMerge();
    requireChangeId.configuredValue = p.getRequireChangeID();
    createNewChangeForAllNotInTarget.configuredValue = p.getCreateNewChangeForAllNotInTarget();
    enableSignedPush.configuredValue = p.getEnableSignedPush();
    requireSignedPush.configuredValue = p.getRequireSignedPush();
    rejectImplicitMerges.configuredValue = p.getRejectImplicitMerges();

    ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
    if (parentState != null) {
      useContributorAgreements.inheritedValue = parentState.isUseContributorAgreements();
      useSignedOffBy.inheritedValue = parentState.isUseSignedOffBy();
      useContentMerge.inheritedValue = parentState.isUseContentMerge();
      requireChangeId.inheritedValue = parentState.isRequireChangeID();
      createNewChangeForAllNotInTarget.inheritedValue =
          parentState.isCreateNewChangeForAllNotInTarget();
      enableSignedPush.inheritedValue = projectState.isEnableSignedPush();
      requireSignedPush.inheritedValue = projectState.isRequireSignedPush();
      rejectImplicitMerges.inheritedValue = projectState.isRejectImplicitMerges();
    }

    this.useContributorAgreements = useContributorAgreements;
    this.useSignedOffBy = useSignedOffBy;
    this.useContentMerge = useContentMerge;
    this.requireChangeId = requireChangeId;
    this.rejectImplicitMerges = rejectImplicitMerges;
    this.createNewChangeForAllNotInTarget = createNewChangeForAllNotInTarget;
    if (serverEnableSignedPush) {
      this.enableSignedPush = enableSignedPush;
      this.requireSignedPush = requireSignedPush;
    }

    MaxObjectSizeLimitInfo maxObjectSizeLimit = new MaxObjectSizeLimitInfo();
    maxObjectSizeLimit.value =
        config.getEffectiveMaxObjectSizeLimit(projectState) == config.getMaxObjectSizeLimit()
            ? config.getFormattedMaxObjectSizeLimit()
            : p.getMaxObjectSizeLimit();
    maxObjectSizeLimit.configuredValue = p.getMaxObjectSizeLimit();
    maxObjectSizeLimit.inheritedValue = config.getFormattedMaxObjectSizeLimit();
    this.maxObjectSizeLimit = maxObjectSizeLimit;

    this.submitType = p.getSubmitType();
    this.state =
        p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE
            ? p.getState()
            : null;

    this.commentlinks = new LinkedHashMap<>();
    for (CommentLinkInfo cl : projectState.getCommentLinks()) {
      this.commentlinks.put(cl.name, cl);
    }

    pluginConfig =
        getPluginConfig(control.getProjectState(), pluginConfigEntries, cfgFactory, allProjects);

    actions = new TreeMap<>();
    for (UiAction.Description d :
        UiActions.from(views, new ProjectResource(control), Providers.of(control.getUser()))) {
      actions.put(d.getId(), new ActionInfo(d));
    }
    this.theme = projectState.getTheme();
  }