Skip to content

Commit

Permalink
Fixed some bugs with docgen.
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Aug 12, 2013
1 parent 6c36a65 commit 1a4d17c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 18 deletions.
22 changes: 20 additions & 2 deletions src/main/java/com/laytonsmith/abstraction/Implementation.java
Expand Up @@ -23,6 +23,16 @@ public final class Implementation {
private Implementation() {
}
private static Implementation.Type serverType = null;
private static boolean useAbstractEnumThread = true;

/**
* Sets whether or not we should verify enums when setServerType is called.
* Defaults to true.
* @param on
*/
public static void useAbstractEnumThread(boolean on){
useAbstractEnumThread = on;
}

public static void setServerType(Implementation.Type type) {
if (serverType == null) {
Expand All @@ -35,7 +45,7 @@ public static void setServerType(Implementation.Type type) {
}

//Fire off our abstractionenum checks in a new Thread
if (type != Type.TEST && type != Type.SHELL) {
if (type != Type.TEST && type != Type.SHELL && useAbstractEnumThread) {
Thread abstractionenumsThread;
abstractionenumsThread = new Thread(new Runnable() {
public void run() {
Expand Down Expand Up @@ -94,7 +104,15 @@ public void run() {

}
} catch (Exception e) {
if (Prefs.DebugMode()) {
boolean debugMode;
try {
debugMode = Prefs.DebugMode();
} catch(RuntimeException ex){
//Set it to true if we fail to load prefs, which can happen
//with a buggy front end.
debugMode = true;
}
if (debugMode) {
//If we're in debug mode, sure, go ahead and print the stack trace,
//but otherwise we don't want to bother the user.
e.printStackTrace();
Expand Down
Expand Up @@ -15,7 +15,7 @@ public class CacheAnnotations {
public static void main(String[] args) throws Exception {
File outputDir = new File(args[0]);
File scanDir = new File(args[1]);
if(outputDir.toString().startsWith("-classpath")){
if(outputDir.toString().startsWith("-classpath") || outputDir.toString().startsWith("-Xdebug")){
//This happens when running locally. I dunno what that is, but we
//can skip this step.
System.out.println("Skipping annotation caching, running locally.");
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/laytonsmith/core/Prefs.java
Expand Up @@ -15,7 +15,7 @@ private Prefs(){}
private static Object pref(PNames name){
if(prefs == null){
//Uh oh.
throw new Error("Preferences have not been initialized!");
throw new RuntimeException("Preferences have not been initialized!");
}
return prefs.getPreference(name.config());
}
Expand Down Expand Up @@ -63,7 +63,7 @@ public static void init(File f) throws IOException {
a.add(new Preference(PNames.BASE_DIR.config(), "", Preferences.Type.STRING, "The base directory that scripts can read and write to. If left blank, then the default of the server directory will be used. "
+ "This setting affects functions like include and read."));
a.add(new Preference(PNames.PLAY_DIRTY.config(), "false", Preferences.Type.BOOLEAN, "Makes CommandHelper play dirty and break all sorts of programming rules, so that other plugins can't interfere with the operations that you defined. Note that doing this essentially makes CommandHelper have absolute say over commands. Use this setting only if you can't get another plugin to cooperate with CH, because it is a global setting."));
a.add(new Preference(PNames.CASE_SENSITIVE.config(), "true", Preferences.Type.BOOLEAN, "Makes command matching be case sensitive. If set to false, if your config defines /cmd, but the user runs /CMD, it will trigger the command anyways."));
a.add(new Preference(PNames.CASE_SENSITIVE.config(), "false", Preferences.Type.BOOLEAN, "Makes command matching be case sensitive. If set to false, if your config defines /cmd, but the user runs /CMD, it will trigger the command anyways."));
a.add(new Preference(PNames.MAIN_FILE.config(), "main.ms", Preferences.Type.STRING, "The path to the main file, relative to the CommandHelper folder"));
a.add(new Preference(PNames.ALLOW_DEBUG_LOGGING.config(), "false", Preferences.Type.BOOLEAN, "If set to false, the Debug class of functions will do nothing."));
a.add(new Preference(PNames.DEBUG_LOG_FILE.config(), "logs/debug/%Y-%M-%D-debug.log", Preferences.Type.STRING, "The path to the debug output log file. Six variables are available, %Y, %M, and %D, %h, %m, %s, which are replaced with the current year, month, day, hour, minute and second respectively. It is highly recommended that you use at least year, month, and day if you are for whatever reason leaving logging on, otherwise the file size would get excessively large. The path is relative to the CommandHelper directory and is not bound by the base-dir restriction. The logger preferences file is created in the same directory this file is in as well, and is named loggerPreferences.txt"));
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/com/laytonsmith/core/functions/Regex.java
Expand Up @@ -117,8 +117,11 @@ public Set<OptimizationOption> optimizationOptions() {
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Basic usage", "reg_match('(\\\\d)(\\\\d)(\\\\d)', 'abc123')"),
new ExampleScript("Named captures", "reg_match('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')"),
new ExampleScript("Named captures with backreferences", "reg_match('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')['foo']")
//Java 7 can't be assumed to be working on the system running the doc gen, so we'll hardcode these.
new ExampleScript("Named captures (Only works if your system is running Java 7)",
"reg_match('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')", "{0: abc123xyz, 1: 123, 2: xyz, foo: 123}"),
new ExampleScript("Named captures with backreferences (Only works if your system is running Java 7)",
"reg_match('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')['foo']", "123")
};
}

Expand Down Expand Up @@ -205,8 +208,11 @@ public Set<OptimizationOption> optimizationOptions() {
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Basic usage", "reg_match_all('(\\\\d{3})', 'abc123456')"),
new ExampleScript("Named captures", "reg_match_all('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')[0]['foo']"),
new ExampleScript("Named captures with backreferences", "reg_match_all('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')[0]['foo']")
//Same thing here, can't guarantee we're running Java 7 when these are generated.
new ExampleScript("Named captures (Only works if your system is running Java 7)",
"reg_match_all('abc(?<foo>\\\\d+)(xyz)', 'abc123xyz')[0]['foo']", "123"),
new ExampleScript("Named captures with backreferences (Only works if your system is running Java 7)",
"reg_match_all('abc(?<foo>\\\\d+)def\\\\k<foo>', 'abc123def123')[0]['foo']", "123")
};
}

Expand Down Expand Up @@ -300,7 +306,8 @@ public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Basic usage", "reg_replace('\\\\d', 'Z', '123abc')"),
new ExampleScript("Using backreferences", "reg_replace('abc(\\\\d+)', '$1', 'abc123'"),
new ExampleScript("Using backreferences with named captures", "reg_replace('abc(?<foo>\\\\d+)', '${foo}', 'abc123')")
new ExampleScript("Using backreferences with named captures (Only works if your system is running Java 7)",
"reg_replace('abc(?<foo>\\\\d+)', '${foo}', 'abc123')", "123")
};
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/com/laytonsmith/tools/docgen/DocGen.java
Expand Up @@ -8,6 +8,7 @@
import com.laytonsmith.PureUtilities.StringUtils;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.annotations.api;
import com.laytonsmith.commandhelper.CommandHelperFileLocations;
import com.laytonsmith.core.CHLog;
import com.laytonsmith.core.Documentation;
import com.laytonsmith.core.Installer;
Expand Down Expand Up @@ -42,9 +43,9 @@ public static void main(String[] args) throws Exception {
try{
//Boilerplate startup stuff
Implementation.setServerType(Implementation.Type.BUKKIT);
Installer.Install(DocGenUI.chDirectory);
Prefs.init(new File(DocGenUI.chDirectory, "preferences.ini"));
CHLog.initialize(DocGenUI.chDirectory);
Installer.Install(CommandHelperFileLocations.getDefault().getConfigDirectory());
Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile());
CHLog.initialize(CommandHelperFileLocations.getDefault().getConfigDirectory());

//System.out.println(functions("wiki", api.Platforms.INTERPRETER_JAVA, true));
System.out.println(examples("string_append", true));
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java
@@ -1,10 +1,14 @@
package com.laytonsmith.tools.docgen;

import com.laytonsmith.PureUtilities.ClassDiscovery;
import com.laytonsmith.PureUtilities.UIUtils;
import com.laytonsmith.abstraction.Implementation;
import com.laytonsmith.annotations.api;
import com.laytonsmith.commandhelper.CommandHelperFileLocations;
import com.laytonsmith.core.CHLog;
import com.laytonsmith.core.Installer;
import com.laytonsmith.core.Prefs;
import com.laytonsmith.core.functions.FunctionList;
import com.laytonsmith.tools.Interpreter;
import java.io.File;
import java.io.IOException;
Expand All @@ -26,8 +30,6 @@
*/
public class DocGenUI extends javax.swing.JFrame {

private static final File jarLocation = new File(Interpreter.class.getProtectionDomain().getCodeSource().getLocation().getFile()).getParentFile();
static final File chDirectory = new File(jarLocation, "CommandHelper/");
DocGenUIHandler handler;
DocGenUIHandler.ProgressManager manager = new DocGenUIHandler.ProgressManager() {

Expand Down Expand Up @@ -279,8 +281,8 @@ private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-

public void run() {
try {
Prefs.init(new File(chDirectory, "preferences.ini"));
CHLog.initialize(chDirectory);
Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile());
CHLog.initialize(CommandHelperFileLocations.getDefault().getConfigDirectory());
} catch (IOException ex) {
Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -298,6 +300,11 @@ private void singleFunctionUploadButtonActionPerformed(java.awt.event.ActionEven
* @param args the command line arguments
*/
public static void main(String args[]) {
try {
Prefs.init(CommandHelperFileLocations.getDefault().getPreferencesFile());
} catch (IOException ex) {
Logger.getLogger(DocGenUI.class.getName()).log(Level.SEVERE, null, ex);
}

try {
SwingUtilities.invokeAndWait(new Runnable() {
Expand All @@ -323,15 +330,19 @@ public void run() {
}
}

ClassDiscovery.getDefaultInstance().addDiscoveryLocation(ClassDiscovery.GetClassContainer(DocGenUI.class));
Implementation.setServerType(Implementation.Type.BUKKIT);
Installer.Install(chDirectory);
Installer.Install(CommandHelperFileLocations.getDefault().getConfigDirectory());

/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DocGenUI().setVisible(true);
}
});

//This goes ahead and initializes the platform.
FunctionList.getFunctionList(api.Platforms.INTERPRETER_JAVA);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JCheckBox events;
Expand Down

0 comments on commit 1a4d17c

Please sign in to comment.