This is a patch that adds a css target to invoke
com.google.gwt.resources.css.InterfaceGenerator to generate interface
files based on a css file, similar to how i18n works. I needed to
change the JavaCommand, as the css generator outputs to standard out
instead off to a target file. It's configured with either a single
cssFile, or a list off cssFiles to invoke on. The resulting interface
will have it's name based off the css file.
I hope this can be included into the gwt maven plugin.
I also changed the DebugMojo to use the jpda.address, as that is what
is set by maven when invoked in debug mode (at least from netbeans).
Index: src/main/java/org/codehaus/mojo/gwt/shell/AbstractGwtShellMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/gwt/shell/AbstractGwtShellMojo.java (revision 12363)
+++ src/main/java/org/codehaus/mojo/gwt/shell/AbstractGwtShellMojo.java (working copy)
@@ -355,6 +355,12 @@
public void execute()
throws MojoExecutionException
{
+ execute(out);
+ }
+
+ public void execute(StreamConsumer out)
+ throws MojoExecutionException
+ {
List<String> command = new ArrayList<String>();
command.addAll( getJvmArgs() );
command.add( "-classpath" );
Index: src/main/java/org/codehaus/mojo/gwt/shell/DebugMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/gwt/shell/DebugMojo.java (revision 12363)
+++ src/main/java/org/codehaus/mojo/gwt/shell/DebugMojo.java (working copy)
@@ -38,7 +38,7 @@
/**
* Port to listen for debugger connection on.
*
- * @parameter default-value="8000"
+ * @parameter expression="${jpda.address}"
*/
private int debugPort;
Index: src/main/java/org/codehaus/mojo/gwt/shell/CSSMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/gwt/shell/CSSMojo.java (revision 12145)
+++ src/main/java/org/codehaus/mojo/gwt/shell/CSSMojo.java (working copy)
@@ -20,175 +20,112 @@
*/
package org.codehaus.mojo.gwt.shell;
-import java.io.File;
-
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.mojo.gwt.GwtRuntime;
+import org.codehaus.plexus.util.cli.StreamConsumer;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.List;
+
/**
* Creates I18N interfaces for constants and messages files.
*
- * @goal i18n
+ * @author Ståle Undheim <[email protected]>
+ * @goal css
* @phase process-resources
* @requiresDependencyResolution compile
- * @description Creates I18N interfaces for constants and messages files.
- * @author Sascha-Matthias Kulawik <[email protected]>
- * @author ccollins
- * @version $Id$
+ * @description Creates CSS interfaces for css files
*/
-public class I18NMojo
- extends AbstractGwtShellMojo
-{
+public class CSSMojo extends AbstractGwtShellMojo {
/**
- * List of resourceBundles that should be used to generate i18n Messages interfaces.
+ * List of resourceBundles that should be used to generate CSS interfaces.
*
* @parameter
- * @alias i18nMessagesNames
*/
- private String[] i18nMessagesBundles;
+ private String[] cssFiles;
/**
- * Shortcut for a single i18nMessagesBundle
+ * Shortcut for a single cssFile
*
* @parameter
*/
- private String i18nMessagesBundle;
+ private String cssFile;
- /**
- * List of resourceBundles that should be used to generate i18n Constants interfaces.
- *
- * @parameter
- * @alias i18nConstantsNames
- */
- private String[] i18nConstantsBundles;
-
- /**
- * Shortcut for a single i18nConstantsBundle
- *
- * @parameter
- */
- private String i18nConstantsBundle;
-
- /**
- * List of resourceBundles that should be used to generate i18n ConstantsWithLookup interfaces.
- *
- * @parameter
- */
- private String[] i18nConstantsWithLookupBundles;
-
- /**
- * Shortcut for a single i18nConstantsWithLookupBundle
- *
- * @parameter
- */
- private String i18nConstantsWithLookupBundle;
-
- public void doExecute( GwtRuntime runtime )
- throws MojoExecutionException, MojoFailureException
- {
+ public void doExecute(GwtRuntime runtime)
+ throws MojoExecutionException, MojoFailureException {
setup();
boolean generated = false;
- // constants with lookup
- if ( i18nConstantsWithLookupBundles != null )
- {
- for ( String target : i18nConstantsWithLookupBundles )
- {
- ensureTargetPackageExists( getGenerateDirectory(), target );
-
- new JavaCommand( "com.google.gwt.i18n.tools.I18NSync", runtime )
- .withinScope( Artifact.SCOPE_COMPILE )
- .arg( "-out" )
- .arg( getGenerateDirectory().getAbsolutePath() )
- .arg( "-createConstantsWithLookup" )
- .arg( target )
- .execute();
- generated = true;
+// java -cp gwt-dev.jar:gwt-user.jar
+// com.google.gwt.resources.css.InterfaceGenerator -standalone -typeName some.package.MyCssResource -css input.css
+ if (cssFiles != null) {
+ for (String file : cssFiles) {
+ final String typeName = file.substring(0, file.lastIndexOf('.')).replace(File.separatorChar, '.');
+ final File javaOutput = new File(getGenerateDirectory(), typeName.replace('.', File.separatorChar)+".java");
+ final StringBuilder content = new StringBuilder();
+ for (Resource resource : (List<Resource>) getProject().getResources()) {
+ final File candidate = new File(resource.getDirectory(), file);
+ if (candidate.exists()) {
+ getLog().info("Generating "+javaOutput);
+ ensureTargetPackageExists(getGenerateDirectory(), typeName);
+ new JavaCommand("com.google.gwt.resources.css.InterfaceGenerator", runtime)
+ .withinScope(Artifact.SCOPE_COMPILE)
+ .arg("-standalone")
+ .arg("-typeName")
+ .arg(typeName)
+ .arg("-css")
+ .arg(candidate.getAbsolutePath())
+ .execute(new StreamConsumer() {
+ public void consumeLine(final String s) {
+ content.append(s).append('\n');
+ }
+ });
+ try {
+ final FileWriter outputWriter = new FileWriter(javaOutput);
+ outputWriter.write(content.toString());
+ outputWriter.close();
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to write to file: "+javaOutput);
+ }
+ generated = true;
+ break;
+ }
+ }
+ if (content.length() == 0) {
+ throw new MojoExecutionException("Could not find "+file+" in any resource path.");
+ }
}
}
- // constants
- if ( i18nConstantsBundles != null )
- {
- for ( String target : i18nConstantsBundles )
- {
- ensureTargetPackageExists( getGenerateDirectory(), target );
-
- new JavaCommand( "com.google.gwt.i18n.tools.I18NSync", runtime )
- .withinScope( Artifact.SCOPE_COMPILE )
- .arg( "-out" )
- .arg( getGenerateDirectory().getAbsolutePath() )
- .arg( target )
- .execute();
- generated = true;
- }
+ if (generated) {
+ getLog().debug("add compile source root " + getGenerateDirectory());
+ addCompileSourceRoot(getGenerateDirectory());
}
-
- // messages
- if ( i18nMessagesBundles != null )
- {
- for ( String target : i18nMessagesBundles )
- {
- ensureTargetPackageExists( getGenerateDirectory(), target );
-
- new JavaCommand( "com.google.gwt.i18n.tools.I18NSync", runtime )
- .withinScope( Artifact.SCOPE_COMPILE )
- .arg( "-out" )
- .arg( getGenerateDirectory().getAbsolutePath() )
- .arg( "-createMessages" )
- .arg( target )
- .execute();
- generated = true;
- }
- }
-
- if ( generated )
- {
- getLog().debug( "add compile source root " + getGenerateDirectory() );
- addCompileSourceRoot( getGenerateDirectory() );
- }
}
private void setup()
- throws MojoExecutionException
- {
- if ( i18nConstantsWithLookupBundles == null && i18nConstantsWithLookupBundle != null )
- {
- i18nConstantsWithLookupBundles = new String[] { i18nConstantsWithLookupBundle };
+ throws MojoExecutionException {
+ if (cssFiles == null && cssFile != null) {
+ cssFiles = new String[]{cssFile};
}
-
- if ( i18nConstantsBundles == null && i18nConstantsBundle != null )
- {
- i18nConstantsBundles = new String[] { i18nConstantsBundle };
- }
-
- if ( i18nMessagesBundles == null && i18nMessagesBundle != null )
- {
- i18nMessagesBundles = new String[] { i18nMessagesBundle };
- }
-
- if ( i18nMessagesBundles == null && i18nConstantsBundles == null && i18nConstantsWithLookupBundles == null )
- {
- throw new MojoExecutionException(
- "neither i18nConstantsBundles, i18nMessagesBundles nor i18nConstantsWithLookupBundles present. \n"
- + "Cannot execute i18n goal" );
- }
}
- private void ensureTargetPackageExists( File generateDirectory, String targetName )
- {
- targetName = targetName.substring( 0, targetName.lastIndexOf( '.' ) );
- String targetPackage = targetName.replace( '.', File.separatorChar );
- getLog().debug( "ensureTargetPackageExists, targetName : " + targetName + ", targetPackage : " + targetPackage );
- File targetPackageDirectory = new File( generateDirectory, targetPackage );
- if ( !targetPackageDirectory.exists() )
- {
+ private void ensureTargetPackageExists(File generateDirectory, String targetName) {
+ targetName = targetName.substring(0, targetName.lastIndexOf('.'));
+ String targetPackage = targetName.replace('.', File.separatorChar);
+ getLog().debug("ensureTargetPackageExists, targetName : " + targetName + ", targetPackage : " + targetPackage);
+ File targetPackageDirectory = new File(generateDirectory, targetPackage);
+ if (!targetPackageDirectory.exists()) {
targetPackageDirectory.mkdirs();
}
}
-}
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email