}
List<Term> results = new ArrayList<Term>();
Term submitRule;
ProjectState projectState = getProjectControl().getProjectState();
PrologEnvironment env;
try {
env = projectState.newPrologEnvironment();
} catch (CompileException err) {
return logRuleError("Cannot consult rules.pl for "
+ getProject().getName(), err);
}
try {
env.set(StoredValues.REVIEW_DB, db);
env.set(StoredValues.CHANGE, change);
env.set(StoredValues.CHANGE_DATA, cd);
env.set(StoredValues.PATCH_SET, patchSet);
env.set(StoredValues.CHANGE_CONTROL, this);
submitRule = env.once(
"gerrit", "locate_submit_rule",
new VariableTerm());
if (submitRule == null) {
return logRuleError("No user:submit_rule found for "
+ getProject().getName());
}
if (fastEvalLabels) {
env.once("gerrit", "assume_range_from_label");
}
try {
for (Term[] template : env.all(
"gerrit", "can_submit",
submitRule,
new VariableTerm())) {
results.add(template[1]);
}
} catch (PrologException err) {
return logRuleError("Exception calling " + submitRule + " on change "
+ change.getId() + " of " + getProject().getName(), err);
} catch (RuntimeException err) {
return logRuleError("Exception calling " + submitRule + " on change "
+ change.getId() + " of " + getProject().getName(), err);
}
ProjectState parentState = projectState.getParentState();
PrologEnvironment childEnv = env;
Set<Project.NameKey> projectsSeen = new HashSet<Project.NameKey>();
projectsSeen.add(getProject().getNameKey());
while (parentState != null) {
if (!projectsSeen.add(parentState.getProject().getNameKey())) {
//parent has been seen before, stop walk up inheritance tree
break;
}
PrologEnvironment parentEnv;
try {
parentEnv = parentState.newPrologEnvironment();
} catch (CompileException err) {
return logRuleError("Cannot consult rules.pl for "
+ parentState.getProject().getName(), err);
}
parentEnv.copyStoredValues(childEnv);
Term filterRule =
parentEnv.once("gerrit", "locate_submit_filter", new VariableTerm());
if (filterRule != null) {
try {
if (fastEvalLabels) {
env.once("gerrit", "assume_range_from_label");
}
Term resultsTerm = toListTerm(results);
results.clear();
Term[] template = parentEnv.once(
"gerrit", "filter_submit_results",
filterRule,
resultsTerm,
new VariableTerm());
@SuppressWarnings("unchecked")