Spice up Play! with Lombok

198 views
Skip to first unread message

Philipp Eichhorn

unread,
May 15, 2011, 3:26:58 PM5/15/11
to Project Lombok
Today I finally had some time to toy around with the Play! Framework
(http://www.playframework.org).
Sadly, Lombok and Play! didn't work together out of the box. So I
investigated and came up with a pretty simple solution.
The basic idea is to add Lombok as a JVM-Agent when Play! does it's
wizardry. This makes sense because Play! uses the Eclipse compiler to
compile modified classes and hotswap them into the running system and
Lombok hooks itself into eclipse as a JVM-Agent.

<-- Small How-To-Guide: -->

Tested with Play! 1.2.1 and the Lombok edge-release.

1. Get Play! and Lombok
2. Add the 'lombok.jar' to '${PLAY_HOME}/framework/'
3. Add the 'org.eclipse.equinox.common.jar' to '${PLAY_HOME}/framework/
lib'.
4. Apply the following patch to update the 'application.py':

--- a/framework/pym/play/application.py
+++ b/framework/pym/play/application.py
@@ -139,7 +139,8 @@ class PlayApplication:

# The default
classpath.append(os.path.normpath(os.path.join(self.path,
'conf')))
-
classpath.append(os.path.normpath(os.path.join(self.play_env["basedir"],
'framework/play-%s.jar' % self.play_env['version'])))
+ classpath.append(os.path.normpath(self.play_path()))
+ classpath.append(os.path.normpath(self.lombok_path()))

# The application
if os.path.exists(os.path.join(self.path, 'lib')):
@@ -163,9 +164,12 @@ class PlayApplication:

return classpath

- def agent_path(self):
+ def play_path(self):
return os.path.join(self.play_env["basedir"], 'framework/play-
%s.jar' % self.play_env['version'])

+ def lombok_path(self):
+ return os.path.join(self.play_env["basedir"], 'framework/
lombok.jar')
+
def cp_args(self):
classpath = self.getClasspath()
cp_args = ':'.join(classpath)
@@ -246,7 +250,7 @@ class PlayApplication:
java_args.append('-Xrunjdwp:transport=dt_socket,address=
%s,server=y,suspend=n' % self.jpda_port)
java_args.append('-Dplay.debug=yes')

- java_cmd = [self.java_path(), '-javaagent:%s' %
self.agent_path()] + java_args + ['-classpath', cp_args, '-
Dapplication.path=%s' % self.path, '-Dplay.id=%s' %
self.play_env["id"], className] + args
+ java_cmd = [self.java_path(), '-javaagent:%s' %
self.lombok_path(), '-javaagent:%s' % self.play_path()] + java_args +
['-classpath', cp_args, '-Dapplication.path=%s' % self.path, '-
Dplay.id=%s' % self.play_env["id"], className] + args
return java_cmd

class PlayConfParser:

5. If you use Eclipse, make sure to eclipify your application again.


It would be nice if some of you guys would try it out and tell me how
it went. Feedback is very welcome.

Note:
I haven't tested deployment yet, but when the time comes I let you
know if I stumbled over something.

-Philipp

Reinier Zwitserloot

unread,
May 15, 2011, 5:01:53 PM5/15/11
to project...@googlegroups.com
Heh, nice. Technically lombok switches between "full-blown-eclipse" and "ecj" mode based on how the agent was loaded (injected 'live' or before main VM start via -javaagent). In other words, when you do that, lombok thinks its fixing eclipse and not ecj.

I'm fairly sure we split it up a while ago because we insert some eclipse-only calls here and there which would result in NoClassDefError or MethodNotFoundError issues if applied to ecj. In other words, I don't think this actually works. But, if it does, hey, more power to you. Fixing it isn't _too_ difficult, in case you do run into issues.

Play cannot work with lombok any other way because it breaks java spec. Specifically, it simply does not run any annotation processors, period. So, it's javaagent or patching Play itself to always add lombok as an annotation processor anytime it compiles anything.

 --Reinier Zwitserloot



--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

Philipp Eichhorn

unread,
May 15, 2011, 6:19:57 PM5/15/11
to Project Lombok
Thanks for the heads-up.
So forth I've been using a lot of lombok-fu, including @Delegate, val
and some transformers of mine that hook them-selfs into ecj in a
similar fashion (via Patch), without any disturbance what-so ever.
I'm having a blast right now. Thanks again!

-Philipp

On May 15, 11:01 pm, Reinier Zwitserloot <rein...@zwitserloot.com>
wrote:
> > Groups group forhttp://projectlombok.org/

Aaron Freeman

unread,
May 16, 2011, 10:34:59 AM5/16/11
to Project Lombok
I did some work with getting Lombok to work with Play! a few weeks
ago.

I wrote a blog post about how I first got it working here:
http://technicallypossible.blogspot.com/2011/04/getting-lombok-to-play.html

Then I decided to make it easier, so I created a Play! module that
makes Lombok work. You can find it here: https://github.com/aaronfreeman/play-lombok

I am using this on two apps in production right now, and everything
seems to be working fine.

Let me know if anyone finds any issues with it!

-Aaron

Philipp Eichhorn

unread,
May 16, 2011, 11:13:46 AM5/16/11
to Project Lombok
Nice, a much cleaner solution, thanks for sharing.

On May 16, 4:34 pm, Aaron Freeman <aaronwfree...@gmail.com> wrote:
> I did some work with getting Lombok to work with Play! a few weeks
> ago.
>
> I wrote a blog post about how I first got it working here:http://technicallypossible.blogspot.com/2011/04/getting-lombok-to-pla...
Reply all
Reply to author
Forward
0 new messages