Use locate_helper to replace locate_* predicates
locate_submit_rule and locate_submit_filter are now refactored into locate_helper. To make that easier, a noop_filter is introduced in order to have a default filter implementation (same like default_submit is a default implementation of submit rule) and avoid need to handle the case of non-existing filter. Also removed checks for non-null return values from locate_* predicates. If a locate_* predicate returns null then this is bug in its implementation. Change-Id: I9cef2b6a01ac0288874154a898ddead2ea9446c3 Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
committed by
Gerrit Code Review
parent
ee59a26b39
commit
3531ca4b8f
@@ -116,10 +116,6 @@ public class SubmitRuleEvaluator {
|
|||||||
env.set(StoredValues.CHANGE_CONTROL, changeControl);
|
env.set(StoredValues.CHANGE_CONTROL, changeControl);
|
||||||
|
|
||||||
submitRule = env.once("gerrit", userRuleLocatorName, new VariableTerm());
|
submitRule = env.once("gerrit", userRuleLocatorName, new VariableTerm());
|
||||||
if (submitRule == null) {
|
|
||||||
throw new RuleEvalException(userRuleLocatorName + " returned null");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fastEvalLabels) {
|
if (fastEvalLabels) {
|
||||||
env.once("gerrit", "assume_range_from_label");
|
env.once("gerrit", "assume_range_from_label");
|
||||||
}
|
}
|
||||||
@@ -160,30 +156,28 @@ public class SubmitRuleEvaluator {
|
|||||||
parentEnv.copyStoredValues(childEnv);
|
parentEnv.copyStoredValues(childEnv);
|
||||||
Term filterRule =
|
Term filterRule =
|
||||||
parentEnv.once("gerrit", filterRuleLocatorName, new VariableTerm());
|
parentEnv.once("gerrit", filterRuleLocatorName, new VariableTerm());
|
||||||
if (filterRule != null) {
|
try {
|
||||||
try {
|
if (fastEvalLabels) {
|
||||||
if (fastEvalLabels) {
|
env.once("gerrit", "assume_range_from_label");
|
||||||
env.once("gerrit", "assume_range_from_label");
|
|
||||||
}
|
|
||||||
|
|
||||||
Term resultsTerm = toListTerm(results);
|
|
||||||
results.clear();
|
|
||||||
Term[] template =
|
|
||||||
parentEnv.once("gerrit", filterRuleWrapperName, filterRule,
|
|
||||||
resultsTerm, new VariableTerm());
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
final List<? extends Term> termList =
|
|
||||||
((ListTerm) template[2]).toJava();
|
|
||||||
results.addAll(termList);
|
|
||||||
} catch (PrologException err) {
|
|
||||||
throw new RuleEvalException("Exception calling " + filterRule
|
|
||||||
+ " on change " + change.getId() + " of "
|
|
||||||
+ parentState.getProject().getName(), err);
|
|
||||||
} catch (RuntimeException err) {
|
|
||||||
throw new RuleEvalException("Exception calling " + filterRule
|
|
||||||
+ " on change " + change.getId() + " of "
|
|
||||||
+ parentState.getProject().getName(), err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Term resultsTerm = toListTerm(results);
|
||||||
|
results.clear();
|
||||||
|
Term[] template =
|
||||||
|
parentEnv.once("gerrit", filterRuleWrapperName, filterRule,
|
||||||
|
resultsTerm, new VariableTerm());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final List<? extends Term> termList =
|
||||||
|
((ListTerm) template[2]).toJava();
|
||||||
|
results.addAll(termList);
|
||||||
|
} catch (PrologException err) {
|
||||||
|
throw new RuleEvalException("Exception calling " + filterRule
|
||||||
|
+ " on change " + change.getId() + " of "
|
||||||
|
+ parentState.getProject().getName(), err);
|
||||||
|
} catch (RuntimeException err) {
|
||||||
|
throw new RuleEvalException("Exception calling " + filterRule
|
||||||
|
+ " on change " + change.getId() + " of "
|
||||||
|
+ parentState.getProject().getName(), err);
|
||||||
}
|
}
|
||||||
|
|
||||||
parentState = parentState.getParentState();
|
parentState = parentState.getParentState();
|
||||||
|
|||||||
@@ -153,6 +153,21 @@ is_all_ok([label(_, may(__)) | Ls]) :- is_all_ok(Ls).
|
|||||||
is_all_ok(_) :- fail.
|
is_all_ok(_) :- fail.
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
%%
|
||||||
|
%% locate_helper
|
||||||
|
%%
|
||||||
|
%% Returns user:Func if it exists otherwise returns gerrit:Default
|
||||||
|
|
||||||
|
locate_helper(Func, Default, Arity, user:Func) :-
|
||||||
|
'$compiled_predicate'(user, Func, Arity), !.
|
||||||
|
locate_helper(Func, Default, Arity, user:Func) :-
|
||||||
|
listN(Arity, P), C =.. [Func | P], clause(user:C, _), !.
|
||||||
|
locate_helper(Func, Default, _, gerrit:Default).
|
||||||
|
|
||||||
|
listN(0, []).
|
||||||
|
listN(N, [_|T]) :- N > 0, N1 is N - 1, listN(N1, T).
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
%%
|
%%
|
||||||
%% locate_submit_rule/1:
|
%% locate_submit_rule/1:
|
||||||
@@ -164,17 +179,7 @@ is_all_ok(_) :- fail.
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
locate_submit_rule(RuleName) :-
|
locate_submit_rule(RuleName) :-
|
||||||
'$compiled_predicate'(user, submit_rule, 1),
|
locate_helper(submit_rule, default_submit, 1, RuleName).
|
||||||
!,
|
|
||||||
RuleName = user:submit_rule
|
|
||||||
.
|
|
||||||
locate_submit_rule(RuleName) :-
|
|
||||||
clause(user:submit_rule(_), _),
|
|
||||||
!,
|
|
||||||
RuleName = user:submit_rule
|
|
||||||
.
|
|
||||||
locate_submit_rule(RuleName) :-
|
|
||||||
RuleName = gerrit:default_submit.
|
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
@@ -316,14 +321,15 @@ call_submit_filter(X, R, S) :- F =.. [X, R, S], F.
|
|||||||
:- public locate_submit_filter/1.
|
:- public locate_submit_filter/1.
|
||||||
%%
|
%%
|
||||||
locate_submit_filter(FilterName) :-
|
locate_submit_filter(FilterName) :-
|
||||||
'$compiled_predicate'(user, submit_filter, 2),
|
locate_helper(submit_filter, noop_filter, 2, FilterName).
|
||||||
!,
|
|
||||||
FilterName = user:submit_filter
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
.
|
%%
|
||||||
locate_submit_filter(FilterName) :-
|
%% noop_filter/2:
|
||||||
clause(user:submit_filter(_,_), _),
|
%%
|
||||||
FilterName = user:submit_filter
|
:- public noop_filter/2.
|
||||||
.
|
%%
|
||||||
|
noop_filter(In, In).
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|||||||
Reference in New Issue
Block a user