View Javadoc
1   package org.codehaus.mojo.gwt.shell;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.plugin.MojoFailureException;
25  import org.apache.maven.plugins.annotations.Execute;
26  import org.apache.maven.plugins.annotations.LifecyclePhase;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.Parameter;
29  import org.apache.maven.plugins.annotations.ResolutionScope;
30  import org.apache.maven.project.MavenProject;
31  
32  import java.io.File;
33  
34  /**
35   * Runs GWT modules with Super Dev Mode.
36   *
37   * @author t.broyer
38   * @since 2.5.0-rc1
39   */
40  @Mojo(name = "run-codeserver", requiresDirectInvocation = true, requiresDependencyResolution = ResolutionScope.COMPILE)
41  @Execute(phase = LifecyclePhase.PROCESS_CLASSES)
42  public class SuperDevModeMojo extends AbstractGwtShellMojo
43  {
44  
45      /**
46       * Set SuperDevMode's bindAddress.
47       * <p>
48       * Can be set from command line using '-Dgwt.bindAddress=...'
49       */
50      @Parameter(property = "gwt.bindAddress")
51      private String bindAddress;
52  
53      /**
54       * The port where the code server will run.
55       */
56      @Parameter(property = "gwt.codeServerPort")
57      private Integer codeServerPort;
58  
59      /**
60       * The root of the directory tree where the code server will write compiler output.
61       * If not supplied, a temporary directory will be used.
62       */
63      @Parameter
64      private File codeServerWorkDir;
65  
66      /**
67       * Precompile modules.
68       * 
69       * @since 2.6.0-rc1
70       */
71      @Parameter(defaultValue = "true", property = "gwt.codeServer.precompile")
72      private boolean precompile;
73  
74      /**
75       * Specifies Java source level.
76       *
77       * @since 2.6.0-rc1
78       */
79      @Parameter(defaultValue = "auto", property = "maven.compiler.source")
80      private String sourceLevel;
81  
82      /**
83       * Stop compiling if a module has a Java file with a compile error, even if unused.
84       * <p>
85       * Can be set from command line using '-Dgwt.compiler.strict=true'.
86       * 
87       * @since 2.7.0-rc1
88       */
89      @Parameter(alias = "strict", defaultValue = "false", property = "gwt.compiler.strict")
90      private boolean failOnError;
91  
92      /**
93       * Compiles faster by reusing data from the previous compile.
94       * 
95       * @since 2.7.0-rc1
96       */
97      @Parameter(alias = "compilePerFile", defaultValue = "true", property = "gwt.compiler.incremental")
98      private boolean incremental;
99  
100     /**
101      * Generate exports for JsInterop purposes.
102      *
103      * @since 2.8.0-rc1
104      */
105     @Parameter(alias = "generateJsInteropExports", defaultValue = "false", property = "gwt.compiler.generateJsInteropExports")
106     private boolean generateJsInteropExports;
107 
108     /**
109      * EXPERIMENTAL: Emit extra information allow chrome dev tools to display Java identifiers in many places instead of JavaScript functions.
110      * <p>
111      * Value can be one of NONE, ONLY_METHOD_NAME, ABBREVIATED or FULL.
112      * 
113      * @since 2.7.0-rc1
114      */
115     @Parameter(defaultValue = "NONE", property = "gwt.compiler.methodNameDisplayMode")
116     private String methodNameDisplayMode;
117 
118     /**
119      * An output directory where files for launching Super Dev Mode will be written. (Optional.)
120      * 
121      * @since 2.7.0
122      */
123     @Parameter(property = "gwt.codeServer.launcherDir")
124     private File launcherDir;
125 
126     /**
127      * The MavenProject executed by the "process-classes" phase.
128      */
129     @Parameter(defaultValue = "${executedProject}")
130     private MavenProject executedProject;
131 
132     @Override
133     public void doExecute()
134         throws MojoExecutionException, MojoFailureException
135     {
136         JavaCommand cmd = createJavaCommand()
137             .setMainClass( "com.google.gwt.dev.codeserver.CodeServer" );
138 
139         if ( gwtSdkFirstInClasspath )
140         {
141             cmd.addToClasspath( getGwtUserJar() )
142                 .addToClasspath( getGwtDevJar() );
143         }
144 
145         cmd.addToClasspath( getClasspath( Artifact.SCOPE_COMPILE ) );
146         addCompileSourceArtifacts( cmd );
147         addPersistentUnitCache(cmd);
148 
149         if ( !gwtSdkFirstInClasspath )
150         {
151             cmd.addToClasspath( getGwtUserJar() )
152                 .addToClasspath( getGwtDevJar() );
153         }
154 
155         cmd.arg( "-logLevel", getLogLevel() );
156         cmd.arg( !precompile, "-noprecompile" );
157         cmd.arg( "-sourceLevel", sourceLevel );
158         cmd.arg( failOnError, "-failOnError" );
159         cmd.arg( !incremental, "-noincremental" );
160         cmd.arg( generateJsInteropExports, "-generateJsInteropExports" );
161 
162         if ( style != null && style.length() > 0 )
163         {
164             cmd.arg( "-style", style );
165         }
166 
167         if ( methodNameDisplayMode != null && methodNameDisplayMode.length() > 0 && !methodNameDisplayMode.equals( "NONE" ))
168         {
169             cmd.arg( "-XmethodNameDisplayMode", methodNameDisplayMode );
170         }
171         if ( bindAddress != null && bindAddress.length() > 0 )
172         {
173             cmd.arg( "-bindAddress", bindAddress );
174         }
175         if ( codeServerPort != null )
176         {
177             cmd.arg( "-port", String.valueOf( codeServerPort ) );
178         }
179         if ( codeServerWorkDir != null )
180         {
181             codeServerWorkDir.mkdirs();
182             cmd.arg( "-workDir", codeServerWorkDir.getAbsolutePath() );
183         }
184 
185         if ( launcherDir != null )
186         {
187             cmd.arg( "-launcherDir", launcherDir.getAbsolutePath() );
188         }
189 
190         for ( String module : getModules() )
191         {
192             cmd.arg( module );
193         }
194 
195         try
196         {
197             cmd.execute();
198         }
199         catch ( JavaCommandException e )
200         {
201             throw new MojoExecutionException( e.getMessage(), e );
202         }
203     }
204 
205     public void setExecutedProject( MavenProject executedProject )
206     {
207         this.executedProject = executedProject;
208     }
209 
210     @Override
211     public MavenProject getProject()
212     {
213         return executedProject;
214     }
215 }
216