Minor maintenance on ToolTask classes

- Use default method on AutoToolTask interface in favor of abstract SimpleAutoTask class
- Adjust the path in various .tpl.md files
- Remove unused constant in ToolsConstants
This commit is contained in:
ljacqu 2016-10-23 18:17:09 +02:00
parent 8f6643207e
commit 9d21a4cda2
14 changed files with 37 additions and 55 deletions

View File

@ -4,8 +4,8 @@ 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;
@ -19,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 extends SimpleAutoTask {
public class CheckTestMocks implements AutoToolTask {
private List<String> errors = new ArrayList<>();

View File

@ -1,26 +1,20 @@
package tools.docs;
import com.google.common.collect.ImmutableSet;
import tools.docs.commands.CommandPageCreater;
import tools.docs.hashmethods.HashAlgorithmsDescriptionTask;
import tools.docs.permissions.PermissionsListWriter;
import tools.docs.translations.TranslationPageGenerator;
import fr.xephi.authme.ClassCollector;
import fr.xephi.authme.TestHelper;
import tools.utils.AutoToolTask;
import tools.utils.ToolTask;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
/**
* Task that runs all tasks which update files in the docs folder.
*/
public class UpdateDocsTask implements AutoToolTask {
private static final Set<Class<? extends ToolTask>> TASKS = ImmutableSet
.of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class,
PermissionsListWriter.class, TranslationPageGenerator.class);
@Override
public String getTaskName() {
return "updateDocs";
@ -40,19 +34,18 @@ public class UpdateDocsTask implements AutoToolTask {
});
}
private static ToolTask instantiateTask(Class<? extends ToolTask> clazz) {
try {
return clazz.newInstance();
} catch (IllegalAccessException | InstantiationException e) {
throw new UnsupportedOperationException("Could not instantiate task class '" + clazz + "'", e);
}
}
private static void executeTasks(Consumer<ToolTask> taskRunner) {
for (Class<? extends ToolTask> taskClass : TASKS) {
ToolTask task = instantiateTask(taskClass);
private void executeTasks(Consumer<ToolTask> taskRunner) {
for (ToolTask task : getDocTasks()) {
System.out.println("\nRunning " + task.getTaskName() + "\n-------------------");
taskRunner.accept(task);
}
}
private List<ToolTask> getDocTasks() {
ClassCollector classCollector =
new ClassCollector(TestHelper.TEST_SOURCES_FOLDER, "tools/docs");
return classCollector.getInstancesOfType(ToolTask.class).stream()
.filter(task -> task.getClass() != getClass())
.collect(Collectors.toList());
}
}

View File

@ -5,15 +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;
public class CommandPageCreater extends SimpleAutoTask {
public class CommandPageCreater implements AutoToolTask {
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "commands.md";

View File

@ -1,5 +1,5 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See commands/commands.tpl.md -->
<!-- File auto-generated on {gen_date}. See docs/commands/commands.tpl.md -->
## AuthMe Commands
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`

View File

@ -1,8 +1,8 @@
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;
@ -14,7 +14,7 @@ import java.util.Map;
*
* @see fr.xephi.authme.security.HashAlgorithm
*/
public class HashAlgorithmsDescriptionTask extends SimpleAutoTask {
public class HashAlgorithmsDescriptionTask implements AutoToolTask {
private static final String CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/hashmethods/";
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md";

View File

@ -1,5 +1,5 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See hashmethods/hash_algorithms.tpl.md -->
<!-- File auto-generated on {gen_date}. See docs/hashmethods/hash_algorithms.tpl.md -->
## Hash Algorithms
AuthMe supports the following hash algorithms for storing your passwords safely.

View File

@ -1,7 +1,7 @@
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;
@ -12,7 +12,7 @@ import java.util.Map;
* Task responsible for formatting a permissions node list and
* for writing it to a file if desired.
*/
public class PermissionsListWriter extends SimpleAutoTask {
public class PermissionsListWriter implements AutoToolTask {
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";

View File

@ -1,5 +1,5 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See permissions/permission_nodes.tpl.md -->
<!-- File auto-generated on {gen_date}. See docs/permissions/permission_nodes.tpl.md -->
## AuthMe Permission Nodes
The following are the permission nodes that are currently supported by the latest dev builds.

View File

@ -2,8 +2,8 @@ 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;
@ -17,7 +17,7 @@ import static com.google.common.base.Objects.firstNonNull;
/**
* Generates the translations page in docs.
*/
public class TranslationPageGenerator extends SimpleAutoTask {
public class TranslationPageGenerator implements AutoToolTask {
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";

View File

@ -1,5 +1,5 @@
<!-- {gen_warning} -->
<!-- File auto-generated on {gen_date}. See translations/translations.tpl.md -->
<!-- File auto-generated on {gen_date}. See docs/translations/translations.tpl.md -->
# AuthMe Translations
The following translations are available in AuthMe. Set `messagesLanguage` to the language code

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;
@ -26,7 +26,7 @@ import java.util.stream.Collectors;
/**
* Generates the command and permission section of plugin.yml.
*/
public class GeneratePluginYml extends SimpleAutoTask {
public class GeneratePluginYml implements AutoToolTask {
private static final String PLUGIN_YML_FILE = ToolsConstants.MAIN_RESOURCES_ROOT + "plugin.yml";

View File

@ -1,5 +1,7 @@
package tools.utils;
import java.util.Scanner;
/**
* Interface for tasks that can be run automatically, i.e. without any user input.
*/
@ -10,4 +12,9 @@ public interface AutoToolTask extends ToolTask {
*/
void executeDefault();
@Override
default void execute(Scanner scanner) {
executeDefault();
}
}

View File

@ -1,15 +0,0 @@
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();
}
}

View File

@ -9,9 +9,6 @@ public final class ToolsConstants {
public static final String MAIN_RESOURCES_ROOT = "src/main/resources/";
// Add specific `fr.xephi.authme` package as not to include the tool tasks in the `tools` package
public static final String TEST_SOURCE_ROOT = "src/test/java/fr/xephi/authme";
public static final String TOOLS_SOURCE_ROOT = "src/test/java/tools/";
public static final String DOCS_FOLDER = "docs/";