#989 Create configuration docs page
- Create tool task to generate a doc page with the generated config.yml - Rename tools.utils.FileUtils to FileIoUtils to avoid naming conflict with fr.xephi.authme.utils.FileUtils - Make all doc tasks output a success message at the end - Update all docs pages that have changed
This commit is contained in:
@@ -6,7 +6,7 @@ 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.FileIoUtils;
|
||||
import tools.utils.TagValue.NestedTagValue;
|
||||
import tools.utils.TagValueHolder;
|
||||
import tools.utils.ToolsConstants;
|
||||
@@ -29,7 +29,7 @@ public class CommandPageCreater implements AutoToolTask {
|
||||
NestedTagValue commandTags = new NestedTagValue();
|
||||
addCommandsInfo(commandTags, baseCommands);
|
||||
|
||||
FileUtils.generateFileFromTemplate(
|
||||
FileIoUtils.generateFileFromTemplate(
|
||||
ToolsConstants.TOOLS_SOURCE_ROOT + "docs/commands/commands.tpl.md",
|
||||
OUTPUT_FILE,
|
||||
TagValueHolder.create().put("commands", commandTags));
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package tools.docs.config;
|
||||
|
||||
import com.github.authme.configme.SettingsManager;
|
||||
import com.github.authme.configme.resource.YamlFileResource;
|
||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import tools.utils.AutoToolTask;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.TagValueHolder;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Task for updating the config docs page.
|
||||
*/
|
||||
public class UpdateConfigPageTask implements AutoToolTask {
|
||||
|
||||
private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/config/config.tpl.md";
|
||||
private static final String OUTPUT_FILE = ToolsConstants.DOCS_FOLDER + "config.md";
|
||||
|
||||
@Override
|
||||
public String getTaskName() {
|
||||
return "updateConfigPage";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeDefault() {
|
||||
File config = null;
|
||||
try {
|
||||
// Create empty temporary .yml file and save the config to it
|
||||
config = File.createTempFile("authme-config-", ".yml");
|
||||
SettingsManager settingsManager = new SettingsManager(
|
||||
new YamlFileResource(config), null, AuthMeSettingsRetriever.buildConfigurationData());
|
||||
settingsManager.save();
|
||||
|
||||
// Get the contents and generate template file
|
||||
TagValueHolder tagValueHolder = TagValueHolder.create()
|
||||
.put("config", FileIoUtils.readFromFile(config.toPath()));
|
||||
FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, OUTPUT_FILE, tagValueHolder);
|
||||
System.out.println("Wrote to '" + OUTPUT_FILE + "'");
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
} finally {
|
||||
FileUtils.delete(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<!-- {gen_warning} -->
|
||||
<!-- File auto-generated on {gen_date}. See docs/config/config.tpl.md -->
|
||||
|
||||
## AuthMe Configuration
|
||||
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
||||
with which you can configure various settings. This following is the initial contents of
|
||||
the generated config.yml file.
|
||||
|
||||
```yml
|
||||
{config}
|
||||
```
|
||||
|
||||
To change settings on a running server, save your changes to config.yml and use
|
||||
`/authme reload`.
|
||||
|
||||
{gen_footer}
|
||||
@@ -2,7 +2,7 @@ package tools.docs.hashmethods;
|
||||
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import tools.utils.AutoToolTask;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.TagValue.NestedTagValue;
|
||||
import tools.utils.TagValueHolder;
|
||||
import tools.utils.ToolsConstants;
|
||||
@@ -28,7 +28,8 @@ public class HashAlgorithmsDescriptionTask implements AutoToolTask {
|
||||
|
||||
// Write to the docs file
|
||||
TagValueHolder tags = TagValueHolder.create().put("algorithms", methodRows);
|
||||
FileUtils.generateFileFromTemplate(CUR_FOLDER + "hash_algorithms.tpl.md", OUTPUT_FILE, tags);
|
||||
FileIoUtils.generateFileFromTemplate(CUR_FOLDER + "hash_algorithms.tpl.md", OUTPUT_FILE, tags);
|
||||
System.out.println("Wrote to '" + OUTPUT_FILE + "'");
|
||||
}
|
||||
|
||||
private static NestedTagValue constructMethodRows(Map<HashAlgorithm, MethodDescription> descriptions) {
|
||||
|
||||
@@ -2,7 +2,7 @@ package tools.docs.permissions;
|
||||
|
||||
import fr.xephi.authme.ClassCollector;
|
||||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
import java.util.EnumSet;
|
||||
@@ -103,7 +103,7 @@ public class PermissionNodesGatherer {
|
||||
*/
|
||||
private static <T extends Enum<T> & PermissionNode> String getSourceForClass(Class<T> clazz) {
|
||||
String classFile = ToolsConstants.MAIN_SOURCE_ROOT + clazz.getName().replace(".", "/") + ".java";
|
||||
return FileUtils.readFromFile(classFile);
|
||||
return FileIoUtils.readFromFile(classFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package tools.docs.permissions;
|
||||
|
||||
import tools.utils.AutoToolTask;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.TagValue.NestedTagValue;
|
||||
import tools.utils.TagValueHolder;
|
||||
import tools.utils.ToolsConstants;
|
||||
@@ -27,9 +27,8 @@ public class PermissionsListWriter implements AutoToolTask {
|
||||
final NestedTagValue permissionsTagValue = generatePermissionsList();
|
||||
|
||||
TagValueHolder tags = TagValueHolder.create().put("nodes", permissionsTagValue);
|
||||
FileUtils.generateFileFromTemplate(TEMPLATE_FILE, PERMISSIONS_OUTPUT_FILE, tags);
|
||||
FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, PERMISSIONS_OUTPUT_FILE, tags);
|
||||
System.out.println("Wrote to '" + PERMISSIONS_OUTPUT_FILE + "'");
|
||||
System.out.println("Before committing, please verify the output!");
|
||||
}
|
||||
|
||||
private static NestedTagValue generatePermissionsList() {
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.FileIoUtils;
|
||||
import tools.utils.TagValue.NestedTagValue;
|
||||
import tools.utils.TagValueHolder;
|
||||
import tools.utils.ToolsConstants;
|
||||
@@ -57,7 +57,8 @@ public class TranslationPageGenerator implements AutoToolTask {
|
||||
}
|
||||
|
||||
TagValueHolder tags = TagValueHolder.create().put("languages", translationValuesHolder);
|
||||
FileUtils.generateFileFromTemplate(TEMPLATE_FILE, DOCS_PAGE, tags);
|
||||
FileIoUtils.generateFileFromTemplate(TEMPLATE_FILE, DOCS_PAGE, tags);
|
||||
System.out.println("Wrote to '" + DOCS_PAGE + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,7 @@ 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.FileIoUtils;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
import java.io.StringReader;
|
||||
@@ -46,7 +46,7 @@ public class GeneratePluginYml implements AutoToolTask {
|
||||
configuration.set("commands", generateCommands());
|
||||
configuration.set("permissions", generatePermissions());
|
||||
|
||||
FileUtils.writeToFile(PLUGIN_YML_FILE,
|
||||
FileIoUtils.writeToFile(PLUGIN_YML_FILE,
|
||||
pluginYmlStart + "\n" + configuration.saveToString());
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class GeneratePluginYml implements AutoToolTask {
|
||||
* @return file configuration with the lower part of the plugin.yml file
|
||||
*/
|
||||
private FileConfiguration loadPartialPluginYmlFile() {
|
||||
List<String> pluginYmlLines = FileUtils.readLinesFromFile(Paths.get(PLUGIN_YML_FILE));
|
||||
List<String> pluginYmlLines = FileIoUtils.readLinesFromFile(Paths.get(PLUGIN_YML_FILE));
|
||||
int lineNr = 0;
|
||||
for (String line : pluginYmlLines) {
|
||||
if (line.equals("commands:")) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.google.common.collect.Multimap;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@@ -104,7 +104,7 @@ public class MessageFileVerifier {
|
||||
* @param defaultMessages The collection of default messages
|
||||
*/
|
||||
public void addMissingKeys(FileConfiguration defaultMessages) {
|
||||
final List<String> fileLines = FileUtils.readLinesFromFile(messagesFile.toPath());
|
||||
final List<String> fileLines = FileIoUtils.readLinesFromFile(messagesFile.toPath());
|
||||
|
||||
List<MissingKey> keysToAdd = new ArrayList<>();
|
||||
for (MissingKey entry : missingKeys) {
|
||||
@@ -135,7 +135,7 @@ public class MessageFileVerifier {
|
||||
addCommentForMissingTags(fileLines, key, entry.getValue());
|
||||
}
|
||||
|
||||
FileUtils.writeToFile(messagesFile.toPath(), String.join("\n", fileLines));
|
||||
FileIoUtils.writeToFile(messagesFile.toPath(), String.join("\n", fileLines));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import tools.messages.MessageFileVerifier;
|
||||
import tools.messages.VerifyMessagesTask;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.ToolTask;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
@@ -108,9 +108,9 @@ public class ImportMessagesTask implements ToolTask {
|
||||
* @param file The file whose to-do comments should be removed
|
||||
*/
|
||||
private static void removeAllTodoComments(String file) {
|
||||
String contents = FileUtils.readFromFile(file);
|
||||
String contents = FileIoUtils.readFromFile(file);
|
||||
String regex = "^# TODO .*$";
|
||||
contents = Pattern.compile(regex, Pattern.MULTILINE).matcher(contents).replaceAll("");
|
||||
FileUtils.writeToFile(file, contents);
|
||||
FileIoUtils.writeToFile(file, contents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package tools.messages.translation;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import tools.utils.FileUtils;
|
||||
import tools.utils.FileIoUtils;
|
||||
import tools.utils.ToolsConstants;
|
||||
|
||||
import java.io.File;
|
||||
@@ -31,7 +31,7 @@ public class WriteAllExportsTask extends ExportMessagesTask {
|
||||
for (File file : messageFiles) {
|
||||
String code = file.getName().substring("messages_".length(), file.getName().length() - ".yml".length());
|
||||
String json = convertToJson(code, defaultMessages, YamlConfiguration.loadConfiguration(file));
|
||||
FileUtils.writeToFile(OUTPUT_FOLDER + "messages_" + code + ".json", json);
|
||||
FileIoUtils.writeToFile(OUTPUT_FOLDER + "messages_" + code + ".json", json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -9,11 +9,11 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Utility class for reading from and writing to files.
|
||||
* Utility class for I/O operations on files.
|
||||
*/
|
||||
public final class FileUtils {
|
||||
public final class FileIoUtils {
|
||||
|
||||
private FileUtils() {
|
||||
private FileIoUtils() {
|
||||
}
|
||||
|
||||
public static void generateFileFromTemplate(String templateFile, String destinationFile, TagValueHolder tags) {
|
||||
@@ -43,8 +43,12 @@ public final class FileUtils {
|
||||
}
|
||||
|
||||
public static String readFromFile(String file) {
|
||||
return readFromFile(Paths.get(file));
|
||||
}
|
||||
|
||||
public static String readFromFile(Path file) {
|
||||
try {
|
||||
return new String(Files.readAllBytes(Paths.get(file)), StandardCharsets.UTF_8);
|
||||
return new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
throw new UnsupportedOperationException("Could not read from file '" + file + "'", e);
|
||||
}
|
||||
Reference in New Issue
Block a user