Setting up Hudson for your Maven 2 project hosted on GoogleCode – step by step

December 12, 2009 by chenglee

You started your GoogleCode project but don’t know how to set your project up with Hudson? If so, read on.

Step one: get authenticated with SVN repository

First you should be aware that SVN client caches your credentials. So in the machine where Hudson runs, log in as the user that runs Hudson and issue a SVN command against your repository as instructed here:

http://blogs.open.collab.net/svn/2009/07/subversion-16-security-improvements.html

Step two: set up Hudson plugin for GoogleCode

To install the plugin go to to Hudson Dashboard -> Manage Hudson -> Manage Plugins. Under the Available tab, find the GoogleCode plugin and click on install.

Step three: set up your project

Go to Hudson Dashboard -> New Job. Enter the project name and click on “Build a maven2 project”. Click on ok. Enter the Google code website which should be:

http://code.google.com/p/<project name>/

For the source management section, please note that there is a bug in GoogleCode plugin that will fail to authenticate the developer connection with GoogleCode so please follow the workaround here to complete your setup:

http://malsserver.blogspot.com/2009/04/hudson-maven-release-plug-in-plug-in.html

And that’s it! Happy coding!

Perforce BEST & WORSE practices

October 8, 2009 by chenglee

All regular work should be done in trunk, rather than branches

The reason to do this is that all changes to trunk should be traceable from day zero and by branching we lose the revision history. The purpose of a branch is generally to create a release and apply patches to it, thus it makes sense to isolate the revision history from the trunk since we already know the changelist at which we branched from trunk. The same concept applies to development branches.

If big changes are to be made on branches involving file locations change, create a branch spec

Certain kinds of changes like maven-ization require moving files around to comply with the Maven convention though it’s best to override the convention by specifying multiple resource directories and at a later time divide them into multiple modules to conform a Maven multi-module project. But in case you must move them because of other reasons (e.g. you mistyped the name), create a branch spec that maps the original location of the moved elements to the new location so that you can integrate changes from the trunk until you finish your work in your branch. Note that SVN won’t detect which revisions have already been integrated unlike Perforce, so you are URGED to put the integrated revisions in your commit message to keep track of integrated revisions.

Maven scope tips and tricks

September 8, 2009 by chenglee

I think most of us are aware of the benefit of making an Eclipse project A depend on another project B directly, instead of depending on the project B jar. Just in case you don’t, consider the scenario where project A is a WAR application and B is a JAR containing your domain objects. Then you deployed it using WTP server support or Sysdeo Tomcat plugin to test it locally. The difference is the following:

  • Using a JAR of project B means that if you happen to modify any class in B, then the JAR is inconsistent and you will need to restart the context to see the changes.
  • On the other hand, if you depend on project B, then you can take advantage of the JVM’s code HotSwap and see your changes right away, without restarting the web application context.

In order to make your multi-module maven project declare dependencies between the modules of the project, you should use <scope>compile</scope> and not any other combination (such as “provided” as I’ve seen in some production code). This way, Eclipse will recognize the dependency as a Eclipse project and won’t include it as a JAR

Live Messenger not notifying new mails / updating read mail count

June 15, 2009 by chenglee

Somewhere in the time, I’ve updated to a newer Live Messenger and stopped receiving new mail notificacions (the familiar popup windows saying “You’ve received a new mail from XYZ”). I’ve checked the option to notify me of new mails in Tools -> Settings without luck:

mail-alert-checked

The "Display alerts when e-mail is received" option is checked

What’s more, the new mail count does not update after messages are read as it used to behave. Now, you have to sign out of Live Messenger and log back in again to have them refreshed. I talked to a bunch of friends running Live Messenger and the problem seems to be widespread; there are people running Live Messenger 2008, 2009 and a lot of them where having problems.

The new mail count does not update at all after mails being read

The new mail count does not update at all after mails being read

Having that said, I decided to report a bug to Microsoft but Google is not telling me the place where I could report it. So, I’m posting here until someone points me to the right URL.

Blogger vs. WordPress (part 2)

June 3, 2008 by chenglee

Well, while writing another post I found out another missing feature for Blogger. It seems that I’m not giving Blogger a break after all ;)

Have you ever tried to add an internal link to your post? Consider a really long post:

This is a loooooong post which links to paragrah 3 in this post.

Paragraph 1…..

Paragraph 2…..

Paragraph 3 !!!

Try to do the same in Blogger

WordPress 7 – Blogger 1

OSCache + Spring Framework

June 3, 2008 by chenglee

Since I didn’t find a good reference to using OSCache with Spring after browsing the web for a day or so I thought that it would be useful to have this posted.

This example uses source level metadata (JDK 5.0 annotation) to tag methods as cacheable and configure the refreshPeriod for a particular OSCache’s cache group (it’s the same concept as cache region when using OSCache with Hibernate).

We first tag the methods with annotations:

@Cacheable(modelId = "testCaching")
public List<Listing> getListings() {
  // some implementation
}

@Cacheable(modelId = "testFlushing")
public void saveListings(List<Listing> listing) {
  // some implementation
}

And then we add the following to the application-context.xml for Spring:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
  <!-- Domain -->
  <bean id="listingRepositoryXmlImpl"
    class="com.myco.service.ListingRepositoryXmlImpl"/>

  <!-- Cache Setup -->
  <bean id="autoproxy"
    class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" />

  <!--
    The created cache manager is a singleton instance of
    com.opensymphony.oscache.general.GeneralCacheAdministrator
  -->
  <bean id="cacheManager"
    class="org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean">
    <!-- Optional properties -->
    <property name="configLocation"
      value="classpath:oscache.properties" />
  </bean>

  <bean id="cacheProviderFacade"
    class="org.springmodules.cache.provider.oscache.OsCacheFacade">
    <property name="cacheManager" ref="cacheManager" />
  </bean>

  <!-- Cache-feature Weaving -->
  <bean id="cachingAttributeSource"
    class="org.springmodules.cache.annotations.AnnotationCachingAttributeSource">
  </bean>

  <bean id="cachingInterceptor"
    class="org.springmodules.cache.interceptor.caching.MetadataCachingInterceptor">
    <property name="cacheProviderFacade" ref="cacheProviderFacade" />
    <property name="cachingAttributeSource"
      ref="cachingAttributeSource" />
    <property name="cachingListeners">
      <list>
        <!-- We don't have any listener for now
          <ref bean="cachingListener" />
        -->
      </list>
    </property>
    <property name="cachingModels">
      <props>
        <!--
          Bean properties are set here for the underlying CachingModel implementation (OsCacheCachingModel).
          Here we are setting the "group" and "refreshPeriod".
          Note that the PropertyEditor will translate the semicolon separated key-values into a java.util.Map
        -->

        <prop key="testCaching"><!-- Here we map the modelId "testCaching" (Spring) to group "testCache" (OSCache), we also set the refresh period -->
          groups=testCache;refreshPeriod=5
        </prop>
      </props>
    </property>
  </bean>

  <bean id="cachingAttributeSourceAdvisor"
    class="org.springmodules.cache.interceptor.caching.CachingAttributeSourceAdvisor">
    <constructor-arg ref="cachingInterceptor" />
  </bean>

  <bean id="flushingAttributeSource"
    class="org.springmodules.cache.annotations.AnnotationFlushingAttributeSource">
  </bean>

  <bean id="flushingInterceptor"
    class="org.springmodules.cache.interceptor.flush.MetadataFlushingInterceptor">
    <property name="cacheProviderFacade" ref="cacheProviderFacade" />
    <property name="flushingAttributeSource"
      ref="flushingAttributeSource" />
    <property name="flushingModels">
      <props>
        <!-- Refresh period is set here for the underlying CachingModel implementation (OsCacheCachingModel) -->

        <prop key="testFlushing"><!-- Here we map the modelId "testFlushing" (Spring) to group "testCache" (OSCache) -->
          groups=testCache
        </prop>
      </props>
    </property>
  </bean>

  <bean id="flushingAttributeSourceAdvisor"
    class="org.springmodules.cache.interceptor.flush.FlushingAttributeSourceAdvisor">
    <constructor-arg ref="flushingInterceptor" />
  </bean>

</beans>

And that’s all there is to it. Happy caching!

Blogger vs. WordPress

May 19, 2008 by chenglee

As a regular Blogger user, I think it is time for me to expose some facts that I hate about being a Blogger. It’s become a pain in the neck and I very doubtly believe I’m the sole user in the blogosphere having problems. Anyway, what I have here is a crash-me test of WordPress against Blogger.

First, let’s see if after a bullet list, I can still write normal paragraphs, i.e. hitting double Enter key will not create a new paragraph

Sample list:

  • Item 1
  • Item 2
  • Item 3

Now, if we check the HTML code, we see that there is no <p> tag after the bullet list. If we instead do the same at Blogger, everytime we hit Enter key, it will create a new <p> tag around the text to create a paragraph. I wouldn’t be bothered if all texts were wrapped around <p> tags but this inconsistent behavior only makes my post look ugly.

WordPress 1 – Blogger 0

By the way, ever wondered how to make a nested bullet list? Just use the button “Show/Hide Kitchen Sink” from the toolbar and then click on the Indent Right button to create the following nested list:

  • hello
    • I’m nested!

There is just not any equivalent feature in Blogger.

WordPress 2 – Blogger 0

Now, let’s check if WordPress has problem with the characters “<”, “>” while we shift forth and back from HTML code to visual mode….. so far so good! It correctly converts “<” to “&lt;” and “&gt;” in HTML view. Got to love this! Blogger bites the dust on this test!

WordPress 3 – Blogger 0

Next test is preformated text, i.e. <pre> tags in this post. For that, I will switch to HTML mode and edit by hand since I need to paste in some indentated text like the one below:

  <html>
    <body>
    </body>
  </html>

Now, I’ve switched from Visual to HTML mode 4 times already and the indented text is intact, perfectly indented. If I used Blogger, every switch would “eat” a space from the indentation so at the end of 4 Visual to HTML switches, I would end up with a text like the following:

<html>
<body>
</body>
</html>

which makes Blogger totally useless for anyone who wishes to edit HTML code once in a while.

WordPress 4 – Blogger 0

How about undo? what if I made a few mistakes and would like to undo my actions? Blogger doesn’t have undo.

WordPress 5 – Blogger 0

Fullscreen edit? WordPress still remains as Queen of the castle

WordPress 6 – Blogger 0 

Ok let’s give Blogger some credit since it seems to manage changing text color correctly. In my test with Internet Explorer, selecting a text and trying to change its color raises a “do you wish to navigate way from this page” dialog box. This would not happen in Blogger.

WordPress 6 – Blogger 1

Well, I think I will stop for now and just let Blogger catch a breath and fix the bugs before I start again with the crash-me test. Hope next time I write WordPress and Blogger are even.