Monthly Archives: September 2012

git-svn vs Maven Build Number plugin

Recently I joined a project with sources hosted on external Subversion server. Migration to Git is out of the question since the central repository is located in different country and used by many teams from departments spread all over this international corporation. Fortunately, there’s “git-svn” tool which can provide many great Git features. After setting it up I initialized my repo, downloaded the latest revision and launched Maven build. Surprisingly, it exploded with following error message:

Provider message:
The svn command failed.
Command output:
svn: ‘.’ is not a working copy

[INFO] ————————————————————————
[ERROR] BUILD ERROR
[INFO] ————————————————————————
[INFO] Cannot get the revision information from the scm repository :
Error!

After quick investigation (mainly scouring through lenghty POM hierarchy) I found the culprit:

Maven Build Number plugin

This plugin gives many possibilities of generating build numbers as variables and then use them for any purpose. In my case, the plugin was included only to obtain the last svn revision number and store it in some variable. Then the value supposed to be put in .war Manifest file. Since I downloaded the sources via “git svn” there was no .svn directory anywhere and the plugin refused to work, so it terminated the whole build.

Solution

There are many options to avoid this problem, for example disabling the plugin in POM file or removing it entirely. Such methods are, however, too invasive and I didn’t want to mess with project configuration, even if it’s only on my machine. We all know that such “temporary” modifications are very likely to be eventually accidentally committed to central repo with painful consequences. Having that in mind, I went with another trick.

Silencing plugin from the inside

I downloaded source code of Maven Build Number plugin and erased most of it, leaving empty mojos with no bodies in execute() methods. Then I built it and replaced the original plugin in local maven repo with my “dummy”. Next, I launched the main project build and noticed no more svn errors. Everything went smoothly

The cost

The cost of my tinkering is of course invalid revision number in the Manifest file but I don’t believe it has any relevance for me during the development. Let the Continuous Integration server use it and save it, I am totally happy with my option.

What next?

There could be a distinction between different build types with possibility to switch them with Maven profiles. However, it adds some complexity for every person using the project, which I would like to avoid. I seem satisfied that the problem has been resolved quickly and without touching the project itself, so I can focus back on  coding.

Advertisements

Flash debug on Linux Mint 13

After a nasty struggle with configuration of Flash debugger on my 64-bit Linux dev machine, I finally found a solution. It’s a combination of few tips found on other blogs, so I decided to put it all together and publish here. Here’s a recipe that works for me, only on Chrome:

The problem

Adobe announced end of releases of Linux Flash player and browser plugin. The last official version is 11.2. Additionally, there is no 64-bit flashplayer debugger browser plugin. I have no idea why Adobe website states that there is, whilst clicking on link gives you the “i386” version.

Steps to take

Remove your current browser plugin

Depending on your Linux distribution, the flashplayer plugin can have different name or location on filesystem. First of all, uninstall your browser plugin with commands (some of them should work):

sudo apt-get purge flashplayer-mozilla
sudo apt-get purge flashplugin-installer
sudo apt-get purge flashplugin-nonfree
sudo apt-get purge mint-flashplugin-11
sudo apt-get purge mint-flashplugin

I have no idea why there is such a MESS with all these different packages, but who cares. Kill it with fire.

Download the debugger plugin

Go to Adobe website and pick the plugin named Linux Flash Player 11.2 Plugin content debugger. Notice that downloaded .zip file has “i386” in its name. This means it’s for 32-bit architecture and you are going to wrap it with ndiswrapper to make it work. Extract it and copy the libflashplayer.so file to your mozilla plugins directory. In my case it was /usr/lib/mozilla/plugins/

Wrap the library

Note it’s time for the magic part. Use following ancient spell to make your library wrapped and ready for 64-bit:

nspluginwrapper -v -a -i

Check the output, you should find a line similar to following:

Install plugin /usr/lib/mozilla/plugins/libflashplayer.so
into /home/kciesielski/.mozilla/plugins/npwrapper.libflashplayer.so

which gave me some hope that all went well.

Configure Chrome

Open Chrome and enter following address: about:plugins

You should now see a summary of your browser plugins. Your list should contain an entry for Flash player, visible as Flash (2 files). If there is only one file, then something went wrong. Click on “Details” on the right and your plugin description should expand. Disable all flash plugins except npwrapper.libflashplayer.so. Restart your browser.
Disclaimer: Why Chrome? This browser comes with a built-in Flash player and detects mozilla plugins, giving a possibility to easily switch between them. I could not manage to get the debugger plugin working on Firefox.

Verify

Open Chrome and run any flash video. Click on it with right mouse button and check the menu that appeared. If you can see an option called Debugger then it means that your browser is running the debug flash player.

Command vs Command

After an interesting meeting in new company I decided to make a quick review of Command concept from different point of views. First of all, there is the classic Command design pattern by Gang of Four. On the other hand, we have more and more popular subject of Command-Query Responsibility Segregation, which is inspired by good old Command-Query Separation (but not same thing, Wikipedia is wrong). When you design a system, you might need to make sure that you and your teammates are on the same page.

In this case, let’s make sure that we all know the difference between these two concepts of Command:

GoF Command Pattern

In this pattern, we have some abstraction of Command which represents a contract of unknown behavior. For example (in Java):

public interface Command
{
  void execute();
}

Any behavior that fits this interface can be represented as a class extending our interface.

public class RemoveAllExpiredProductsCommand implements Command
{
  public void execute()
  {
    // logic, delegation, whatever works for you
  }
}

We can now have many objects of type Command and queue them, or, for example, attach to different executors to make dynamic customizable UI. There are many other appliances of this pattern, but in order to make sense out of it, let’s sum up how it works:

  • Each command implements same interface with a simple method to fire
  • Each commands represents a behavior

Command in CQRS

In CQRS, a Command means something different. It’s mostly a simple value object representing data, not behavior. Example:

public class RemoveAllExpiredProductsCommand implements Serializable
{
  private Date expirationLimit;

  public RemoveAllExpiredProductsCommand(Date expirationLimit)
  {
    this.expirationLimit = expirationLimit;
  }

  public void getExpirationLimit()
  {
    return new Date(expirationLimit.getTime()); // hello, shitty Java time API
  }
}

Now our Command is just a sad kind of “struct“, so we could implement it much easier with, for example, Scala case class and get free getters, equals+hashCode and immutability (still, watch out for Date class). Let’s leave this subject for now. In order to execute a concrete behavior, we get such object and throw it into a generic listener, who is capable of finding an appropriate Command Handler. Such handler can then deal with logic or delegation:


public class RemoveAllExpiredProductsCommandHandler implements CommandHandler<RemoveAllExpiredProductsCommand>
{
 @Override
 public void handle(RemoveAllExpiredProductsCommand command)
 {
   // proper handling
 }
}

So, to sum up:

  • Command is a dumb DTO-like structure representing execution request parameters
  • Command Handler is responsible for capturing our DTO and it represents the behavior

If you want to build your model using DDD and CQRS then you are looking for the DTO+Handler option. Here’s github link to a good example in Java. It clearly fits architectural ideas and well-known building blocks from this realm, where a Command encapsulating behavior (the GoF option) is a nice pattern but can be confusing inside a domain where normally the behavior is implemented within entities, services and other blocks designated for that purpose.