Phase 1 of readying samples for distro; do not produce Elipse stuff.

Still TODO:
- Produce a top-level ant file for the distro/samples.
- Add dependency on gwt-dev to Showcase (or all samples)?

Review by: amitmanjhi

git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4570 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/samples/common.ant.xml b/samples/common.ant.xml
index ef167f4..248acd2 100755
--- a/samples/common.ant.xml
+++ b/samples/common.ant.xml
@@ -77,6 +77,7 @@
           <java classname="com.google.gwt.user.tools.WebAppCreator" classpath="${gwt.user.jar}:${gwt.dev.jar}" failonerror="true">
             <!-- Relative path is important! Paths will be relative in final distro -->
             <sysproperty key="gwt.devjar" value="../../gwt-dev-@{platform}.jar" />
+            <arg value="-XnoEclipse" />
             <arg value="-overwrite" />
             <arg value="-out" />
             <arg file="${samples.scripts}/@{platform}/${sample.upper}" />
diff --git a/user/src/com/google/gwt/user/tools/WebAppCreator.java b/user/src/com/google/gwt/user/tools/WebAppCreator.java
index d324a83..7ba8afc 100644
--- a/user/src/com/google/gwt/user/tools/WebAppCreator.java
+++ b/user/src/com/google/gwt/user/tools/WebAppCreator.java
@@ -24,6 +24,7 @@
 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.ArgHandlerFlag;
 import com.google.gwt.util.tools.ArgHandlerOutDir;
 import com.google.gwt.util.tools.Utility;
 
@@ -55,6 +56,8 @@
       registerHandler(new ArgHandlerIgnoreExtension());
       registerHandler(new ArgHandlerModuleName());
       registerHandler(new ArgHandlerOutDirExtension());
+      registerHandler(new ArgHandlerNoEclipse());
+      registerHandler(new ArgHandlerOnlyEclipse());
     }
 
     @Override
@@ -75,10 +78,6 @@
     }
   }
 
-  /*
-   * Arguments for the application creator.
-   */
-
   private final class ArgHandlerModuleName extends ArgHandlerExtra {
     @Override
     public boolean addExtraArg(String arg) {
@@ -114,6 +113,52 @@
     }
   }
 
+  private final class ArgHandlerNoEclipse extends ArgHandlerFlag {
+    @Override
+    public String getPurpose() {
+      return "Do not generate eclipse files";
+    }
+
+    @Override
+    public String getTag() {
+      return "-XnoEclipse";
+    }
+
+    @Override
+    public boolean isUndocumented() {
+      return true;
+    }
+
+    @Override
+    public boolean setFlag() {
+      noEclipse = true;
+      return true;
+    }
+  }
+
+  private final class ArgHandlerOnlyEclipse extends ArgHandlerFlag {
+    @Override
+    public String getPurpose() {
+      return "Generate only eclipse files";
+    }
+
+    @Override
+    public String getTag() {
+      return "-XonlyEclipse";
+    }
+
+    @Override
+    public boolean isUndocumented() {
+      return true;
+    }
+
+    @Override
+    public boolean setFlag() {
+      onlyEclipse = true;
+      return true;
+    }
+  }
+
   private final class ArgHandlerOverwriteExtension extends ArgHandlerOverwrite {
     @Override
     public boolean setFlag() {
@@ -127,8 +172,8 @@
   }
 
   private static final class FileCreator {
-    private final String destName;
     private final File destDir;
+    private final String destName;
     private final String sourceName;
 
     public FileCreator(File destDir, String destName, String sourceName) {
@@ -149,16 +194,19 @@
     System.exit(1);
   }
 
+  private boolean ignore = false;
+  private String moduleName;
+  private boolean noEclipse;
+  private boolean onlyEclipse;
+  private File outDir;
+  private boolean overwrite = false;
+
   /**
-   * @param moduleName name of the fully-qualified GWT module to create as an
-   *          Application.
-   * @param outDir Where to put the output files
-   * @param overwrite Overwrite an existing files if they exist.
-   * @param ignore Ignore existing files if they exist.
-   * @throws IOException
+   * Create the sample app.
+   * 
+   * @throws IOException if any disk write fails
    */
-  static void createApplication(String moduleName, File outDir,
-      boolean overwrite, boolean ignore) throws IOException {
+  protected void doRun() throws IOException {
 
     // Figure out the installation directory
     String installPath = Utility.getInstallPath();
@@ -213,24 +261,52 @@
     replacements.put("@vmargs", isMacOsX ? "&#10;-XstartOnFirstThread" : "");
     replacements.put("@renameTo", moduleShortName.toLowerCase());
 
+    String antEclipseRule = "";
+    if (noEclipse) {
+      /*
+       * Generate a rule into the build file that allows for the generation of
+       * an eclipse project later on. This is primarily for distro samples. This
+       * is a quick and dirty way to inject a build rule, but it works.
+       */
+      antEclipseRule = "\n\n"
+          + "  <target name=\"eclipse.generate\" depends=\"libs\" description=\"Generate eclipse project\">\n"
+          + "    <java failonerror=\"true\" fork=\"true\" classname=\""
+          + this.getClass().getName() + "\">\n" + "      <classpath>\n"
+          + "        <pathelement location=\"" + gwtUserPath + "\"/>\n"
+          + "        <pathelement location=\"" + gwtDevPath + "\"/>\n"
+          + "      </classpath>\n" + "      <arg value=\"-XonlyEclipse\"/>\n"
+          + "      <arg value=\"-ignore\"/>\n" + "      <arg value=\""
+          + moduleName + "\"/>\n" + "    </java>\n" + "  </target>";
+    } else {
+      antEclipseRule = "";
+    }
+    replacements.put("@antEclipseRule", antEclipseRule);
+
     List<FileCreator> files = new ArrayList<FileCreator>();
-    files.add(new FileCreator(moduleDir, moduleShortName + ".gwt.xml",
-        "Module.gwt.xml"));
-    files.add(new FileCreator(warDir, moduleShortName + ".html", "AppHtml.html"));
-    files.add(new FileCreator(warDir, moduleShortName + ".css", "AppCss.css"));
-    files.add(new FileCreator(webInfDir, "web.xml", "web.xml"));
-    files.add(new FileCreator(clientDir, moduleShortName + ".java",
-        "AppClassTemplate.java"));
-    files.add(new FileCreator(clientDir, "EchoService" + ".java",
-        "RpcClientTemplate.java"));
-    files.add(new FileCreator(clientDir, "EchoServiceAsync" + ".java",
-        "RpcAsyncClientTemplate.java"));
-    files.add(new FileCreator(serverDir, "EchoServiceImpl" + ".java",
-        "RpcServerTemplate.java"));
-    files.add(new FileCreator(outDir, "build.xml", "project.ant.xml"));
-    files.add(new FileCreator(outDir, ".project", ".project"));
-    files.add(new FileCreator(outDir, ".classpath", ".classpath"));
-    files.add(new FileCreator(outDir, moduleShortName + ".launch", "App.launch"));
+    if (!onlyEclipse) {
+      files.add(new FileCreator(moduleDir, moduleShortName + ".gwt.xml",
+          "Module.gwt.xml"));
+      files.add(new FileCreator(warDir, moduleShortName + ".html",
+          "AppHtml.html"));
+      files.add(new FileCreator(warDir, moduleShortName + ".css", "AppCss.css"));
+      files.add(new FileCreator(webInfDir, "web.xml", "web.xml"));
+      files.add(new FileCreator(clientDir, moduleShortName + ".java",
+          "AppClassTemplate.java"));
+      files.add(new FileCreator(clientDir, "EchoService" + ".java",
+          "RpcClientTemplate.java"));
+      files.add(new FileCreator(clientDir, "EchoServiceAsync" + ".java",
+          "RpcAsyncClientTemplate.java"));
+      files.add(new FileCreator(serverDir, "EchoServiceImpl" + ".java",
+          "RpcServerTemplate.java"));
+      files.add(new FileCreator(outDir, "build.xml", "project.ant.xml"));
+    }
+    if (!noEclipse) {
+      assert new File(gwtDevPath).isAbsolute();
+      files.add(new FileCreator(outDir, ".project", ".project"));
+      files.add(new FileCreator(outDir, ".classpath", ".classpath"));
+      files.add(new FileCreator(outDir, moduleShortName + ".launch",
+          "App.launch"));
+    }
 
     for (FileCreator fileCreator : files) {
       File file = Utility.createNormalFile(fileCreator.destDir,
@@ -247,14 +323,9 @@
     }
   }
 
-  private boolean ignore = false;
-  private String moduleName;
-  private File outDir;
-  private boolean overwrite = false;
-
   protected boolean run() {
     try {
-      createApplication(moduleName, outDir, overwrite, ignore);
+      doRun();
       return true;
     } catch (IOException e) {
       System.err.println(e.getClass().getName() + ": " + e.getMessage());
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 9b6e4a9..0b3f664 100644
--- a/user/src/com/google/gwt/user/tools/project.ant.xmlsrc
+++ b/user/src/com/google/gwt/user/tools/project.ant.xmlsrc
@@ -53,7 +53,7 @@
       <arg value="@moduleName"/>
       <!-- Additional arguments like -style PRETTY or -logLevel DEBUG -->
     </java>
-  </target>
+  </target>@antEclipseRule
 
   <target name="build" depends="gwtc" description="Build this project" />