Minor - create abstract SimpleAutoTask for simple tool tasks

This commit is contained in:
ljacqu 2016-10-23 13:14:06 +02:00
parent d09964f1cb
commit edf7c227b2
7 changed files with 27 additions and 52 deletions

View File

@ -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<String> 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);

View File

@ -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();

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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

View File

@ -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();
}
}