From edf7c227b218458369c451132e3901e5e8d1ef52 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 23 Oct 2016 13:14:06 +0200 Subject: [PATCH] Minor - create abstract SimpleAutoTask for simple tool tasks --- .../java/tools/checktestmocks/CheckTestMocks.java | 10 ++-------- .../tools/docs/commands/CommandPageCreater.java | 10 ++-------- .../HashAlgorithmsDescriptionTask.java | 10 ++-------- .../docs/permissions/PermissionsListWriter.java | 14 ++------------ .../translations/TranslationPageGenerator.java | 10 ++-------- .../tools/filegeneration/GeneratePluginYml.java | 10 ++-------- src/test/java/tools/utils/SimpleAutoTask.java | 15 +++++++++++++++ 7 files changed, 27 insertions(+), 52 deletions(-) create mode 100644 src/test/java/tools/utils/SimpleAutoTask.java diff --git a/src/test/java/tools/checktestmocks/CheckTestMocks.java b/src/test/java/tools/checktestmocks/CheckTestMocks.java index def4e822f..1e8817aa2 100644 --- a/src/test/java/tools/checktestmocks/CheckTestMocks.java +++ b/src/test/java/tools/checktestmocks/CheckTestMocks.java @@ -4,15 +4,14 @@ import com.google.common.collect.Sets; import fr.xephi.authme.ClassCollector; import fr.xephi.authme.TestHelper; import org.mockito.Mock; -import tools.utils.AutoToolTask; import tools.utils.InjectorUtils; +import tools.utils.SimpleAutoTask; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Scanner; import java.util.Set; import java.util.stream.Collectors; @@ -20,7 +19,7 @@ import java.util.stream.Collectors; * Task checking if all tests' {@code @Mock} fields have a corresponding * {@code @Inject} field in the class they are testing. */ -public class CheckTestMocks implements AutoToolTask { +public class CheckTestMocks extends SimpleAutoTask { private List errors = new ArrayList<>(); @@ -29,11 +28,6 @@ public class CheckTestMocks implements AutoToolTask { return "checkTestMocks"; } - @Override - public void execute(Scanner scanner) { - executeDefault(); - } - @Override public void executeDefault() { ClassCollector collector = new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, TestHelper.PROJECT_ROOT); diff --git a/src/test/java/tools/docs/commands/CommandPageCreater.java b/src/test/java/tools/docs/commands/CommandPageCreater.java index b975c34f5..eab18256a 100644 --- a/src/test/java/tools/docs/commands/CommandPageCreater.java +++ b/src/test/java/tools/docs/commands/CommandPageCreater.java @@ -5,16 +5,15 @@ import fr.xephi.authme.command.CommandDescription; import fr.xephi.authme.command.CommandInitializer; import fr.xephi.authme.command.CommandUtils; import fr.xephi.authme.permission.PermissionNode; -import tools.utils.AutoToolTask; import tools.utils.FileUtils; +import tools.utils.SimpleAutoTask; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; import tools.utils.ToolsConstants; import java.util.Collection; -import java.util.Scanner; -public class CommandPageCreater implements AutoToolTask { +public class CommandPageCreater extends SimpleAutoTask { private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "commands.md"; @@ -23,11 +22,6 @@ public class CommandPageCreater implements AutoToolTask { return "createCommandPage"; } - @Override - public void execute(Scanner scanner) { - executeDefault(); - } - @Override public void executeDefault() { CommandInitializer commandInitializer = new CommandInitializer(); diff --git a/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java b/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java index 95da44d53..d6ba721cc 100644 --- a/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java +++ b/src/test/java/tools/docs/hashmethods/HashAlgorithmsDescriptionTask.java @@ -1,30 +1,24 @@ package tools.docs.hashmethods; import fr.xephi.authme.security.HashAlgorithm; -import tools.utils.AutoToolTask; import tools.utils.FileUtils; +import tools.utils.SimpleAutoTask; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; import tools.utils.ToolsConstants; import java.util.Map; -import java.util.Scanner; /** * Task for generating the markdown page describing the AuthMe hash algorithms. * * @see fr.xephi.authme.security.HashAlgorithm */ -public class HashAlgorithmsDescriptionTask implements AutoToolTask { +public class HashAlgorithmsDescriptionTask extends SimpleAutoTask { private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/hashmethods/"; private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md"; - @Override - public void execute(Scanner scanner) { - executeDefault(); - } - @Override public void executeDefault() { // Gather info and construct a row for each method diff --git a/src/test/java/tools/docs/permissions/PermissionsListWriter.java b/src/test/java/tools/docs/permissions/PermissionsListWriter.java index 6d1b48d74..ffd418e21 100644 --- a/src/test/java/tools/docs/permissions/PermissionsListWriter.java +++ b/src/test/java/tools/docs/permissions/PermissionsListWriter.java @@ -1,19 +1,18 @@ package tools.docs.permissions; -import tools.utils.AutoToolTask; import tools.utils.FileUtils; +import tools.utils.SimpleAutoTask; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; import tools.utils.ToolsConstants; import java.util.Map; -import java.util.Scanner; /** * Task responsible for formatting a permissions node list and * for writing it to a file if desired. */ -public class PermissionsListWriter implements AutoToolTask { +public class PermissionsListWriter extends SimpleAutoTask { private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/permissions/permission_nodes.tpl.md"; private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md"; @@ -23,17 +22,8 @@ public class PermissionsListWriter implements AutoToolTask { return "writePermissionsList"; } - @Override - public void execute(Scanner scanner) { - generateAndWriteFile(); - } - @Override public void executeDefault() { - generateAndWriteFile(); - } - - private static void generateAndWriteFile() { final NestedTagValue permissionsTagValue = generatePermissionsList(); TagValueHolder tags = TagValueHolder.create().put("nodes", permissionsTagValue); diff --git a/src/test/java/tools/docs/translations/TranslationPageGenerator.java b/src/test/java/tools/docs/translations/TranslationPageGenerator.java index e7785bd7a..80619ba56 100644 --- a/src/test/java/tools/docs/translations/TranslationPageGenerator.java +++ b/src/test/java/tools/docs/translations/TranslationPageGenerator.java @@ -2,15 +2,14 @@ package tools.docs.translations; import com.google.common.collect.ImmutableMap; import tools.docs.translations.TranslationsGatherer.TranslationInfo; -import tools.utils.AutoToolTask; import tools.utils.FileUtils; +import tools.utils.SimpleAutoTask; import tools.utils.TagValue.NestedTagValue; import tools.utils.TagValueHolder; import tools.utils.ToolsConstants; import java.util.Arrays; import java.util.Map; -import java.util.Scanner; import java.util.stream.Collectors; import static com.google.common.base.Objects.firstNonNull; @@ -18,7 +17,7 @@ import static com.google.common.base.Objects.firstNonNull; /** * Generates the translations page in docs. */ -public class TranslationPageGenerator implements AutoToolTask { +public class TranslationPageGenerator extends SimpleAutoTask { private static final String DOCS_PAGE = ToolsConstants.DOCS_FOLDER + "translations.md"; private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md"; @@ -42,11 +41,6 @@ public class TranslationPageGenerator implements AutoToolTask { return "updateTranslations"; } - @Override - public void execute(Scanner scanner) { - executeDefault(); - } - @Override public void executeDefault() { NestedTagValue translationValuesHolder = new NestedTagValue(); diff --git a/src/test/java/tools/filegeneration/GeneratePluginYml.java b/src/test/java/tools/filegeneration/GeneratePluginYml.java index c3d332f24..633c5aac8 100644 --- a/src/test/java/tools/filegeneration/GeneratePluginYml.java +++ b/src/test/java/tools/filegeneration/GeneratePluginYml.java @@ -9,8 +9,8 @@ import fr.xephi.authme.permission.PermissionNode; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import tools.docs.permissions.PermissionNodesGatherer; -import tools.utils.AutoToolTask; import tools.utils.FileUtils; +import tools.utils.SimpleAutoTask; import tools.utils.ToolsConstants; import java.io.StringReader; @@ -20,14 +20,13 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Scanner; import java.util.TreeMap; import java.util.stream.Collectors; /** * Generates the command and permission section of plugin.yml. */ -public class GeneratePluginYml implements AutoToolTask { +public class GeneratePluginYml extends SimpleAutoTask { private static final String PLUGIN_YML_FILE = ToolsConstants.MAIN_RESOURCES_ROOT + "plugin.yml"; @@ -56,11 +55,6 @@ public class GeneratePluginYml implements AutoToolTask { return "generatePluginYml"; } - @Override - public void execute(Scanner scanner) { - executeDefault(); - } - /** * Because some parts above the commands section have placeholders that aren't valid YAML, we need * to split the contents into an upper part that we ignore and a lower part we load as YAML. When diff --git a/src/test/java/tools/utils/SimpleAutoTask.java b/src/test/java/tools/utils/SimpleAutoTask.java new file mode 100644 index 000000000..4c0c936d0 --- /dev/null +++ b/src/test/java/tools/utils/SimpleAutoTask.java @@ -0,0 +1,15 @@ +package tools.utils; + +import java.util.Scanner; + +/** + * Abstract class for auto tool tasks that perform exactly the same action for + * {@link ToolTask#execute(Scanner)} and {@link AutoToolTask#executeDefault()}. + */ +public abstract class SimpleAutoTask implements AutoToolTask { + + @Override + public final void execute(Scanner scanner) { + executeDefault(); + } +}