Revision: 8207
Author: jlaba...@google.com
Date: Tue May 25 06:21:53 2010
Log: This patch adds to webAppCreator the ability to create maven configuration file (issue 4878). Also fixes issue 4652 where build.xml compiles test classes in the same directory as the source. Adds tests to WebAppCreator.
http://gwt-code-reviews.appspot.com/397801/show

Author: manolo.carrasco
Review by: jlabanca

http://code.google.com/p/google-web-toolkit/source/detail?r=8207

Added:
 /branches/2.1/user/src/com/google/gwt/user/tools/project.maven.xmlsrc
 /branches/2.1/user/test/com/google/gwt/user/tools
 /branches/2.1/user/test/com/google/gwt/user/tools/ToolsSuite.java
 /branches/2.1/user/test/com/google/gwt/user/tools/WebAppCreatorTest.java
Modified:
 /branches/2.1/dev/core/src/com/google/gwt/dev/ArgProcessorBase.java
 /branches/2.1/dev/core/src/com/google/gwt/util/tools/ToolBase.java
 /branches/2.1/user/src/com/google/gwt/user/tools/.classpathsrc
 /branches/2.1/user/src/com/google/gwt/user/tools/App.launchsrc
 /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc
 /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc
 /branches/2.1/user/src/com/google/gwt/user/tools/README.txtsrc
 /branches/2.1/user/src/com/google/gwt/user/tools/WebAppCreator.java
 /branches/2.1/user/src/com/google/gwt/user/tools/project.ant.xmlsrc

=======================================
--- /dev/null
+++ /branches/2.1/user/src/com/google/gwt/user/tools/project.maven.xmlsrc Tue May 25 06:21:53 2010
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>
+
+  <!-- POM file generated with GWT webAppCreator -->
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>@modulePackageName</groupId>
+  <artifactId>@moduleShortName</artifactId>
+  <packaging>war</packaging>
+  <version>1.0-SNAPSHOT</version>
+  <name>@moduleName</name>
+
+  <properties>
+      <!-- Convenience property to set the GWT version -->
+      <gwtVersion>@gwtVersion</gwtVersion>
+      <!-- GWT needs at least java 1.5 -->
+      <maven.compiler.source>1.5</maven.compiler.source>
+      <maven.compiler.target>1.5</maven.compiler.target>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>com.google.gwt</groupId>
+      <artifactId>gwt-servlet</artifactId>
+      <version>${gwtVersion}</version>
+      <scope>runtime</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.gwt</groupId>
+      <artifactId>gwt-user</artifactId>
+      <version>${gwtVersion}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.google.gwt</groupId>
+      <artifactId>gwt-dev</artifactId>
+      <version>${gwtVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.4</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <!-- Generate compiled stuff in the folder used for developing mode -->
+    <outputDirectory>target/www/WEB-INF/classes</outputDirectory>
+
+    <plugins>
+
+      <!-- GWT Maven Plugin-->
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>gwt-maven-plugin</artifactId>
+ <!-- JS is only needed in the package phase, this speeds up testing -->
+        <executions>
+          <execution>
+            <phase>prepare-package</phase>
+            <goals>
+              <goal>compile</goal>
+            </goals>
+          </execution>
+        </executions>
+        <!-- Plugin configuration. There are many available options,
+             see gwt-maven-plugin documentation at codehaus.org -->
+        <configuration>
+ <!-- URL that should be automatically opened in the GWT shell (gwt:run). -->
+          <runTarget>@moduleShortName.html</runTarget>
+ <!-- Location of the develop-mode web application structure (gwt:run). -->
+          <hostedWebapp>target/www</hostedWebapp>
+ <!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
+          <soyc>true</soyc>
+        </configuration>
+      </plugin>
+
+ <!-- Add source folders to test classpath in order to run gwt-tests as normal junit-tests -->
+      <plugin>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <additionalClasspathElements>
+ <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement> + <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
+          </additionalClasspathElements>
+          <useManifestOnlyJar>false</useManifestOnlyJar>
+          <forkMode>always</forkMode>
+
+          <!-- Folder for generated testing stuff -->
+          <systemProperties>
+            <property>
+              <name>gwt.args</name>
+              <value>-out target/www</value>
+            </property>
+          </systemProperties>
+        </configuration>
+      </plugin>
+
+      <!-- Copy static web files before executing gwt:run -->
+      <plugin>
+        <artifactId>maven-resources-plugin</artifactId>
+        <executions>
+          <execution>
+            <phase>compile</phase>
+            <goals>
+              <goal>copy-resources</goal>
+            </goals>
+            <configuration>
+              <outputDirectory>target/www</outputDirectory>
+              <resources>
+                <resource>
+                  <directory>src/main/webapp</directory>
+                </resource>
+              </resources>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+
+      <!-- Delete gwt generated stuff -->
+      <plugin>
+        <artifactId>maven-clean-plugin</artifactId>
+        <configuration>
+          <filesets>
+ <fileset><directory>src/main/webapp/@renameTo</directory></fileset> + <fileset><directory>src/main/webapp/WEB-INF/classes</directory></fileset>
+            <fileset><directory>tomcat</directory></fileset>
+            <fileset><directory>www-test</directory></fileset>
+            <fileset><directory>.gwt-tmp</directory></fileset>
+          </filesets>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+</project>
+
+
=======================================
--- /dev/null
+++ /branches/2.1/user/test/com/google/gwt/user/tools/ToolsSuite.java Tue May 25 06:21:53 2010
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.user.tools;
+
+import com.google.gwt.junit.tools.GWTTestSuite;
+
+import junit.framework.Test;
+
+/**
+ * Tests of the tools package.
+ */
+public class ToolsSuite {
+  public static Test suite() {
+    GWTTestSuite suite = new GWTTestSuite("Test for suite for tools");
+    suite.addTestSuite(WebAppCreatorTest.class);
+    return suite;
+  }
+}
=======================================
--- /dev/null
+++ /branches/2.1/user/test/com/google/gwt/user/tools/WebAppCreatorTest.java Tue May 25 06:21:53 2010
@@ -0,0 +1,310 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.user.tools;
+
+import com.google.gwt.user.tools.WebAppCreator.ArgProcessor;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Test Class for WebAppCreator.
+ */
+public class WebAppCreatorTest extends TestCase {
+
+  private static final String MY_PROJECT = "com.foo.Hello";
+  private String mockJar;
+  private String projectFolder;
+  private File tempFolder;
+  private String tempPath;
+
+  @Override
+  public void setUp() throws Exception {
+    // Create a temporary folder for the test
+    tempFolder = File.createTempFile("gwt-test-webappcreator-", "");
+    assertTrue(tempFolder.delete());
+    assertTrue(tempFolder.mkdir());
+    tempPath = tempFolder.getAbsolutePath();
+
+    // Generate an empty .jar
+    mockJar = tempPath + File.separatorChar + "mock-junit.jar";
+    assertTrue(new File(mockJar).createNewFile());
+
+    // Verify that project folder doesn't exist
+    projectFolder = tempPath + File.separatorChar + "project";
+    assertFalse(new File(projectFolder).exists());
+  }
+
+  @Override
+  public void tearDown() {
+    // Delete temporary folder
+    deleteDir(tempFolder);
+  }
+
+  /**
+   * Default options, generate ant and eclipse files.
+   */
+  public void testAppCreatorAnt() throws IOException {
+    runCreator("-out", projectFolder, MY_PROJECT);
+    assertFileExists(".project");
+    assertFileExists(".classpath");
+    assertFileExists("build.xml");
+    assertFileExists("README.txt");
+    assertFileExists("Hello.launch");
+    assertFileExists("war/Hello.html");
+    assertFileExists("war/Hello.css");
+    assertFileExists("war/WEB-INF/web.xml");
+    assertFileExists("src/com/foo/Hello.gwt.xml");
+    assertFileExists("src/com/foo/client/GreetingServiceAsync.java");
+    assertFileExists("src/com/foo/client/GreetingService.java");
+    assertFileExists("src/com/foo/client/Hello.java");
+    assertFileExists("src/com/foo/shared/FieldVerifier.java");
+    assertFileExists("src/com/foo/server/GreetingServiceImpl.java");
+    assertFileDoesNotExist("HelloTest-dev.launch");
+    assertFileDoesNotExist("HelloTest-prod.launch");
+    assertFileDoesNotExist("test/com/foo/HelloJUnit.gwt.xml");
+    assertFileDoesNotExist("test/com/foo/client/HelloTest.java");
+  }
+
+  /**
+   * Adding a valid junit.jar, the test stuff is generated.
+   */
+  public void testCreatorAntJunit() throws IOException {
+    runCreator("-out", projectFolder, "-junit", mockJar, MY_PROJECT);
+    assertFileExists(".project");
+    assertFileExists(".classpath");
+    assertFileExists("build.xml");
+    assertFileExists("README.txt");
+    assertFileExists("Hello.launch");
+    assertFileExists("HelloTest-dev.launch");
+    assertFileExists("HelloTest-prod.launch");
+    assertFileExists("war/Hello.html");
+    assertFileExists("war/Hello.css");
+    assertFileExists("war/WEB-INF/web.xml");
+    assertFileExists("src/com/foo/Hello.gwt.xml");
+    assertFileExists("src/com/foo/client/GreetingServiceAsync.java");
+    assertFileExists("src/com/foo/client/GreetingService.java");
+    assertFileExists("src/com/foo/client/Hello.java");
+    assertFileExists("src/com/foo/shared/FieldVerifier.java");
+    assertFileExists("src/com/foo/server/GreetingServiceImpl.java");
+    assertFileExists("test/com/foo/HelloJUnit.gwt.xml");
+    assertFileExists("test/com/foo/client/HelloTest.java");
+  }
+
+  /**
+   * Check illegal argument combinations.
+   */
+  public void testCreatorBadArguments() {
+
+    ArgProcessor argProcessor = new WebAppCreator().new ArgProcessor();
+    assertFalse(argProcessor.processArgs("-out", projectFolder,
+        "unknown_parameter", MY_PROJECT));
+
+    argProcessor = new WebAppCreator().new ArgProcessor();
+    assertFalse(argProcessor.processArgs("-out", projectFolder,
+        "wrong_project_name"));
+
+    argProcessor = new WebAppCreator().new ArgProcessor();
+    assertFalse(argProcessor.processArgs("-out", projectFolder, "-ignore",
+        "-overwrite", MY_PROJECT));
+
+    argProcessor = new WebAppCreator().new ArgProcessor();
+ assertFalse(argProcessor.processArgs("-out", projectFolder, "-overwrite",
+        "-ignore", MY_PROJECT));
+  }
+
+  /**
+   * Do not generate eclipse files.
+   */
+  public void testCreatorNoAnt() throws IOException {
+ runCreator("-out", projectFolder, "-noant", "-junit", mockJar, MY_PROJECT);
+    assertFileExists(".project");
+    assertFileExists(".classpath");
+    assertFileDoesNotExist("build.xml");
+    assertFileExists("README.txt");
+    assertFileExists("Hello.launch");
+    assertFileExists("HelloTest-dev.launch");
+    assertFileExists("HelloTest-prod.launch");
+    assertFileExists("war/Hello.html");
+    assertFileExists("war/Hello.css");
+    assertFileExists("war/WEB-INF/web.xml");
+    assertFileExists("src/com/foo/Hello.gwt.xml");
+    assertFileExists("src/com/foo/client/GreetingServiceAsync.java");
+    assertFileExists("src/com/foo/client/GreetingService.java");
+    assertFileExists("src/com/foo/client/Hello.java");
+    assertFileExists("src/com/foo/shared/FieldVerifier.java");
+    assertFileExists("src/com/foo/server/GreetingServiceImpl.java");
+    assertFileExists("test/com/foo/HelloJUnit.gwt.xml");
+    assertFileExists("test/com/foo/client/HelloTest.java");
+  }
+
+  /**
+   * Do not generate eclipse files.
+   */
+  public void testCreatorNoEclipse() throws IOException {
+    runCreator("-out", projectFolder, "-XnoEclipse", "-junit", mockJar,
+        MY_PROJECT);
+    assertFileDoesNotExist(".project");
+    assertFileDoesNotExist(".classpath");
+    assertFileExists("build.xml");
+    assertFileExists("README.txt");
+    assertFileDoesNotExist("Hello.launch");
+    assertFileDoesNotExist("HelloTest-dev.launch");
+    assertFileDoesNotExist("HelloTest-prod.launch");
+    assertFileExists("war/Hello.html");
+    assertFileExists("war/Hello.css");
+    assertFileExists("war/WEB-INF/web.xml");
+    assertFileExists("src/com/foo/Hello.gwt.xml");
+    assertFileExists("src/com/foo/client/GreetingServiceAsync.java");
+    assertFileExists("src/com/foo/client/GreetingService.java");
+    assertFileExists("src/com/foo/client/Hello.java");
+    assertFileExists("src/com/foo/shared/FieldVerifier.java");
+    assertFileExists("src/com/foo/server/GreetingServiceImpl.java");
+    assertFileExists("test/com/foo/HelloJUnit.gwt.xml");
+    assertFileExists("test/com/foo/client/HelloTest.java");
+  }
+
+  /**
+   * Generate a maven2 project. Note that -junit option is not needed.
+   */
+  public void testCreatorMaven() throws IOException {
+    runCreator("-out", projectFolder, "-maven", MY_PROJECT);
+    assertFileExists(".project");
+    assertFileExists(".classpath");
+    assertFileExists("build.xml");
+    assertFileExists("pom.xml");
+    assertFileExists("README.txt");
+    assertFileExists("src/main/java/com/foo/shared/FieldVerifier.java");
+    assertFileExists("src/main/java/com/foo/server");
+ assertFileExists("src/main/java/com/foo/server/GreetingServiceImpl.java");
+    assertFileExists("src/main/java/com/foo/Hello.gwt.xml");
+    assertFileExists("src/main/java/com/foo/client");
+    assertFileExists("src/main/java/com/foo/client/Hello.java");
+ assertFileExists("src/main/java/com/foo/client/GreetingServiceAsync.java");
+    assertFileExists("src/main/java/com/foo/client/GreetingService.java");
+    assertFileExists("src/main/webapp/Hello.html");
+    assertFileExists("src/main/webapp/Hello.css");
+    assertFileExists("src/main/webapp/WEB-INF/web.xml");
+    assertFileExists("src/test/java/com/foo/client/HelloTest.java");
+    assertFileExists("src/test/java/com/foo/HelloJUnit.gwt.xml");
+    assertFileExists("Hello.launch");
+    assertFileExists("HelloTest-dev.launch");
+    assertFileExists("HelloTest-prod.launch");
+  }
+
+  /**
+   * Running generator on existing projects.
+   */
+  public void testCreatorMultipleTimes() throws IOException {
+    // Create the project
+    runCreator("-out", projectFolder, MY_PROJECT);
+
+    // Try create the project again without -ignore nor -overwrite
+    try {
+      runCreator("-out", projectFolder, MY_PROJECT);
+      fail("webAppCreator can not be run twice");
+    } catch (IOException e) {
+    }
+
+    // Check -ignore flag
+    try {
+      runCreator("-out", projectFolder, "-ignore", MY_PROJECT);
+    } catch (IOException e) {
+ fail("webAppCreator should not faild with -ignore option when is executed twice");
+    }
+
+    // Check -overwrite flag
+    try {
+      runCreator("-out", projectFolder, "-overwrite", MY_PROJECT);
+    } catch (IOException e) {
+ fail("webAppCreator should not faild with -ignore option when is executed twice");
+    }
+  }
+
+  /**
+   * Generate only eclipse stuff.
+   */
+  public void testCreatorOnlyEclipse() throws IOException {
+    runCreator("-out", projectFolder, "-XonlyEclipse", "-junit", mockJar,
+        MY_PROJECT);
+    assertFileExists(".project");
+    assertFileExists(".classpath");
+    assertFileDoesNotExist("build.xml");
+    assertFileDoesNotExist("README.txt");
+    assertFileExists("Hello.launch");
+    assertFileExists("HelloTest-dev.launch");
+    assertFileExists("HelloTest-prod.launch");
+    assertFileDoesNotExist("war/Hello.html");
+    assertFileDoesNotExist("war/Hello.css");
+    assertFileDoesNotExist("war/WEB-INF/web.xml");
+    assertFileDoesNotExist("src/com/foo/Hello.gwt.xml");
+    assertFileDoesNotExist("src/com/foo/client/GreetingServiceAsync.java");
+    assertFileDoesNotExist("src/com/foo/client/GreetingService.java");
+    assertFileDoesNotExist("src/com/foo/client/Hello.java");
+    assertFileDoesNotExist("src/com/foo/shared/FieldVerifier.java");
+    assertFileDoesNotExist("src/com/foo/server/GreetingServiceImpl.java");
+    assertFileDoesNotExist("test/com/foo/HelloJUnit.gwt.xml");
+    assertFileDoesNotExist("test/com/foo/client/HelloTest.java");
+  }
+
+  /**
+   * Test the main method.
+   */
+  public void testMain() {
+    // This property overrides the default gwt installation path
+ // Note: this only can be set once because Utility.getInstallPath caches it
+    System.setProperty("gwt.devjar", mockJar);
+    assertTrue(WebAppCreator.doMain("-out", projectFolder, MY_PROJECT));
+    assertFalse(WebAppCreator.doMain());
+  }
+
+  private void assertFileDoesNotExist(String file) {
+ assertFalse(new File(projectFolder + File.separatorChar + file).exists());
+  }
+
+  private void assertFileExists(String file) {
+ assertTrue(new File(projectFolder + File.separatorChar + file).exists());
+  }
+
+  /**
+   * Delete a folder recursively.
+   */
+  private boolean deleteDir(File dir) {
+    if (dir.isDirectory()) {
+      String[] children = dir.list();
+      for (String child : children) {
+        if (!deleteDir(new File(dir, child))) {
+          return false;
+        }
+      }
+    }
+    return dir.delete();
+  }
+
+  /**
+   * run appWebCreator.
+   */
+  private void runCreator(String... args) throws IOException {
+    WebAppCreator creator = new WebAppCreator();
+    ArgProcessor argProcessor = creator.new ArgProcessor();
+    if (!argProcessor.processArgs(args)) {
+      throw new IllegalArgumentException();
+    }
+    creator.doRun(tempPath);
+  }
+}
=======================================
--- /branches/2.1/dev/core/src/com/google/gwt/dev/ArgProcessorBase.java Fri Jan 16 11:50:20 2009 +++ /branches/2.1/dev/core/src/com/google/gwt/dev/ArgProcessorBase.java Tue May 25 06:21:53 2010
@@ -25,7 +25,7 @@
    * Overridden to make public.
    */
   @Override
-  public final boolean processArgs(String[] args) {
+  public final boolean processArgs(String... args) {
     return super.processArgs(args);
   }

=======================================
--- /branches/2.1/dev/core/src/com/google/gwt/util/tools/ToolBase.java Tue Oct 13 16:57:19 2009 +++ /branches/2.1/dev/core/src/com/google/gwt/util/tools/ToolBase.java Tue May 25 06:21:53 2010
@@ -179,7 +179,7 @@
     }
   }

-  protected boolean processArgs(String[] args) {
+  protected boolean processArgs(String... args) {
     if (args.length > 0) {
       boolean help = false;
       if ("-help".equalsIgnoreCase(args[0])) {
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/.classpathsrc Wed Nov 18 17:59:53 2009 +++ /branches/2.1/user/src/com/google/gwt/user/tools/.classpathsrc Tue May 25 06:21:53 2010
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="utf-8" ?>
 <classpath>
-   <classpathentry kind="src" path="src"/>@eclipseTestDir
+   <classpathentry kind="src" path="@srcFolder"/>@eclipseTestDir
    <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"/>
+   <classpathentry kind="output" path="@warFolder/WEB-INF/classes"/>
 </classpath>
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/App.launchsrc Wed Nov 18 11:33:25 2009 +++ /branches/2.1/user/src/com/google/gwt/user/tools/App.launchsrc Tue May 25 06:21:53 2010
@@ -4,11 +4,11 @@
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="@shellClass"/>
 <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;@moduleShortName&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/> -<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/> +<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/@srcFolder&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/> <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento project=&quot;@moduleShortName&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>
 </listAttribute>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256M"/> -<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-startupUrl @startupUrl&#10;@moduleName"/> +<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-war @warFolder -startupUrl @startupUrl @moduleName"/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="@moduleShortName"/> <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
 </launchConfiguration>
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc Fri Jan 15 10:33:21 2010 +++ /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-dev.launchsrc Tue May 25 06:21:53 2010
@@ -6,8 +6,8 @@
 <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
 <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;@moduleShortName&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/> -<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> -<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/test&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> +<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/@srcFolder&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> +<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/@testFolder&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#13;&#10;&lt;memento project=&quot;@moduleShortName&quot;/&gt;&#13;&#10;&lt;/runtimeClasspathEntry&gt;&#13;&#10;"/> <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry externalArchive=&quot;@gwtDevPath&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
 </listAttribute>
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc Fri Jan 15 10:33:21 2010 +++ /branches/2.1/user/src/com/google/gwt/user/tools/JUnit-prod.launchsrc Tue May 25 06:21:53 2010
@@ -6,8 +6,8 @@
 <stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
 <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;@moduleShortName&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#13;&#10;"/> -<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/src&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> -<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/test&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> +<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/@srcFolder&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> +<listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/@moduleShortName/@testFolder&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/> <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#13;&#10;&lt;memento project=&quot;@moduleShortName&quot;/&gt;&#13;&#10;&lt;/runtimeClasspathEntry&gt;&#13;&#10;"/> <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry externalArchive=&quot;@gwtDevPath&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>
 </listAttribute>
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/README.txtsrc Wed Nov 18 17:52:02 2009 +++ /branches/2.1/user/src/com/google/gwt/user/tools/README.txtsrc Tue May 25 06:21:53 2010
@@ -67,3 +67,18 @@
folder (this is somewhat unusual but GWT needs access to your source files).

 If you get stuck, try to mimic what the Ant 'build.xml' would do.
+
+-- Option D: Using Maven --
+
+If you have generated your project with the option '-maven', you have a 'pom.xml' +file ready to use. Assuming you have 'maven2' installed in your system, 'mvn' is +in your path, and you have access to maven repositories, you should be able to run:
+
+mvn clean         # delete temporary stuff
+mvn test          # run all the tests (gwt and junit)
+mvn gwt:run       # run development mode
+mvn gwt:compile   # compile to javascript
+mvn package       # generate a .war package ready to deploy
+
+For more information about other available goals, read maven and gwt-maven-plugin +documentation (http://maven.apache.org, http://mojo.codehaus.org/gwt-maven-plugin)
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/WebAppCreator.java Wed Jan 6 12:18:02 2010 +++ /branches/2.1/user/src/com/google/gwt/user/tools/WebAppCreator.java Tue May 25 06:21:53 2010
@@ -31,9 +31,7 @@
 import com.google.gwt.util.tools.Utility;

 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -63,6 +61,8 @@
       registerHandler(new ArgHandlerNoEclipse());
       registerHandler(new ArgHandlerOnlyEclipse());
       registerHandler(new ArgHandlerJUnitPath());
+      registerHandler(new ArgHandlerMaven());
+      registerHandler(new ArgHandlerNoAnt());
     }

     @Override
@@ -214,6 +214,42 @@
       return true;
     }
   }
+
+  private final class ArgHandlerMaven extends ArgHandlerFlag {
+    @Override
+    public String getPurpose() {
+ return "Create a maven2 project structure and pom file (default disabled)";
+    }
+
+    @Override
+    public String getTag() {
+      return "-maven";
+    }
+
+    @Override
+    public boolean setFlag() {
+      maven = true;
+      return true;
+    }
+  }
+
+  private final class ArgHandlerNoAnt extends ArgHandlerFlag {
+    @Override
+    public String getPurpose() {
+      return "Do not create an ant configuration file";
+    }
+
+    @Override
+    public String getTag() {
+      return "-noant";
+    }
+
+    @Override
+    public boolean setFlag() {
+      ant = false;
+      return true;
+    }
+  }

   private static final class FileCreator {
     private final File destDir;
@@ -228,17 +264,21 @@
   }

   public static void main(String[] args) {
+    System.exit(doMain(args) ? 0 : 1);
+  }
+
+  protected static boolean doMain(String... args) {
     WebAppCreator creator = new WebAppCreator();
     ArgProcessor argProcessor = creator.new ArgProcessor();
     if (argProcessor.processArgs(args)) {
-      if (creator.run()) {
-        return;
-      }
-    }
-    System.exit(1);
+      return creator.run();
+    }
+    return false;
   }

+  private boolean ant = true;
   private boolean ignore = false;
+  private boolean maven = false;
   private String moduleName;
   private boolean noEclipse;
   private boolean onlyEclipse;
@@ -250,14 +290,24 @@
    * Create the sample app.
    *
    * @throws IOException if any disk write fails
+   * @deprecated as of GWT 2.1, replaced by {...@link #doRun(String)}
    */
+  @Deprecated
   protected void doRun() throws IOException {
-
-    // Figure out the installation directory
-    String installPath = Utility.getInstallPath();
+    doRun(Utility.getInstallPath());
+  }
+
+  /**
+   * Create the sample app.
+   *
+   * @param installPath directory containing GWT libraries
+   * @throws IOException if any disk write fails
+   */
+  protected void doRun(String installPath) throws IOException {
+
+    // GWT libraries
     String gwtUserPath = installPath + '/' + "gwt-user.jar";
     String gwtDevPath = installPath + '/' + "gwt-dev.jar";
-    String gwtServletPath = installPath + '/' + "gwt-servlet.jar";
     String gwtOophmPath = installPath + '/' + "gwt-dev-oophm.jar";

     // Public builds generate a DTD reference.
@@ -276,28 +326,31 @@
     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) {
+ // pro-actively let ant user know that this script can also create tests.
+    if (junitPath == null && !maven) {
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);
+    String srcFolder = maven ? "src/main/java" : "src";
+    String testFolder = maven ? "src/test/java" : "test";
+    String warFolder = maven ? "src/main/webapp" : "war";
+    File srcDir = Utility.getDirectory(outDir, srcFolder, true);
+    File warDir = Utility.getDirectory(outDir, warFolder, true);
     File webInfDir = Utility.getDirectory(warDir, "WEB-INF", true);
-    File libDir = Utility.getDirectory(webInfDir, "lib", true);
File moduleDir = Utility.getDirectory(srcDir, modulePackageName.replace(
         '.', '/'), true);
     File clientDir = Utility.getDirectory(moduleDir, "client", true);
     File serverDir = Utility.getDirectory(moduleDir, "server", true);
     File sharedDir = Utility.getDirectory(moduleDir, "shared", true);
-    File moduleTestDir = Utility.getDirectory(outDir, "test/"
+    File moduleTestDir = Utility.getDirectory(outDir, testFolder + "/"
         + modulePackageName.replace('.', '/'), true);
File clientTestDir = Utility.getDirectory(moduleTestDir, "client", true);

     // Create a map of replacements
     Map<String, String> replacements = new HashMap<String, String>();
     replacements.put("@moduleShortName", moduleShortName);
+    replacements.put("@modulePackageName", modulePackageName);
     replacements.put("@moduleName", moduleName);
     replacements.put("@clientPackage", modulePackageName + ".client");
     replacements.put("@serverPackage", modulePackageName + ".server");
@@ -312,6 +365,10 @@
     replacements.put("@compileClass", Compiler.class.getName());
     replacements.put("@startupUrl", moduleShortName + ".html");
     replacements.put("@renameTo", moduleShortName.toLowerCase());
+    replacements.put("@moduleNameJUnit", moduleName + "JUnit");
+    replacements.put("@srcFolder", srcFolder);
+    replacements.put("@testFolder", testFolder);
+    replacements.put("@warFolder", warFolder);

     String antEclipseRule = "";
     if (noEclipse) {
@@ -338,9 +395,11 @@
       String testTargetsEnd = "";
       String junitJarPath = junitPath;
       String eclipseTestDir = "";
-      if (junitPath != null) {
- eclipseTestDir = "\n <classpathentry kind=\"src\" path=\"test\"/>";
-      } else {
+      if (junitPath != null || maven) {
+        eclipseTestDir = "\n   <classpathentry kind=\"src\" path=\""
+            + testFolder + "\"/>";
+      }
+      if (junitPath == null) {
         testTargetsBegin = "\n<!--"
             + "\n"
+ "Test targets suppressed because -junit argument was not specified when running webAppCreator.\n";
@@ -353,8 +412,8 @@
       replacements.put("@eclipseTestDir", eclipseTestDir);
     }

+    // Create a list with the files to create
     List<FileCreator> files = new ArrayList<FileCreator>();
-    List<FileCreator> libs = new ArrayList<FileCreator>();
     if (!onlyEclipse) {
       files.add(new FileCreator(moduleDir, moduleShortName + ".gwt.xml",
           "Module.gwt.xml"));
@@ -372,9 +431,14 @@
           "RpcServerTemplate.java"));
       files.add(new FileCreator(sharedDir, "FieldVerifier.java",
           "SharedClassTemplate.java"));
-      files.add(new FileCreator(outDir, "build.xml", "project.ant.xml"));
+      if (ant) {
+        files.add(new FileCreator(outDir, "build.xml", "project.ant.xml"));
+      }
+      if (maven) {
+        files.add(new FileCreator(outDir, "pom.xml", "project.maven.xml"));
+      }
       files.add(new FileCreator(outDir, "README.txt", "README.txt"));
-      if (junitPath != null) {
+      if (junitPath != null || maven) {
         // create the test file.
         files.add(new FileCreator(moduleTestDir, moduleShortName
             + "JUnit.gwt.xml", "JUnit.gwt.xml"));
@@ -383,13 +447,11 @@
       }
     }
     if (!noEclipse) {
-      assert new File(gwtDevPath).isAbsolute();
-      libs.add(new FileCreator(libDir, "gwt-servlet.jar", gwtServletPath));
       files.add(new FileCreator(outDir, ".project", ".project"));
       files.add(new FileCreator(outDir, ".classpath", ".classpath"));
       files.add(new FileCreator(outDir, moduleShortName + ".launch",
           "App.launch"));
-      if (junitPath != null) {
+      if (junitPath != null || maven) {
files.add(new FileCreator(outDir, moduleShortName + "Test-dev.launch",
             "JUnit-dev.launch"));
files.add(new FileCreator(outDir, moduleShortName + "Test-prod.launch",
@@ -410,22 +472,11 @@
         Utility.writeTemplateFile(file, data, replacements);
       }
     }
-
-    // copy libs directly
-    for (FileCreator fileCreator : libs) {
-      FileInputStream is = new FileInputStream(fileCreator.sourceName);
-      File file = Utility.createNormalFile(fileCreator.destDir,
-          fileCreator.destName, overwrite, ignore);
-      if (file != null) {
-        FileOutputStream os = new FileOutputStream(file);
-        Util.copy(is, os);
-      }
-    }
   }

   protected boolean run() {
     try {
-      doRun();
+      doRun(Utility.getInstallPath());
       return true;
     } catch (IOException e) {
       System.err.println(e.getClass().getName() + ": " + e.getMessage());
=======================================
--- /branches/2.1/user/src/com/google/gwt/user/tools/project.ant.xmlsrc Fri Jan 29 09:46:22 2010 +++ /branches/2.1/user/src/com/google/gwt/user/tools/project.ant.xmlsrc Tue May 25 06:21:53 2010
@@ -7,40 +7,42 @@
   <property name="gwt.sdk" location="@gwtSdk" />

   <path id="project.class.path">
-    <pathelement location="war/WEB-INF/classes"/>
+    <pathelement location="@warFolder/WEB-INF/classes"/>
     <pathelement location="${gwt.sdk}/gwt-user.jar"/>
     <fileset dir="${gwt.sdk}" includes="gwt-dev*.jar"/>
     <!-- Add any additional non-server libs (such as JUnit) -->
-    <fileset dir="war/WEB-INF/lib" includes="**/*.jar"/>
+    <fileset dir="@warFolder/WEB-INF/lib" includes="**/*.jar"/>
   </path>

   <target name="libs" description="Copy libs to WEB-INF/lib">
-    <mkdir dir="war/WEB-INF/lib" />
-    <copy todir="war/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
+    <mkdir dir="@warFolder/WEB-INF/lib" />
+ <copy todir="@warFolder/WEB-INF/lib" file="${gwt.sdk}/gwt-servlet.jar" />
     <!-- Add any additional server libs that need to be copied -->
   </target>

<target name="javac" depends="libs" description="Compile java source to bytecode">
-    <mkdir dir="war/WEB-INF/classes"/>
-    <javac srcdir="src" includes="**" encoding="utf-8"
-        destdir="war/WEB-INF/classes"
+    <mkdir dir="@warFolder/WEB-INF/classes"/>
+    <javac srcdir="@srcFolder" includes="**" encoding="utf-8"
+        destdir="@warFolder/WEB-INF/classes"
         source="1.5" target="1.5" nowarn="true"
         debug="true" debuglevel="lines,vars,source">
       <classpath refid="project.class.path"/>
     </javac>
-    <copy todir="war/WEB-INF/classes">
-      <fileset dir="src" excludes="**/*.java"/>
+    <copy todir="@warFolder/WEB-INF/classes">
+      <fileset dir="@srcFolder" excludes="**/*.java"/>
     </copy>
   </target>

<target name="gwtc" depends="javac" description="GWT compile to JavaScript (production mode)">
     <java failonerror="true" fork="true" classname="@compileClass">
       <classpath>
-        <pathelement location="src"/>
+        <pathelement location="@srcFolder"/>
         <path refid="project.class.path"/>
       </classpath>
<!-- add jvmarg -Xss16M or similar if you see a StackOverflowError -->
       <jvmarg value="-Xmx256M"/>
+      <arg line="-war"/>
+      <arg value="@warFolder"/>
       <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
       <arg line="${gwt.args}"/>
       <arg value="@moduleName"/>
@@ -50,12 +52,14 @@
<target name="devmode" depends="javac" description="Run development mode">
     <java failonerror="true" fork="true" classname="@shellClass">
       <classpath>
-        <pathelement location="src"/>
+        <pathelement location="@srcFolder"/>
         <path refid="project.class.path"/>
       </classpath>
       <jvmarg value="-Xmx256M"/>
       <arg value="-startupUrl"/>
       <arg value="@startupUrl"/>
+      <arg line="-war"/>
+      <arg value="@warFolder"/>
       <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
       <arg line="${gwt.args}"/>
       <arg value="@moduleName"/>
@@ -63,8 +67,9 @@
   </target>@antEclipseRule
 @testTargetsBegin
<target name="javac.tests" depends="javac" description="Compiles test code">
-    <javac srcdir="test" includes="**" encoding="utf-8"
+    <javac srcdir="@testFolder" includes="**" encoding="utf-8"
       source="1.5" target="1.5" nowarn="true"
+      destdir="@warFolder/WEB-INF/classes"
       debug="true" debuglevel="lines,vars,source">
       <classpath location="@junitJar"/>
       <classpath refid="project.class.path"/>
@@ -78,13 +83,13 @@
       <sysproperty key="gwt.args" value="-standardsMode -logLevel WARN" />
       <sysproperty key="java.awt.headless" value="true" />
       <classpath>
-        <pathelement location="src" />
-        <pathelement location="test" />
+        <pathelement location="@srcFolder" />
+        <pathelement location="@testFolder" />
         <path refid="project.class.path" />
         <pathelement location="@junitJar" />
       </classpath>
       <batchtest todir="reports/htmlunit.dev" >
-        <fileset dir="test" >
+        <fileset dir="@testFolder" >
           <include name="**/*Test.java" />
         </fileset>
       </batchtest>
@@ -100,13 +105,13 @@
<sysproperty key="gwt.args" value="-prod -standardsMode -logLevel WARN -standardsMode -out www-test" />
       <sysproperty key="java.awt.headless" value="true" />
       <classpath>
-        <pathelement location="src" />
-        <pathelement location="test" />
+        <pathelement location="@srcFolder" />
+        <pathelement location="@testFolder" />
         <path refid="project.class.path" />
         <pathelement location="@junitJar" />
       </classpath>
       <batchtest todir="reports/htmlunit.prod" >
-        <fileset dir="test" >
+        <fileset dir="@testFolder" >
           <include name="**/*Test.java" />
         </fileset>
       </batchtest>
@@ -115,7 +120,7 @@
     </junit>
   </target>

- <target name="test" description="Run development and production mode tests"> + <target name="@testFolder" description="Run development and production mode tests">
     <antcall target="test.dev" />
     <antcall target="test.prod" />
   </target>
@@ -125,12 +130,12 @@
   <target name="build" depends="gwtc" description="Build this project" />

   <target name="war" depends="build" description="Create a war file">
-    <zip destfile="@moduleShortName.war" basedir="war"/>
+    <zip destfile="@moduleShortName.war" basedir="@warFolder"/>
   </target>

   <target name="clean" description="Cleans this project">
-    <delete dir="war/WEB-INF/classes" failonerror="false" />
-    <delete dir="war/@renameTo" failonerror="false" />
+    <delete dir="@warFolder/WEB-INF/classes" failonerror="false" />
+    <delete dir="@warFolder/@renameTo" failonerror="false" />
   </target>

 </project>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to