Skip to content

Commit

Permalink
Added util to generate configs for wiki pages with comments.
Browse files Browse the repository at this point in the history
Added all generated files from generator utils to the .gitignore, so
they can safely be kept there. Also made the generator utils auto erase
files before starting, so they don't have issues with old files.
  • Loading branch information
me4502 committed Jan 12, 2014
1 parent e58f51e commit f5db25f
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 41 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -46,3 +46,9 @@ debug.log
# Doxygen
/docs/html
debug.txt

# Generated Files
/configs/
/ICList.txt
/config.yml
/en_US.yml
17 changes: 13 additions & 4 deletions src/utils/java/com/me4502/util/GenerateConfiguration.java
Expand Up @@ -12,10 +12,19 @@ public class GenerateConfiguration {

public static void main(String[] args) {

if(!new File("config.yml").exists()) try {
new File("config.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
if(!new File("config.yml").exists()) {
try {
new File("config.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
new File("config.yml").delete();
try {
new File("config.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
BukkitConfiguration config = new BukkitConfiguration(new YAMLProcessor(new File("config.yml"), true, YAMLFormat.EXTENDED), Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
config.load();
Expand Down
83 changes: 46 additions & 37 deletions src/utils/java/com/me4502/util/GenerateDefaultLanguage.java
@@ -1,37 +1,46 @@
package com.me4502.util;

import java.io.File;
import java.io.IOException;
import java.util.Map.Entry;

import com.sk89q.craftbook.common.LanguageManager;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;

public class GenerateDefaultLanguage {

public static void main(String[] args) {

if(!new File("en_US.yml").exists()) try {
new File("en_US.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
YAMLProcessor proc = new YAMLProcessor(new File("en_US.yml"), true, YAMLFormat.EXTENDED);
try {
proc.load();
} catch (IOException e) {
e.printStackTrace();
}

proc.setWriteDefaults(true);

new LanguageManager();

for(Entry<String, String> map : LanguageManager.defaultMessages.entrySet()) {
proc.getString(map.getKey(), map.getValue());
}

proc.save();
}
}
package com.me4502.util;

import java.io.File;
import java.io.IOException;
import java.util.Map.Entry;

import com.sk89q.craftbook.common.LanguageManager;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;

public class GenerateDefaultLanguage {

public static void main(String[] args) {

if(!new File("en_US.yml").exists()) {
try {
new File("en_US.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
new File("en_US.yml").delete();
try {
new File("en_US.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
YAMLProcessor proc = new YAMLProcessor(new File("en_US.yml"), true, YAMLFormat.EXTENDED);
try {
proc.load();
} catch (IOException e) {
e.printStackTrace();
}

proc.setWriteDefaults(true);

new LanguageManager();

for(Entry<String, String> map : LanguageManager.defaultMessages.entrySet()) {
proc.getString(map.getKey(), map.getValue());
}

proc.save();
}
}
92 changes: 92 additions & 0 deletions src/utils/java/com/me4502/util/GenerateWikiConfigLists.java
@@ -0,0 +1,92 @@
package com.me4502.util;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;
import java.util.logging.Logger;

import com.sk89q.craftbook.bukkit.BukkitConfiguration;
import com.sk89q.craftbook.util.RegexUtil;
import com.sk89q.util.yaml.YAMLFormat;
import com.sk89q.util.yaml.YAMLProcessor;

public class GenerateWikiConfigLists {

public static void main(String[] args) {

if(!new File("config.yml").exists()) {
try {
new File("config.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
} else {
new File("config.yml").delete();
try {
new File("config.yml").createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
BukkitConfiguration config = new BukkitConfiguration(new YAMLProcessor(new File("config.yml"), true, YAMLFormat.EXTENDED), Logger.getLogger(Logger.GLOBAL_LOGGER_NAME));
config.load();

File configFolder = new File("configs/");
configFolder.mkdir();

try {
createConfigSectionFile(configFolder, config.config, null);
} catch (IOException e) {
e.printStackTrace();
}
}

public static void createConfigSectionFile(File folder, YAMLProcessor config, String path) throws IOException {

String fpath = path;
if(fpath == null) fpath = "root";
else if(fpath.contains("."))
fpath = RegexUtil.PERIOD_PATTERN.split(fpath)[RegexUtil.PERIOD_PATTERN.split(fpath).length-1];
File file = new File(folder, fpath + ".txt");
if(!file.exists()) {
new File(file.getParent()).mkdirs();
file.createNewFile();
} else {
file.delete();
file.createNewFile();
}
PrintWriter pw = new PrintWriter(file);
int lines = 0;

pw.println("== Configuration ==");
pw.println();
pw.println("{| class=\"wiki-table sortable\"");
pw.println("|-");
pw.println("! Configuration Node and Path");
pw.println("! Default Value");
pw.println("! Effect");

for(String key : config.getKeys(path)) {
if(config.getProperty(path == null ? key : path + "." + key) != null && !(config.getProperty(path == null ? key : path + "." + key) instanceof Map)) {
pw.println("|-");
pw.println("| " + (path == null ? key : path + "." + key));
pw.println("| " + String.valueOf(config.getProperty(path == null ? key : path + "." + key)));
String comment = config.getComment(path == null ? key : path + "." + key);
if(comment == null) comment = "";
if(!comment.trim().isEmpty()) comment = comment.trim().substring(2);
pw.println("| " + comment);
lines++;
} else
createConfigSectionFile(new File(folder, key + "/"), config, path == null ? key : path + "." + key);
System.out.println(key);
}

pw.println("|}");

pw.close();

if(lines == 0)
file.delete();
}
}
4 changes: 4 additions & 0 deletions src/utils/java/com/me4502/util/GenerateWikiICList.java
Expand Up @@ -40,6 +40,10 @@ public static void main(String[] args) {
File file = new File("ICList.txt");
if(!file.exists())
file.createNewFile();
else {
file.delete();
file.createNewFile();
}

PrintWriter writer = new PrintWriter(file);

Expand Down

0 comments on commit f5db25f

Please sign in to comment.