Moved DocumentationPrinter to internal.util.

This commit is contained in:
sk89q 2014-03-30 12:27:10 -07:00
parent dd3f32b8f1
commit e7f7d17f25

View File

@ -1,209 +1,209 @@
// $Id$ // $Id$
/* /*
* WorldEditLibrary * WorldEditLibrary
* Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors * Copyright (C) 2010 sk89q <http://www.sk89q.com> and contributors
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package com.sk89q.worldedit.dev; package com.sk89q.worldedit.internal.util;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.minecraft.util.commands.NestedCommand; import com.sk89q.minecraft.util.commands.NestedCommand;
import com.sk89q.worldedit.commands.BiomeCommands; import com.sk89q.worldedit.commands.BiomeCommands;
import com.sk89q.worldedit.commands.ChunkCommands; import com.sk89q.worldedit.commands.ChunkCommands;
import com.sk89q.worldedit.commands.ClipboardCommands; import com.sk89q.worldedit.commands.ClipboardCommands;
import com.sk89q.worldedit.commands.GeneralCommands; import com.sk89q.worldedit.commands.GeneralCommands;
import com.sk89q.worldedit.commands.GenerationCommands; import com.sk89q.worldedit.commands.GenerationCommands;
import com.sk89q.worldedit.commands.HistoryCommands; import com.sk89q.worldedit.commands.HistoryCommands;
import com.sk89q.worldedit.commands.NavigationCommands; import com.sk89q.worldedit.commands.NavigationCommands;
import com.sk89q.worldedit.commands.RegionCommands; import com.sk89q.worldedit.commands.RegionCommands;
import com.sk89q.worldedit.commands.ScriptingCommands; import com.sk89q.worldedit.commands.ScriptingCommands;
import com.sk89q.worldedit.commands.SelectionCommands; import com.sk89q.worldedit.commands.SelectionCommands;
import com.sk89q.worldedit.commands.SnapshotUtilCommands; import com.sk89q.worldedit.commands.SnapshotUtilCommands;
import com.sk89q.worldedit.commands.ToolCommands; import com.sk89q.worldedit.commands.ToolCommands;
import com.sk89q.worldedit.commands.ToolUtilCommands; import com.sk89q.worldedit.commands.ToolUtilCommands;
import com.sk89q.worldedit.commands.UtilityCommands; import com.sk89q.worldedit.commands.UtilityCommands;
public class DocumentationPrinter { public class DocumentationPrinter {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
File commandsDir = new File(args[0]); File commandsDir = new File(args[0]);
List<Class<?>> commandClasses = getCommandClasses(commandsDir); List<Class<?>> commandClasses = getCommandClasses(commandsDir);
System.out.println("Writing permissions wiki table..."); System.out.println("Writing permissions wiki table...");
writePermissionsWikiTable(commandClasses); writePermissionsWikiTable(commandClasses);
System.out.println("Writing Bukkit plugin.yml..."); System.out.println("Writing Bukkit plugin.yml...");
writeBukkitYAML(); writeBukkitYAML();
System.out.println("Done!"); System.out.println("Done!");
} }
private static List<Class<?>> getCommandClasses(File dir) { private static List<Class<?>> getCommandClasses(File dir) {
List<Class<?>> classes = new ArrayList<Class<?>>(); List<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(BiomeCommands.class); classes.add(BiomeCommands.class);
classes.add(ChunkCommands.class); classes.add(ChunkCommands.class);
classes.add(ClipboardCommands.class); classes.add(ClipboardCommands.class);
classes.add(GeneralCommands.class); classes.add(GeneralCommands.class);
classes.add(GenerationCommands.class); classes.add(GenerationCommands.class);
classes.add(HistoryCommands.class); classes.add(HistoryCommands.class);
classes.add(NavigationCommands.class); classes.add(NavigationCommands.class);
classes.add(RegionCommands.class); classes.add(RegionCommands.class);
classes.add(ScriptingCommands.class); classes.add(ScriptingCommands.class);
classes.add(SelectionCommands.class); classes.add(SelectionCommands.class);
classes.add(SnapshotUtilCommands.class); classes.add(SnapshotUtilCommands.class);
classes.add(ToolUtilCommands.class); classes.add(ToolUtilCommands.class);
classes.add(ToolCommands.class); classes.add(ToolCommands.class);
classes.add(UtilityCommands.class); classes.add(UtilityCommands.class);
/*for (File f : dir.listFiles()) { /*for (File f : dir.listFiles()) {
if (!f.getName().matches("^.*\\.java$")) { if (!f.getName().matches("^.*\\.java$")) {
continue; continue;
} }
String className = "com.sk89q.worldedit.commands." String className = "com.sk89q.worldedit.commands."
+ f.getName().substring(0, f.getName().lastIndexOf(".")); + f.getName().substring(0, f.getName().lastIndexOf("."));
Class<?> cls; Class<?> cls;
try { try {
cls = Class.forName(className, true, cls = Class.forName(className, true,
Thread.currentThread().getContextClassLoader()); Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
continue; continue;
} }
classes.add(cls); classes.add(cls);
}*/ }*/
return classes; return classes;
} }
private static void writePermissionsWikiTable(List<Class<?>> commandClasses) private static void writePermissionsWikiTable(List<Class<?>> commandClasses)
throws IOException { throws IOException {
FileOutputStream stream = null; FileOutputStream stream = null;
try { try {
stream = new FileOutputStream("wiki_permissions.txt"); stream = new FileOutputStream("wiki_permissions.txt");
PrintStream print = new PrintStream(stream); PrintStream print = new PrintStream(stream);
_writePermissionsWikiTable(print, commandClasses, "/"); _writePermissionsWikiTable(print, commandClasses, "/");
} finally { } finally {
if (stream != null) { if (stream != null) {
stream.close(); stream.close();
} }
} }
} }
private static void _writePermissionsWikiTable(PrintStream stream, private static void _writePermissionsWikiTable(PrintStream stream,
List<Class<?>> commandClasses, String prefix) { List<Class<?>> commandClasses, String prefix) {
for (Class<?> cls : commandClasses) { for (Class<?> cls : commandClasses) {
for (Method method : cls.getMethods()) { for (Method method : cls.getMethods()) {
if (!method.isAnnotationPresent(Command.class)) { if (!method.isAnnotationPresent(Command.class)) {
continue; continue;
} }
Command cmd = method.getAnnotation(Command.class); Command cmd = method.getAnnotation(Command.class);
stream.println("|-"); stream.println("|-");
stream.print("| " + prefix + cmd.aliases()[0]); stream.print("| " + prefix + cmd.aliases()[0]);
stream.print(" || "); stream.print(" || ");
if (method.isAnnotationPresent(CommandPermissions.class)) { if (method.isAnnotationPresent(CommandPermissions.class)) {
CommandPermissions perms = CommandPermissions perms =
method.getAnnotation(CommandPermissions.class); method.getAnnotation(CommandPermissions.class);
String[] permKeys = perms.value(); String[] permKeys = perms.value();
for (int i = 0; i < permKeys.length; ++i) { for (int i = 0; i < permKeys.length; ++i) {
if (i > 0) { if (i > 0) {
stream.print(", "); stream.print(", ");
} }
stream.print(permKeys[i]); stream.print(permKeys[i]);
} }
} }
stream.print(" || "); stream.print(" || ");
boolean firstAlias = true; boolean firstAlias = true;
if (cmd.aliases().length != 0) { if (cmd.aliases().length != 0) {
for (String alias : cmd.aliases()) { for (String alias : cmd.aliases()) {
if (!firstAlias) stream.print("<br />"); if (!firstAlias) stream.print("<br />");
stream.print(prefix + alias); stream.print(prefix + alias);
firstAlias = false; firstAlias = false;
} }
} }
stream.print(" || "); stream.print(" || ");
if (cmd.flags() != null && !cmd.flags().equals("")) { if (cmd.flags() != null && !cmd.flags().equals("")) {
stream.print(cmd.flags()); stream.print(cmd.flags());
} }
stream.print(" || "); stream.print(" || ");
if (cmd.desc() != null && !cmd.desc().equals("")) { if (cmd.desc() != null && !cmd.desc().equals("")) {
stream.print(cmd.desc()); stream.print(cmd.desc());
} }
stream.println(); stream.println();
if (method.isAnnotationPresent(NestedCommand.class)) { if (method.isAnnotationPresent(NestedCommand.class)) {
NestedCommand nested = NestedCommand nested =
method.getAnnotation(NestedCommand.class); method.getAnnotation(NestedCommand.class);
Class<?>[] nestedClasses = nested.value(); Class<?>[] nestedClasses = nested.value();
_writePermissionsWikiTable(stream, _writePermissionsWikiTable(stream,
Arrays.asList(nestedClasses), Arrays.asList(nestedClasses),
prefix + cmd.aliases()[0] + " "); prefix + cmd.aliases()[0] + " ");
} }
} }
} }
} }
private static void writeBukkitYAML() private static void writeBukkitYAML()
throws IOException { throws IOException {
FileOutputStream stream = null; FileOutputStream stream = null;
try { try {
stream = new FileOutputStream("plugin.yml"); stream = new FileOutputStream("plugin.yml");
PrintStream print = new PrintStream(stream); PrintStream print = new PrintStream(stream);
_writeBukkitYAML(print); _writeBukkitYAML(print);
} finally { } finally {
if (stream != null) { if (stream != null) {
stream.close(); stream.close();
} }
} }
} }
private static void _writeBukkitYAML(PrintStream stream) { private static void _writeBukkitYAML(PrintStream stream) {
stream.println("name: WorldEdit"); stream.println("name: WorldEdit");
stream.println("main: com.sk89q.worldedit.bukkit.WorldEditPlugin"); stream.println("main: com.sk89q.worldedit.bukkit.WorldEditPlugin");
stream.println("version: ${project.version}"); stream.println("version: ${project.version}");
stream.println("softdepend: [Spout] #hack to fix trove errors"); stream.println("softdepend: [Spout] #hack to fix trove errors");
stream.println(); stream.println();
stream.println(); stream.println();
stream.println("# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms"); stream.println("# Permissions aren't here. Read http://wiki.sk89q.com/wiki/WEPIF/DinnerPerms");
stream.println("# for how WorldEdit permissions actually work."); stream.println("# for how WorldEdit permissions actually work.");
} }
} }