Provide ProjectState instead of ChangeControl to Prolog Engine
This commit provides ProjectState to the Prolog Engine instead of ChangeControl and migrates project_default_submit_type to use this instead. Change-Id: Ia5cdb48cdca70372a0b18e3d9bac732099b84e0d
This commit is contained in:
parent
62ac9d2144
commit
39aced9ace
@ -37,7 +37,7 @@ import com.google.gerrit.server.patch.PatchListNotAvailableException;
|
|||||||
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
import com.google.gerrit.server.patch.PatchSetInfoFactory;
|
||||||
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
|
||||||
import com.google.gerrit.server.permissions.PermissionBackend;
|
import com.google.gerrit.server.permissions.PermissionBackend;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.google.gerrit.server.query.change.ChangeData;
|
import com.google.gerrit.server.query.change.ChangeData;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
import com.googlecode.prolog_cafe.exceptions.SystemException;
|
||||||
@ -54,13 +54,8 @@ public final class StoredValues {
|
|||||||
public static final StoredValue<Emails> EMAILS = create(Emails.class);
|
public static final StoredValue<Emails> EMAILS = create(Emails.class);
|
||||||
public static final StoredValue<ReviewDb> REVIEW_DB = create(ReviewDb.class);
|
public static final StoredValue<ReviewDb> REVIEW_DB = create(ReviewDb.class);
|
||||||
public static final StoredValue<ChangeData> CHANGE_DATA = create(ChangeData.class);
|
public static final StoredValue<ChangeData> CHANGE_DATA = create(ChangeData.class);
|
||||||
|
|
||||||
// Note: no guarantees are made about the user passed in the ChangeControl; do
|
|
||||||
// not depend on this directly. Either use .forUser(otherUser) to get a
|
|
||||||
// control for a specific known user, or use CURRENT_USER, which may be null
|
|
||||||
// for rule types that may not depend on the current user.
|
|
||||||
public static final StoredValue<ChangeControl> CHANGE_CONTROL = create(ChangeControl.class);
|
|
||||||
public static final StoredValue<CurrentUser> CURRENT_USER = create(CurrentUser.class);
|
public static final StoredValue<CurrentUser> CURRENT_USER = create(CurrentUser.class);
|
||||||
|
public static final StoredValue<ProjectState> PROJECT_STATE = create(ProjectState.class);
|
||||||
|
|
||||||
public static Change getChange(Prolog engine) throws SystemException {
|
public static Change getChange(Prolog engine) throws SystemException {
|
||||||
ChangeData cd = CHANGE_DATA.get(engine);
|
ChangeData cd = CHANGE_DATA.get(engine);
|
||||||
|
@ -580,10 +580,10 @@ public class SubmitRuleEvaluator {
|
|||||||
env.set(StoredValues.EMAILS, emails);
|
env.set(StoredValues.EMAILS, emails);
|
||||||
env.set(StoredValues.REVIEW_DB, cd.db());
|
env.set(StoredValues.REVIEW_DB, cd.db());
|
||||||
env.set(StoredValues.CHANGE_DATA, cd);
|
env.set(StoredValues.CHANGE_DATA, cd);
|
||||||
env.set(StoredValues.CHANGE_CONTROL, control);
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
env.set(StoredValues.CURRENT_USER, user);
|
env.set(StoredValues.CURRENT_USER, user);
|
||||||
}
|
}
|
||||||
|
env.set(StoredValues.PROJECT_STATE, projectState);
|
||||||
return env;
|
return env;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ package gerrit;
|
|||||||
|
|
||||||
import com.google.gerrit.extensions.client.SubmitType;
|
import com.google.gerrit.extensions.client.SubmitType;
|
||||||
import com.google.gerrit.rules.StoredValues;
|
import com.google.gerrit.rules.StoredValues;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ProjectState;
|
||||||
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
import com.googlecode.prolog_cafe.exceptions.PrologException;
|
||||||
import com.googlecode.prolog_cafe.lang.Operation;
|
import com.googlecode.prolog_cafe.lang.Operation;
|
||||||
import com.googlecode.prolog_cafe.lang.Predicate;
|
import com.googlecode.prolog_cafe.lang.Predicate;
|
||||||
@ -46,9 +46,8 @@ public class PRED_project_default_submit_type_1 extends Predicate.P1 {
|
|||||||
engine.setB0();
|
engine.setB0();
|
||||||
Term a1 = arg1.dereference();
|
Term a1 = arg1.dereference();
|
||||||
|
|
||||||
ChangeControl control = StoredValues.CHANGE_CONTROL.get(engine);
|
ProjectState projectState = StoredValues.PROJECT_STATE.get(engine);
|
||||||
SubmitType submitType = control.getProject().getSubmitType();
|
SubmitType submitType = projectState.getProject().getSubmitType();
|
||||||
|
|
||||||
if (!a1.unify(term[submitType.ordinal()], engine.trail)) {
|
if (!a1.unify(term[submitType.ordinal()], engine.trail)) {
|
||||||
return engine.fail();
|
return engine.fail();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user