Revision: 7019 Author: amitman...@google.com Date: Wed Nov 18 17:52:02 2009 Log: Rolled junitCreator into webAppCreator.
Patch by: amitmanjhi Review by: rjrjr (desk review) http://code.google.com/p/google-web-toolkit/source/detail?r=7019 Added: /trunk/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc /trunk/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc /trunk/user/src/com/google/gwt/user/tools/JUnitClassTemplate.javasrc Deleted: /trunk/distro-source/mac/src/junitCreator /trunk/distro-source/src/junitCreator /trunk/distro-source/src/junitCreator.cmd /trunk/user/src/com/google/gwt/junit/tools/JUnit-hosted.launchsrc /trunk/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc /trunk/user/src/com/google/gwt/junit/tools/JUnitClassTemplate.javasrc /trunk/user/src/com/google/gwt/junit/tools/junit-hosted.cmdsrc /trunk/user/src/com/google/gwt/junit/tools/junit-hostedsrc /trunk/user/src/com/google/gwt/junit/tools/junit-web.cmdsrc /trunk/user/src/com/google/gwt/junit/tools/junit-websrc /trunk/user/src/com/google/gwt/user/tools/.classpathsrc Modified: /trunk/user/src/com/google/gwt/junit/tools/JUnitCreator.java /trunk/user/src/com/google/gwt/user/tools/README.txtsrc /trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java /trunk/user/src/com/google/gwt/user/tools/project.ant.xmlsrc ======================================= --- /dev/null +++ /trunk/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc Wed Nov 18 17:52:02 2009 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientpacka...@moduleshortnametest"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="@moduleShortName" path="1" type="4"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@moduleShortName/src" path="3" type="2"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@moduleShortName/test" path="3" type="2"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="@moduleShortName"/> </runtimeClasspathEntry> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="@gwtDevPath" path="3" type="2"/> "/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@moduleShortName"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dgwt.args="-logLevel WARN" -Xmx256M"/> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +</launchConfiguration> ======================================= --- /dev/null +++ /trunk/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc Wed Nov 18 17:52:02 2009 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> +<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> +<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> +<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientpacka...@moduleshortnametest"/> +<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> +<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="@moduleShortName" path="1" type="4"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@moduleShortName/src" path="3" type="2"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@moduleShortName/test" path="3" type="2"/> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="@moduleShortName"/> </runtimeClasspathEntry> "/> +<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="@gwtDevPath" path="3" type="2"/> "/> +</listAttribute> +<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@moduleShortName"/> +<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dgwt.args="-web -logLevel WARN -out www-test" -Xmx256M"/> +<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> +</launchConfiguration> ======================================= --- /dev/null +++ /trunk/user/src/com/google/gwt/user/tools/JUnitClassTemplate.javasrc Wed Nov 18 17:52:02 2009 @@ -0,0 +1,24 @@ +package @clientPackage; + +import com.google.gwt.junit.client.GWTTestCase; + +/** + * GWT JUnit tests must extend GWTTestCase. + */ +public class @moduleShortNameTest extends GWTTestCase { + + /** + * Must refer to a valid module that sources this class. + */ + public String getModuleName() { + return "@moduleName"; + } + + /** + * Add as many tests as you like. + */ + public void testSimple() { + assertTrue(true); + } + +} ======================================= --- /trunk/distro-source/mac/src/junitCreator Wed Dec 6 15:14:19 2006 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -HOMEDIR=`dirname $0`; -java -cp $HOMEDIR/gwt-user.jar:$HOMEDIR/gwt-dev-mac.jar com.google.gwt.junit.tools.JUnitCreator "$@"; ======================================= --- /trunk/distro-source/src/junitCreator Tue Oct 13 16:57:19 2009 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -HOMEDIR=`dirname $0`; -java -cp $HOMEDIR/gwt-user.jar:$HOMEDIR/gwt-dev.jar com.google.gwt.junit.tools.JUnitCreator "$@"; ======================================= --- /trunk/distro-source/src/junitCreator.cmd Tue Oct 13 16:57:19 2009 +++ /dev/null @@ -1,1 +0,0 @@ -...@java -cp "%~dp0\gwt-user.jar;%~dp0\gwt-dev.jar" com.google.gwt.junit.tools.JUnitCreator %* ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/JUnit-hosted.launchsrc Tue Dec 23 16:45:21 2008 +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> -<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> -<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> -<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientpacka...@classname"/> -<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> -<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="@projectName" path="1" type="4"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@projectName/src" path="3" type="2"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@projectName/test" path="3" type="2"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="@projectName"/> </runtimeClasspathEntry> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="@gwtDevPath" path="3" type="2"/> "/> -...@eclipseextralaunchpaths -</listAttribute> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@projectName"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dgwt.args="-out www-test" -Xmx256M @vmargs"/> -<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> -</launchConfiguration> ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc Tue Dec 23 16:45:21 2008 +++ /dev/null @@ -1,18 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> -<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> -<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> -<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientpacka...@classname"/> -<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> -<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="@projectName" path="1" type="4"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@projectName/src" path="3" type="2"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/@projectName/test" path="3" type="2"/> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="@projectName"/> </runtimeClasspathEntry> "/> -<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="@gwtDevPath" path="3" type="2"/> "/> -...@eclipseextralaunchpaths -</listAttribute> -<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@projectName"/> -<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dgwt.args="-web -out www-test" -Xmx256M @vmargs"/> -<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/> -</launchConfiguration> ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/JUnitClassTemplate.javasrc Wed May 16 12:43:20 2007 +++ /dev/null @@ -1,24 +0,0 @@ -package @clientPackage; - -import com.google.gwt.junit.client.GWTTestCase; - -/** - * GWT JUnit tests must extend GWTTestCase. - */ -public class @className extends GWTTestCase { - - /** - * Must refer to a valid module that sources this class. - */ - public String getModuleName() { - return "@moduleName"; - } - - /** - * Add as many tests as you like. - */ - public void testSimple() { - assertTrue(true); - } - -} ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/junit-hosted.cmdsrc Tue May 19 08:35:33 2009 +++ /dev/null @@ -1,1 +0,0 @@ -...@java -Dgwt.args="-out www-test" -Xmx256M -cp "%~dp0\src;%~dp0\test;%~dp0\war\WEB-INF\classes;@junitPath;@gwtUserPath;@gwtdevp...@extraclasspathssemicolon" junit.textui.TestRunner @clientpacka...@classname %* ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/junit-hostedsrc Tue May 19 08:35:33 2009 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -APPDIR=`dirname $0`; -java @vmargs -Dgwt.args="-out www-test" -Xmx256M -cp "$APPDIR/src:$APPDIR/test:$APPDIR/war/WEB-INF/classes:@junitPath:@gwtUserPath:@gwtdevp...@extraclasspathscolon" junit.textui.TestRunner @clientpacka...@classname "$@"; ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/junit-web.cmdsrc Tue May 19 08:35:33 2009 +++ /dev/null @@ -1,1 +0,0 @@ -...@java -Dgwt.args="-web -out www-test" -Xmx256M -cp "%~dp0\src;%~dp0\test;%~dp0\war\WEB-INF\classes;@junitPath;@gwtUserPath;@gwtdevp...@extraclasspathssemicolon" junit.textui.TestRunner @clientpacka...@classname %* ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/junit-websrc Tue May 19 08:35:33 2009 +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -APPDIR=`dirname $0`; -java @vmargs -Dgwt.args="-web -out www-test" -Xmx256M -cp "$APPDIR/src:$APPDIR/test:$APPDIR/war/WEB-INF/classes:@junitPath:@gwtUserPath:@gwtdevp...@extraclasspathscolon" junit.textui.TestRunner @clientpacka...@classname "$@"; ======================================= --- /trunk/user/src/com/google/gwt/user/tools/.classpathsrc Fri Feb 6 13:06:24 2009 +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8" ?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="lib" path="@gwtUserPath"/> - <classpathentry kind="lib" path="@gwtDevPath"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> - <classpathentry kind="output" path="war/WEB-INF/classes"/> -</classpath> ======================================= --- /trunk/user/src/com/google/gwt/junit/tools/JUnitCreator.java Tue Oct 13 16:57:19 2009 +++ /trunk/user/src/com/google/gwt/junit/tools/JUnitCreator.java Wed Nov 18 17:52:02 2009 @@ -15,414 +15,18 @@ */ package com.google.gwt.junit.tools; -import com.google.gwt.user.tools.util.ArgHandlerAddToClassPath; -import com.google.gwt.user.tools.util.ArgHandlerEclipse; -import com.google.gwt.user.tools.util.ArgHandlerIgnore; -import com.google.gwt.user.tools.util.ArgHandlerOverwrite; -import com.google.gwt.user.tools.util.CreatorUtilities; -import com.google.gwt.util.tools.ArgHandlerExtra; -import com.google.gwt.util.tools.ArgHandlerOutDir; -import com.google.gwt.util.tools.ArgHandlerString; -import com.google.gwt.util.tools.ToolBase; -import com.google.gwt.util.tools.Utility; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import com.google.gwt.user.tools.WebAppCreator; /** - * Tool to create JUnit test case. + * Legacy JUnitCreator that will let users know that they should run + * {...@link WebAppCreator} instead. * */ -public final class JUnitCreator extends ToolBase { - - /** - * Arg Handler for <code>JUnitCreator</code>. - */ - protected class ArgHandlerTestClass extends ArgHandlerExtra { - - @Override - public boolean addExtraArg(String arg) { - if (fullClassName != null) { - System.err.println("Too many arguments."); - return false; - } - - // Check className for certain properties - if (!arg.matches("[\\w\\$]+(\\.[\\w\\$]+)+")) { - System.err.println("'" - + arg - + "' does not appear to be a valid fully-qualified Java class name."); - return false; - } - - // Check out the class name. - // - if (arg.indexOf('$') != -1) { - System.err.println("'" + arg - + "': This version of the tool does not support nested classes"); - return false; - } - - String[] parts = arg.split("\\."); - if (parts.length < 2) { - System.err.println("'" + arg - + "': Cannot live in the root package. Please specify a package."); - return false; - } - - fullClassName = arg; - return true; - } - - @Override - public String getPurpose() { - return "The fully-qualified name of the test class to create"; - } - - @Override - public String[] getTagArgs() { - return new String[] {"className"}; - } - - @Override - public boolean isRequired() { - return true; - } - } - - private static final String PACKAGE_PATH; - - static { - String path = JUnitCreator.class.getName(); - path = path.substring(0, path.lastIndexOf('.') + 1); - PACKAGE_PATH = path.replace('.', '/'); - } - +public final class JUnitCreator { + public static void main(String[] args) { - JUnitCreator creator = new JUnitCreator(); - if (creator.processArgs(args)) { - if (creator.run()) { - return; - } - } - + System.err.println("This application no longer exists!"); + System.err.println("Please see " + WebAppCreator.class.getName()); System.exit(1); } - - /** - * @param junitPath the path to the user's junit jar - * @param moduleName the name of the module to contain this test - * @param fullClassName Name of the fully-qualified Java class to create as an - * Application. - * @param outDir Where to put the output files - * @param eclipse The name of a project to attach a .launch config to - * @param extraClassPaths extra class path entries to add to the configuration - * @param overwrite Overwrite an existing files if they exist. - * @param ignore Ignore existing files if they exist. - * @throws IOException - */ - static void createTest(String junitPath, String moduleName, - String fullClassName, File outDir, String eclipse, - List<String> extraClassPaths, boolean overwrite, boolean ignore) - throws IOException { - - // Figure out the installation directory - String installPath = Utility.getInstallPath(); - String gwtUserPath = installPath + '/' + "gwt-user.jar"; - String gwtDevPath = installPath + '/' + "gwt-dev.jar"; - - // Check to see that the passed extra path/module arguments are valid. - if (!CreatorUtilities.validatePathsAndModules(gwtUserPath, extraClassPaths, - null)) { - return; - } - - // Figure out what platform we're on - // - boolean isWindows = gwtDevPath.substring(gwtDevPath.lastIndexOf('/') + 1).indexOf( - "windows") >= 0; - boolean isMacOsX = gwtDevPath.substring(gwtDevPath.lastIndexOf('/') + 1).indexOf( - "mac") >= 0; - - // If the path from here to the install directory is relative, we need to - // set specific "base" directory tags; this is for sample generation during - // the build. - String basePathEnv; - if (!new File(installPath).isAbsolute()) { - if (isWindows) { - basePathEnv = "%~dp0\\"; - } else { - basePathEnv = "$APPDIR/"; - } - } else { - basePathEnv = ""; - } - - // Check if junit path is absolute, add base if needed - if (!new File(junitPath).isAbsolute() - && junitPath.charAt(0) != File.separatorChar) { - if (isWindows) { - junitPath = "%~dp0\\" + junitPath; - } else { - junitPath = "$APPDIR/" + junitPath; - } - } - - // Check out the class and package names. - // - int pos = fullClassName.lastIndexOf('.'); - String clientPackageName = fullClassName.substring(0, pos); - String className = fullClassName.substring(pos + 1); - - // Is the requested moduleName in a parent package of the clientPackage? - // - pos = moduleName.lastIndexOf('.'); - if (pos >= 0) { - String modulePackageName = moduleName.substring(0, pos); - if (modulePackageName.length() == clientPackageName.length() - || !clientPackageName.startsWith(modulePackageName + '.')) { - System.err.println("Warning: '" + modulePackageName - + "' is not a parent package of '" + clientPackageName - + "'. The source for '" + className + "' may be unavailable."); - } - } - - // Compute module name and directories - // - pos = clientPackageName.lastIndexOf('.'); - File clientDir = Utility.getDirectory(outDir, "test", true); - if (pos >= 0) { - String clientPackage = clientPackageName.replace('.', '/'); - clientDir = Utility.getDirectory(clientDir, clientPackage, true); - } - - // Create a map of replacements - // - Map<String, String> replacements = new HashMap<String, String>(); - replacements.put("@className", className); - replacements.put("@moduleName", moduleName); - replacements.put("@clientPackage", clientPackageName); - replacements.put("@junitPath", junitPath); - replacements.put("@gwtUserPath", basePathEnv + gwtUserPath); - replacements.put("@gwtDevPath", basePathEnv + gwtDevPath); - replacements.put("@vmargs", isMacOsX ? "-XstartOnFirstThread" : ""); - replacements.put("@eclipseExtraLaunchPaths", - CreatorUtilities.createEclipseExtraLaunchPaths(extraClassPaths)); - replacements.put("@extraClassPathsColon", CreatorUtilities.appendPaths(":", - extraClassPaths)); - replacements.put("@extraClassPathsSemicolon", CreatorUtilities.appendPaths(";", extraClassPaths)); - - { - // Create a skeleton Test class - File javaClass = Utility.createNormalFile(clientDir, className + ".java", - overwrite, ignore); - if (javaClass != null) { - String out = Utility.getFileFromClassPath(PACKAGE_PATH - + "JUnitClassTemplate.javasrc"); - Utility.writeTemplateFile(javaClass, out, replacements); - } - } - - if (eclipse != null) { - // Create an eclipse launch config - replacements.put("@projectName", eclipse); - - File hostedConfig = Utility.createNormalFile(outDir, className - + "-hosted.launch", overwrite, ignore); - if (hostedConfig != null) { - String out = Utility.getFileFromClassPath(PACKAGE_PATH - + "JUnit-hosted.launchsrc"); - Utility.writeTemplateFile(hostedConfig, out, replacements); - } - - File webConfig = Utility.createNormalFile(outDir, className - + "-web.launch", overwrite, ignore); - if (webConfig != null) { - String out = Utility.getFileFromClassPath(PACKAGE_PATH - + "JUnit-web.launchsrc"); - Utility.writeTemplateFile(webConfig, out, replacements); - } - } - - // create startup files - String extension; - if (isWindows) { - extension = ".cmd"; - } else { - extension = ""; - } - - File junitHosted = Utility.createNormalFile(outDir, className + "-hosted" - + extension, overwrite, ignore); - if (junitHosted != null) { - String out = Utility.getFileFromClassPath(PACKAGE_PATH + "junit-hosted" - + extension + "src"); - Utility.writeTemplateFile(junitHosted, out, replacements); - if (extension.length() == 0) { - Runtime.getRuntime().exec("chmod u+x " + junitHosted.getAbsolutePath()); - } - } - - File junitWeb = Utility.createNormalFile(outDir, className + "-web" - + extension, overwrite, ignore); - if (junitWeb != null) { - String out = Utility.getFileFromClassPath(PACKAGE_PATH + "junit-web" - + extension + "src"); - Utility.writeTemplateFile(junitWeb, out, replacements); - if (extension.length() == 0) { - Runtime.getRuntime().exec("chmod u+x " + junitWeb.getAbsolutePath()); - } - } - } - - private String eclipse = null; - - private String fullClassName = null; - - private boolean ignore = false; - private String junitPath = null; - private String moduleName = null; - private File outDir; - private boolean overwrite = false; - private ArgHandlerAddToClassPath classPathHandler = new ArgHandlerAddToClassPath(); - - protected JUnitCreator() { - - registerHandler(new ArgHandlerString() { - - @Override - public String[] getDefaultArgs() { - return null; - } - - @Override - public String getPurpose() { - return "Specifies the path to your junit.jar (required)"; - } - - @Override - public String getTag() { - return "-junit"; - } - - @Override - public String[] getTagArgs() { - return new String[] {"pathToJUnitJar"}; - } - - @Override - public boolean isRequired() { - return true; - } - - @Override - public boolean setString(String str) { - File f = new File(str); - if (!f.exists() || !f.isFile()) { - System.err.println("File not found: " + str); - return false; - } - junitPath = str; - return true; - } - }); - - registerHandler(new ArgHandlerString() { - - @Override - public String[] getDefaultArgs() { - return null; - } - - @Override - public String getPurpose() { - return "Specifies the name of the GWT module to use (required)"; - } - - @Override - public String getTag() { - return "-module"; - } - - @Override - public String[] getTagArgs() { - return new String[] {"moduleName"}; - } - - @Override - public boolean isRequired() { - return true; - } - - @Override - public boolean setString(String str) { - moduleName = str; - return true; - } - }); - - registerHandler(new ArgHandlerEclipse() { - @Override - public String getPurpose() { - return "Creates a debug launch config for the named eclipse project"; - } - - @Override - public boolean setString(String str) { - eclipse = str; - return true; - } - }); - - registerHandler(new ArgHandlerOutDir() { - - @Override - public void setDir(File dir) { - outDir = dir; - } - }); - - registerHandler(new ArgHandlerOverwrite() { - - @Override - public boolean setFlag() { - if (ignore) { - System.err.println("-overwrite cannot be used with -ignore."); - return false; - } - overwrite = true; - return true; - } - }); - - registerHandler(new ArgHandlerIgnore() { - - @Override - public boolean setFlag() { - if (overwrite) { - System.err.println("-ignore cannot be used with -overwrite."); - return false; - } - ignore = true; - return true; - } - }); - - registerHandler(new ArgHandlerTestClass()); - registerHandler(classPathHandler); - } - - protected boolean run() { - try { - createTest(junitPath, moduleName, fullClassName, outDir, eclipse, - classPathHandler.getExtraClassPathList(), overwrite, ignore); - return true; - } catch (IOException e) { - System.err.println(e.getClass().getName() + ": " + e.getMessage()); - return false; - } - } -} +} ======================================= --- /trunk/user/src/com/google/gwt/user/tools/README.txtsrc Mon Nov 16 14:42:51 2009 +++ /trunk/user/src/com/google/gwt/user/tools/README.txtsrc Wed Nov 18 17:52:02 2009 @@ -33,6 +33,9 @@ You can now use the built-in debugger to debug your web app in development mode. +If you supplied the junit path when invoking webAppCreator, you should see +launch configurations for running your tests in development and production +mode. -- Option B: Build from the command line with Ant -- @@ -48,6 +51,9 @@ To compile and also bundle into a .war file, type 'ant war'. +If you supplied the junit path when invoking webAppCreator, you can type 'ant +test' to run tests in development and production mode. + For a full listing of other targets, type 'ant -p'. -- Option C: Using another IDE -- ======================================= --- /trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java Wed Nov 18 11:33:25 2009 +++ /trunk/user/src/com/google/gwt/user/tools/WebAppCreator.java Wed Nov 18 17:52:02 2009 @@ -27,6 +27,7 @@ import com.google.gwt.util.tools.ArgHandlerExtra; import com.google.gwt.util.tools.ArgHandlerFlag; import com.google.gwt.util.tools.ArgHandlerOutDir; +import com.google.gwt.util.tools.ArgHandlerString; import com.google.gwt.util.tools.Utility; import java.io.File; @@ -61,6 +62,7 @@ registerHandler(new ArgHandlerOutDirExtension()); registerHandler(new ArgHandlerNoEclipse()); registerHandler(new ArgHandlerOnlyEclipse()); + registerHandler(new ArgHandlerJUnitPath()); } @Override @@ -173,6 +175,45 @@ return true; } } + + private final class ArgHandlerJUnitPath extends ArgHandlerString { + + @Override + public String[] getDefaultArgs() { + return null; + } + + @Override + public String getPurpose() { + return "Specifies the path to your junit.jar (optional)"; + } + + @Override + public String getTag() { + return "-junit"; + } + + @Override + public String[] getTagArgs() { + return new String[] {"pathToJUnitJar"}; + } + + @Override + public boolean isRequired() { + return false; + } + + @Override + public boolean setString(String str) { + File f = new File(str); + if (!f.exists() || !f.isFile()) { + System.err.println("File not found: " + str); + return false; + } + junitPath = str; + return true; + } + } private static final class FileCreator { private final File destDir; @@ -203,6 +244,7 @@ private boolean onlyEclipse; private File outDir; private boolean overwrite = false; + private String junitPath = null; /** * Create the sample app. @@ -225,13 +267,19 @@ gwtModuleDtd = "\n<!DOCTYPE module PUBLIC \"-//Google Inc.//DTD Google Web Toolkit " + About.getGwtVersionNum() + "//EN\" \"http://google-web-toolkit.googlecode.com/svn/tags/" - + About.getGwtVersionNum() + "/distro-source/core/src/gwt-module.dtd\">"; + + About.getGwtVersionNum() + + "/distro-source/core/src/gwt-module.dtd\">"; } // Compute module package and name. int pos = moduleName.lastIndexOf('.'); String modulePackageName = moduleName.substring(0, pos); String moduleShortName = moduleName.substring(pos + 1); + + // pro-actively let user know that this script can also create tests. + if (junitPath == null) { + System.err.println("Not creating tests because -junit argument was not specified.\n"); + } // Compute module name and directories File srcDir = Utility.getDirectory(outDir, "src", true); @@ -242,6 +290,8 @@ '.', '/'), true); File clientDir = Utility.getDirectory(moduleDir, "client", true); File serverDir = Utility.getDirectory(moduleDir, "server", true); + File clientTestDir = Utility.getDirectory(outDir, "test/" + + modulePackageName.replace('.', '/') + "/client", true); // Create a map of replacements Map<String, String> replacements = new HashMap<String, String>(); @@ -280,6 +330,26 @@ } replacements.put("@antEclipseRule", antEclipseRule); + { + String testTargetsBegin = ""; + String testTargetsEnd = ""; + String junitJarPath = junitPath; + String eclipseTestDir = ""; + if (junitPath != null) { + eclipseTestDir = "\n <classpathentry kind=\"src\" path=\"test\"/>"; + } else { + testTargetsBegin = "\n<!--" + + "\n" + + "Test targets suppressed because -junit argument was not specified when running webAppCreator.\n"; + testTargetsEnd = "-->\n"; + junitJarPath = "path_to_the_junit_jar"; + } + replacements.put("@testTargetsBegin", testTargetsBegin); + replacements.put("@testTargetsEnd", testTargetsEnd); + replacements.put("@junitJar", junitJarPath); + replacements.put("@eclipseTestDir", eclipseTestDir); + } + List<FileCreator> files = new ArrayList<FileCreator>(); List<FileCreator> libs = new ArrayList<FileCreator>(); if (!onlyEclipse) { @@ -299,6 +369,11 @@ "RpcServerTemplate.java")); files.add(new FileCreator(outDir, "build.xml", "project.ant.xml")); files.add(new FileCreator(outDir, "README.txt", "README.txt")); + if (junitPath != null) { + // create the test file. + files.add(new FileCreator(clientTestDir, moduleShortName + "Test" + + ".java", "JUnitClassTemplate.java")); + } } if (!noEclipse) { assert new File(gwtDevPath).isAbsolute(); @@ -307,6 +382,12 @@ files.add(new FileCreator(outDir, ".classpath", ".classpath")); files.add(new FileCreator(outDir, moduleShortName + ".launch", "App.launch")); + if (junitPath != null) { + files.add(new FileCreator(outDir, moduleShortName + "Test-dev.launch", + "JUnit-dev.launch")); + files.add(new FileCreator(outDir, moduleShortName + "Test-prod.launch", + "JUnit-prod.launch")); + } } // copy source files, replacing the content as needed ======================================= --- /trunk/user/src/com/google/gwt/user/tools/project.ant.xmlsrc Wed Nov 18 11:33:25 2009 +++ /trunk/user/src/com/google/gwt/user/tools/project.ant.xmlsrc Wed Nov 18 17:52:02 2009 @@ -56,7 +56,63 @@ <arg value="@moduleName"/> </java> </target>@antEclipseRule - +...@testtargetsbegin + <target name="javac.tests" depends="javac" description="Compiles test code"> + <javac srcdir="test" includes="**" encoding="utf-8" + source="1.5" target="1.5" nowarn="true" + debug="true" debuglevel="lines,vars,source"> + <classpath location="@junitJar"/> + <classpath refid="project.class.path"/> + </javac> + </target> + + <target name="test.dev" depends="javac.tests" description="Run development mode tests"> + <mkdir dir="reports/htmlunit.dev" /> + <junit fork="yes" printsummary="yes" haltonfailure="yes"> + <jvmarg line="-Xmx256m" /> + <sysproperty key="gwt.args" value="-logLevel WARN" /> + <sysproperty key="java.awt.headless" value="true" /> + <classpath> + <pathelement location="test" /> + <path refid="project.class.path" /> + <pathelement location="@junitJar" /> + </classpath> + <batchtest todir="reports/htmlunit.dev" > + <fileset dir="test" > + <include name="**/*Test.java" /> + </fileset> + </batchtest> + <formatter type="plain" /> + <formatter type="xml" /> + </junit> + </target> + + <target name="test.prod" depends="javac.tests" description="Run production mode tests"> + <mkdir dir="reports/htmlunit.prod" /> + <junit fork="yes" printsummary="yes" haltonfailure="yes"> + <jvmarg line="-Xmx256m" /> + <sysproperty key="gwt.args" value="-web -logLevel WARN -out www-test" /> + <sysproperty key="java.awt.headless" value="true" /> + <classpath> + <pathelement location="test" /> + <path refid="project.class.path" /> + <pathelement location="@junitJar" /> + </classpath> + <batchtest todir="reports/htmlunit.prod" > + <fileset dir="test" > + <include name="**/*Test.java" /> + </fileset> + </batchtest> + <formatter type="plain" /> + <formatter type="xml" /> + </junit> + </target> + + <target name="test" description="Run development and production mode tests"> + <antcall target="test.dev" /> + <antcall target="test.prod" /> + </target> +...@testtargetsend <target name="hosted" depends="devmode" description="Run development mode (NOTE: the 'hosted' target is deprecated)" /> <target name="build" depends="gwtc" description="Build this project" /> -- http://groups.google.com/group/Google-Web-Toolkit-Contributors