diff --git a/src/tools/ToolsRunner.java b/src/tools/ToolsRunner.java index a0589f1b..04093bd1 100644 --- a/src/tools/ToolsRunner.java +++ b/src/tools/ToolsRunner.java @@ -12,18 +12,24 @@ import java.util.Map; 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) { // Collect tasks and show them File toolsFolder = new File(ToolsConstants.TOOLS_SOURCE_ROOT); Map tasks = new HashMap<>(); collectTasksInDirectory(toolsFolder, tasks); - showHelp(tasks); + listAllTasks(tasks); // Prompt user for task and handle input System.out.println("Please enter the task to run:"); @@ -57,13 +63,19 @@ public class ToolsRunner { task.execute(inputOptions); } - private static void showHelp(Map taskCollection) { + private static void listAllTasks(Map taskCollection) { System.out.println("The following tasks are available:"); for (String key : taskCollection.keySet()) { 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 // of this recursive collector private static void collectTasksInDirectory(File dir, Map 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 - * @return ToolTask instance or null if not applicable + * @return ToolTask instance, or null if not applicable */ private static ToolTask getTaskFromFile(File file) { Class 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 */ @@ -118,7 +130,7 @@ public class ToolsRunner { String filePath = file.getPath(); String className = filePath .substring(ToolsConstants.TOOLS_SOURCE_ROOT.length(), filePath.length() - 5) - .replace(DIR_SEPARATOR, "."); + .replace(File.separator, "."); try { Class clazz = ClassLoader.getSystemClassLoader().loadClass(className); return ToolTask.class.isAssignableFrom(clazz) && isInstantiable(clazz) diff --git a/src/tools/messages/VerifyMessagesTask.java b/src/tools/messages/VerifyMessagesTask.java index f0fe3533..cb1d3f45 100644 --- a/src/tools/messages/VerifyMessagesTask.java +++ b/src/tools/messages/VerifyMessagesTask.java @@ -24,8 +24,11 @@ import static java.lang.String.format; */ public final class VerifyMessagesTask implements ToolTask { + /** The folder containing the message files. */ 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"); + /** Tag that is replaced to the messages folder in user input. */ private static final String SOURCES_TAG = "{msgdir}"; @Override diff --git a/src/tools/utils/TaskOption.java b/src/tools/utils/TaskOption.java index ad5acdd6..f4d32efa 100644 --- a/src/tools/utils/TaskOption.java +++ b/src/tools/utils/TaskOption.java @@ -10,6 +10,14 @@ public class TaskOption { private final String defaultOption; 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) { this.name = name; this.description = description;