Revision: 4756 http://sourceforge.net/p/jump-pilot/code/4756 Author: edso Date: 2016-01-10 16:20:45 +0000 (Sun, 10 Jan 2016) Log Message: ----------- adapt to new Logger introduce new commandline parameter to switch log verbosity '-v, -verbosity' utilizing the new Logger
Modified Paths: -------------- core/trunk/src/com/vividsolutions/jump/util/commandline/OptionSpec.java core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java Modified: core/trunk/src/com/vividsolutions/jump/util/commandline/OptionSpec.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/util/commandline/OptionSpec.java 2016-01-10 16:11:37 UTC (rev 4755) +++ core/trunk/src/com/vividsolutions/jump/util/commandline/OptionSpec.java 2016-01-10 16:20:45 UTC (rev 4756) @@ -36,6 +36,11 @@ import java.util.Iterator; import java.util.Vector; +import org.apache.commons.lang.StringUtils; + +import com.vividsolutions.jump.I18N; +import com.vividsolutions.jump.workbench.JUMPWorkbench; + /** * Specifies the syntax for a single option on a command line. */ @@ -51,12 +56,12 @@ String doc = ""; // option description Vector<Option> options = new Vector<Option>(); - public OptionSpec(String[] optNames, int needed, String desc) { + public OptionSpec(String[] optNames, int numberOfNeededArgs, String desc) { for (String name : optNames) { names.add(name.toLowerCase()); } doc = desc; - nNeededArgs = needed; + nNeededArgs = numberOfNeededArgs; } public OptionSpec(String optName, int needed, String desc) { @@ -133,8 +138,11 @@ // we complain only if there are too few arguments // more can as well be files that were carelessly placed else if (args.length < nNeededArgs) { - throw new ParseException("option " + names + ": expected " + nNeededArgs - + " args, found " + args.length); + String msg = I18N.getMessage(JUMPWorkbench.I18NPREFIX + + "option-{0}-needs-{1}-parameters-but-only-{2}-were-given.", + StringUtils.join(names, ", "), nNeededArgs, args.length); + msg += "\n\n" + getDesc(); + throw new ParseException(msg); } } Modified: core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java 2016-01-10 16:11:37 UTC (rev 4755) +++ core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java 2016-01-10 16:20:45 UTC (rev 4756) @@ -73,6 +73,7 @@ import com.vividsolutions.jump.util.LangUtil; import com.vividsolutions.jump.util.StringUtil; import com.vividsolutions.jump.util.commandline.CommandLine; +import com.vividsolutions.jump.util.commandline.Option; import com.vividsolutions.jump.util.commandline.OptionSpec; import com.vividsolutions.jump.util.commandline.ParseException; import com.vividsolutions.jump.workbench.driver.DriverManager; @@ -154,6 +155,7 @@ public final static String PLUG_IN_DIRECTORY_OPTION = "plug-in-directory"; public final static String I18N_FILE = "i18n"; public static final String INITIAL_PROJECT_FILE = "project"; + public static final String I18NPREFIX = JUMPWorkbench.class.getPackage().getName()+"."; public static final String STATE_OPTION = "state"; // Added by STanner to allow I18N to have access to this @@ -245,8 +247,7 @@ // files // properties = new WorkbenchPropertiesFile(defaultFile, frame); } else { - System.out - .println("JUMP: Warning: Default plugins file does not exist: " + Logger.warn("Default plugins file does not exist: " + defaultFile); } } @@ -261,7 +262,7 @@ // properties = new WorkbenchPropertiesFile(propertiesFile, frame); propertiesFileExists = true; } else { - System.out.println("JUMP: Warning: Properties file does not exist: " + Logger.warn("Properties file does not exist: " + propertiesFile); } } @@ -281,8 +282,7 @@ extensionsDirectory = new File(commandLine.getOption( PLUG_IN_DIRECTORY_OPTION).getArg(0)); if (!extensionsDirectory.exists()) { - System.out - .println("JUMP: Warning: Extensions directory does not exist: " + Logger.warn("Extensions directory does not exist: " + extensionsDirectory); extensionsDirectory = null; } @@ -291,8 +291,7 @@ if (!extensionsDirectory.exists()) { // Added further information so that debug user will know where // it is actually looking for as the extension directory. [Ed Deen] - System.out - .println("JUMP: Warning: Extensions directory does not exist: " + Logger.warn("Extensions directory does not exist: " + extensionsDirectory + " where homedir = [" + System.getProperty("user.dir") + "]"); extensionsDirectory = null; @@ -363,6 +362,17 @@ System.exit(0); } + // set logging level according to parameter + if (commandLine.hasOption("verbosity")) { + Option v = commandLine.getOption("verbosity"); + if (v.getNumArgs() < 1) { + printProperly(I18N.get(v.getSpec().getDesc())); + System.exit(1); + } + + Logger.setLevel(v.getArg(0)); + } + // Init the L&F before instantiating the progress monitor [Jon Aquino] initLookAndFeel(); // fix lnf (weird windows non-unicode locale bug) @@ -385,22 +395,27 @@ splashPanel.addProgressMonitor(progressMonitor); main(args, I18N.get("JUMPWorkbench.jump"), splashPanel, progressMonitor); - System.out.println("OJ start took " + Logger.info("OJ start took " + PlugInManager.secondsSinceString(start) + "s alltogether."); } catch (final Throwable t) { - t.printStackTrace(); try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { + try { + initLookAndFeel(); + } catch (Exception e) { + // fail silently + } ErrorDialog.show(null, - StringUtil.toFriendlyName(t.getClass().getName()), + StringUtil.toFriendlyName(t.getClass().getSimpleName()), WorkbenchFrame.toMessage(t), StringUtil.stackTrace(t)); } }); } catch (Throwable t2) { - t2.printStackTrace(); + Logger.error(t2); } + Logger.error(t); System.exit(1); } } @@ -476,7 +491,7 @@ Font ta_font = (Font) defaults.get("TextArea.font"); if (ta_font.getSize() < 11) { UIManager.put("TextArea.font", ta_font.deriveFont(13f)); - System.out.println("Info: Fix text area font size bug."); + Logger.info("Fix text area font size bug."); } } @@ -641,7 +656,7 @@ printProperly(in + "\n" + out); } - private static void parseCommandLine(String[] args) throws WorkbenchException { + private static void parseCommandLine(String[] args) throws ParseException { commandLine = new CommandLine('-'); commandLine.addOptionSpec(new OptionSpec(PROPERTIES_OPTION, 1, "workbench property file (activate extensions and plugins)")); @@ -662,21 +677,20 @@ STATE_OPTION, 1, "where to save workbench settings, default OJ_HOME folder or USER_HOME/.openjump/")); + // add logging + commandLine.addOptionSpec(new OptionSpec(new String[] { "v", "verbosity" }, 1, + "logging verbosity, either: off, error, warn, info, debug, trace, all")); // add help commandLine.addOptionSpec(new OptionSpec(new String[] { "h", "help" }, 0, "show this help")); // add version - commandLine.addOptionSpec(new OptionSpec(new String[] { "v", "version" }, + commandLine.addOptionSpec(new OptionSpec(new String[] { "version", "-version" }, 0, "show version information")); // show properties (for debugging purposes) commandLine.addOptionSpec(new OptionSpec(new String[] { "p", "print-properties" }, 0, "print a list of runtime properties")); - try { - commandLine.parse(args); - } catch (ParseException e) { - throw new WorkbenchException(e.getLocalizedMessage()); - } + commandLine.parse(args); } public PlugInManager getPlugInManager() { ------------------------------------------------------------------------------ Site24x7 APM Insight: Get Deep Visibility into Application Performance APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month Monitor end-to-end web transactions and take corrective actions now Troubleshoot faster and improve end-user experience. Signup Now! http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140 _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel