mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-23 09:08:15 +01:00
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:
parent
8f6643207e
commit
9d21a4cda2
@ -4,8 +4,8 @@ import com.google.common.collect.Sets;
|
|||||||
import fr.xephi.authme.ClassCollector;
|
import fr.xephi.authme.ClassCollector;
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.InjectorUtils;
|
import tools.utils.InjectorUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -19,7 +19,7 @@ import java.util.stream.Collectors;
|
|||||||
* Task checking if all tests' {@code @Mock} fields have a corresponding
|
* Task checking if all tests' {@code @Mock} fields have a corresponding
|
||||||
* {@code @Inject} field in the class they are testing.
|
* {@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<>();
|
private List<String> errors = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
package tools.docs;
|
package tools.docs;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
import fr.xephi.authme.ClassCollector;
|
||||||
import tools.docs.commands.CommandPageCreater;
|
import fr.xephi.authme.TestHelper;
|
||||||
import tools.docs.hashmethods.HashAlgorithmsDescriptionTask;
|
|
||||||
import tools.docs.permissions.PermissionsListWriter;
|
|
||||||
import tools.docs.translations.TranslationPageGenerator;
|
|
||||||
import tools.utils.AutoToolTask;
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.ToolTask;
|
import tools.utils.ToolTask;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task that runs all tasks which update files in the docs folder.
|
* Task that runs all tasks which update files in the docs folder.
|
||||||
*/
|
*/
|
||||||
public class UpdateDocsTask implements AutoToolTask {
|
public class UpdateDocsTask implements AutoToolTask {
|
||||||
|
|
||||||
private static final Set<Class<? extends ToolTask>> TASKS = ImmutableSet
|
|
||||||
.of(CommandPageCreater.class, HashAlgorithmsDescriptionTask.class,
|
|
||||||
PermissionsListWriter.class, TranslationPageGenerator.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTaskName() {
|
public String getTaskName() {
|
||||||
return "updateDocs";
|
return "updateDocs";
|
||||||
@ -40,19 +34,18 @@ public class UpdateDocsTask implements AutoToolTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ToolTask instantiateTask(Class<? extends ToolTask> clazz) {
|
private void executeTasks(Consumer<ToolTask> taskRunner) {
|
||||||
try {
|
for (ToolTask task : getDocTasks()) {
|
||||||
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);
|
|
||||||
System.out.println("\nRunning " + task.getTaskName() + "\n-------------------");
|
System.out.println("\nRunning " + task.getTaskName() + "\n-------------------");
|
||||||
taskRunner.accept(task);
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,15 @@ import fr.xephi.authme.command.CommandDescription;
|
|||||||
import fr.xephi.authme.command.CommandInitializer;
|
import fr.xephi.authme.command.CommandInitializer;
|
||||||
import fr.xephi.authme.command.CommandUtils;
|
import fr.xephi.authme.command.CommandUtils;
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileUtils;
|
import tools.utils.FileUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
import tools.utils.TagValue.NestedTagValue;
|
import tools.utils.TagValue.NestedTagValue;
|
||||||
import tools.utils.TagValueHolder;
|
import tools.utils.TagValueHolder;
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
|
|
||||||
import java.util.Collection;
|
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";
|
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "commands.md";
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!-- {gen_warning} -->
|
<!-- {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
|
## AuthMe Commands
|
||||||
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
|
You can use the following commands to use the features of AuthMe. Mandatory arguments are marked with `< >`
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package tools.docs.hashmethods;
|
package tools.docs.hashmethods;
|
||||||
|
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileUtils;
|
import tools.utils.FileUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
import tools.utils.TagValue.NestedTagValue;
|
import tools.utils.TagValue.NestedTagValue;
|
||||||
import tools.utils.TagValueHolder;
|
import tools.utils.TagValueHolder;
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
@ -14,7 +14,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @see fr.xephi.authme.security.HashAlgorithm
|
* @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 CUR_FOLDER = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/hashmethods/";
|
||||||
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md";
|
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "hash_algorithms.md";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!-- {gen_warning} -->
|
<!-- {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
|
## Hash Algorithms
|
||||||
AuthMe supports the following hash algorithms for storing your passwords safely.
|
AuthMe supports the following hash algorithms for storing your passwords safely.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package tools.docs.permissions;
|
package tools.docs.permissions;
|
||||||
|
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileUtils;
|
import tools.utils.FileUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
import tools.utils.TagValue.NestedTagValue;
|
import tools.utils.TagValue.NestedTagValue;
|
||||||
import tools.utils.TagValueHolder;
|
import tools.utils.TagValueHolder;
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
@ -12,7 +12,7 @@ import java.util.Map;
|
|||||||
* Task responsible for formatting a permissions node list and
|
* Task responsible for formatting a permissions node list and
|
||||||
* for writing it to a file if desired.
|
* 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 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";
|
private static final String PERMISSIONS_OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "permission_nodes.md";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!-- {gen_warning} -->
|
<!-- {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
|
## AuthMe Permission Nodes
|
||||||
The following are the permission nodes that are currently supported by the latest dev builds.
|
The following are the permission nodes that are currently supported by the latest dev builds.
|
||||||
|
@ -2,8 +2,8 @@ package tools.docs.translations;
|
|||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import tools.docs.translations.TranslationsGatherer.TranslationInfo;
|
import tools.docs.translations.TranslationsGatherer.TranslationInfo;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileUtils;
|
import tools.utils.FileUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
import tools.utils.TagValue.NestedTagValue;
|
import tools.utils.TagValue.NestedTagValue;
|
||||||
import tools.utils.TagValueHolder;
|
import tools.utils.TagValueHolder;
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
@ -17,7 +17,7 @@ import static com.google.common.base.Objects.firstNonNull;
|
|||||||
/**
|
/**
|
||||||
* Generates the translations page in docs.
|
* 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 DOCS_PAGE = ToolsConstants.DOCS_FOLDER + "translations.md";
|
||||||
private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md";
|
private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<!-- {gen_warning} -->
|
<!-- {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
|
# AuthMe Translations
|
||||||
The following translations are available in AuthMe. Set `messagesLanguage` to the language code
|
The following translations are available in AuthMe. Set `messagesLanguage` to the language code
|
||||||
|
@ -9,8 +9,8 @@ import fr.xephi.authme.permission.PermissionNode;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import tools.docs.permissions.PermissionNodesGatherer;
|
import tools.docs.permissions.PermissionNodesGatherer;
|
||||||
|
import tools.utils.AutoToolTask;
|
||||||
import tools.utils.FileUtils;
|
import tools.utils.FileUtils;
|
||||||
import tools.utils.SimpleAutoTask;
|
|
||||||
import tools.utils.ToolsConstants;
|
import tools.utils.ToolsConstants;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
@ -26,7 +26,7 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* Generates the command and permission section of plugin.yml.
|
* 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";
|
private static final String PLUGIN_YML_FILE = ToolsConstants.MAIN_RESOURCES_ROOT + "plugin.yml";
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package tools.utils;
|
package tools.utils;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for tasks that can be run automatically, i.e. without any user input.
|
* 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();
|
void executeDefault();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void execute(Scanner scanner) {
|
||||||
|
executeDefault();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,9 +9,6 @@ public final class ToolsConstants {
|
|||||||
|
|
||||||
public static final String MAIN_RESOURCES_ROOT = "src/main/resources/";
|
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 TOOLS_SOURCE_ROOT = "src/test/java/tools/";
|
||||||
|
|
||||||
public static final String DOCS_FOLDER = "docs/";
|
public static final String DOCS_FOLDER = "docs/";
|
||||||
|
Loading…
Reference in New Issue
Block a user