Revision: 6330 Author: j...@google.com Date: Thu Oct 8 14:16:26 2009 Log: Delay processing the -runStyle argument so JUnitShell's logger is available for the runstyles.
http://code.google.com/p/google-web-toolkit/source/detail?r=6330 Modified: /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java /changes/jat/abstractui/user/src/com/google/gwt/junit/JUnitShell.java /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleManual.java /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleSelenium.java ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Wed Oct 7 16:56:57 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Thu Oct 8 14:16:26 2009 @@ -850,6 +850,15 @@ protected abstract void doShutDownServer(); + /** + * Perform any startup tasks, including initializing the UI (if any) and the + * logger, updates checker, and the development mode code server. + * + * <p>Subclasses that override this method should be careful what facilities + * are used before the super implementation is called. + * + * @return true if startup was successful + */ protected boolean doStartup() { // Create the main app window. ui.initialize(); ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/JUnitShell.java Wed Oct 7 16:56:57 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/JUnitShell.java Thu Oct 8 14:16:26 2009 @@ -189,42 +189,8 @@ @Override public boolean setString(String runStyleArg) { - String runStyleName = runStyleArg; - String args = null; - int colon = runStyleArg.indexOf(':'); - if (colon >= 0) { - runStyleName = runStyleArg.substring(0, colon); - args = runStyleArg.substring(colon + 1); - } - if (runStyleName.indexOf('.') < 0) { - runStyleName = RunStyle.class.getName() + runStyleName; - } - Throwable caught = null; - try { - Class<?> clazz = Class.forName(runStyleName); - Class<? extends RunStyle> runStyleClass = clazz.asSubclass( - RunStyle.class); - Constructor<? extends RunStyle> ctor = runStyleClass.getConstructor( - JUnitShell.class); - runStyle = ctor.newInstance(JUnitShell.this); - return runStyle.initialize(args); - } catch (ClassNotFoundException e) { - caught = e; - } catch (SecurityException e) { - caught = e; - } catch (NoSuchMethodException e) { - caught = e; - } catch (IllegalArgumentException e) { - caught = e; - } catch (InstantiationException e) { - caught = e; - } catch (IllegalAccessException e) { - caught = e; - } catch (InvocationTargetException e) { - caught = e; - } - throw new RuntimeException("Unable to create runStyle " + runStyleArg, - caught); + runStyleName = runStyleArg; + return true; } }); @@ -524,8 +490,6 @@ if (!argProcessor.processArgs(args)) { throw new JUnitFatalLaunchException("Error processing shell arguments"); } - unitTestShell.finalizeArguments(); - unitTestShell.messageQueue = new JUnitMessageQueue( unitTestShell.numClients); @@ -613,6 +577,12 @@ */ private RunStyle runStyle = null; + /** + * The argument passed to -runStyle. This is parsed later so we can pass in + * a logger. + */ + private String runStyleName = null; + private boolean shouldAutoGenerateResources = true; /** @@ -672,6 +642,11 @@ if (!super.doStartup()) { return false; } + if (!createRunStyle()) { + // RunStyle already logged reasons for its failure + return false; + } + if (!runStyle.setupMode(getTopLogger(), developmentMode)) { getTopLogger().log(TreeLogger.ERROR, "Run style does not support " + (developmentMode ? "development" : "production") + " mode"); @@ -822,13 +797,52 @@ } /** - * Finish processing command line arguments. + * Create the specified (or default) runStyle. + * + * @return true if the runStyle was successfully created/initialized */ - private void finalizeArguments() { - if (runStyle == null) { + private boolean createRunStyle() { + if (runStyleName == null) { // Default to HtmlUnit runstyle with no args runStyle = new RunStyleHtmlUnit(this); - runStyle.initialize(null); + return runStyle.initialize(null); + } else { + String args = null; + String name = runStyleName; + int colon = name.indexOf(':'); + if (colon >= 0) { + args = name.substring(colon + 1); + name = name.substring(0, colon); + } + if (name.indexOf('.') < 0) { + name = RunStyle.class.getName() + name; + } + Throwable caught = null; + try { + Class<?> clazz = Class.forName(name); + Class<? extends RunStyle> runStyleClass = clazz.asSubclass( + RunStyle.class); + Constructor<? extends RunStyle> ctor = runStyleClass.getConstructor( + JUnitShell.class); + runStyle = ctor.newInstance(JUnitShell.this); + return runStyle.initialize(args); + } catch (ClassNotFoundException e) { + caught = e; + } catch (SecurityException e) { + caught = e; + } catch (NoSuchMethodException e) { + caught = e; + } catch (IllegalArgumentException e) { + caught = e; + } catch (InstantiationException e) { + caught = e; + } catch (IllegalAccessException e) { + caught = e; + } catch (InvocationTargetException e) { + caught = e; + } + throw new RuntimeException("Unable to create runStyle " + runStyleName, + caught); } } ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java Tue Sep 29 11:27:01 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleExternalBrowser.java Thu Oct 8 14:16:26 2009 @@ -76,9 +76,10 @@ @Override public boolean initialize(String args) { if (args == null || args.length() == 0) { - throw new IllegalArgumentException("ExternalBrowser runstyle requires an " + getLogger().log(TreeLogger.ERROR, "ExternalBrowser runstyle requires an " + "argument listing one or more executables of external browsers to " + "launch"); + return false; } String browsers[] = args.split(","); synchronized (this) { ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java Thu Oct 8 11:27:39 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleHtmlUnit.java Thu Oct 8 14:16:26 2009 @@ -195,10 +195,17 @@ for (String browserName : args.split(",")) { BrowserVersion browser = BROWSER_MAP.get(browserName); if (browser == null) { - throw new IllegalArgumentException("Expected browser name: one of " - + BROWSER_MAP.keySet() + ", actual name: " + browserName); - } - browserSet.add(browser); + getLogger().log(TreeLogger.WARN, "RunStyleHtmlUnit: Ignoring unknown " + + "browser name " + browserName + ", expected browser name: one of " + + BROWSER_MAP.keySet()); + } else { + browserSet.add(browser); + } + } + if (browserSet.isEmpty()) { + getLogger().log(TreeLogger.WARN, + "RunStyleHtmlUnit: No valid browser names, using FF3"); + browserSet.add(BrowserVersion.FIREFOX_3); } browsers = Collections.unmodifiableSet(browserSet); return true; ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleManual.java Tue Sep 29 13:48:12 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleManual.java Thu Oct 8 14:16:26 2009 @@ -15,6 +15,7 @@ */ package com.google.gwt.junit; +import com.google.gwt.core.ext.TreeLogger; import com.google.gwt.core.ext.UnableToCompleteException; /** @@ -36,8 +37,9 @@ try { numClients = Integer.parseInt(args); } catch (NumberFormatException e) { - throw new RuntimeException("Error parsing argument \"" + args + "\"", - e); + getLogger().log(TreeLogger.ERROR, "Error parsing argument \"" + + args + "\"", e); + return false; } } shell.setNumClients(numClients); ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java Tue Sep 29 13:48:12 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleRemoteWeb.java Thu Oct 8 14:16:26 2009 @@ -27,7 +27,6 @@ import java.net.SocketTimeoutException; import java.rmi.Naming; import java.rmi.server.RMISocketFactory; -import java.security.Permission; /** * Runs in web mode via browsers managed over RMI. This feature is experimental @@ -159,25 +158,18 @@ @Override public boolean initialize(String args) { if (args == null || args.length() == 0) { - throw new JUnitFatalLaunchException( + getLogger().log(TreeLogger.ERROR, "RemoteWeb runstyle requires comma-separated RMI URLs"); + return false; } String[] urls = args.split(","); try { RMISocketFactoryWithTimeouts.init(); } catch (IOException e) { - throw new JUnitFatalLaunchException("Error initializing RMISocketFactory", - e); - } - System.setSecurityManager(new SecurityManager() { - @Override - public void checkPermission(Permission perm) { - } - - @Override - public void checkPermission(Permission perm, Object context) { - } - }); + getLogger().log(TreeLogger.ERROR, + "RemoteWeb: Error initializing RMISocketFactory", e); + return false; + } int numClients = urls.length; shell.setNumClients(numClients); BrowserManager[] browserManagers = new BrowserManager[numClients]; @@ -186,7 +178,8 @@ try { browserManagers[i] = (BrowserManager) Naming.lookup(urls[i]); } catch (Exception e) { - String message = "Error connecting to browser manager at " + urls[i]; + String message = "RemoteWeb: Error connecting to browser manager at " + + urls[i]; Throwable cause = e; if (e.getCause() instanceof SocketTimeoutException) { long elapsed = System.currentTimeMillis() - callStart; @@ -194,9 +187,8 @@ + "ms waiting to connect to browser manager."; cause = e.getCause(); } - System.err.println(message); - cause.printStackTrace(); - throw new JUnitFatalLaunchException(message, cause); + getLogger().log(TreeLogger.ERROR, message, cause); + return false; } } synchronized (this) { ======================================= --- /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleSelenium.java Tue Sep 29 13:48:12 2009 +++ /changes/jat/abstractui/user/src/com/google/gwt/junit/RunStyleSelenium.java Thu Oct 8 14:16:26 2009 @@ -89,8 +89,9 @@ @Override public boolean initialize(String args) { if (args == null || args.length() == 0) { - throw new JUnitFatalLaunchException( + getLogger().log(TreeLogger.ERROR, "Selenium runstyle requires comma-separated Selenium-RC targets"); + return false; } String[] targetsIn = args.split(","); RCSelenium targets[] = new RCSelenium[targetsIn.length]; @@ -99,8 +100,9 @@ for (int i = 0; i < targets.length; ++i) { Matcher matcher = pattern.matcher(targetsIn[i]); if (!matcher.matches()) { - throw new JUnitFatalLaunchException("Unable to parse Selenium target " + getLogger().log(TreeLogger.ERROR, "Unable to parse Selenium target " + targetsIn[i] + " (expected format is [host]:[port]/[browser])"); + return false; } RCSelenium instance = new RCSelenium(matcher.group(3), matcher.group(1), Integer.parseInt(matcher.group(2))); --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---