Tuesday, January 5, 2010

IDEA 9, Gradle and Eating Your Own Dogfood

After reading the comment on a post a few weeks ago regarding Intellij 9 and Gradle, I had to laugh. Having worked on open source projects for 15+ years and presenting at countless conferences and user groups, I have stated roughly the same comment countless times... "It's open source, if you don't like it or you want a change, then do it!". Thanks to Peter for the suggestion and encouragement. It clearly seems that my actions were a surprise as Peter's first comment in a private email exchange was "Great you're doing this!"

Intellij 9 Development Experience
Getting the source and setting up for the first run was fairly painless after you find the download information. It was nice to see that the code repository was git. I ran into 2 issues in getting setup:
  1. Git clone failed with an unclear message initially. It turned out I was trying to clone using the git protocol behind a corporate firewall which was blocking it. As soon I was not behind the firewall, all went well. Be prepared... it is 924 MB.
  2. Setting up the run configuration wasn't complex, but it wasn't as advertised.

Here is what the Building and Running from the IDE from the checkout and build page should read:
  • Open the project as a "new" directory-based project
  • Configure a JSDK named "IDEA jdk", pointing to an installation of either JDK 1.6 (recommended) or JDK 1.5. This is on the project tab of the project structure.
  • Increase the compiler heap size... default is 128M, it works with 512M :)
  • Use Build | Make Project to build the code
  • To run the code, use the provided shared run configuration "IDEA".

Important notes:
  1. You will see that there are circular dependencies between 4 of the project modules.
  2. With the default compiler heap size, you will get a compilation error ( which is erroneous )
  3. There are a number of deprecation warnings during compilation... this might be a great place for someone to get involved and do some clean up.

After you have an Intellij running another instance of Intellij :) Here is a list of resources to be familiar with:
  1. Source Repository Layout
  2. View PSI structure (under the tool menu) - PSI is an IDEA AST abstraction, which was the toughest learning curve. Learn it! Then look at the following clases and their usage in the code base: PsiUtilBase, PsiUtil, PsiResolveHelper, PsiResolveHelperImpl

End Result
In the end, I spent 4 hours adding in additional gradle task support into Intellij 9, created a patch and submitted to Peter... a few days later I was informed that it was committed to repository. Enhanced Gradle support is on it's way!

I had mixed feels when IDEA announced it was going open source, but now that it is... Let's get in there and make this an even better editor!

Kudos to JetBrains and it's community!

Thursday, December 31, 2009

3 Core Principles from 1998

I was off for the holidays which gave me some time to clean out the storage area. I ran across some notes from a conference I attended in 1998 and 3 core principles stood out that I thought I would share as we start this new year.

Core Principles (as I wrote them many years ago):
1. Smaller is better than larger
2. Understood is better than unknown
3. Progress is better than promises

Smaller is better than larger
There was nothing else written and I left nothing by way of context... regardless of what it meant then, it is clear that this is a great principle when it comes to code. Less code that does the same amount of work is better. The paradox is that it may take a little more time to develop a smaller code solution, but it pays off. The skill is in not being so abstract and so small as to not be readable or maintainable. It is this balance that makes a true software craftsman.

Understood is better than unknown
If there is one word that we would use to describe the issues of software development... it is the word "unknown". Estimating the known is easy. Estimating the unknown, is unknowable. The skill in software development is to separate the unknowns from the knows. Estimate the knowns and provide a SWAG estimate for the unknowns... these are estimates that you need to keep in check. It is best to delay the estimates and work of the unknowns until ( what Kevlin Henney brilliantly describes as) the last responsible moment. Of course this only works for the known unknowns... what will get you is the unknown unknowns:)

Progress is better than promises
This is why I have been a practitioner and trainer for XP and agile practices for many years. It is all about developing business value on a regular and iterative basis. Promises are meaningless... progress is all that matters.

Happy New Year!!

Monday, December 14, 2009

Intellij 9 and Gradle

One of the hidden gems of the Intellij 9 release is it's support for Gradle. Some of the information on the web is out of date and some features are not intuitive. This post will detail some of the nuances and follow it up with a wish list for the next update :)

Gradle Support
The information from JetBrains is out of date. In order to setup gradle after the GA release, all you need to do is configure the gradle home under File -> Other Settings -> Template Setttings.


Gradle Intellij Nuances
After setting up IDEA to work with Gradle, you'll need a build file. I didn't discover a way to create a gradle build file from IDEA. Just create a new file and name it "build.gradle" in the root of the module directory structure.

When writing the build script, Intellij expects to work with gradle in a way that is depreciated. It will pick up on a createTask(..) method. If the cursor is on a task such as this, and you hit ctrl+shft+F10, it will auto-discover and run that task in the script. (cool stuff)

Hotkeys to know:
ctrl+shft+F10 - runs task the cursor is on
shft+F10 - runs the last script (or the last run)
alt+shft+F10 - pops up a run menu (with all previously run gradle run configs)

The figure below shows an alt+shft+F10 when the cursor is on a task called task2.


If you code gradle in a non-depreciated way... then IDEA does not auto-discover the tasks. Below is what one would expect in a gradle build file:

usePlugin 'java'

repositories {
mainCentral()
}

// from the gradle user guide
// http://www.gradle.org/0.8/docs/userguide/tutorial_using_tasks.html
task hello << {
println 'Hello world'
}
task intro(dependsOn: hello) << {
println "I'm Gradle"
}

Tasks would normally be created this way... It is still great that IDEA has gradle support in general regardless of this oversight. After a run configuration is configured with a targeted task, it worlds with no pain. Also you could add:
 defaultTasks "intro"
and gradle runs this as the fallback when IDEA doesn't provide the required task.

Intellij / Gradle features I'm looking forward to:
  1. IDEA understands proper task configuration
  2. IDEA makes it easy to create new projects with a structure maven and gradle expects.
  3. IDEA treats gradle as a peer with Maven and Ant. This includes:
    a. Gradle Window (similar to the ant build and maven projects panels)
    b. Before Launch Gradle tasks in the run configurations

Saturday, December 5, 2009

More Trouble with Java and Apple

Well the latest update for Java from Apple came through recently. Destroying all in its path...
If you followed my advice in the past on getting Java 1.5 working on a Snow Leopard, then the new Apple update destroys that with the follow error for a Java 5 java -version:
Error occurred during initialization of VM
Unable to load native library: libjava.jnilib
Abort trap

I didn't track down the exact issue... however it is easy to detect that the Java update converts the symbolic links for Java 1.5 to point back to Java 6... Apparently Apple is NOT sorry for their crazy choice of ignorantly doing this in the first place. The solution is to completely go through the process out lined at OneSwarm again and re-establish the symbolic links. This will require you to delete the symbolic links that point to "CurrentJDK" for 1.4, 1.4.2, 1.5, and 1.5.0.

After edits an ls -l in the /System/Library/Frameworks/JavaVM.framework/Versions should look like:

drwxr-xr-x 15 root wheel 510 Dec 5 22:18 .
drwxr-xr-x 12 root wheel 408 Dec 5 22:15 ..
lrwxr-xr-x 1 root wheel 5 Dec 5 21:35 1.3 -> 1.3.1
drwxr-xr-x 3 root wheel 102 Jul 20 18:35 1.3.1
lrwxr-xr-x 1 root wheel 5 Dec 5 22:18 1.4 -> 1.4.2
lrwxr-xr-x 1 root wheel 14 Dec 5 22:18 1.4.2 -> 1.4.2-leopard/
drwxr-xr-x@ 9 root wheel 306 Feb 12 2009 1.4.2-leopard
lrwxr-xr-x 1 root wheel 5 Dec 5 22:01 1.5 -> 1.5.0
lrwxr-xr-x 1 root wheel 14 Dec 5 22:00 1.5.0 -> 1.5.0-leopard/
drwxr-xr-x@ 10 root wheel 340 Dec 5 21:59 1.5.0-leopard
lrwxr-xr-x 1 root wheel 5 Dec 5 21:35 1.6 -> 1.6.0
drwxr-xr-x 8 root wheel 272 Nov 8 14:35 1.6.0
drwxr-xr-x 9 root wheel 306 Dec 5 21:35 A
lrwxr-xr-x 1 root wheel 1 Dec 5 21:35 Current -> A
lrwxr-xr-x 1 root wheel 3 Dec 5 21:35 CurrentJDK -> 1.6


Happy coding!

Friday, November 27, 2009

Syntax Highlighting on Blogspot

I've been very interested in providing some syntax highlighting in my blog posts, which I've been slow in general getting out... ( I have 6 or so queued up ). I finally found something I like and thought I would share the love. Special thanks to @ecounysis on twitter from whom I made this discovery. There are no excuses for my future posts... they will all have nice highlighting and be more easily copied (via the clipboard feature).

The place to start is: http://alexgorbatchev.com/wiki/SyntaxHighlighter:Hosting

From there you'll see the link to: http://blog.cartercole.com/2009/10/awesome-syntax-highlighting-made-easy.html

One important thing to note for those on blogger / blogspot. The initial update of the head tag didn't take for me. The solution for me was to add the highlighting entries at the tail end of head, just prior to the closing tag.

In addition to many of the bundled options... I've added F# and Objective-C from undermyhat.

Thursday, September 3, 2009

Fixing Java on Mac Snow Leopard

I have long documented some of the issues and differences for a Java developer on the Mac OS X. Most of that has been on Leopard, OS X 10.5. For quick links the most significant articles are: Java is a 2nd Class Citizen on MAC OSX, Fixing Java Memory Tools on Mac OS X and Java 7 on Mac OS X.

Monday I was faced with a new situation, Snow Leopard OS X 10.6. There are several issues with Java on the new Mac OSX 10.6 "Snow Leopard". This post will outline the known issues and will provide fixes for several of them (or provide links where fixes are already explained).

Known Issues:
  1. Java 5 is not installed
  2. Java 5 symbolic links are set to Java 6
  3. jmap - some aspects of jmap do not function
  4. javascript runtime is still missing
As a consequence, applications that used Java 5 either don't work, or provide a message as shown here from my favorite stock trading application.



* I'm still looking for more issues, so if you can add to the list, please add comments, email or twitter.
** I have tested the latest BTrace and it works fine.


Java 5 on Snow Leopard
Whither you agree with the removal of Java 5 or not, it is unbelievable to me that the Java 5 symbolic links are pointing to the CurrentJDK which points to 1.6. For those new to this space the Java version live under /System/Library/Frameworks/JavaVM.framework/Versions . I would advise you to either:
  1. replace Java 5 using instructions provided at leopard http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard
  2. simply delete the java 5 symbolic links
As a side note, I use a script for swapping between JVM versions. I modified the original script to just include 3 important functions when sourced in. I'll add the script to the bottom of this post as a reference. The 3 functions are jvms, setJava, unsetJava.
  • jvms reads through the version directory and reports what it reads of the file system.
  • setJava allows you to type in the name of the version and switches JAVA_HOME and path to this version of the JVM.
  • unsetJava reverts the set to the original java version
JMap on Snow Leopard
My initial execution of jmap on snow leopard failed with the following error message:

kensipe$ jmap 3407
Attaching to process ID 3407, please wait...
sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol "heapOopSize" in any of the known library names (-)
at sun.jvm.hotspot.HotSpotTypeDataBase.lookupInProcess(HotSpotTypeDataBase.java:399)
at sun.jvm.hotspot.HotSpotTypeDataBase.readVMIntConstants(HotSpotTypeDataBase.java:319)
at sun.jvm.hotspot.HotSpotTypeDataBase.(HotSpotTypeDataBase.java:88)
at sun.jvm.hotspot.MacOSXTypeDataBase.(MacOSXTypeDataBase.java:36)
at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:578)
at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:499)
at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:337)
at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
at sun.jvm.hotspot.tools.PMap.main(PMap.java:67)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.tools.jmap.JMap.runTool(JMap.java:179)
at sun.tools.jmap.JMap.main(JMap.java:110)
Debugger attached successfully.

The good news is that the debugger attached successfully :)

Information regarding this issue is scarce. It turns out to likely be an issue with the version of Java that is distributed with snow leopard. The JDK 1.6 rev 14 appears (based on non-confirmed web sources) to have this issue. The latest is JDK 1.6 rev 16 should have the fix, however using the apple distro, we are left waiting for Apple for the fix. Although jmap fails with no arguments it does succeed for certain commands such as jmap -histo 3407.
After replacing the JDK 5 with the leopard distro as advertised above and switching to this version with the script above, jmap works fine. However jdk 5 jmap only works against jdk 5 running applications. It fails against java 6.

javascript
As record in a posting from a year ago, called Fixing Java Memory Tools on Mac OS X, the javascript library is still not provided by Apple as part of the Java distro. You will need to following the instructions there to fix it. Unfortunately the Rhino download has disappeared from the Mozilla site, so if you didn't keep a copy, ping me and I will send you want I have. You will also need to duplicate this for each version of Java if you install the Java 5 Leopard package.
The test to see if this is setup correctly for you is: jrunscript -q
If that command only returns AppleScript, then you are missing the javascript engine which is need for a number of tools in the JDK.

After these changes, it appears that Snow Leopard is ready for some hard core Java development. Good Luck and Happy Coding!

Java Switching Script that I use:



# *************************************************************************
# Originally written by Shawn Erickson - shawn at freetimesw.com
#
#
# Last Update: 2008y 08m 8d
#
# The following functions are meant for use with bash shell which is currently the
# default on Mac OS X 10.4 (starting with 10.3 IIRC) unless otherwise configured.
# Good info on why not sym links: http://lists.apple.com/archives/Java-dev/2006/Jan/msg00290.html
#
# from: http://lists.apple.com/archives/Java-dev/2005/Aug/msg00506.html
# http://homepage.mac.com/shawnce/misc/java_functions_bashrc.txt
#
# *************************************************************************

### Prompt ###

export CURRENT_MODE_STRING="";

### Java Environment Functions ###

J_VERSIONS_DIRECTORY="/System/Library/Frameworks/JavaVM.framework/Versions"
J_COMMANDS_SUBPATH="Commands"
J_HOME_SUBPATH="Home"

function availableJVMs()
{
ls -1 $J_VERSIONS_DIRECTORY | grep ^[0-9].[0-9]
}

function jvms()
{
clear
echo "Available JVMs: "$jvms
ls -1 $J_VERSIONS_DIRECTORY | grep ^[0-9].[0-9] # look to remove redundant call
echo " "

echo "Current Java:"
java -version
}

function setJava()
{
local target_jvm=""
local jvms=$(availableJVMs)

# Validate that the user requested an available JVM present on the system

for jvm in $jvms ; do
if [ "$jvm" == "$@" ]; then
target_jvm=$@
fi
done

if [ "$target_jvm" == "" ]; then
echo "Unsupported Java version requested"
return;
fi

# If we get here the user asked for a valid JVM, so configure it

echo "Configuring Shell Environment for Java "$@
export JAVA_VERSION=$@

# First unset any current set java, back to default before doing configuration
_unsetJava

# Generate the paths needed for the JVM requested
local jcmd="${J_VERSIONS_DIRECTORY}/$@/${J_COMMANDS_SUBPATH}"
local jhome="${J_VERSIONS_DIRECTORY}/$@/${J_HOME_SUBPATH}"

# We save the original path so we can toggle back if unset
ORIGINAL_PATH="$PATH"
PATH="$jcmd:${PATH}"

# We save the original JAVA_HOME so we can toggle back if unset
ORIGINAL_JAVA_HOME="$JAVA_HOME"
JAVA_HOME="$jhome"

# Update command prompt mode tag to note JVM setting
CURRENT_MODE_STRING="J$@"

echo "Current Java:"
java -version
}

function _unsetJava()
{
if [ "$CURRENT_MODE_STRING" != "" ]; then
PATH="$ORIGINAL_PATH"
JAVA_HOME="$ORIGINAL_JAVA_HOME"
CURRENT_MODE_STRING=""
fi
}

function unsetJava()
{
echo "Configuring Shell Environment for default Java"
_unsetJava

echo "Current Java:"
java -version
}


Wednesday, August 19, 2009

97 Things Every Project Manager Should Know


The book 97 Things Every Project Manager Should Know put together by Barbee Davis is out, and worth picking up... why the magical 97? Apparently 101 was way over used... or perhaps Barbee couldn't get the last 4 in before it was time to publish :)

This book has some great insights from a number of sources, which is a huge value add to any project manager or senior developer. This is the top advice from experts in the field around team building, running a software project, and generally how to herd cats.

Most books in this space are limited to the experience of the author and his/her circle of influence. The beautiful part of this book, is the fact that Barbee has captured the most interesting and important tid bits stories of success and failures of software projects from a large sample of project managers and developers each providing a view from different industry verticals.

Well done Barbee!