diff --git a/src/main/java/com/laytonsmith/abstraction/Implementation.java b/src/main/java/com/laytonsmith/abstraction/Implementation.java index cfd668f6f..2b23f9ae1 100644 --- a/src/main/java/com/laytonsmith/abstraction/Implementation.java +++ b/src/main/java/com/laytonsmith/abstraction/Implementation.java @@ -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) { @@ -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() { @@ -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(); diff --git a/src/main/java/com/laytonsmith/annotations/processors/CacheAnnotations.java b/src/main/java/com/laytonsmith/annotations/processors/CacheAnnotations.java index 816351295..523763c00 100644 --- a/src/main/java/com/laytonsmith/annotations/processors/CacheAnnotations.java +++ b/src/main/java/com/laytonsmith/annotations/processors/CacheAnnotations.java @@ -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."); diff --git a/src/main/java/com/laytonsmith/core/Prefs.java b/src/main/java/com/laytonsmith/core/Prefs.java index 2b42e2990..2d4a7beb2 100644 --- a/src/main/java/com/laytonsmith/core/Prefs.java +++ b/src/main/java/com/laytonsmith/core/Prefs.java @@ -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()); } @@ -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")); diff --git a/src/main/java/com/laytonsmith/core/functions/Regex.java b/src/main/java/com/laytonsmith/core/functions/Regex.java index 3962036d7..854bad227 100644 --- a/src/main/java/com/laytonsmith/core/functions/Regex.java +++ b/src/main/java/com/laytonsmith/core/functions/Regex.java @@ -117,8 +117,11 @@ public Set 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(?\\\\d+)(xyz)', 'abc123xyz')"), - new ExampleScript("Named captures with backreferences", "reg_match('abc(?\\\\d+)def\\\\k', '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(?\\\\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(?\\\\d+)def\\\\k', 'abc123def123')['foo']", "123") }; } @@ -205,8 +208,11 @@ public Set 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(?\\\\d+)(xyz)', 'abc123xyz')[0]['foo']"), - new ExampleScript("Named captures with backreferences", "reg_match_all('abc(?\\\\d+)def\\\\k', '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(?\\\\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(?\\\\d+)def\\\\k', 'abc123def123')[0]['foo']", "123") }; } @@ -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(?\\\\d+)', '${foo}', 'abc123')") + new ExampleScript("Using backreferences with named captures (Only works if your system is running Java 7)", + "reg_replace('abc(?\\\\d+)', '${foo}', 'abc123')", "123") }; } diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGen.java b/src/main/java/com/laytonsmith/tools/docgen/DocGen.java index f5c2b8609..1a63dfb90 100644 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGen.java +++ b/src/main/java/com/laytonsmith/tools/docgen/DocGen.java @@ -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; @@ -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)); diff --git a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java b/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java index c9afe2b83..538db08d4 100644 --- a/src/main/java/com/laytonsmith/tools/docgen/DocGenUI.java +++ b/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; @@ -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() { @@ -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); } @@ -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() { @@ -323,8 +330,9 @@ 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() { @@ -332,6 +340,9 @@ 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;