From 35bd9ce9717772823ce2de2bbb281f46d84cfcbe Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 1 Sep 2009 12:10:02 +0000 Subject: [PATCH] enhancement to app runner (ability to specify default packages for quicker access to tests) svn changeset:8617/svn branch:6.1 --- WebContent/WEB-INF/web.xml | 10 ++-- .../gwt/server/ApplicationRunnerServlet.java | 51 ++++++++++++++----- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/WebContent/WEB-INF/web.xml b/WebContent/WEB-INF/web.xml index 652179b7dc..61ec738724 100644 --- a/WebContent/WEB-INF/web.xml +++ b/WebContent/WEB-INF/web.xml @@ -32,10 +32,12 @@ IT Mill Testing Tools URI - - VaadinApplicationRunner - com.vaadin.terminal.gwt.server.ApplicationRunnerServlet - + + VaadinApplicationRunner + com.vaadin.terminal.gwt.server.ApplicationRunnerServlet + defaultPackages + com.vaadin.tests,com.vaadin.demo,com.vaadin.tests,com.vaadin.tests.components,com.vaadin.tests.components.layouts,com.vaadin.tests.components.panel,com.vaadin.tests.components.combobox,com.vaadin.tests.components.popupview,com.vaadin.tests.components.datefield,com.vaadin.tests.components.richtextarea,com.vaadin.tests.components.absolutelayout,com.vaadin.tests.components.embedded,com.vaadin.tests.components.splitpanel,com.vaadin.tests.components.abstractfield,com.vaadin.tests.components.form,com.vaadin.tests.components.table,com.vaadin.tests.components.accordion,com.vaadin.tests.components.label,com.vaadin.tests.components.tabsheet,com.vaadin.tests.components.beanitemcontainer,com.vaadin.tests.components.link,com.vaadin.tests.components.textfield,com.vaadin.tests.components.button,com.vaadin.tests.components.optiongroup,com.vaadin.tests.components.tree,com.vaadin.tests.components.caption,com.vaadin.tests.components.orderedlayout,com.vaadin.tests.components.window + diff --git a/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java b/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java index c9c0f314fb..8ffd7b3f16 100644 --- a/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java +++ b/src/com/vaadin/terminal/gwt/server/ApplicationRunnerServlet.java @@ -18,20 +18,25 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { * The name of the application class currently used. Only valid within one * request. */ - String applicationClassName = ""; + private String[] defaultPackages; + private HttpServletRequest request; @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); + String initParameter = servletConfig + .getInitParameter("defaultPackages"); + if (initParameter != null) { + defaultPackages = initParameter.split(","); + } } @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - applicationClassName = getApplicationRunnerApplicationClassName(request); + this.request = request; super.service(request, response); - applicationClassName = ""; - + this.request = null; } @Override @@ -40,7 +45,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { URL url = super.getApplicationUrl(request); String path = url.toString(); - path += applicationClassName; + path += getApplicationRunnerApplicationClassName(request); path += "/"; return new URL(path); @@ -52,11 +57,8 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { // Creates a new application instance try { - Class applicationClass = getClassLoader().loadClass( - applicationClassName); - final Application application = (Application) applicationClass + final Application application = (Application) getApplicationClass() .newInstance(); - return application; } catch (final IllegalAccessException e) { throw new ServletException(e); @@ -66,7 +68,7 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { throw new ServletException( new InstantiationException( "Failed to load application class: " - + applicationClassName)); + + getApplicationRunnerApplicationClassName(request))); } } @@ -145,7 +147,31 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { @Override protected Class getApplicationClass() throws ClassNotFoundException { // TODO use getClassLoader() ? - return getClass().getClassLoader().loadClass(applicationClassName); + + Class appClass = null; + + String baseName = getApplicationRunnerApplicationClassName(request); + try { + appClass = (Class) getClass() + .getClassLoader().loadClass(baseName); + return appClass; + } catch (Exception e) { + // + for (int i = 0; i < defaultPackages.length; i++) { + try { + appClass = (Class) getClass() + .getClassLoader().loadClass( + defaultPackages[i] + "." + baseName); + } catch (Exception e2) { + // TODO: handle exception + } + if (appClass != null) { + return appClass; + } + } + } + + throw new ClassNotFoundException(); } @Override @@ -155,7 +181,8 @@ public class ApplicationRunnerServlet extends AbstractApplicationServlet { return null; } - path = path.substring(1 + applicationClassName.length()); + path = path.substring(1 + getApplicationRunnerApplicationClassName( + request).length()); return path; } -- 2.39.5