RuleBase: Remove reading from deprecated config file
Reading from 'action.config' file has been deprecated for about 3 and a
half years.
Change-Id: I516a12d5267febb3f5bde5133e55a03ed412ac3b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
index 1cd2b74..9fb2b3d 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/its/InitIts.java
@@ -21,7 +21,10 @@
import com.google.gerrit.pgm.init.api.ConsoleUI;
import com.google.gerrit.pgm.init.api.InitStep;
import com.google.gerrit.pgm.init.api.Section;
+import com.google.gerrit.server.config.SitePaths;
+import com.google.inject.Inject;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.EnumSet;
import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.Config;
@@ -41,6 +44,8 @@
ENFORCED
}
+ @Inject private SitePaths sitePaths;
+
private final String pluginName;
private final String itsDisplayName;
protected final ConsoleUI ui;
@@ -61,7 +66,18 @@
}
@Override
- public void run() throws IOException, ConfigInvalidException {}
+ public void run() throws IOException, ConfigInvalidException {
+ Path deprecatedRules = sitePaths.etc_dir.normalize().resolve("its").resolve("action.config");
+ if (deprecatedRules.toFile().exists()) {
+ ui.error(
+ "Deprecated rules file '%s' (No trailing 's' in 'action') will not be read. "
+ + "Please migrate to 'etc/its/actions.config' (Trailing 's' in 'actions') and retry "
+ + "the init step.\n",
+ deprecatedRules);
+ throw new ConfigInvalidException(
+ "Deprecated configuration file found: " + deprecatedRules.toRealPath());
+ }
+ }
@Override
public void postRun() throws IOException, ConfigInvalidException {
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
index cd9c2b9..ee0c568 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBase.java
@@ -116,26 +116,6 @@
private void reloadRules() {
rules = Lists.newArrayList();
- // Add rules from file with typo in filename
- //
- // While the documentation called for "actions.config" (Trailing "s" in
- // "actions"), the code previously only loaded "action.config" (No
- // trailing "s" in "action"). To give users time to gracefully migrate to
- // "actions.config" (with trailing "s", we (for now) load files from both
- // locations, but consider "actions.config" (with trailing "s" the
- // canonical place.
- File faultyNameRuleFile =
- new File(
- sitePath.toFile(),
- "etc" + File.separatorChar + "its" + File.separator + "action.config");
- if (faultyNameRuleFile.exists()) {
- log.warn(
- "Loading rules from deprecated 'etc/its/action.config' (No "
- + "trailing 's' in 'action'). Please migrate to "
- + "'etc/its/actions.config' (Trailing 's' in 'actions').");
- addRulesFromFile(faultyNameRuleFile);
- }
-
// Add global rules
File globalRuleFile = new File(sitePath.toFile(), ITS_CONFIG_FILE_START + ITS_CONFIG_FILE_END);
addRulesFromFile(globalRuleFile);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
index 80e12fb..371b9d5 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/workflow/RuleBaseTest.java
@@ -48,7 +48,6 @@
private enum RuleBaseKind {
GLOBAL,
ITS,
- FAULTY
}
public void testWarnNonExistingRuleBase() {
@@ -221,41 +220,6 @@
assertEquals("Matched actionRequests do not match", expected, actual);
}
- public void testWarnExistingFaultyNameRuleBaseFile() throws IOException {
- injectRuleBase("", RuleBaseKind.FAULTY);
-
- replayMocks();
-
- createRuleBase();
-
- assertLogMessageContains("Please migrate"); // Migration warning for old name
- assertLogMessageContains("Neither global"); // For rule file at at usual places
- }
-
- public void testSimpleFaultyNameRuleBase() throws IOException {
- injectRuleBase(
- "[rule \"rule1\"]\n" + "\tconditionA = value1\n" + "\taction = action1",
- RuleBaseKind.FAULTY);
-
- Rule rule1 = createMock(Rule.class);
- expect(ruleFactory.create("rule1")).andReturn(rule1);
-
- Condition condition1 = createMock(Condition.class);
- expect(conditionFactory.create("conditionA", "value1")).andReturn(condition1);
- rule1.addCondition(condition1);
-
- ActionRequest actionRequest1 = createMock(ActionRequest.class);
- expect(actionRequestFactory.create("action1")).andReturn(actionRequest1);
- rule1.addActionRequest(actionRequest1);
-
- replayMocks();
-
- createRuleBase();
-
- assertLogMessageContains("Please migrate"); // Migration warning for old name
- assertLogMessageContains("Neither global"); // For rule file at at usual places
- }
-
public void testSimpleItsRuleBase() throws IOException {
injectRuleBase(
"[rule \"rule1\"]\n" + "\tconditionA = value1\n" + "\taction = action1", RuleBaseKind.ITS);
@@ -277,25 +241,12 @@
}
public void testAllRuleBaseFilesAreLoaded() throws IOException {
- injectRuleBase("[rule \"rule1\"]\n" + "\taction = action1", RuleBaseKind.FAULTY);
-
injectRuleBase("[rule \"rule2\"]\n" + "\taction = action2", RuleBaseKind.GLOBAL);
injectRuleBase("[rule \"rule3\"]\n" + "\taction = action3", RuleBaseKind.ITS);
Collection<Property> properties = Collections.emptySet();
- Rule rule1 = createMock(Rule.class);
- expect(ruleFactory.create("rule1")).andReturn(rule1);
-
- ActionRequest actionRequest1 = createMock(ActionRequest.class);
- expect(actionRequestFactory.create("action1")).andReturn(actionRequest1);
- rule1.addActionRequest(actionRequest1);
-
- List<ActionRequest> rule1Match = Lists.newArrayListWithCapacity(1);
- rule1Match.add(actionRequest1);
- expect(rule1.actionRequestsFor(properties)).andReturn(rule1Match);
-
Rule rule2 = createMock(Rule.class);
expect(ruleFactory.create("rule2")).andReturn(rule2);
@@ -325,13 +276,10 @@
Collection<ActionRequest> actual = ruleBase.actionRequestsFor(properties);
List<ActionRequest> expected = Lists.newArrayListWithCapacity(3);
- expected.add(actionRequest1);
expected.add(actionRequest2);
expected.add(actionRequest3);
assertEquals("Matched actionRequests do not match", expected, actual);
-
- assertLogMessageContains("Please migrate"); // Migration warning for old name
}
private RuleBase createRuleBase() {
@@ -351,9 +299,6 @@
case ITS:
baseName = "actions-ItsTestName";
break;
- case FAULTY:
- baseName = "action";
- break;
default:
fail("Unknown ruleBaseKind");
}