Rolled junitCreator into webAppCreator.
Patch by: amitmanjhi
Review by: rjrjr (desk review)
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7019 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/distro-source/mac/src/junitCreator b/distro-source/mac/src/junitCreator
deleted file mode 100644
index fee4e42..0000000
--- a/distro-source/mac/src/junitCreator
+++ /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 "$@";
diff --git a/distro-source/src/junitCreator b/distro-source/src/junitCreator
deleted file mode 100755
index df2655f..0000000
--- a/distro-source/src/junitCreator
+++ /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 "$@";
diff --git a/distro-source/src/junitCreator.cmd b/distro-source/src/junitCreator.cmd
deleted file mode 100755
index b8cebe8..0000000
--- a/distro-source/src/junitCreator.cmd
+++ /dev/null
@@ -1 +0,0 @@
-@java -cp "%~dp0\gwt-user.jar;%~dp0\gwt-dev.jar" com.google.gwt.junit.tools.JUnitCreator %*
diff --git a/user/src/com/google/gwt/junit/tools/JUnit-hosted.launchsrc b/user/src/com/google/gwt/junit/tools/JUnit-hosted.launchsrc
deleted file mode 100644
index eea3a6b..0000000
--- a/user/src/com/google/gwt/junit/tools/JUnit-hosted.launchsrc
+++ /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="@clientPackage.@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>
diff --git a/user/src/com/google/gwt/junit/tools/JUnitCreator.java b/user/src/com/google/gwt/junit/tools/JUnitCreator.java
index 281a104..f0bbb53 100644
--- a/user/src/com/google/gwt/junit/tools/JUnitCreator.java
+++ b/user/src/com/google/gwt/junit/tools/JUnitCreator.java
@@ -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;
- }
- }
}
diff --git a/user/src/com/google/gwt/junit/tools/junit-hosted.cmdsrc b/user/src/com/google/gwt/junit/tools/junit-hosted.cmdsrc
deleted file mode 100644
index 37b2d96..0000000
--- a/user/src/com/google/gwt/junit/tools/junit-hosted.cmdsrc
+++ /dev/null
@@ -1 +0,0 @@
-@java -Dgwt.args="-out www-test" -Xmx256M -cp "%~dp0\src;%~dp0\test;%~dp0\war\WEB-INF\classes;@junitPath;@gwtUserPath;@gwtDevPath@extraClassPathsSemicolon" junit.textui.TestRunner @clientPackage.@className %*
\ No newline at end of file
diff --git a/user/src/com/google/gwt/junit/tools/junit-hostedsrc b/user/src/com/google/gwt/junit/tools/junit-hostedsrc
deleted file mode 100644
index 81bd88b..0000000
--- a/user/src/com/google/gwt/junit/tools/junit-hostedsrc
+++ /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:@gwtDevPath@extraClassPathsColon" junit.textui.TestRunner @clientPackage.@className "$@";
diff --git a/user/src/com/google/gwt/junit/tools/junit-web.cmdsrc b/user/src/com/google/gwt/junit/tools/junit-web.cmdsrc
deleted file mode 100644
index 7f88577..0000000
--- a/user/src/com/google/gwt/junit/tools/junit-web.cmdsrc
+++ /dev/null
@@ -1 +0,0 @@
-@java -Dgwt.args="-web -out www-test" -Xmx256M -cp "%~dp0\src;%~dp0\test;%~dp0\war\WEB-INF\classes;@junitPath;@gwtUserPath;@gwtDevPath@extraClassPathsSemicolon" junit.textui.TestRunner @clientPackage.@className %*
\ No newline at end of file
diff --git a/user/src/com/google/gwt/junit/tools/junit-websrc b/user/src/com/google/gwt/junit/tools/junit-websrc
deleted file mode 100644
index d938d34..0000000
--- a/user/src/com/google/gwt/junit/tools/junit-websrc
+++ /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:@gwtDevPath@extraClassPathsColon" junit.textui.TestRunner @clientPackage.@className "$@";
diff --git a/user/src/com/google/gwt/user/tools/.classpathsrc b/user/src/com/google/gwt/user/tools/.classpathsrc
deleted file mode 100644
index 570ab72..0000000
--- a/user/src/com/google/gwt/user/tools/.classpathsrc
+++ /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>
diff --git a/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc b/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc
similarity index 74%
rename from user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc
rename to user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc
index 97eff72..e3871ed 100644
--- a/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc
+++ b/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc
@@ -2,17 +2,16 @@
<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="@clientPackage.@className"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientPackage.@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="@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 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"/> "/>
-@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"/>
+<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>
diff --git a/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc b/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc
similarity index 74%
copy from user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc
copy to user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc
index 97eff72..fde54fe 100644
--- a/user/src/com/google/gwt/junit/tools/JUnit-web.launchsrc
+++ b/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc
@@ -2,17 +2,16 @@
<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="@clientPackage.@className"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@clientPackage.@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="@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 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"/> "/>
-@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"/>
+<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>
diff --git a/user/src/com/google/gwt/junit/tools/JUnitClassTemplate.javasrc b/user/src/com/google/gwt/user/tools/JUnitClassTemplate.javasrc
similarity index 86%
rename from user/src/com/google/gwt/junit/tools/JUnitClassTemplate.javasrc
rename to user/src/com/google/gwt/user/tools/JUnitClassTemplate.javasrc
index 17e3973..25a6a58 100644
--- a/user/src/com/google/gwt/junit/tools/JUnitClassTemplate.javasrc
+++ b/user/src/com/google/gwt/user/tools/JUnitClassTemplate.javasrc
@@ -5,7 +5,7 @@
/**
* GWT JUnit tests must extend GWTTestCase.
*/
-public class @className extends GWTTestCase {
+public class @moduleShortNameTest extends GWTTestCase {
/**
* Must refer to a valid module that sources this class.
diff --git a/user/src/com/google/gwt/user/tools/README.txtsrc b/user/src/com/google/gwt/user/tools/README.txtsrc
index 4bd8a3a..bdf4521 100644
--- a/user/src/com/google/gwt/user/tools/README.txtsrc
+++ b/user/src/com/google/gwt/user/tools/README.txtsrc
@@ -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 --
diff --git a/user/src/com/google/gwt/user/tools/WebAppCreator.java b/user/src/com/google/gwt/user/tools/WebAppCreator.java
index 0ff763f..ab20988 100644
--- a/user/src/com/google/gwt/user/tools/WebAppCreator.java
+++ b/user/src/com/google/gwt/user/tools/WebAppCreator.java
@@ -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
@@ -174,6 +176,45 @@
}
}
+ 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;
private final String destName;
@@ -203,6 +244,7 @@
private boolean onlyEclipse;
private File outDir;
private boolean overwrite = false;
+ private String junitPath = null;
/**
* Create the sample app.
@@ -225,7 +267,8 @@
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.
@@ -233,6 +276,11 @@
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);
File warDir = Utility.getDirectory(outDir, "war", 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
diff --git a/user/src/com/google/gwt/user/tools/project.ant.xmlsrc b/user/src/com/google/gwt/user/tools/project.ant.xmlsrc
index 27a224f..36a2af1 100644
--- a/user/src/com/google/gwt/user/tools/project.ant.xmlsrc
+++ b/user/src/com/google/gwt/user/tools/project.ant.xmlsrc
@@ -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" />