Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying GWT's user.agent when releasing

Tags:

maven-2

gwt

When developing, I set the user.agent property to a single value, to keep compile times down. When releasing, I have a WAR file built for all user agents.

I unfortunately seem to keep forgetting to switch the property, either:

  • wasting development time waiting for compiles, or
  • preparing a WAR file with incomplete browser support ( not yet deployed , thankfully ).

I want to automate this, preferably using the maven-release-plugin.

like image 937
Robert Munteanu Avatar asked Jun 07 '09 23:06

Robert Munteanu


2 Answers

You want to have 2 different .gwt.xml files - one used for development and one used for production.

There is a good example on the 'Renaming modules' section of Developer Guide/Organizing projects.

The gwt.xml file used for development would inherit from the gwt.xml file used for production and set the user.agent property as well. e.g.:

<module rename-to="com.foo.MyModule">
  <inherits name="com.foo.MyModule" />
  <set-property name="user.agent" value="ie6" />
</module>

Now, when doing development, you would use the development gwt.xml file, and when doing a production build. you would use the production gwt.xml file.


The easiest way to achieve this with Maven is to activate the development module using a profile. I've written in detail about this at Maven Recipe : GWT development profile.

like image 144
Chi Avatar answered Nov 16 '22 02:11

Chi


Create a MavenFilteredUserAgent module that sets user.agent from various profiles in the pom.xml.

MavenFilteredUserAgent.gwt.xml

...
<set-property name="user.agent" value="${gwt.compile.user.agent}" />
...

pom.xml

...
<properties>
  <!-- By default we still want all five rendering engines when none of the following profiles is explicitly specified -->
  <gwt.compile.user.agent>ie6,ie8,gecko,gecko1_8,safari,opera</gwt.compile.user.agent>
</properties>
<profiles>
  <profile>
    <id>gwt-firefox</id>
    <properties>
      <gwt.compile.user.agent>gecko1_8</gwt.compile.user.agent>
    </properties>
  </profile>
</profiles>
<!-- Add additional profiles for the browsers you want to singly support -->
....
<build>
  <resources>
    <resource>
      <!-- Put the filtered source files into a directory that later gets added to the build path -->
      <directory>src/main/java-filtered</directory>
      <filtering>true</filtering>
      <targetPath>${project.build.directory}/filtered-sources/java</targetPath>
    </resource>
    <resource>
      <directory>${project.basedir}/src/main/resources</directory>
    </resource>
    </resources>
  <plugins>
  ...
  <plugin>
    <!-- Add the filtered sources directory to the build path-->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
      <execution>
        <id>add-source</id>
        <phase>generate-sources</phase>
        <goals>
          <goal>add-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>${project.build.directory}/filtered-sources/java</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>
  ...
</plugins>
...

Have all of your modules inherit the MavenFilteredUserAgent module.

Then you can build for just firefox like so.

mvn install -Pgwt-firefox

http://9mmedia.com/blog/?p=854 has more details.

like image 44
Gabriel Avatar answered Nov 16 '22 02:11

Gabriel