Friday, December 11, 2009

New Apache.org artifact repositories for Maven you should be aware of

I recently tried creating a Maven core integration test using the archetype that the team kindly created. However when I tried to use it I got Unable to find resource 'org.apache.maven.its:maven-it-sample-archetype:jar:1.0-SNAPSHOT'.

Turns out this artifact does not live in http://people.apache.org/repo/m2-snapshot-repository - instead I've learned that Apache has new Maven repositories set up now that projects there are slowly adopting.

Wondering why I never heard about it before....

Anyways I added a proxy for https://repository.apache.org/content/groups/snapshots-group/ to my local Nexus install. Then I disabled my old proxy for http://people.apache.org/repo/m2-snapshot-repository since the snapshots-group includes the PAO repo. Finally I added the new repo to my 'All Repositories' and 'Public Snapshot Repositories' group in Nexus so that my Maven build will pick it up.




Here is some information I found out about the new repos.

http://www.apache.org/dev/repository-faq.html

https://issues.apache.org/jira/browse/INFRA-1896

The new Apache.org artifact repositories - use em' or else.

Thursday, December 10, 2009

Robustly enforcing a minimum Maven version for your project

Maven user's quickly realize that it is a good idea to force a fixed (or at least minimum) version of Maven to be used to build their Maven project. Initially one may gravitate towards using the following pom snippet:

<prerequisites>
  <maven>2.0.10</maven>
</prerequisites>

Looks good, except there are a couple gotchas
1. Typos. If you make one then you will get no warning or complaints from maven. You might as well have this.

<prerequisites>
  <maven>Maven treats this string as older than any Maven version you might use</maven>
</prerequisites>

A bug is even more likely if you do this:

<prerequisites>
  <maven>${maven.min-version}</maven>
</prerequisites>

Let's say that property can't be resolved for whatever reason - typos? - again Maven will treat that 'version' as older than any valid Maven version you could be executing the POM with. This is actually not a bug but by design since Maven does not force project's ( in this case Maven itself) to a strict version number specification.

2. Another problem is that section is not even used at all by the next major version of Maven 3.x as of today. So even if you did have it right, it is not future proof.

3. Finally maven considers versions like "1.0-alpha-2" to be newer than "1.0-alpha-15" as of Maven 2.x series at least. A bug indeed in the version compare logic - the failing test cases being commented out in the source code. Although Maven 3.x ignores prerequisites in pom, at least the version comparison noted here is fixed.

4. Lastly the <maven> element does not handle version ranges. So when it sees [2.0.6,2.0.8], we are just back to problem 1.

So what to do?

Use the maven-enforcer-plugin instead. The benefits are:

1. Many different rules supported, not just Maven version.
2. Write your own rules.
3. Version ranges are supported.
4. Version comparisons are more robust.
5. Bind the version check to Maven lifecycle phases or profiles.

Below is an example configuration for the plugin to require a minimum Maven version 2.0.9 and above. The unique thing about this example is that there are three executions, one for each pre-defined Maven build lifecycle. Usually you just see the first execution only, which is bound to the validate phase of the default lifecycle. However if one were to do
mvn clean
or
mvn site
then the version validation would not be enforced since those goals do not have a validate phase. Having all three executions covers all the bases.

The other best practice is define a property to hold the Maven versions so that it can be changed in one place only or manipulated on the cmd line.

<properties>
  <maven.min-version>2.0.9</maven.min-version>
</properties>

<plugin>
  <artifactId>maven-enforcer-plugin</artifactId>
  <executions>
    <execution>
      <id>enforce-default</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireMavenVersion>
            <version>[${maven.min-version},)</version>
          </requireMavenVersion>
        </rules>
      </configuration>
    </execution>
    <execution>
      <id>enforce-clean</id>
      <phase>pre-clean</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireMavenVersion>
            <version>[${maven.min-version},)</version>
          </requireMavenVersion>
        </rules>
      </configuration>
    </execution>
    <execution>
      <id>enforce-site</id>
      <phase>pre-site</phase>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireMavenVersion>
            <version>[${maven.min-version},)</version>
          </requireMavenVersion>
        </rules>
      </configuration>
    </execution>
  </executions>
</plugin>

Sunday, November 29, 2009

Maven plugin groupId org.codehaus.mojo not searched by default??

I got interested in removing all my explicit org.codehaus.mojo declarations on my plugin dependencies since now Maven supports searching that groupId for a plugin's artifactId. This feature was added a while ago I guess.

Just came across a nasty little bug in Maven 2.2.1 which has been reported since 2.0.9.

[#MNG-4001] Unable to resolve Dashboard mojo from Central - jira.codehaus.org

The summary above is very misleading. In fact I consider myself lucky to find it since it more has to do with any org.codehaus.mojo based plugin.

When I did try to remove my plugin's groupIds I got the classic "Unable to find resource 'org.apache.maven.plugins:buildnumber-maven-plugin:pom:1.0-beta-4' in repository central".

Turns out this may be related to maven metadata in my local repo and/or the remote repos being randomly deleting version info???? See the bug followups for more info.

In fact this bug is nasty because
1. there is no mention in the error that is what could be wrong.
2. Adding a pluginGroups section to your ~/.m2/settings.xml file with that group changes nothing, even in the error output. Plus using -X shows that maven does not even try to locate org.codehaus.mojo version of that plugin or any other groupId specified in your pluginGroups settings. It may have looked at the metadata, but we would never know.
3. Deleting your local maven metadata may only fix the error temporarily or not at all.
4. Try this: Define your plugin configuration in pluginManagement without the groupId. Next, define the same plugin in a profile with the groupId. Run a mvn cmd that activates the profile and you will notice that none of your plugin settings inside plguinManagement gets picked up - and of course there is no warning or messages in the debug output that complain. Add the group id to the pluginManagement section and it all of a sudden works as expected.

So the rule of thumb is leave well enough alone and always explicitly specify the groupId for all plugins except org.apache.maven.plugins groupId which still work.

Saturday, November 28, 2009

Blogger: Awesome code syntax highlighting made easy

This post represents my to-date findings on the best way to paste source code into a Blogger based blog post. The goal is to have something with enough sugar for reading the post in the browser and also having it RSS reader compatible.

Several poor man solutions are out there. Examples are here and here.
Basically these are javascript based apps which take your code and apply some html escaping and wrap it with a <pre> tag and inline styles.

I remembered liking what YUI uses on their site. It is a syntax highlighter written by Alex Gorbatchev and can be found here. A summary of how to add it to your Blogger posts is here. This is more advanced in terms of display and user options.

While 'pretty', the Gorbatchev highlighter has the caveat that all the sugar goes away in RSS readers. I mean it works, however the result is just monospaced font.

By combining the Gorbatchev highlighter with the simplified source code formatters approach, I can have the best of both. Code that looks good in the browser and also when read with an RSS reader.

1. Edit your blogger template following the instructions outlined here to activate the Gorbatchev SyntaxHighlighter.

2. (Optional) Install this Firefox add-on Clippings to make pasting the required html into the blogger editor easy.

3. Use the following html to wrap your source code you paste into the editor. Remember that any source code must be html escaped ( < brackets must be escaped!)

<pre class="brush: xml;" style="font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace, monospace;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:14px;">
<!-- your code goes here -->
</pre>

The "brush: xml" part indicates what type of source code you are formatting. I suggest making a new clipping in the Clippings add-on (step 2) for each type source code you typically are pasting into your blog. See this page for more info on brushes and this page on how to specify additional parameters to the source code formatter.

Make sure to use the pre element version of the code block and not the script element version since script tags are removed in rss feeds.

4. Test it out. Create a new blog post, click the 'Edit Html' tab of the blogger editor. Make sure the Post Options include "Show HTML Literally" checked. Right click inside the editor textbox and select a clipping from the Clippings menu to paste a preconfigured pre block. Add some source code and publish your post.
Note: To see the full effect remember to publish your post since the popup preview window in Blogger editor only shows the simplified version of the formatting.

Here is an example of what code will look like when viewed in a browser.

/**
 * SyntaxHighlighter  
 */  
function foo()  
{  
  // it works!  
}

Here is an example of what RSS readers typically display. The class attribute will have no effect.

/**
 * SyntaxHighlighter  
 */  
function foo()  
{  
  // it works!  
}


Caveats:
1. The flash based toolbar will not show up on some mobile platforms for obvious reasons. Not a big deal as that is just sugar.
2. The described solution I use depends on using the Clippings add-on in Firefox and therefore the Firefox browser. Other browsers may have some similar plugins available - I dunno. Either way it is not critical.

If anyone has found a better solution please let me know.

buildnumber-maven-plugin helpful improvements

I've used the buildnumber-maven-plugin to include revision ids and timestamps in my builds for many years. Today I upgraded to the most recent version and that helped get rid of a few workarounds I had in place.

Using a previous version of the plugin, if there was no svn on your path, or your project was not checked in yet to subversion, the plugin failed the build due to svn checks. The workaround I had was to add it to a profile that only got executed when .svn file existed and/or the useReleaseProfile property was 'true'.

Now I am relieved to see I don't need to do that anymore.

For one, there is a 'revisionOnScmFailure' property you can set in the configuration that will be used if there is any type of scm exception - a byproduct of which disables further scm communication.

Second you can specify the plugin to use the javasvn scm provider implementation in case there is no 'svn' executable on your PATH. At first pass it might seem unlikely that when dealing with a subversion based project a developer would not have svn on the path, and that is likely true. Consider though that the svn version may be wrong (in which case svn may complain about not being new enough and fail the build) or you are building in a continuous integration env like hudson and you want reproducible use of the same svn tool. In those cases it makes good sense to configure the plugin with "javasvn". See below example:

<plugin>
  <groupid>org.codehaus.mojo</groupid>
  <artifactid>buildnumber-maven-plugin</artifactid>
  <version>1.0-beta-4</version>
  <configuration>
    <revisiononscmfailure>UNKNOWN_REVISION</revisiononscmfailure>
    <providerimplementations>
      <svn>javasvn</svn>
    </providerimplementations>
  </configuration>
  <executions>
    <execution>
      <id>buildnumber-one</id>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
    </execution>
    <execution>
      <id>buildnumber-two</id>
      <phase>validate</phase>
      <goals>
        <goal>create</goal>
      </goals>
      <configuration>
        <format>r${buildNumber} {0,date,yyyy-MM-dd'T'HH:mm:ss.SSSZ}</format>
        <items>
          <item>timestamp</item>
        </items> 
      </configuration>
    </execution>
  </executions>
</plugin>

The two executions is so that I can give some context to the ${buildNumber} by prefixing it with 'r' and adding a timestamp formatted along with it.

There are a bunch of other useful properties in this latest release. Thanks to open source.

Friday, November 27, 2009

Mac OS X environment variables + Netbeans + Maven

Applications that are not launched through your terminal in OS X do not read environment variables from ~/.profile, ~/.bash_profile and similar. These applications that launch directly can get their environment from each user's ~/.MacOSX/environment.plist file. ( You have to create it!)

I heard of this before, but I wanted to make note of a quick way to ease the maintaining of that file and finally had a need because of Netbeans.
  1. Downloaded Brian D Foy's Perl plist lib and installed it.
  2. Used a 3 line script to generate the ~/.MacOSX/environment.plist file from my terminal's ENV variable as he suggested.
  3.  Log out and log in for the file to take effect.
Now I can be sure the PATH that Netbeans sees is the same thing that mvn and other tools are seeing when I execute them on the cmd line. Also I don't really have to worry about maintaining my env in two places as one is derived from the other.

References
Technical Q&A QA1067: Setting environment variables for user processes
Helpful Summary of other ways to set env variables in OS X
Brian D Foy's Perl plist reader lib and blog post
Netbeans documentation on working with OS X Environment variables

Update
Another method is setting environment variables inside your
/etc/launchd.conf
file as described here - there are clear benefits to this for apps launched outside your personal login.

Thursday, November 26, 2009

Maven Special Character Encoding Properties for Sites and Reports

Thanks to the post on the Sonatype blog I've got two other global properties to set in my global parent pom that sets the encoding for Maven reports - most of them anyways.

Sonatype Blog: Special Character Encoding Properties

project.build.sourceEncoding
project.reporting.outputEncoding

Thanks for the summary Anders Hammar.

Saturday, November 14, 2009

Slipstream Service Pack 3 into Your Windows XP Installation CD

So I finally got bored of installing Windows XP a few times during some cross platform testing, setting it up with all my options and service packs etc.

I've got a Windows XP SP1a CD, but I wanted an SP3 install out-of-box. I had slipstreamed before, but somehow lost the CD during some moves. The good folks at lifehacker set me straight.

Slipstream Service Pack 3 into Your Windows XP Installation CD - Customization - Lifehacker

What I like about this solution the most is the use of nLite to create the whole package, which worked great! No cmd line work at all. It couldn't be easier I suppose.

Lastly since I was burning it from Windows XP running in VMWare Fusion, I had to enable DMA on the IDE channel my Mac Pro's CD drive was attached with.
Else nLite was throwing a burning error. Simple workaround below courtesy of this link here as a reminder.

To enable DMA mode using the Device Manager
  1. Open Device Manager.
  2. Double-click IDE ATA/ATAPI Controllers to display the list of controllers and channels.
  3. Right-click the icon for the channel to which the device is connected, select Properties, and then click the Advanced Settings tab.
  4. In the Current Transfer Mode drop-down box, select DMA if Available if the current setting is "PIO Only."
    If the drop-down box already shows "DMA if Available" but the current transfer mode is PIO, then the user must toggle the settings. That is:

    • Change the selection from "DMA if available" to PIO only, and click OK.
    • Then repeat the steps above to change the selection to DMA if Available.


Friday, October 30, 2009

Will I be saved by The Energy Detective (TED)?

So long story short...

I was living in the dark ages with a low power bill and a 13" TV. We decide to get a new TV. Want good picture, large screen and low price. Can't have it all. So I buy a soon to be dinosaur Panasonic Plasma 40". Return it if I don't like up until 30 days. Sounds fine.

Meanwhile at day 32 I happen to get the latest power bill. MORE THAN DOUBLED!!!! Too late - can't return it.

Decide immediate course of action is use power bar on TV and peripherals suspecting phantom power ( let alone regular use of this beast). Decide to order one of the Energy Detective ( TED 5000-C ) devices and look for other ways to reduce power. So popular of course I may have to wait 3-6 weeks before it arrives.

Preparing for the worse - may end of selling the plasma to save hundreds of dollars each month.

Saturday, August 22, 2009

Patching Office 2000 with SR1

I recently needed to install Microsoft Office 2000 fully patched from an old CD I had lying around. After installing the original release, I started down the patch trail, because it looked like the Excel file I was trying to read wasn't going to display properly in the Excel viewer app that M offers.

After trying the SR-1 patch from the Microsoft website, it failed with a error in the log of


Starting execution.
Command line: /c /L2
Opening the patch source file, C:\DOCUME~1\plynch\LOCALS~1\Temp\IXP001.TMP\source.ini.
Searching installed products.
Detected the following products for patching:
Microsoft Office 2000 Premium (9.0.2720), {00000409-78E1-11D2-B60F-006097C998E7}
Product is patchable.
{00010409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00020409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00030409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00100409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00110409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00120409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00130409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00160409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00170409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00180409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00040409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00140409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{004A0409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{00150409-78E1-11D2-B60F-006097C998E7}
Product is not installed.
{3C5E0FF2-BE09-11D1-998E-00A0C90A43B3}
Product is not installed.
The following patches are applicable:
Office 2000 SR-1 Core Update, {0DC0F122-1B1C-11D4-AED6-00C04F022C53}
Location: http://download.microsoft.com/download/office2000prem/Update/3821h/WIN98/EN-US/data1.msp
The version of IE installed on the computer is 8.0.6001.18702
IE has already been updated to the level of Office 2000 SR-1 or above
Error: The file, C:\DOCUME~1\plynch\LOCALS~1\Temp\sr1patch\{0DC0F122-1B1C-11D4-AED6-00C04F022C53}, has an invalid size.
Beginning download of http://download.microsoft.com/download/office2000prem/Update/3821h/WIN98/EN-US/data1.msp.
Finished downloading http://download.microsoft.com/download/office2000prem/Update/3821h/WIN98/EN-US/data1.msp.
Error: The file, C:\DOCUME~1\plynch\LOCALS~1\Temp\sr1patch\{0DC0F122-1B1C-11D4-AED6-00C04F022C53}, has an invalid size.

Well that was fun....

Apparently the fully standalone SR-1 update was no longer available from Microsoft. The office update site just offers the 166k setup installer o2ksr1a.exe which has to contact the Microsoft website to download the real guts.

So I had to resort to patching the original office setup files with the administrators patch file. Since I never did that before I thought I would make note of it here:

  1. Copy the entire administrative share or create a new administrative share of the Office installation to a directory ( Example c:/sr1 ).
  2. Download the Data1.exe file found here. ( Edit: As noted here use the direct link to Data1.exe because since I wrote this post it no longer appears listed on the download page). Then run the exe and extract the contents to c:/sr1
  3. Open a cmd prompt, cd c:/sr1 and type the following to update the original release of office to be sr1 in your administrative share. More info here. C:\sr1>msiexec /p DATA1.MSP /a data1.msi SHORTFILENAMES=TRUE /qb /L* log.log
  4. Now run the office setup again and sr1 should get installed.
  5. Continue on with the rest of the updates to office, which can be found here.

Tuesday, June 9, 2009

IPhone 3GS is coming June 19

I've been strategizing how and when I will get an IPhone ever since I bought one for my wife back in February. Now that the latest hardware is due out June 19, I expect to be taking action soon.

Rogers seems to be missing any mention of the launch on its homepage. Who ever is in charge of marketing there appears to be missing the boat. Fido at least has one banner ad, although it just points to the apple home page. Curious...and typical Canadian...

Watch the Keynote.

If you haven't checked out the WWDC Keynote mentioning all the latest Apple goodies, I recommend it.

Update
Fido at least now has a FAQ. Good news is the prices appear to be the same as the US prices.

Sunday, June 7, 2009

Ebooks on the IPhone

My previous solution to reading documents on the IPod Touch was emailing myself the document as an attachment and opening it up in the email reader on the device. Inspired by the many ebooks offered at Pragmatic Bookshelf, I tried to find a better way today.

It seems I have just found a pretty good solution thanks to this post. The parts are:
  1. Calibre -"a complete e-library solution and thus includes library management, format conversion, news feeds to ebook conversion, as well as e-book reader sync features and an integrated e-book viewer."
  2. Stanza for IPhone - The most popular IPhone ereader.
There are limitations with converting a pdf for example and displaying that on the device. For example, I took an Apple developer library PDF file, converted it to epub format with Calibre and synced it too my touch. Opened it in Stanza and most of the text was missing. The same book opened in Stanza desktop opened and showed words just fine, however lacked the images.
I also tried the Stanza desktop app for converting the pdf and syncing it to my device. It couldn't open the PDF file and display it correctly for some reason.

I guess converting pdfs is still a fine art. It appears that for books targetted as ebooks, the Stanza reader will work out just fine and Calibre will do its job helping to keep it all organized.

Learning Objective-C Begins

So I've primarily been a Java and Web Application Developer for the past ten years. Seeing how it was always easy to find new technologies/strategies/methodologies to learn in the Java world, I never gave serious thoughts on trying to focus on other languages. I still think I could work in Java for the next 10 years and still not get bored or run out of things to learn.

However the realities of my situation have motivated me to at least explore learning Objective-C and developing something for the Apple platforms.
  1. I own a very powerful Mac Pro and an IPod Touch. I love them both and don't see me switching to a Windows or any other OS ever again. Aside from my day to day hacking, I seem to be squandering an opportunity to really make use of this hardware at my disposal.
  2. I am currently not employed. Most likely I have the entire summer to try anything else other than what an employer needs from me.
So I've waded into the shallow end and it is not bad at all. First up were the Coding in Objective-C screencasts by Bill Dudney over at Pragmatic Bookshelf. Bill does a good job with these and I breezed through without any problem. Next I picked up Programming in Objective-C 2.0 by Stephan Kochan. It's always nice to have a reference like this on hand in hard copy. I've gone through the first couple chapters and the book is showing me exactly what I need to know.

First impressions are Objective-C is not that difficult to get started in. I am really impressed with the power of Apple's XCode IDE as well. I regret not making the time to start playing with it sooner. This looks like it is going to be fun.

Saturday, June 6, 2009

Latest Greatest Google Invention: Google Wave

Despite what one may think of Google, I think it is nice that there are companies that can afford to have very smart people dream up new technologies for the rest of us. I took 1h 20m to watch and listen to the Google Wave presentation at Google I/O and was glad I did.



I can't help admit the demos were pretty cool. The real time translation at the end was a showstopper. What do you think?

Sorting Account List in Thunderbird

It has always annoyed me that sorting the account list in the left pane of Thunderbird was not a built in option. I finally broke down and did something about it - I found a great Thunderbird add-on called Folderpane Tools 0.0.5.1 that does just this and now I can put all my old email accounts at the bottom of the list.

Problem solved. Thanks to the author.

Saturday, May 30, 2009

Integrate Mac OSX Address Book and Thunderbird

Since I have an Ipod Touch, I pretty much have to store my contacts in Mac OSX Address Book application so that they can sync to my device. Problem is, I also prefer Mozilla Thunderbird to handle my email. When I had looked in Sept 2007 ( when i got my Mac Pro ) there was no easy way to have my contacts in Address Book available to Thunderbird. In fact there was a bug open since 2003. Hoping this has been addressed (no pun intended), I did a quick Google and found that there is now a way... and actually there had been for a long time which either I missed or ignored before. A good summary of options to share address books with Thunderbird is here.

Since the release of Thunderbird 3 in 2008 never happened, I am left with the choice to install beta2, one of the nightlies, or build from scratch myself. The nightlies are found here.

I downloaded the May 30 nightly, but I have not decided to give it a whack yet. If I do I'll post back to let you know my experience.