如何创建开发/调试和生产设置 [英] How to create a development/debug and production setup

查看:97
本文介绍了如何创建开发/调试和生产设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近无意中部署了我们的游戏typrX
的调试版本(在 www.typrx.com - 尝试它很有趣)。
它很快就被纠正了,但我知道它可能会再次发生。在Google上挖掘
后,我发现了一些信息,如何创建2个不同的配置文件,其中一个
用于具有调试功能的开发模式,另一个用于
部署。以下是我从Google IO演示文稿中找到的内容。
人有没有这种设置?有人可以解释如何运行它?

  MyAppCommon.gwt.xml 

< module>
...
< define-property values =debug,releasename =app.config/>
< replace-with class =myapp.debug.DebugConsole>
< when-type-is class =myapp.Console/>
< when-property-is name =app.configvalue =debug/>
< / replace-with>
...
< / module>
MyAppDebug.gwt.xml
< module>
...
< set-property name =app.configvalue =debug/>
< / module>


解决方案

使用特定模块进行调试的想法在某些时间浮动,并且在此Google中也有提及I / O演示文稿(请参见幻灯片33或从视频中的0h31m开始)。



基本思想是您有一个标准 GWT模块和第二个 debug 模块,该模块继承此标准模块,配置一些属性,并在调试时使用GWT的延迟绑定来替换某些具有特定实例的类。



然后,你只需要配置你的Maven / ant build来编译相应的模块,具体取决于你处于开发模式还是释放模式。



在我的项目中,我没有创建app.config延迟绑定属性,但我可能会在稍后执行此操作。我做了以下事情:

创建一个标准模块



com / example / MainModule.gwt.xml :

 < module rename-to =mainModule> 
<继承名称=com.smartgwt.SmartGwt/>

<! - - (其他配置) - >

<! - gwt-log配置 - >
< define-property name =log_levelvalues =OFF,DEBUG/>
<继承名称=com.allen_sauer.gwt.log.gwt-log-common/>

<! - 我们想要编译的语言环境 - >
< extend-property name =localevalues =en/>
< extend-property name =localevalues =fr_FR/>

< / module>



创建了一个调试模块,它继承了标准模块并为开发配置了一些额外的属性< h3>

com / example / MainModuleDebug.gwt.xml:

 < module重命名到= mainModule > 
< inherits name =com.example.MainModule/>

< set-property name =user.agentvalue =gecko1_8/>
< set-property name =localevalue =fr_FR/>
< / module>


注意:重命名属性在这里非常重要,因为您希望两个模块都以完全相同的名称进行部署。当您在开发过程中编译时,您不希望必须更改所有的html主机页面以指向调试模块。


配置Maven和gwt-maven-plugin来编译正确的模块

 <项目> 
(...)
<属性>
(...)
<! -
附加到我们在子项目中编译的GWT模块的名称后缀。
默认情况下为空,该后缀被某些配置文件覆盖以指定要编译的替代模块。
- >
< gwt.module.suffix>< /gwt.module.suffix>
<! - 我们强制默认重新编译GWT(除非使用gwtDebug配置文件 - 请参阅下面的更多信息) - >
< / properties>
(...)

< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> gwt-maven-plugin< / artifactId>
<配置>
(...)
< module> com.example.MainModule $ {gwt.module.suffix}< / module>
< / configuration>
< / plugin>

(...)

<个人资料>
<! - 此配置文件应在*开发*期间使用 - >>
<个人资料>
< id> gwtDebug< / id>
<属性>
< gwt.module.suffix>调试< /gwt.module.suffix>
<! - 告诉gwt-maven-plugin仅在必要时重新编译GWT模块 - >
< / properties>
<激活>
<属性>
<名称> gwtDebug< /名称>
< / property>
< / activation>
< / profile>
< / profiles>
< / project>

只需执行maven clean install即可编译生产模块。在开发过程中,您可以使用mvn clean install -DgwtDebug来激活gwtDebug配置文件,然后编译调试模块。

.m2 / settings.xml始终定义gwtDebug属性...



同样的想法也适用于Ant。但是我对它并不熟悉。






当你开始玩弄重写真实模块的想法时一个调试模块,您开始设想一些非常酷的可能性:




  • 您可以添加性能日志,这些性能日志会在代码中被修剪您可以将所有toString()方法配置为在调试模式下返回有用的内容,并在生产时返回空字符串(从而减少.js大小)。
  • li>
  • 您可以通过指定一个语言环境/一个浏览器/一个日志级别来减少排列次数,从而加快编译速度(但不要忘记随时测试其他语言环境/浏览器)。


I recently deployed inadvertently a debug version of our game typrX (typing races at www.typrx.com - try it it's fun). It was quickly corrected but I know it may happen again. After digging on Google I found some info how to create 2 different profiles, one for development mode that has the debug functions and one used for deployment. Here is what I found from a Google IO presentation. Does anyone have this setup? Can someone explains how to run this?

MyAppCommon.gwt.xml 

<module> 
  ... 
  <define-property values="debug, release" name="app.config" /> 
  <replace-with class="myapp.debug.DebugConsole"> 
    <when-type-is class="myapp.Console" /> 
    <when-property-is name="app.config" value="debug" /> 
  </replace-with> 
  ... 
</module> 
MyAppDebug.gwt.xml 
<module> 
  ... 
  <set-property name="app.config" value="debug" /> 
</module> 

解决方案

The idea of using a specific module for debugging has been floating around for some times, and was also mentioned in this Google I/O presentation (see slide 33 from PDF or at 0h31m in the video).

The basic idea is that you have a standard GWT module, and a second debug module that inherits this standard module, configures some properties, and uses GWT's deferred binding to replace some classes with specific instances when debugging.

Then, you only have to configure your Maven / ant build to compile the appropriate module depending on wether you are in development mode or in release mode.


In my project, I did not create an "app.config" deferred binding property, but I might do that later on. What I did was the following:

Created a standard module

com/example/MainModule.gwt.xml:

<module rename-to="mainModule">
    <inherits name="com.smartgwt.SmartGwt" />

    <!-- (other configurations) -->

    <!-- gwt-log configuration -->
    <define-property name="log_level" values="OFF,DEBUG" />
    <inherits name="com.allen_sauer.gwt.log.gwt-log-common" />

    <!-- Locales we want to compile for -->
    <extend-property name="locale" values="en" />
    <extend-property name="locale" values="fr_FR" />

</module>

Created a "debug" module, that inherits the standard module and configures some additional properties for development

com/example/MainModuleDebug.gwt.xml:

<module rename-to="mainModule">
    <inherits name="com.example.MainModule" />

    <set-property name="user.agent" value="gecko1_8" />
    <set-property name="locale" value="fr_FR"/>
    <set-property name="log_level" value="DEBUG" />
</module>

Note: the rename-to attribute is very important here, since you want both modules to be deployed under the exact same name. When you compile during development, you do not want to have to change all your html host pages to point to the debug module.

Configured Maven and the gwt-maven-plugin to compile the right module

<project>
    (...)
    <properties>
    (...)
    <!--
    Suffix appended to the names of the GWT modules we compile in our child projects.
    Empty by default, this suffix is overriden by some profiles to specify an alternative module to compile.
     -->
    <gwt.module.suffix></gwt.module.suffix>
    <!-- We force GWT-recompilation by default (except when using the "gwtDebug" profile - see below for more info) -->
    <gwt.compiler.force>true</gwt.compiler.force>
    </properties>
    (...)

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>gwt-maven-plugin</artifactId>
    <configuration>
        (...)
        <module>com.example.MainModule${gwt.module.suffix}</module>
    </configuration>
</plugin>

    (...)

    <profiles>
    <!-- This profile should be used during *DEVELOPMENT* -->
        <profile>
            <id>gwtDebug</id>
            <properties>
                <gwt.module.suffix>Debug</gwt.module.suffix>
             <!-- Tells gwt-maven-plugin to recompile GWT modules only when necessary -->
                <gwt.compiler.force>false</gwt.compiler.force>
            </properties>
            <activation>
                <property>
                    <name>gwtDebug</name>
                </property>
            </activation>
        </profile>
    </profiles>
</project>

Simply doing "maven clean install" will compile the production module. In development, you use "mvn clean install -DgwtDebug" to activate the gwtDebug profile, which in turn compiles the debug module.

Of course, you could configure your ~/.m2/settings.xml to always define the "gwtDebug" property...

The same idea would also apply to Ant. But I'm not well versed with it.


When you starts to toy with the idea of overriding your real module with a debug module, you start to envision some very cool possibilities:

  • You could add performance logs, which would be pruned from the code when in production.
  • You could configure all your toString() methods to return something useful when in debug mode, and the empty string when in production (and thus reduce the .js size).
  • You may reduce the number of permutations by specifying only one locale / one browser / one log level, to speed up the compilation (but do not forget to test for other locales / browsers from time to time).

这篇关于如何创建开发/调试和生产设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆