Change GWT application behavior between deployed and debug environment - gwt

I would like to have my GWT application use different constants when debugging or developing vs when deployed. What is the right way to do this? My web searches turn up a lot of pages about debugging GWT applications, which isn't what I'm looking for.

This looks like a job for deferred binding! ;)
It would look something like this (put this in your module XML file, I haven't actually tested it, but you should get the gist of it):
<define-property name="debug" values="true,false" />
<set-property name="debug" value="true" />
<replace-with class="package.Constants">
<when-type-is class="package.Constants"/>
</replace-with>
<replace-with class="package.ConstantsDebug">
<when-type-is class="package.Constants" />
<when-property-is name="debug" value="true"/>
</replace-with>
See the docs for more information on available parameters, rules and whatnot.

Related

How to differentiate between build configurations in Eclipse (C) project template to setup build cfg sepcific settings?

I'm trying to play with Eclipse (C) project template. I found this very descriptive answer of how to work with Eclipse project template from #Jonah Graham and went through Eclipse documentation - How to add project templates to CDT
I'm able to create the project template and setup some settings by "SetMBSStringOptionValue"
<!-- Set TMP setting by adding textual build settings -->
<process
type="org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue">
<simple name="projectName" value="$(projectName)" />
<complex-array name="resourcePaths">
<element>
<simple name="id" value=".*compiler\.option\.misc\.other*" />
<simple name="value" value="TMP_SETTING_RELEASE" />
<simple name="path" value="" />
</element>
</complex-array>
</process>
My question is how do I differentiate between build configurations? E.g. I want to setup different settings for "Debug" and "Release" build configuration. How should I do that?
AFAIK no one has provided a "process runner" that allows the configuration to be specified when setting the options.
What you can do is add your own subclass of org.eclipse.cdt.core.templateengine.process.ProcessRunner, basing it on org.eclipse.cdt.managedbuilder.core.SetMBSStringOptionValue that additionally lets you specify the configuration to apply it to. The Eclipse extension point you need is org.eclipse.cdt.core.templateProcessTypes.
Keep in mind when you do that users do a new project wizard they can choose to have/not have Debug/Release configs as shown in this screenshot:

How we can use custom settings for sonar in eclipse?

I am using SonarLint for better code. This is using default settings. I have an xml file with following entries.
<profile>
<name>Sonar Way with Custom rules</name>
<language>java</language>
<rules>
<rule>
<repositoryKey>common-java</repositoryKey>
<key>DuplicatedBlocks</key>
<priority>MINOR</priority>
</rule>
<rule>
<repositoryKey>common-java</repositoryKey>
<key>InsufficientBranchCoverage</key>
<priority>MAJOR</priority>
<parameters>
<parameter>
<key>minimumBranchCoverageRatio</key>
<value>65.0</value>
</parameter>
</parameters>
</rule>
<profile>
My question is how I can use this xml as my custom settings for SonarLint.
Thanks
The correct way of doing it is to define a Quality Profile in a SonarQube server with the rules that you want to activate and connect SonarLint to it.
For more information, check the "Connected mode" section for the IDE you are using in http://www.sonarlint.org.

How to speed up Alfresco Share development

I'm developing and performing some customization on Share. My IDE is Eclipse Juno and workspace is made up of the next elements:
alfresco web project
extensions Java project
share web project
Both alfresco and share web projects are deployed in separate Tomcat instances, this way I can slightly speed up my development tasks by restarting only the Tomcat instance where Share is deployed.
My extensions Java project has the same structure as the Eclipse project proposed by Alfresco. Y the provided Ant tasks for compiling, compressing JavaScript files, packaging and deploying the resultant JAR file in Tomcat.
I'm developing some new JavaScript client-side widgets, which means every time I make a change I have to stop Tomcat, launch Ant build script and start again so as I have to do it very often, you can guess what a pain it is becoming. I was just wondering if there exist any way to speed up development tasks on Share. How do Alfresco developers team do it? What kind of environment do they set up?
I was thinking about creating a new Ant target which hot deploys extension project's content into deployed Share web project, taking into account paths of course; that mechanism must allow the reverse operation by the way. Would that be viable? The idea would be to have a similar deploy mechanism as when you develop regular web projects: when you make any change you just push the "Publish" button and the changes are populated into the server.
I would like to know some tips and ideas, specifically from Alfresco developers team if possible.
PS: I have already read https://forums.alfresco.com/en/viewtopic.php?f=47&t=44850 and https://forums.alfresco.com/en/viewtopic.php?f=48&t=18749.
Two things that speeds up things a lot:
Invest in a jrebel license for class reloading without server restart http://zeroturnaround.com/software/jrebel/
Construct ant tasks that copy webscripts to the target folder and reloads webscripts with curl if necessary.
Example of a task that reloads an Alfresco Share webscript:
<target name="deploy-share-webscripts" depends="Share: Copy files" description="Refreshes the list of webscripts">
<exec executable="curl">
<arg value="-d"/>
<arg value="reset=on"/>
<arg value="http://admin:admin#${share.web.url}/page/console?reset=webscripts"/>
</exec>
</target>
Appending the copying part of the ant task (the src-dirs are declared as properties in the beginning of the buildfile):
<echo message="- Copying java classes" />
<copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
<fileset dir="${warTargetJavaDir}" />
</copy>
<echo message="- Copying resource files" />
<copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
<fileset dir="${warSrcResourcesDir}" >
<include name="**/model/*"/>
<include name="**/templates/**/*"/>
<include name="**/custom-model-context.xml"/>
<include name="**/web-client-config-custom.xml"/>
<include name="**/webclient.properties"/>
<include name="**/aka-model-resourcebundle*"/>
<include name="log4j.properties"/>
</fileset>
</copy>
<echo message="- Copying resource files from amp into war for quick deployment." />
<copy todir="${warWebappTargetClasses}" overwrite="false" verbose="true">
<fileset dir="${projectAmpResourcesSrcDir}" />
<fileset dir="${projectAmpClassesDir}" />
<fileset dir="${listmanagerAmpResourcesSrcDir}" />
</copy>
<echo message="- Copying config files from amp into war for quick deployment." />
<copy todir="${warWebappTargetClasses}\alfresco\module\Project-amp\" overwrite="false" verbose="true">
<fileset dir="${projectAmpConfigSrcDir}" />
</copy>
</target>
I use the maven alfresco lifecycle http://wiki.alfresco.com/wiki/Managing_Alfresco_Lifecyle_with_Maven for my setup, which also speeds up things. I sure a lot can be added to this topic.
You can avoid copying the webscripts to the tomcat by configuring additional paths for tomcats shared classloader. This is a setting in tomcat/conf/catalina.properties. I set this directly to the projects source directory so there is no need for the compile step.
shared.loader=${catalina.home}/shared/classes,${catalina.home}/shared/lib/*.jar,\
/path/to/my/dashlet/src/main/resources,\
I also have the following settings in shared/classes/alfresco/web-extension/share-config-custom.xml to enable automatic refresh of templates and webscripts.
<alfresco-config>
<!-- Global config section -->
<config replace="true">
<flags>
<!-- Developer debugging setting - DEBUG mode for client scripts in the browser -->
<client-debug>true</client-debug>
<!-- LOGGING can be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
This flag automatically activates logging on page load. -->
<client-debug-autologging>false</client-debug-autologging>
</flags>
</config>
<config evaluator="string-compare" condition="WebFramework">
<web-framework>
<!-- Autowire Runtime Settings -->
<autowire>
<!--
Developers can set mode to 'production' or 'development' (to disable; SpringSurf caches,
FreeMarker template caching and Rhino JavaScript compilation.)
-->
<mode>development</mode>
</autowire>
</web-framework>
</config>
</alfresco-config>
Well this is the solution that is working 100% as I expected. I came up with this after the answers of #erik-b and #jorn-horstmann and taking into account some posts I have read.
So basically I have the next Ant target which hot deploys the content of my Share extensions Java project:
<!--
Hot copy individual files into appropriate deployment folder (e.g. $TOMCAT_HOME/webapps/share)
-->
<target name="hotdeploy-tomcat-share" depends="clean, prepare, build-jar" description="Hot copy individual files into appropriate deployment folder (e.g. $TOMCAT_HOME/webapps/share)">
<echo message="Generating and deploying JAR file with custom configuration files" />
<jar destfile="${dist.dir}/${jar.name}">
<!-- Only including configuration XML files such as share-config-custom.xml -->
<fileset dir="${build.jar.dir}" includes="**/META-INF/*.xml" />
</jar>
<copy todir="${tomcat.share.deployment.path}/WEB-INF/lib">
<fileset file="${dist.dir}/${jar.name}" />
</copy>
<echo message="Hot deploying Share files" />
<copy todir="${tomcat.share.deployment.path}/WEB-INF/classes" includeEmptyDirs="false">
<fileset dir="${build.jar.dir}">
<patternset refid="hotdeploy-tomcat-patternset" />
</fileset>
</copy>
</target>
Auto-reloading modules feature must be disabled, otherwise every time you execute the above Ant target Tomcat will reload Share and other web apps deployed. Additionally, I believe it is also possible to hot deploy in the $TOMCAT_HOME/shared/ directory but I haven't tried it out yet.
The Java project I'm using for developing my extensions is this model project: http://code.google.com/p/share-extras/wiki/SampleProject. There is the full build script with the other targets required.
I'm also using this in my share-config-custom.xml:
<!-- Global config section -->
<config replace="true">
<flags>
<!--
Developer debugging setting to turn on DEBUG mode for client scripts in the browser
-->
<client-debug>true</client-debug>
<!--
LOGGING can always be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
This flag automatically activates logging on page load.
-->
<client-debug-autologging>false</client-debug-autologging>
</flags>
</config>
<config evaluator="string-compare" condition="WebFramework">
<web-framework>
<!-- SpringSurf Autowire Runtime Settings -->
<!--
Developers can set mode to 'development' to disable; SpringSurf caches,
FreeMarker template caching and Rhino JavaScript compilation.
-->
<autowire>
<!-- Pick the mode: "production" or "development" -->
<mode>development</mode>
</autowire>
<!-- Allows extension modules with <auto-deploy> set to true to be automatically deployed -->
<module-deployment>
<mode>manual</mode>
<enable-auto-deploy-modules>true</enable-auto-deploy-modules>
</module-deployment>
</web-framework>
</config>
The last XML snippet avoids to refresh webscripts after any change performed on an FTL page, for example.
I have also performed some tests with JRebel but after my experience I would say it doesn't helps a lot in Share development.
There is also interesting stuff in the next articles:
http://blogs.alfresco.com/wp/kevinr/2010/04/07/developer-tips-for-alfresco-share-33/
http://techblog.zabuchy.net/2012/debugging-javascript-in-alfresco/
Hope it helps others.
I'm usually working on private instances so I can afford myself to run exploded apps, so any changes are visible immediately for me. I only need to restart tomcat when I change the datamodel, deploy some new java-backed modules or webscripts or similar. Even though some of those can get reloaded live too.

GWT *.devmode.js only being built

I'm working on a GWT project in Eclipse and for some reason the .nocache.js file is no longer being built, but a .devmode.js is. I cannot find any setting that would control this. Could anyone point me in the right direction?
Edit: My gwt.xml is below
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='myapp'>
<inherits name='com.google.gwt.user.User' />
<inherits name='com.google.gwt.gadgets.Gadgets' />
<inherits name='org.adamtacy.GWTEffects' />
<inherits name='com.google.gwt.user.theme.clean.Clean' />
<entry-point class='myapp.Entry' />
</module>
Update
This appears to be related to the use of gwt-gadgets. Inheriting the library and the use of a class that extends Gadget as an entry point causes things to be built only with devmode.js and not nocache.js.
Has anyone therefore developed any Google Gadgets using GWT and deployed them successfully?
Update 2
Turns out this is not an issue, although it seems a bit odd. If Gadgets are deployed using the generated gadget.xml, then this references devmode.js and so things work as expected. The naming is off-putting though.

intelliJ idea 10 community edition and GWT plugin

Having hard time installing GWT plugin. Tried to search for GWT plugins and all I was able to find was GWT Imagebundle which is pretty outdated. Tried File Menu -> configure plugins but didn't help as the plugin is not installed yet.
Is there a support for GWT plugin in intelliJ 10 community edition? If there is can some one please point me to the right document to install it? Just to make sure, I installed scala plugin and I am able to see it in "Add modules" section.
This is my first time using intellij and I love it so far.
There is no GWT support in the Community Edition.
Starting from the version 11 it's not possible to add PROJECT_FOLDER/src as it was described in the previously posted (by ctorx) link http://java.dzone.com/tips/gwt-development-intellij-idea. Once we add a source folder it appears as an "Empty library" and doesn't work. This is because IDEA treats it as a folder where should be compiled classes not sources.
But there is a workaround. To fix it we have to hack the module's IML file. Find the following lines in the IML file of your entry point module
<orderEntry type="module-library">
<library>
<CLASSES />
<JAVADOC />
<SOURCES>
<root url="file://$MODULE_DIR$/src/main/java" />
</SOURCES>
</library>
</orderEntry>
and move your path into the CLASSES tag, so the entire thing looks like the following
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/src/main/java" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>