Jan 11

Hibernate 2/3, XDoclet 1/2, and Annotations

Tech No Comments »

We are in an interesting time for some technologies. For example, if you are starting a project now in which you want to use Hibernate, and you want to annotate your model rather than using XML, then you have some choices:

  • Hibernate 2.*, XDoclet 1 (Stable): This is the stable choice. Tried and true. Hibernate 2.* is pretty stable, as is XDoclet 1. However, they aren’t getting as much attention as the new kids on their block.
  • Hibernate 2.*, XDoclet 2 (Quick fix): There have been certain cases where XDoclet 1 + the hibernate module for it, can’t generate the Hibernate mapping files the way I want them. Some of these have revolved around inheritence heirachies that muck with implementing interfaces. These problems have actually been fixed, but fixed in XDoclet 2. The problem here though is that X2 is far from a release, and although I built it and it works well, it seems a little scary to jump down that road now. Also, depending on what else you are generating with XDoclet, you may not be able to make the jump since all of the functionality hasn’t been ported from X1
  • Hibernate 3, Annotations (New World): As Gavin has said, Hibernate3 is what has been in the works for the last year or so. We have a beta which seems pretty stable (for a beta), and as well as the EJB 3 annotation support, they just released enhanced annotations for hibernate specific functionality support too. To make this jump, you are assuming that a stable H3 will be around by the time you get further down the road in your project, OR maybe it is just a pet project to play with. You also get to make the leap to Java 5 to play with the full on annotations, although of course you can stick with 1.4 and use other means. The nice side-effect of the annotations support is that you don’t have to go into your build and tweak it out to have that extra xdoclet step.

So, we are at an interesting transition point at the moment. A lot of people are waiting for EJB 3. A lot of people are wondering when to make leaps of faith. And there are a lot of options on putting together these technologies.

Jan 06

Harder to find power than WiFi

Tech, Wireless No Comments »

CP talks about the problem finding power for your laptop, not wireless.

Slashdot reported on this and it is spot on.

This was particularly telling for me when I was in europe. I didn’t have all of the power adapters that I should so I had to chain them together at one point. For example:

US plug -> US/UK adapter -> UK/Euro adapter

One of the adapters was so bad that I had to wrig up something so it kinda tied itself to the plug, and wouldn’t just fall off when I plugged in my iPod charger. What a pallava!

I even have one of the iGo systems which lets you interchange ends.

Back to power for mobile. I thought I read somewhere a year about, that companies are working on wireless power. How cool would that be :)

Jan 06

Book Shipped: Eclipse AspectJ

AOP, Tech No Comments »

Congrats to Adrian Colyer, Andy Clement, George Harley, & Matthew Webster. They have just released their book: “Eclipse AspectJ”.

The book has examples which use real world technology. For example some of the projects use Hibernate and Spring and you can see how AOP can really help you out.

I’m pleased to say that the book “Eclipse AspectJ” (http://tinyurl.com/5enrc) is now shipping.

As well as comprehensive coverage of the AspectJ language, we use AJDT to teach and demonstrate both AJDT and AspectJ itself (a technique we have found works well when we give our talks and tutorials). The book has a running example of a simple insurance application that builds to eventually include full Hibernate and Spring integration.

The insurance application and many other samples are available for download as Eclipse projects via an update site. This will be on the Addison-Wesley site as soon as possible, and in the meantime we have mirrored it on the aspectprogrammer site: see http://www.aspectprogrammer.org/eclipseaspectj for install instructions.

You can see a full table of contents and download a sample chapter from:

http://www.awprofessional.com/title/0321245873

We hope you enjoy the book. Feedback is always welcome, and reviews posted to Amazon or B&N would be great too.

Thanks,
Adrian Colyer, Andy Clement, George Harley, & Matthew Webster.

Jan 06

Sun /FreeBSD all just miscommunication

Tech No Comments »

After I blogged about the FreeBSD/Sun issue, a couple of people from Sun contacted me, stating that they thought it was all just bad communication, and asked how to get ahold of the people on the FreeBSD side.

They got ahold of them, and it looks like everything is sorted out:

FreeBSD’s Secretary/Treasurer: Java License Troubles Being Worked Out

Recently the FreeBSD Foundation issued a newsletter stating its frustration with Sun Microsystems over licensing of the Java Virtual Machine. Specifically, the Foundation had its license revoked, and had been trying to renegotiate with little success reaching anyone at Sun who could do anything about it.

OSDir has followed up with Justin Gibbs, Secretary/Treasurer of the Foundation to see what has resulted from the publicity resulting of the issue.

Mr Gibbs had this to say, “The Foundation’s Java licensing issue boils down to poor communication on all sides. Our newsletter caught the attention of the ‘right person’ at Sun to cut through the clutter and we now expect to quickly find a satisfactory resolution. The FreeBSD Foundation will follow up its newsletter with an update on Java licensing as soon as we can announce the good news, but our current belief is that this little hiccup will have no impact to the allowed uses for our binary distributions.”

Jan 05

Scripting COM with Groovy

Groovy, Tech No Comments »

I saw a link to COM Scripting via James’ blog.

Scriptom is an optional Groovy module developed by Guillaume Laforge leveraging the Jacob library (JAva COm Bridge). Once installed in your Groovy installation, you can use a wrapper to script any ActiveX or COM component from within your Groovy scripts. Of course, this module can be used on Windows only.

Scriptom is especially interesting if you are developing Groovy shell scripts under Windows. You can combine both Groovy code and any Java library with the platform-specific features available to Windows Scripting Host or OLE COM automation from Office.

Nice work Guillaume. Dynamic languages offer a cool alternative for working with IE, Word, Excel, and any other component!

Jan 05

lucenebook.com

Tech No Comments »

Manning: “Erik, can you create an index for you book”

Erik: DING DING DING . o ( What type of index! )

So the Lucene in Action book now has eaten some of its dog food, and you can search the contents yourself at:

http://www.lucenebook.com/blog

I am still waiting for my signed book! ;)

Jan 05

Syncing up your IntelliJ IML files with Maven and Groovy

Builds, Groovy, Tech No Comments »

I often use the Maven IntelliJ plugin to create project files (.ipr/.iml/.iws).

A quick:

% maven idea

does the job nicely.

However, when dependencies change, I don’t want to re-run the idea task, as it wacks a lot of project settings that I may have had. What I really want to do is take the current .iml file, and tweak the classpath which has entries such as:

<orderEntry type="module-library">
<library name="asm">
<CLASSES>
<root url="jar://C:/Documents and Settings/Dion/.maven/repository/asm/jars/asm-1.4.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>

So, I put together a quick groovy script which does just this.

#!/bin/env groovy
# -----------------------------------------------------------------------------
# ideaSync.g: Take a given project.xml and an IntelliJ IDEA .iml file,
#             and sync up the dependencies
# -----------------------------------------------------------------------------

import groovy.util.XmlParser
import java.io.File
import java.io.OutputStream
import java.util.*

import org.dom4j.Document
import org.dom4j.io.XMLWriter
import org.dom4j.io.OutputFormat

# -- Enforce the project.xml and dir
if (args.length < 3) {
println """
Usage: ideaSync.g project.xml
.iml /path/to/maven/repo

e.g. ideaSync.g /foo/project.xml /foo/project.iml /www/adigio/maven
"""
System.exit(1)
}

# -- Variables
projectxml   = args[0]
intellijxml  = args[1]
mavenRepoDir = args[2]
indent       = 0

# -- Open up the IntelliJ
.iml file
intellij = new XmlParser().parse(intellijxml)

# -- Open up the project.xml file and get the dependencies, and create an updated XML node
project = new XmlParser().parse(projectxml)

# -- Build the order entries
orderEntries = []

project.dependencies.dependency.each {
groupId    = it.groupId[0].text()
artifactId = it.artifactId[0].text()
version    = it.version[0].text()

orderEntry = buildOrderEntry(groupId, "jar://${mavenRepoDir}/${groupId}/jars/${artifactId}-${version}.jar!/")

orderEntries += orderEntry
}

# -- Grab Order Entries
intellij.module.component.each { | c |
if (c['@name'] == 'NewModuleRootManager') {
oldOrderEntries = c.findAll { !it.orderEntry }
c = orderEntries
}
}

# -- Print the Header
println ''

outputDOM(intellij)

# -----------------------------------------------------------------------------
#  From the given group ID and URL, return an Order Entry node
# -----------------------------------------------------------------------------
def buildOrderEntry(groupId, url) {
# -- Builder
builder = new groovy.util.NodeBuilder()

return builder.orderEntry(type: 'module-library') {
library(name: groupId) {
CLASSES() {
root(url: "jar://${mavenRepoDir}/${groupId}/jars/${artifactId}-${version}.jar!/")
}
JAVADOC()
SOURCES()
}
}
}

# -----------------------------------------------------------------------------
#  Recursive function which outputs a node, and then child nodes
# -----------------------------------------------------------------------------
def outputDOM(node) {
String tagName = node.name()
Object tagValue = node.value()
boolean hasChildren = false;
String attributes = ""

printIndent()

print "<${tagName}"

# -- Print out any attributes
node.attributes().each { |entry|
attributes = " ${entry.key}=\"${entry.value}\"" + attributes
}
print attributes

if (tagValue instanceof String) {
println "${tagValue}"
hasChildren = true;
}

List children = node.children()

if (children != null && !children.isEmpty()) {
hasChildren = true
}

println( (hasChildren) ? ">" : " />" )

for (child in children) {
indent++
outputDOM(child)
indent--
}

if (hasChildren) {
printIndent()
println ""
}
}

# -----------------------------------------------------------------------------
#  Print out the correct indent
# -----------------------------------------------------------------------------
def printIndent() {
print "  " * indent
}

I was hoping that I could use the NodePrinter that is already in Groovy, but it prints out the nodes like foo() { bar(); …. not in XML.

I think it would be good to have an XMLNodePrinter, or just have a toXML() method in the NodePrinter to do that work, as I think this script follows a common pattern:

  • Suck in an XML document into nodes
  • Munge the nodes in some way
  • Print out the new XML document

I would also really like to add this functionality to the maven plugin itself, so I could:

% maven idea:resynciml

or something like that. I think I will wait for m2 though, and see if I can use something other than Jelly for it? ;)

Jan 05

Syncing up your IntelliJ IML files with Maven and Groovy

Builds, Groovy, Tech No Comments »

I often use the Maven IntelliJ plugin to create project files (.ipr/.iml/.iws).

A quick:

% maven idea

does the job nicely.

However, when dependencies change, I don’t want to re-run the idea task, as it wacks a lot of project settings that I may have had. What I really want to do is take the current .iml file, and tweak the classpath which has entries such as:

<orderEntry type="module-library">
<library name="asm">
<CLASSES>
<root url="jar://C:/Documents and Settings/Dion/.maven/repository/asm/jars/asm-1.4.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>

So, I put together a quick groovy script which does just this.

#!/bin/env groovy
# -----------------------------------------------------------------------------
# ideaSync.g: Take a given project.xml and an IntelliJ IDEA .iml file,
#             and sync up the dependencies
# -----------------------------------------------------------------------------

import groovy.util.XmlParser
import java.io.File
import java.io.OutputStream
import java.util.*

import org.dom4j.Document
import org.dom4j.io.XMLWriter
import org.dom4j.io.OutputFormat

# -- Enforce the project.xml and dir
if (args.length < 3) {
println """
Usage: ideaSync.g project.xml
.iml /path/to/maven/repo

e.g. ideaSync.g /foo/project.xml /foo/project.iml /www/adigio/maven
"""
System.exit(1)
}

# -- Variables
projectxml   = args[0]
intellijxml  = args[1]
mavenRepoDir = args[2]
indent       = 0

# -- Open up the IntelliJ
.iml file
intellij = new XmlParser().parse(intellijxml)

# -- Open up the project.xml file and get the dependencies, and create an updated XML node
project = new XmlParser().parse(projectxml)

# -- Build the order entries
orderEntries = []

project.dependencies.dependency.each {
groupId    = it.groupId[0].text()
artifactId = it.artifactId[0].text()
version    = it.version[0].text()

orderEntry = buildOrderEntry(groupId, "jar://${mavenRepoDir}/${groupId}/jars/${artifactId}-${version}.jar!/")

orderEntries += orderEntry
}

# -- Grab Order Entries
intellij.module.component.each { | c |
if (c['@name'] == 'NewModuleRootManager') {
oldOrderEntries = c.findAll { !it.orderEntry }
c = orderEntries
}
}

# -- Print the Header
println ''

outputDOM(intellij)

# -----------------------------------------------------------------------------
#  From the given group ID and URL, return an Order Entry node
# -----------------------------------------------------------------------------
def buildOrderEntry(groupId, url) {
# -- Builder
builder = new groovy.util.NodeBuilder()

return builder.orderEntry(type: 'module-library') {
library(name: groupId) {
CLASSES() {
root(url: "jar://${mavenRepoDir}/${groupId}/jars/${artifactId}-${version}.jar!/")
}
JAVADOC()
SOURCES()
}
}
}

# -----------------------------------------------------------------------------
#  Recursive function which outputs a node, and then child nodes
# -----------------------------------------------------------------------------
def outputDOM(node) {
String tagName = node.name()
Object tagValue = node.value()
boolean hasChildren = false;
String attributes = ""

printIndent()

print "<${tagName}"

# -- Print out any attributes
node.attributes().each { |entry|
attributes = " ${entry.key}=\"${entry.value}\"" + attributes
}
print attributes

if (tagValue instanceof String) {
println "${tagValue}"
hasChildren = true;
}

List children = node.children()

if (children != null && !children.isEmpty()) {
hasChildren = true
}

println( (hasChildren) ? ">" : " />" )

for (child in children) {
indent++
outputDOM(child)
indent--
}

if (hasChildren) {
printIndent()
println ""
}
}

# -----------------------------------------------------------------------------
#  Print out the correct indent
# -----------------------------------------------------------------------------
def printIndent() {
print "  " * indent
}

I was hoping that I could use the NodePrinter that is already in Groovy, but it prints out the nodes like foo() { bar(); …. not in XML.

I think it would be good to have an XMLNodePrinter, or just have a toXML() method in the NodePrinter to do that work, as I think this script follows a common pattern:

  • Suck in an XML document into nodes
  • Munge the nodes in some way
  • Print out the new XML document

I would also really like to add this functionality to the maven plugin itself, so I could:

% maven idea:resynciml

or something like that. I think I will wait for m2 though, and see if I can use something other than Jelly for it? ;)

Jan 04

Intelligent Design drives me nuts

Personal No Comments »

The creationalists lost awhile back in the US. They are always fighting back though. Remember the “if the Theory of Evolution is just a theory, it obviously isn’t right”.

Now they have done what certain companies do. They change their name.

So, we have Intelligent Design. They have law suits in 38 states and counting, and they are WINNING some of these suites. So my kids have to sit there and learn about their crap? “The world was created about 6 thousand years ago. It took 6 days”.

In my local paper, Arthu Naebig summed it up with:

What the argument comes down to is the scientific evidence balanced against no evidence. Scientists collect evidence and attempt to formulate answers to the questions about our world, but admit they may never have all of the answers. Creationalists (Intelligent Designers?) collect no evidence and state that they already have all the answers. A thinking person should have no trouble deciding which group to believe.

Jan 04

Hierarchy of the Apache Software Foundation

Open Source, Tech No Comments »

It is interesting to see the Hierarchy of the Apache Software Foundation.

It is amazing to think of the amount of hard work and effort that goes into open source communities such as Apache (and others).