Changeset 581 for trunk/quest-runner/src/main/java/de/ugoe/cs/quest
- Timestamp:
- 08/21/12 11:06:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/quest-runner/src/main/java/de/ugoe/cs/quest/ui/Runner.java
r579 r581 1 1 2 package de.ugoe.cs.quest.ui; 2 3 … … 30 31 public class Runner { 31 32 32 33 34 33 public enum UITYPE { 34 text, swt 35 }; 35 36 36 37 38 37 public enum LOG4JTYPE { 38 enable, disable 39 } 39 40 40 41 42 43 44 45 46 * if parameters are defined, they are interpreted as commands 47 * for the {@link Console} and executed before the user can use 48 * the console; can be used toperform batch operations49 50 41 /** 42 * <p> 43 * Main method of the application. 44 * </p> 45 * 46 * @param args 47 * if parameters are defined, they are interpreted as commands for the 48 * {@link Console} and executed before the user can use the console; can be used to 49 * perform batch operations 50 */ 51 public static void main(String[] args) { 51 52 52 CommandExecuter.getInstance().addCommandPackage( 53 "de.ugoe.cs.quest.ui.commands"); 54 CommandExecuter.getInstance().addCommandPackage( 55 "de.ugoe.cs.quest.ui.swt.commands"); 53 CommandExecuter.getInstance().addCommandPackage("de.ugoe.cs.quest.ui.commands"); 54 CommandExecuter.getInstance().addCommandPackage("de.ugoe.cs.quest.ui.swt.commands"); 56 55 57 // The following four command packages are added automatically, once the 58 // plugin-mechanism works correctly. Hence, these calls should be 59 // removed then. 60 CommandExecuter.getInstance().addCommandPackage( 61 "de.ugoe.cs.quest.plugin.mfc.commands"); 62 CommandExecuter.getInstance().addCommandPackage( 63 "de.ugoe.cs.quest.plugin.php.commands"); 64 CommandExecuter.getInstance().addCommandPackage( 65 "de.ugoe.cs.quest.plugin.guitar.commands"); 66 CommandExecuter.getInstance().addCommandPackage( 67 "de.ugoe.cs.quest.plugin.jfc.commands"); 68 69 int i; 70 if(false) { 71 int j; 72 } 73 74 new java.util.Date().getDate(); 56 // The following four command packages are added automatically, once the 57 // plugin-mechanism works correctly. Hence, these calls should be 58 // removed then. 59 /* 60 * CommandExecuter.getInstance().addCommandPackage( "de.ugoe.cs.quest.plugin.mfc.commands"); 61 * CommandExecuter.getInstance().addCommandPackage( "de.ugoe.cs.quest.plugin.php.commands"); 62 * CommandExecuter.getInstance().addCommandPackage( 63 * "de.ugoe.cs.quest.plugin.guitar.commands"); 64 * CommandExecuter.getInstance().addCommandPackage( "de.ugoe.cs.quest.plugin.jfc.commands"); 65 */ 75 66 76 /* 77 * Code for loading plugins. Should be uncommented once the 78 * plugin-mechanism works correctly. 79 * TODO: uncomment as soon as plug-in mechanism works 80 * 81 * PluginLoader pluginLoader = new PluginLoader(new File("plugins")); 82 * pluginLoader.load(); 83 * 84 * for( QuestPlugin plugin : pluginLoader.getPlugins()) { for( String 85 * commandPackage : plugin.getCommandPackages()) { 86 * CommandExecuter.getInstance().addCommandPackage(commandPackage); } } 87 */ 67 PluginLoader pluginLoader = new PluginLoader(new File("plugins")); 68 pluginLoader.load(); 88 69 89 OptionParser parser = new OptionParser(); 90 OptionSpec<LOG4JTYPE> log4j = parser 91 .accepts("log4j", "Allowed values: enable, disable") 92 .withRequiredArg().ofType(LOG4JTYPE.class) 93 .defaultsTo(LOG4JTYPE.enable); 94 OptionSpec<UITYPE> ui = parser 95 .accepts("ui", "Allowed values: text, swt").withRequiredArg() 96 .ofType(UITYPE.class).defaultsTo(UITYPE.text); 97 OptionSpec<LOG4JTYPE> trace = parser 98 .accepts("trace", "Allowed values: enable, disable") 99 .withRequiredArg().ofType(LOG4JTYPE.class) 100 .defaultsTo(LOG4JTYPE.enable); 101 OptionSet options = parser.parse(args); 70 for (QuestPlugin plugin : pluginLoader.getPlugins()) { 71 for (String commandPackage : plugin.getCommandPackages()) { 72 CommandExecuter.getInstance().addCommandPackage(commandPackage); 73 } 74 } 102 75 103 List<String> startupCommands = options.nonOptionArguments(); 104 try { 105 switch (options.valueOf(log4j)) { 106 case enable: 107 new Log4JLogger(); 108 break; 109 case disable: 110 // do nothing 111 break; 112 default: 113 throw new AssertionError( 114 "reached source code that should be unreachable"); 115 } 76 OptionParser parser = new OptionParser(); 77 OptionSpec<LOG4JTYPE> log4j = 78 parser.accepts("log4j", "Allowed values: enable, disable").withRequiredArg() 79 .ofType(LOG4JTYPE.class).defaultsTo(LOG4JTYPE.enable); 80 OptionSpec<UITYPE> ui = 81 parser.accepts("ui", "Allowed values: text, swt").withRequiredArg() 82 .ofType(UITYPE.class).defaultsTo(UITYPE.text); 83 OptionSpec<LOG4JTYPE> trace = 84 parser.accepts("trace", "Allowed values: enable, disable").withRequiredArg() 85 .ofType(LOG4JTYPE.class).defaultsTo(LOG4JTYPE.enable); 86 OptionSet options = parser.parse(args); 116 87 117 switch (options.valueOf(ui)) { 118 case text: 119 TextConsole textConsole = new TextConsole(); 120 if (options.valueOf(trace) == LOG4JTYPE.disable) { 121 textConsole.setDebug(false); 122 } 123 for (String command : startupCommands) { 124 CommandExecuter.getInstance().exec(command); 125 } 126 textConsole.run(true); 127 break; 128 case swt: 129 MainWindow mainWindow = new MainWindow(startupCommands); 130 mainWindow.open(); 131 break; 132 default: 133 throw new AssertionError( 134 "reached source code that should be unreachable"); 135 } 136 } catch (OptionException e) { 137 System.err.println("Invalid Parameters: " + e.getMessage()); 138 try { 139 parser.printHelpOn(System.out); 140 } catch (IOException e1) { 141 // ignore exception. 142 } 143 } 144 } 88 List<String> startupCommands = options.nonOptionArguments(); 89 try { 90 switch (options.valueOf(log4j)) 91 { 92 case enable: 93 new Log4JLogger(); 94 break; 95 case disable: 96 // do nothing 97 break; 98 default: 99 throw new AssertionError("reached source code that should be unreachable"); 100 } 101 102 switch (options.valueOf(ui)) 103 { 104 case text: 105 TextConsole textConsole = new TextConsole(); 106 if (options.valueOf(trace) == LOG4JTYPE.disable) { 107 textConsole.setDebug(false); 108 } 109 for (String command : startupCommands) { 110 CommandExecuter.getInstance().exec(command); 111 } 112 textConsole.run(true); 113 break; 114 case swt: 115 MainWindow mainWindow = new MainWindow(startupCommands); 116 mainWindow.open(); 117 break; 118 default: 119 throw new AssertionError("reached source code that should be unreachable"); 120 } 121 } 122 catch (OptionException e) { 123 System.err.println("Invalid Parameters: " + e.getMessage()); 124 try { 125 parser.printHelpOn(System.out); 126 } 127 catch (IOException e1) { 128 // ignore exception. 129 } 130 } 131 } 145 132 146 133 }
Note: See TracChangeset
for help on using the changeset viewer.