Change to use Path instead of File for @SitePath annotation Bug: Issue 3299 Change-Id: I5d5208c15e025c35d70358e47bd8d5c7a4139c45
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java index a28c98f..c7108d0 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/GerritHookFilterChangeState.java
@@ -14,6 +14,7 @@ package com.googlesource.gerrit.plugins.hooks.workflow; + import com.google.gerrit.server.config.SitePath; import com.google.gerrit.server.data.ApprovalAttribute; import com.google.gerrit.server.data.ChangeAttribute; @@ -36,6 +37,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -51,7 +53,7 @@ @Inject @SitePath - private File sitePath; + private Path sitePath; @Inject private IssueExtractor issueExtractor; @@ -151,7 +153,7 @@ } private List<Transition> loadTransitions() { - File configFile = new File(sitePath, "etc/issue-state-transition.config"); + File configFile = new File(sitePath.toFile(), "etc/issue-state-transition.config"); FileBasedConfig cfg = new FileBasedConfig(configFile, FS.DETECTED); try { cfg.load();
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/RuleBase.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/RuleBase.java index c6b669d..346946f 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/RuleBase.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/RuleBase.java
@@ -14,6 +14,7 @@ package com.googlesource.gerrit.plugins.hooks.workflow; + import com.google.common.collect.Lists; import com.google.gerrit.extensions.annotations.PluginName; import com.google.gerrit.server.config.SitePath; @@ -27,6 +28,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.Path; import java.util.Collection; /** @@ -56,7 +58,7 @@ */ private static final String ACTION_KEY = "action"; - private final File sitePath; + private final Path sitePath; private final Rule.Factory ruleFactory; private final Condition.Factory conditionFactory; private final ActionRequest.Factory actionRequestFactory; @@ -69,7 +71,7 @@ } @Inject - public RuleBase(@SitePath File sitePath, Rule.Factory ruleFactory, + public RuleBase(@SitePath Path sitePath, Rule.Factory ruleFactory, Condition.Factory conditionFactory, ActionRequest.Factory actionRequestFactory, @PluginName String pluginName) { @@ -135,7 +137,7 @@ // "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, "etc" + File.separatorChar + 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 " @@ -145,12 +147,12 @@ } // Add global rules - File globalRuleFile = new File(sitePath, ITS_CONFIG_FILE_START + + File globalRuleFile = new File(sitePath.toFile(), ITS_CONFIG_FILE_START + ITS_CONFIG_FILE_END); addRulesFromFile(globalRuleFile); // Add its-specific rules - File itsSpecificRuleFile = new File(sitePath, ITS_CONFIG_FILE_START + "-" + + File itsSpecificRuleFile = new File(sitePath.toFile(), ITS_CONFIG_FILE_START + "-" + pluginName + ITS_CONFIG_FILE_END); addRulesFromFile(itsSpecificRuleFile);
diff --git a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/action/AddVelocityComment.java b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/action/AddVelocityComment.java index 0a61316..7fce725 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/action/AddVelocityComment.java +++ b/src/main/java/com/googlesource/gerrit/plugins/hooks/workflow/action/AddVelocityComment.java
@@ -32,6 +32,7 @@ import java.io.File; import java.io.IOException; import java.io.StringWriter; +import java.nio.file.Path; import java.util.Arrays; import java.util.Set; @@ -56,11 +57,11 @@ "its" + File.separator + "templates"; private final ItsFacade its; - private final File sitePath; + private final Path sitePath; private final RuntimeInstance velocityRuntime; @Inject - public AddVelocityComment(RuntimeInstance velocityRuntime, @SitePath File sitePath, ItsFacade its) { + public AddVelocityComment(RuntimeInstance velocityRuntime, @SitePath Path sitePath, ItsFacade its) { this.velocityRuntime = velocityRuntime; this.sitePath = sitePath; this.its = its; @@ -104,7 +105,7 @@ if (templateName.isEmpty()) { log.error("No template name given in " + actionRequest); } else { - File templateFile = new File(sitePath, ITS_TEMPLATE_DIR + + File templateFile = new File(sitePath.toFile(), ITS_TEMPLATE_DIR + File.separator + templateName + ".vm"); if (templateFile.canRead()) { template = FileUtils.readAllText(templateFile);