Add per-project prolog submit rule files
When loading the prolog environment, now checks refs/meta/config branch for a file called rules.pl. If it exists, consult the file. Expects a predicate called submit_rule. If no file is found, uses the default_submit predicate in common_rules.pl. Change-Id: Ia76d0dc5aba67cf3c68c56589fe013c63157bca5
This commit is contained in:
committed by
Shawn O. Pearce
parent
9f2535231b
commit
f93796cd53
@@ -29,10 +29,17 @@ import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import com.googlecode.prolog_cafe.compiler.CompileException;
|
||||
import com.googlecode.prolog_cafe.lang.JavaObjectTerm;
|
||||
import com.googlecode.prolog_cafe.lang.Prolog;
|
||||
import com.googlecode.prolog_cafe.lang.SymbolTerm;
|
||||
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PushbackReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -121,9 +128,24 @@ public class ProjectState {
|
||||
}
|
||||
|
||||
/** @return Construct a new PrologEnvironment for the calling thread. */
|
||||
public PrologEnvironment newPrologEnvironment() {
|
||||
public PrologEnvironment newPrologEnvironment() throws CompileException {
|
||||
// TODO Replace this with a per-project ClassLoader to isolate rules.
|
||||
return envFactory.create(getClass().getClassLoader());
|
||||
PrologEnvironment env = envFactory.create(getClass().getClassLoader());
|
||||
|
||||
//consult rules.pl at refs/meta/config branch for custom submit rules
|
||||
String rules = getConfig().getPrologRules();
|
||||
if (rules != null) {
|
||||
PushbackReader in =
|
||||
new PushbackReader(new StringReader(rules), Prolog.PUSHBACK_SIZE);
|
||||
JavaObjectTerm streamObject = new JavaObjectTerm(in);
|
||||
if (!env.execute(Prolog.BUILTIN, "consult_stream",
|
||||
SymbolTerm.makeSymbol("rules.pl"), streamObject)) {
|
||||
throw new CompileException("Cannot consult rules.pl " +
|
||||
getProject().getName() + " " + getConfig().getRevision());
|
||||
}
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
|
||||
Reference in New Issue
Block a user