[gwt-maven] r1025 committed - Adding 2.0 options

0 views
Skip to first unread message

codesite...@google.com

unread,
Dec 16, 2009, 4:42:22 PM12/16/09
to gwt-ma...@googlegroups.com
Revision: 1025
Author: kebernet
Date: Wed Dec 16 13:41:57 2009
Log: Adding 2.0 options
http://code.google.com/p/gwt-maven/source/detail?r=1025

Added:

/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterUnix20.java
Modified:

/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/AbstractGWTMojo.java

/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterFactory.java

/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterUnix.java

/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/util/BuildClasspathUtil.java

=======================================
--- /dev/null
+++
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterUnix20.java
Wed Dec 16 13:41:57 2009
@@ -0,0 +1,412 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.totsp.mavenplugin.gwt.scripting;
+
+import com.totsp.mavenplugin.gwt.AbstractGWTMojo;
+import com.totsp.mavenplugin.gwt.DebugMojo;
+import com.totsp.mavenplugin.gwt.util.BuildClasspathUtil;
+import com.totsp.mavenplugin.gwt.util.DependencyScope;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.HiddenFileFilter;
+import org.apache.commons.io.filefilter.WildcardFileFilter;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.StringUtils;
+
+
+/**
+ *
+ * @author kebernet
+ */
+public class ScriptWriterUnix20 implements ScriptWriter16 {
+
+ /** Creates a new instance of ScriptWriterUnix */
+ public ScriptWriterUnix20() {
+ }
+
+ /**
+ * Write run script.
+ *
+ * @param mojo The Mojo calling this (contianing config parametersd)
+ * @return the script file that was written.
+ * @throws org.apache.maven.plugin.MojoExecutionException general
purpose exception.
+ */
+ public File writeRunScript(AbstractGWTMojo mojo) throws
MojoExecutionException {
+ String filename = (mojo instanceof
DebugMojo) ? "debug.sh" : "run.sh";
+ File file = new File(mojo.getBuildDir(), filename);
+ PrintWriter writer = this.getPrintWriterWithClasspath(mojo, file,
DependencyScope.RUNTIME);
+
+ String extra = (mojo.getExtraJvmArgs() != null) ?
mojo.getExtraJvmArgs() : "";
+
+ writer.print("\"" + mojo.getJavaCommand() + "\" " + extra + " -cp
$CP ");
+
+ if (mojo instanceof DebugMojo) {
+ writer.print(" -Xdebug -Xnoagent -Djava.compiler=NONE
-Xrunjdwp:transport=dt_socket,server=y,address=");
+ writer.print(mojo.getDebugPort());
+
writer.print(mojo.isDebugSuspend() ? ",suspend=y " : ",suspend=n ");
+ }
+
+ writer.print(" com.google.gwt.dev.DevMode");
+ writer.print(" -logLevel ");
+ writer.print(mojo.getLogLevel());
+ if (mojo.isEnableAssertions()) {
+ writer.print(" -ea ");
+ }
+
+ if ((mojo.isShowTreeLogger())) {
+ writer.print(" -treeLogger ");
+ }
+
+// writer.print(" -workDir ");
+// mojo.getWorkDir().mkdirs();
+// writer.print(mojo.getWorkDir().getAbsolutePath());
+// writer.print(" -extra ");
+// mojo.getExtraDir().mkdirs();
+// writer.print(mojo.getExtraDir());
+ writer.print(" -war ");
+ writer.print("\"" + mojo.getOutput().getAbsolutePath() + "\" ");
+ writer.print(" -port ");
+ writer.print(Integer.toString(mojo.getPort()));
+
+ if (mojo.isNoServer()) {
+ writer.print(" -noserver ");
+ }
+
+ if ((mojo.getWhitelist() != null) && (mojo.getWhitelist().length()
> 0)) {
+ writer.print(" -whitelist \"");
+ writer.print(mojo.getWhitelist());
+ writer.print("\" ");
+ }
+
+ if ((mojo.getBlacklist() != null) && (mojo.getBlacklist().length()
> 0)) {
+ writer.print(" -blacklist \"");
+ writer.print(mojo.getBlacklist());
+ writer.print("\" ");
+ }
+
+ writer.print(" -startupUrl " + mojo.getRunTarget());
+ writer.print(" ");
+ writer.print(mojo.getCompileTarget()[0]);
+ writer.println();
+
+ writer.flush();
+ writer.close();
+
+ this.chmodUnixFile(file);
+
+ return file;
+ }
+
+ /**
+ * Write compile script.
+ *
+ * @param mojo The Mojo calling this (contianing config parametersd)
+ * @return the script file that was written.
+ * @throws org.apache.maven.plugin.MojoExecutionException general
purpose exception.
+ */
+ public File writeCompileScript(AbstractGWTMojo mojo) throws
MojoExecutionException {
+ return this.writeCompilerInvocationScript(mojo, false);
+ }
+
+ /**
+ * Write compile script.
+ *
+ * @param mojo The Mojo calling this (contianing config parametersd)
+ * @return the script file that was written.
+ * @throws org.apache.maven.plugin.MojoExecutionException general
purpose exception.
+ */
+ protected File writeCompilerInvocationScript(AbstractGWTMojo mojo,
boolean validateOnly)
+ throws MojoExecutionException {
+ File file = new File(mojo.getBuildDir(),
validateOnly ? "validate.sh" : "compile.sh");
+ PrintWriter writer = this.getPrintWriterWithClasspath(mojo, file,
DependencyScope.COMPILE);
+
+ String extra = (mojo.getExtraJvmArgs() != null) ?
mojo.getExtraJvmArgs() : "";
+
+
+ writer.print("\"" + mojo.getJavaCommand() + "\" " + extra + " -cp
\"$CP\" ");
+ writer.print(" com.google.gwt.dev.Compiler ");
+ writer.print(" -gen ");
+ writer.print(mojo.getGen().getAbsolutePath());
+ writer.print(" -logLevel ");
+ writer.print(mojo.getLogLevel());
+ writer.print(" -style ");
+ writer.print(mojo.getStyle());
+
+ if (mojo.isEnableAssertions()) {
+ writer.print(" -ea ");
+ }
+
+ if ((mojo.isShowTreeLogger())) {
+ writer.print(" -treeLogger ");
+ }
+
+ writer.print(" -workDir ");
+ writer.print(mojo.getWorkDir().getAbsolutePath());
+ writer.print(" -extra ");
+ writer.print(mojo.getExtraDir());
+ writer.print(" -war ");
+ writer.print("\"" + mojo.getOutput().getAbsolutePath() + "\"");
+ writer.print(" -localWorkers ");
+ writer.print(mojo.getLocalWorkers());
+ writer.print(" ");
+ for (String target : mojo.getCompileTarget()) {
+ writer.print(target);
+ writer.print(" ");
+ }
+
+ writer.println();
+
+ writer.flush();
+ writer.close();
+
+ this.chmodUnixFile(file);
+
+ return file;
+ }
+
+ /**
+ * Write i18n script.
+ *
+ */
+ public File writeI18nScript(AbstractGWTMojo mojo) throws
MojoExecutionException {
+ File file = new File(mojo.getBuildDir(), "i18n.sh");
+
+ if (!file.exists()) {
+ if (mojo.getLog().isDebugEnabled()) {
+ mojo.getLog().debug("File '" + file.getAbsolutePath() + "'
does not exsists, trying to create.");
+ }
+
+ try {
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+
+ if (mojo.getLog().isDebugEnabled()) {
+ mojo.getLog().debug("New file '" +
file.getAbsolutePath() + "' created.");
+ }
+ } catch (Exception exe) {
+ mojo.getLog().error(
+ "Couldn't create file '" + file.getAbsolutePath()
+ "'. Reason: " + exe.getMessage(), exe);
+ }
+ }
+
+ PrintWriter writer = this.getPrintWriterWithClasspath(mojo, file,
DependencyScope.COMPILE);
+
+ // constants
+ if (mojo.getI18nConstantsNames() != null) {
+ for (String target : mojo.getI18nConstantsNames()) {
+ String extra = (mojo.getExtraJvmArgs() != null) ?
mojo.getExtraJvmArgs() : "";
+
+ if (AbstractGWTMojo.OS_NAME.startsWith("mac") &&
(extra.indexOf("-XstartOnFirstThread") == -1)) {
+ extra = "-XstartOnFirstThread " + extra;
+ }
+
+ writer.print("\"" + mojo.getJavaCommand() + "\" " + extra
+ " -cp \"$CP\" ");
+ writer.print(" com.google.gwt.i18n.tools.I18NSync");
+ writer.print(" -out ");
+ writer.print(mojo.getI18nOutputDir());
+ writer.print(mojo.isI18nConstantsWithLookup() ? "
-createConstantsWithLookup " : " ");
+ writer.print(target);
+ writer.println();
+ }
+ }
+
+ // messages
+ if (mojo.getI18nMessagesNames() != null) {
+ for (String target : mojo.getI18nMessagesNames()) {
+ String extra = (mojo.getExtraJvmArgs() != null) ?
mojo.getExtraJvmArgs() : "";
+
+ if (AbstractGWTMojo.OS_NAME.startsWith("mac") &&
(extra.indexOf("-XstartOnFirstThread") == -1)) {
+ extra = "-XstartOnFirstThread " + extra;
+ }
+
+ writer.print("\"" + mojo.getJavaCommand() + "\" " + extra
+ " -cp \"$CP\" ");
+ writer.print(" com.google.gwt.i18n.tools.I18NSync");
+ writer.print(" -createMessages ");
+ writer.print(" -out ");
+ writer.print(mojo.getI18nOutputDir());
+ writer.print(" ");
+ writer.print(target);
+ writer.println();
+ }
+ }
+
+ writer.flush();
+ writer.close();
+
+ this.chmodUnixFile(file);
+
+ return file;
+ }
+
+ /**
+ * Write test scripts.
+ */
+ public void writeTestScripts(AbstractGWTMojo mojo) throws
MojoExecutionException {
+ // get extras
+ String extra = (mojo.getExtraJvmArgs() != null) ?
mojo.getExtraJvmArgs() : "";
+
+ String testExtra = (mojo.getExtraTestArgs() != null) ?
mojo.getExtraTestArgs() : "";
+
+ // make sure output dir is present
+ File outputDir = new File(mojo.getBuildDir(), "gwtTest");
+ outputDir.mkdirs();
+ outputDir.mkdir();
+
+ // for each test compile source root, build a test script
+ List<String> testCompileRoots =
mojo.getProject().getTestCompileSourceRoots();
+
+ for (String currRoot : testCompileRoots) {
+ // TODO better file filter here
+ Collection<File> coll = FileUtils.listFiles(new File(currRoot),
+ new WildcardFileFilter(mojo.getTestFilter()),
HiddenFileFilter.VISIBLE);
+
+ for (File currFile : coll) {
+ String testName = currFile.toString();
+ mojo.getLog().debug(("gwtTest test match found (after
filter applied) - " + testName));
+
+ // parse off the extension
+ if (testName.lastIndexOf('.') >
testName.lastIndexOf(File.separatorChar)) {
+ testName = testName.substring(0,
testName.lastIndexOf('.'));
+ }
+
+ if (testName.startsWith(currRoot)) {
+ testName = testName.substring(currRoot.length());
+ }
+
+ if (testName.startsWith(File.separator)) {
+ testName = testName.substring(1);
+ }
+
+ testName = StringUtils.replace(testName,
File.separatorChar, '.');
+ mojo.getLog().debug("testName after parsing - " +
testName);
+
+ // start script inside gwtTest output dir, and name it
with test class name
+ File file = new File(mojo.getBuildDir() + File.separator
+ "gwtTest", "gwtTest-" + testName + ".sh");
+ PrintWriter writer =
this.getPrintWriterWithClasspath(mojo, file, DependencyScope.TEST);
+
+ // build Java command
+ writer.print("\"" + mojo.getJavaCommand() + "\" ");
+
+ if (extra.length() > 0) {
+ writer.print(" " + extra + " ");
+ }
+
+ if(mojo.isUseHtmlUnit() ){
+ testExtra += " -Dgwt.args=\"-runStyle HtmlUnit:";
+ boolean first = true;
+ for(String mode : mojo.getHtmlUnitBrowsers() ){
+ if(!first){
+ testExtra+=",";
+ }
+ testExtra+=mode;
+ first = false;
+ }
+ testExtra +="\" ";
+ }
+
+ if (testExtra.length() > 0) {
+ writer.print(" " + testExtra + " ");
+ }
+
+
+
+
+ writer.print(" -cp \"$CP\" ");
+ writer.print("junit.textui.TestRunner ");
+ writer.print(testName);
+
+
+
+ // write script out
+ writer.flush();
+ writer.close();
+ this.chmodUnixFile(file);
+ }
+ }
+ }
+
+ /**
+ * Util to get a PrintWriter with Unix preamble and classpath.
+ *
+ * @param mojo
+ * @param file
+ * @return
+ * @throws MojoExecutionException
+ */
+ private PrintWriter getPrintWriterWithClasspath(final AbstractGWTMojo
mojo, File file, final DependencyScope scope)
+ throws MojoExecutionException {
+ PrintWriter writer = null;
+
+ try {
+ writer = new PrintWriter(new FileWriter(file));
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error creating script - " +
file, e);
+ }
+
+ File sh = new File("/bin/bash");
+
+ if (!sh.exists()) {
+ sh = new File("/usr/bin/bash");
+ }
+
+ if (!sh.exists()) {
+ sh = new File("/bin/sh");
+ }
+
+ writer.println("#!" + sh.getAbsolutePath());
+ writer.println();
+
+ try {
+ Collection<File> classpath =
BuildClasspathUtil.buildClasspathList(mojo, scope);
+ writer.print("CP=");
+
+ Iterator it = classpath.iterator();
+
+ while (it.hasNext()) {
+ File f = (File) it.next();
+
+ if (it.hasNext()) {
+ writer.print("\"" + f.getAbsolutePath() + "\":");
+ } else {
+ writer.print("\"" + f.getAbsolutePath() + "\"");
+ }
+ }
+ } catch (DependencyResolutionRequiredException e) {
+ throw new MojoExecutionException("Error creating script - " +
file, e);
+ }
+
+ writer.println();
+ writer.println();
+
+ return writer;
+ }
+
+ /**
+ * Util to chmod Unix file.
+ *
+ * @param file
+ */
+ private void chmodUnixFile(File file) {
+ try {
+ ProcessWatcher pw = new ProcessWatcher(new String[]
{ "chmod", "+x", file.getAbsolutePath() });
+ pw.startProcess(System.out, System.err);
+ pw.waitFor();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public File writeValidationScript(AbstractGWTMojo mojo) throws
MojoExecutionException {
+ return this.writeCompilerInvocationScript(mojo, true);
+ }
+}
=======================================
---
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/AbstractGWTMojo.java
Wed Aug 19 04:03:45 2009
+++
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/AbstractGWTMojo.java
Wed Dec 16 13:41:57 2009
@@ -387,7 +387,21 @@
* @parameter default-value="${project.build.directory}/gwtExtra"
*/
private File extraDir;
-
+
+
+ /**
+ * Toggles HTMLUnit testing (GWT 2.0+)
+ * @parameter
+ */
+ private boolean useHtmlUnit;
+
+ /**
+ * Browser configs to use in HTML unit
+ * @parameter
+ */
+ private String[] htmlUnitBrowsers;
+
+
// ctor


@@ -879,4 +893,32 @@
public void setUseOophm(boolean useOophm) {
this.useOophm = useOophm;
}
-}
+
+ /**
+ * @return the useHtmlUnit
+ */
+ public boolean isUseHtmlUnit() {
+ return useHtmlUnit;
+ }
+
+ /**
+ * @param useHtmlUnit the useHtmlUnit to set
+ */
+ public void setUseHtmlUnit(boolean useHtmlUnit) {
+ this.useHtmlUnit = useHtmlUnit;
+ }
+
+ /**
+ * @return the htmlUnitBrowsers
+ */
+ public String[] getHtmlUnitBrowsers() {
+ return htmlUnitBrowsers;
+ }
+
+ /**
+ * @param htmlUnitBrowsers the htmlUnitBrowsers to set
+ */
+ public void setHtmlUnitBrowsers(String[] htmlUnitBrowsers) {
+ this.htmlUnitBrowsers = htmlUnitBrowsers;
+ }
+}
=======================================
---
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterFactory.java
Tue Feb 24 18:59:07 2009
+++
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterFactory.java
Wed Dec 16 13:41:57 2009
@@ -27,12 +27,16 @@
ScriptWriter sw = null;
if (AbstractGWTMojo.OS_NAME.startsWith(AbstractGWTMojo.WINDOWS)) {
sw = new ScriptWriterWindows();
+ System.out.println("windows");
} else {
- if( mojo.getGwtVersion().startsWith("1.6") ){
+ if(mojo.getGwtVersion().startsWith("2.") ){
+ sw = new ScriptWriterUnix20();
+ } else if( mojo.getGwtVersion().startsWith("1.6") ){
sw = new ScriptWriterUnix16();
} else {
sw = new ScriptWriterUnix();
}
+ System.out.println("unix");
}
return sw;
}
=======================================
---
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterUnix.java
Tue Mar 31 17:19:42 2009
+++
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/scripting/ScriptWriterUnix.java
Wed Dec 16 13:41:57 2009
@@ -201,7 +201,7 @@
writer.print(" -createMessages ");
writer.print(" -out ");
writer.print(mojo.getI18nOutputDir());
- writer.print(" ");
+ writer.print(mojo.isI18nConstantsWithLookup() ? "
-createConstantsWithLookup " : " ");
writer.print(target);
writer.println();
}
=======================================
---
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/util/BuildClasspathUtil.java
Wed Aug 19 04:03:45 2009
+++
/trunk/maven-googlewebtoolkit2-plugin/src/main/java/com/totsp/mavenplugin/gwt/util/BuildClasspathUtil.java
Wed Dec 16 13:41:57 2009
@@ -159,7 +159,10 @@
items.add(oophmJar);
}
File userJar = new File(gwtHome, "gwt-user.jar");
- File devJar = new File(gwtHome,
ArtifactNameUtil.guessDevJarName());
+ File devJar = mojo.getGwtVersion().startsWith("2.") ?
+ new File(gwtHome, "gwt-dev.jar")
+ :
+ new File(gwtHome, ArtifactNameUtil.guessDevJarName());
items.add(userJar);
items.add(devJar);

@@ -183,7 +186,11 @@

Artifact gwtUser =
mojo.getArtifactFactory().createArtifactWithClassifier("com.google.gwt", "gwt-user",
mojo.getGwtVersion(), "jar", null);
- Artifact gwtDev =
mojo.getArtifactFactory().createArtifactWithClassifier("com.google.gwt", "gwt-dev",
+ Artifact gwtDev = mojo.getGwtVersion().startsWith("2.") ?
+
mojo.getArtifactFactory().createArtifactWithClassifier("com.google.gwt", "gwt-dev",
+ mojo.getGwtVersion(), "jar", null)
+ :
+
mojo.getArtifactFactory().createArtifactWithClassifier("com.google.gwt", "gwt-dev",
mojo.getGwtVersion(), "jar",
ArtifactNameUtil.getPlatformName());
Artifact oophm = null;
if(mojo.isUseOophm() ){
Reply all
Reply to author
Forward
0 new messages