Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added util to generate configs for wiki pages with comments.
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
Showing
5 changed files
with
161 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,9 @@ debug.log | |
# Doxygen | ||
/docs/html | ||
debug.txt | ||
|
||
# Generated Files | ||
/configs/ | ||
/ICList.txt | ||
/config.yml | ||
/en_US.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 46 additions & 37 deletions
83
src/utils/java/com/me4502/util/GenerateDefaultLanguage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
92
src/utils/java/com/me4502/util/GenerateWikiConfigLists.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters