mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-20 23:57:34 +01:00
Minor - add JavaDoc to tools classes
This commit is contained in:
parent
23d6801baa
commit
0efb419149
@ -12,18 +12,24 @@ import java.util.Map;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point for tool tasks.
|
* Runner for executing tool tasks.
|
||||||
*/
|
*/
|
||||||
public class ToolsRunner {
|
public final class ToolsRunner {
|
||||||
|
|
||||||
private static final String DIR_SEPARATOR = File.separator;
|
private ToolsRunner() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entry point of the runner.
|
||||||
|
*
|
||||||
|
* @param args .
|
||||||
|
*/
|
||||||
public static void main(String... args) {
|
public static void main(String... args) {
|
||||||
// Collect tasks and show them
|
// Collect tasks and show them
|
||||||
File toolsFolder = new File(ToolsConstants.TOOLS_SOURCE_ROOT);
|
File toolsFolder = new File(ToolsConstants.TOOLS_SOURCE_ROOT);
|
||||||
Map<String, ToolTask> tasks = new HashMap<>();
|
Map<String, ToolTask> tasks = new HashMap<>();
|
||||||
collectTasksInDirectory(toolsFolder, tasks);
|
collectTasksInDirectory(toolsFolder, tasks);
|
||||||
showHelp(tasks);
|
listAllTasks(tasks);
|
||||||
|
|
||||||
// Prompt user for task and handle input
|
// Prompt user for task and handle input
|
||||||
System.out.println("Please enter the task to run:");
|
System.out.println("Please enter the task to run:");
|
||||||
@ -57,13 +63,19 @@ public class ToolsRunner {
|
|||||||
task.execute(inputOptions);
|
task.execute(inputOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showHelp(Map<String, ToolTask> taskCollection) {
|
private static void listAllTasks(Map<String, ToolTask> taskCollection) {
|
||||||
System.out.println("The following tasks are available:");
|
System.out.println("The following tasks are available:");
|
||||||
for (String key : taskCollection.keySet()) {
|
for (String key : taskCollection.keySet()) {
|
||||||
System.out.println("- " + key);
|
System.out.println("- " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add all implementations of {@link ToolTask} from the given folder to the provided collection.
|
||||||
|
*
|
||||||
|
* @param dir The directory to scan
|
||||||
|
* @param taskCollection The collection to add results to
|
||||||
|
*/
|
||||||
// Note ljacqu 20151212: If the tools folder becomes a lot bigger, it will make sense to restrict the depth
|
// Note ljacqu 20151212: If the tools folder becomes a lot bigger, it will make sense to restrict the depth
|
||||||
// of this recursive collector
|
// of this recursive collector
|
||||||
private static void collectTasksInDirectory(File dir, Map<String, ToolTask> taskCollection) {
|
private static void collectTasksInDirectory(File dir, Map<String, ToolTask> taskCollection) {
|
||||||
@ -84,10 +96,10 @@ public class ToolsRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@link ToolTask} instance from the given file.
|
* Return a {@link ToolTask} instance defined by the given source file.
|
||||||
*
|
*
|
||||||
* @param file The file to load
|
* @param file The file to load
|
||||||
* @return ToolTask instance or null if not applicable
|
* @return ToolTask instance, or null if not applicable
|
||||||
*/
|
*/
|
||||||
private static ToolTask getTaskFromFile(File file) {
|
private static ToolTask getTaskFromFile(File file) {
|
||||||
Class<? extends ToolTask> taskClass = loadTaskClassFromFile(file);
|
Class<? extends ToolTask> taskClass = loadTaskClassFromFile(file);
|
||||||
@ -105,7 +117,7 @@ public class ToolsRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the class the file defines if it implements a {@link ToolTask}.
|
* Return the class the file defines if it implements {@link ToolTask}.
|
||||||
*
|
*
|
||||||
* @return The class instance, or null if not applicable
|
* @return The class instance, or null if not applicable
|
||||||
*/
|
*/
|
||||||
@ -118,7 +130,7 @@ public class ToolsRunner {
|
|||||||
String filePath = file.getPath();
|
String filePath = file.getPath();
|
||||||
String className = filePath
|
String className = filePath
|
||||||
.substring(ToolsConstants.TOOLS_SOURCE_ROOT.length(), filePath.length() - 5)
|
.substring(ToolsConstants.TOOLS_SOURCE_ROOT.length(), filePath.length() - 5)
|
||||||
.replace(DIR_SEPARATOR, ".");
|
.replace(File.separator, ".");
|
||||||
try {
|
try {
|
||||||
Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(className);
|
Class<?> clazz = ClassLoader.getSystemClassLoader().loadClass(className);
|
||||||
return ToolTask.class.isAssignableFrom(clazz) && isInstantiable(clazz)
|
return ToolTask.class.isAssignableFrom(clazz) && isInstantiable(clazz)
|
||||||
|
@ -24,8 +24,11 @@ import static java.lang.String.format;
|
|||||||
*/
|
*/
|
||||||
public final class VerifyMessagesTask implements ToolTask {
|
public final class VerifyMessagesTask implements ToolTask {
|
||||||
|
|
||||||
|
/** The folder containing the message files. */
|
||||||
private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + "messages/";
|
private static final String MESSAGES_FOLDER = ToolsConstants.MAIN_RESOURCES_ROOT + "messages/";
|
||||||
|
/** Pattern of the message file names. */
|
||||||
private static final Pattern MESSAGE_FILE_PATTERN = Pattern.compile("messages_[a-z]{2,7}\\.yml");
|
private static final Pattern MESSAGE_FILE_PATTERN = Pattern.compile("messages_[a-z]{2,7}\\.yml");
|
||||||
|
/** Tag that is replaced to the messages folder in user input. */
|
||||||
private static final String SOURCES_TAG = "{msgdir}";
|
private static final String SOURCES_TAG = "{msgdir}";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -10,6 +10,14 @@ public class TaskOption {
|
|||||||
private final String defaultOption;
|
private final String defaultOption;
|
||||||
private final String[] options;
|
private final String[] options;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param name Name of the option (to refer to the option)
|
||||||
|
* @param description Description shown to the user when asked to set the option
|
||||||
|
* @param defaultOption The default option. Can be null to force a value from options.
|
||||||
|
* @param options Collection of possible options. Can be null to allow any input.
|
||||||
|
*/
|
||||||
public TaskOption(String name, String description, String defaultOption, String... options) {
|
public TaskOption(String name, String description, String defaultOption, String... options) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
Loading…
Reference in New Issue
Block a user