Showing posts with label IDEA. Show all posts
Showing posts with label IDEA. Show all posts

Wednesday, January 18, 2012

The Best Groovy Inspections You’re Not Using

Many, many tools perform static analysis on code. There are all sorts of automated ways to look through your code and tell you if there are likely errors or not. FindBugs, PMD, and CheckStyle are some of the big names from the Java world. On the Groovy side we have two real options: IntelliJ IDEA and CodeNarc.

This post (over on the Canoo Blog) highlights my favorite static analysis rules for Groovy in IDEA that are not enabled by default. Groovy in IDEA 11 has well over 100 rules, but less than half of them are activated when you install the product. To turn these rules on you’ll need to go into Settings (Ctrl+Alt+S) and enable them under Inspections.

So surf over to the main post and check it out. If you want to leave a comment, then do it on the DZone page. I've been turning comments off on the main posts.

If you like this then you might check out some of my other IDEA related posts: The 10 Best Inspections You’re Not Using (in Java), or the IDEA archive on my blog and the Canoo blog.

And remember if you need Groovy and Grails help, then give me a call or drop me an email at hamlet.darcy@canoo.com

Thursday, January 12, 2012

Android Testing in IntelliJ IDEA

Google’s Android site has some fairly detailed instructions for testing Android applications… from Eclipse. They were nice enough to supply a “Testing from Other IDEs” page, but that is nothing more than instructions on using Ant and the command line. Well, if you are using IntelliJ IDEA then you already believe the IDE is going to be a better tool than Ant for this. It’s easy to set up a test project in IDEA and get your tests running. Here are some simple instructions.

As usual, the full post is over on the Canoo website. Wanna be cool about it? Upvote it at DZone or Reddit.

Thanks for paying attention.

Tuesday, December 20, 2011

IntelliJ IDEA 11 for the Groovy Developer

IntelliJ IDEA 11 was released a few weeks ago, and it contains quite a few new features for the Groovy developer. Everything listed in my blog post is in the free and open source Community Edition of IntelliJ IDEA. There are plenty of new Grails features as well, but I wanted to separate out the Ultimate Edition features into a different post.

To read the full post, surf on over to the Canoo Blog: http://www.canoo.com/blog/2011/12/20/intellij-idea-11-for-the-groovy-developer/

And, as usual, you can vote for this thing over at DZone.

Thanks everyone.

Friday, October 21, 2011

Android and IDEA for the Eclipse Refugee

For the full article jump to: http://www.canoo.com/blog


Earlier this month I switched from writing my Android projects in Eclipse to writing them in IntelliJ IDEA. Overall the experience has been great, and I much prefer using IDEA to Eclipse for Android development. And now that IntelliJ IDEA 11 EAP (Early Access) has a visual layout window, there is almost no reason for me to write my Android apps in anything else. I wrote this post to help other users along their way when converting between the IDEs.


The full article with all the screenshot glory is over on the Canoo Blog


If you want to be a bro and slip me an upvote, then please do: Hackernews, Reddit, or DZone

Monday, May 23, 2011

IntelliJ IDEA 10.5 for the Groovy and Grails Developer

The formal release of IntelliJ IDEA 10.5 came out this month, and the new Groovy features are all part of the free and open source Community Edition, and the Grails features are part of the Ultimate Edition. IDEA X (or 10 to you non-Romans) was a larger release of the product, and I already blogged about IDEA X for Groovy and IDEA X for Grails. There’s still plenty of nice features in 10.5 though. The prices for IDEA recently dropped between $100 and $50, and anyone purchasing IDEA since last November gets 10.5 as a free upgrade.


You can read the full article detailing my overview of the features over on the Canoo blog.

There is also a whole bunch of other IDEA related content on my own blog and on the Canoo blog. And if you're feeling promotional, you can always upvote at DZone. Enjoy.

Friday, May 6, 2011

IntelliJ IDEA Keyboard Stickers

They finally arrived: IntelliJ IDEA keyboard stickers!

Inspired by the Vi Keyboard Stickers, I've been working with JetBrains over the last couple weeks to create keyboard stickers to remind users (and myself) of the most common IDE shortcuts. Here are the stickers applied to my keyboard:

keyboard

Do you see the subliminal advertising? No really, my business card always sits by my monitor like that.

Anyway, the keys and modifiers are color coded. Blue is control, red underline is Shift. So then the F9 key has the word "Compile" with a blue background and a red underline, it means that Ctrl+Shift+F9 is the shortcut for Compile.

sticker

I had to trim a few of the stickers for my Swiss keyboard (the Shift key is much smaller for instance), but otherwise the stickers adhere well and don't come up. I hand wrote all the Shift-values for the numbers, so that I can remember that Shift-3 is the * character (again, good for non-US keyboards). Also, there are one or two stickers that may not apply to non-US keyboards (I can't type Shift+[ for instance).

Remember to be extra careful when applying the stickers. Overlapping on the upper edge tends to catch your fingers, so either center them exactly or err on the side of bottom edge overlaps. And one last errata: the sticker for space is labeled "Backspace". This was my fault, but you can take a pen and scratch out the work "back". Viola, fixed.

Would you like a copy of the stickers for yourself? I have a giant stack of them and so does JetBrains. Here are some ideas on getting them from me, based on location:
  • Near Switzerland? Come to a Hackergarten in Basel or just DM me (@HamletDRC)
  • Denmark? I'll be at GR8 Conf May 17th to 19th
  • Poland? I'll be at GeeCON in Krakow next week
  • In the US? I'll soon be in New York and Salt Lake City for No Fluff, Denver for ÜberConf, and Minneapolis for GR8 in the US
  • Spain? I'll be at Greach in Madrid in November
  • Anywhere else in Europe?
  • Invite me to give a talk at your company! I am happy to jump on a plane and visit almost* anywhere. I can do IntelliJ IDEA specific talks and training, as well as any of the Java, Groovy, or Agile talks listed here. Invite me, and I'll see what I can do.
* I am no longer legally able to visit Barneveld in the Netherlands.

Friday, April 15, 2011

Getting Started with Spock and Groovy

This screencast demonstrates how to create Spock testing specifications. It covers creating basic when/then blocks, given/when/then blocks, expect/where blocks, and data tables. It explains how to create Spock file templates and Spock Live Templates for IDEA.

If there are any playback issues then you might try watching it from the JetBrains.tv site.



Here are some useful links to read for this webcast:

To work with Spock, I use one file template and three live templates.

My file template creates a Spock Specification with the correct java package and javadoc:

idea file template

The text of the template is:

#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end

import spock.lang.Specification

#parse("File Header.java")
class ${NAME} extends Specification {

}

My first Live Template is the when-then template:

when then

The text of the template is:

def "$NAME$"() {
when:
$END$

then:
true
}

The second template is the given/when/then template:

given when then template

The text of the template is:

def "$NAME$"() {
given:
$END$

when:
// TODO: add when

then:
true
}

The last template is the expect/where template:

The text of the template is:

def "$NAME$"() {
expect:
$END$

where:
// TODO add where block
}

I've made a lot of screencasts and blog posts over the years. If you like this, then there are many ways to see the other stuff I've done:

Phew, that's a lot of self-promotion :)

Thanks for watching, and leave a comment!

Friday, April 1, 2011

New in IntelliJ IDEA 10.5: Less Clutter

Tuesday, March 29, 2011

IntelliJ IDEA Static Analysis: Custom Rules with Structural Search & Replace

Well, well, I made another screencast. This time I'm taking on IntelliJ IDEA code inspections, and writing your own static code analysis rule (and quick fix!) using Structural Search & Replace. Not bad for under 5 minutes.

If you have any trouble viewing the video then perhaps you should watch it directly on the JetBrains site. And if you're feeling generous, then clicky clicky to upvote at DZone.



Check out these pages for more information on IDEA inspections:

Read these pages to learn more about Structural Search and Replace:

I've made a lot of screencasts and blog posts over the years. If you like this, then there are many ways to see the other stuff I've done:

Phew, that's a lot of self-promotion :)

Thanks for watching, and leave a comment!

Friday, March 4, 2011

Griffon MVC Groups and Event System

Griffon has a strong MVC focus, and functionality is built using MVC groups. This is not a screen or a form, an MVC group is a piece of functionality, and a single form is made of MVC groups composed together. The way MVC groups talk to each other is through an event bus, rather than being coupled directly to each other.

I created a screencast that demonstrates these concepts in just under 7 minutes. In the video, I create an app, create several MVC groups, and then wire them together with the event bus.

If the video doesn't play correctly, you may want to launch it from the JetBrains.tv site. Also, if you want to be nice then you can upvote this at DZone.



Boom. Winning.

If you like this, you can check out my other screencasts on YouTube (http://www.youtube.com/user/HamletDRC) or JetBrains.tv (http://tv.jetbrains.net/tags/hamlet)

If you want written documentation on these topics, then please read:
* The Griffon RefCard - http://refcardz.dzone.com/refcardz/getting-started-griffon
* The Griffon User Guide - http://dist.codehaus.org/griffon/guide/index.html
* The Griffon Main Site - http://griffon.codehaus.org/

Wednesday, March 2, 2011

CDI Event Bus Basics Screencast

Another day another screencast. This one's about the Event Bus that is part of CDI. Contexts and Dependency Injection is part of Java EE but available in SE using the Weld framework. This screencast shows you how to use CDI events and the event system, which is just one part of the larger CDI feature set. The screencast briefly explains the benefits of an event system and then shows how easy it is to use it from CDI.

If it doesn't play correctly, you may want to launch it from the JetBrains.tv site.



You could do worse with 5 minutes of your time.


If you like this, you can check out my other screencasts on YouTube (http://www.youtube.com/user/HamletDRC) or JetBrains.tv (http://tv.jetbrains.net/tags/hamlet)

Monday, December 20, 2010

IntelliJ IDEA X for Groovy Developers

The new version of IntelliJ IDEA was released last week. Here’s what it means for Groovy developers. I’ve tried out most of these new features, but there are one or two that I haven’t yet seen in action. Also, there’s a whole slew of Grails features that I’ll cover in a later blog post.

Without further ado, read about the features over on the Canoo Blog. As always, if you want to contribute to the hype cycle then vote this up at DZone.

Monday, October 11, 2010

IntelliJ IDEA Shortcut Wallpaper

The fastest developers use the keyboard almost exclusively. To help you learn the IntelliJ IDEA shortcuts, I created a desktop wallpaper that lists the most common ones for Linux, Mac and Windows users. Can't remember the command? Just pop up the desktop and check it out. Bored while waiting for a compile? Ditto.


There are a few resolutions:

IntelliJ IDEA Linux/Windows 1440x900
IntelliJ IDEA Macintosh 1440x900
IntelliJ IDEA Linux/Windows 1680x1050
IntelliJ IDEA Macintosh 1680x1050
IntelliJ IDEA Linux/Windows 1920x1200
IntelliJ IDEA Macintosh 1920x1200


Not on IDEA? You can download the Eclipse Desktop wallpaper from us, or the vim quick reference from our friend Ted Naleid.

doce ut discas - Teach, that you yourself may learn.

Friday, January 22, 2010

Sharing IntelliJ IDEA Project Files in Version Control

There are quite a few benefits to having IDE project files properly stored under version control:

  • most people want to use an IDE and will need to configure the project somehow
  • a shared environment reduces costs within a corporate workplace
  • a VCed project means that the project file branches with your codebase. Need to work on an old branch? No problem, the project file already exists.
  • casual contributors will have an easier time making patches for your project
  • an IDE can provide checkstyle and coding standards to your code
And when the files are stored improperly in version control, you create a nice changelist headache for yourself and turn away the casual contributor.

Here are three simple rules on how to properly share an IntelliJ IDEA project file in version control:

Rule #1 - Check-in the .ipr and .iml files
Rule #2 - Set an ignore flag for the .iws file (your workspace file). All proper VCSs allow you to do this.
Rule #3 - Make IDEA Project Variables for all the variables that vary (it's kinda the definition of variable, you know). Some common variables you'll probably need are "Tomcat Home", "Groovy Home", and "JDK Version".

Creating variables is really easy. Open the .ipr/.iml in a text editor and scan for hardcoded paths or values. When you find one just replace it with $variable_name$. Now when IDEA starts, it prompts you for those variables if they are not defined. These are IDEA variable stored in your HOME directory; they have nothing to do with your operating system environment variables. Here's what a prompt looks like:

See that red dialog? Clicking it opens a screen where you can add values to the variables:


Adding a value should be pretty self-explanatory.

The Gotchas - There are a few gotcha's to be aware of...

Using multiple versions of IDEA is not well supported. Most new versions, even minor releases, try to write some extra info to the project files. Not a problem in the corporate world, but more so in the OS one. You might try checking in a backup copy when the project lead upgrade.

Making the JDK Name variable can be somewhat confusing, as it is not a path on your disk. IDEA keeps track globally (for all projects) of your installed JDKs, and each one is given a name. It is easy to find the place in the .ipr where this is specified, but it is not easy to explain to users what their's should be set to. It needs to be the name of an entry from your SDKs in Settings:

Also, changing the inspection profiles can modify the project. The inspections are the codestyle to the project, so it may make sense to have them baked into the .ipr. However, this is an optional place to put them. An inspection profile can be shared or not. If it is shared then it is written to the .ipr, otherwise it is an external file. The Settings screen should be self-explanatory once you understand the Shared checkbox.


Lastly, adding words to the spell checker will add the word to the .ipr file, with a key of your username. I opened a bug for this, as I feel a user's name should never go in the project file, but the JetBrains guys feel that this is OK considering that switching to the ".idea" alternate project layout will separate the files out and avoid the issue. For now, I guess the best advice is to spell words correctly and, if you're not a committer, live with the fact that your project file may be checked out because of this issue.

Is all this worth it? I recently opened the GPars project files, defined an SDK and a Groovy 1.6.7 library, and ran the tests successfully. For me, it was great.

Rule #4 - Profit!

Thursday, December 10, 2009

Groovy 2009 Year in Review and 2010 Predictions

Groovy in 2009

Groovy 1.6 Released
Groovy 1.6 was released at the beginning of the year, and the most exciting new features have turned out to be Grape and AST Transformations.

Grape allows a developer to declare dependencies within their Groovy source code and then, at runtime, Groovy will download and install the dependencies using Ivy repositories. Want to ship scripts to your operations team? You no longer need to email or build JARs! It's no Jigsaw, but maybe that's a good thing.

AST Transformations allow developers to hook into the Groovy compiler and alter the way the code is compiled. This has enabled great work like the @Bindable and @Delegate annotations, as well as many forward thinking (read: visionary) libraries like the Spock testing framework and the CodeNarc static code analysis tools. Watch for more cool libraries and frameworks to use these features in 2010.

Griffon Released
While Flex and JavaFX duked it out for developer mindshare in the coveted (and hyped) RIA space, a groovier team quietly forked the Grails codebase and adapted it for Swing desktop applications. Griffon is way more than a dynamically typed builder pattern on top of Swing components. Griffon gives you property binding to widgets (you're not the only one Flex), a standard and simple MVC architecture without a spaghetti monster diagram (that's you PureMVC), more components than just a TextBox (the complete JavaFX widget set last Winter), a plugin system that allows you to decompose problems into reusable addons, and an easy way to deploy your app via webstart. If the Griffon team can keep the energy they had in 2009 then 2010 should be the year of the lion. Or eagle... or dog. What the hell is a griffon anyway?

Groovy Tooling Explosion
Looks like IntelliJ IDEA has some competition for best Groovy IDE. The Groovy Eclipse plugin got new life as Andrew Eisenberg revived the project, and SpringSource released better Grails support in SpringSource Tool Suite. Was the open sourcing of IDEA a response to the new competition? Who cares, it's free now! While IDEA is still the best IDE for Groovy, Groovy users will surely benefit from each IDE maker trying to outdo the other.

VMWare Buys SpringSource
Seriously, who saw this coming? This week at Groovy/Grails Exchange, Graeme Rocher demoed deploying to the cloud from his IDE (according to Twitter). Easy cloud deployment is good news... it will end the monthly "who do you use for Java hosting?" questions on user groups. Now if only the price would come down.

GR8 Conference
A Groovy conference created by the community, for the community, and priced for the community. It's great to see not for profit additions to the Groovy conference scene, and next year sees two GR8 events: one in Europe and one in North America (Minneapolis!). In other community news, Chicago Groovy Users Group started posting video sessions to blip.tv. Can we get some other GUGs to do the same?

A Groovy 2010

Don't think of these as predictions... think of them more as premature facts.

Gradle

To be clear: Gradle is not a Groovy technology. It is an enterprise build system written in Java with Groovy used as a build script. Anyway, the 0.9 release will include "Smart Execution/Incremental Compile" and 1.0 will support multi-threaded builds. These are enterprise level features that would be totally unique to Gradle... and they're sure to intice a lot of unhappy Maven developers. If the Gradle team can hit 1.0 and publish a book(!), then a lot of people will migrate.

GPars
I can't find anyone with anything bad to say about either the Fork/Join Framework or BMW Motorcycles... and I just sold my bike to spend more time coding. GParallelizer hasn't been widely adopted to date, in my opinion because it chased the Actor-Model hype a little too strongly. But now it's been rebranded GPars and an all-star team has been assembled to work on it. This isn't a good project to just follow, it's a good project to download and play with. Get the bits and join the mailing list. Your opinion counts! It's too bad that they hate cool the logo I made for them.

Griffon
The decision by the Grails team to make almost everything a plugin was genius. It provides a standard mechanism for everyone to modularize their own applications, and provides an easy path for users to push their non-business-critical plugins back into the community. If Griffon users embrace the plugin system, and then push their plugins back to the community, then Griffon could be a real alternative to JavaFX/Flex by the end of the year.

Java Closures
I wish the JDK team the best of luck meeting their September 2010 release deadline. While I have doubts that JDK 7 will ship in 2010, I do believe the closure syntax will be decided upon. And Groovy will be the first Java language to support that syntax. Whether a version of Groovy containing Java closures actually ships before JDK 7 is probably dependent on how the Groovy team wants to address the modularization issues of Jigsaw, which sounds like a much harder problem to solve.

Groovy IDE Support Improves... a little
IntelliJ IDEA still leads in features by a wide margin, but Eclipse and STS aren't stealing IDEA users, they're stealing TextMate users. People just want to debug without parsing all the files in the world. IDEA will remain the sole provider of Groovy refactorings, intentions, and auto-completions. But Eclipse will finally become a better alternative than a text editor. However, the open sourceing of IDEA should make it easier (and faster) to get IDEA support for newer frameworks, which is a good thing.

Groovy-User Mailing List Shuts Down
For the entire month of June, all posts to groovy-user will be answered with the same response: "This is covered in Groovy in Action 2nd Edition". By the end of the month admins will simply replace the mailing list home page with an advertisement for the book.

What Won't Happen

InvokeDynamic
InvokeDynamic is set to greatly improve implementing and running dynamic languages on the JVM. Only it won't be released until September 2010 at the earliest. Sure you can get the OpenJDK now, but most users won't do that. I predict InvokeDynamic being the story of 2011, not 2010... and even then I bet the JRuby guys beat us to it.

The Java Store
Let me get this straight... you want me to pay US$50 yearly so that I can give my Griffon app away free on the Java Store? You gotta be kidding. Griffon + the Java Store could be a match made in heaven: Griffon makes JNLP Webstart simple to configure and the Java Store handles hosting the files. But Sun/Oracle is turning too many hobbiest and small time developers away with their entrance fee. Are you listening Mr Ellison? I said I want... oh wait, you're not listening. How hard would it be to make the Groovy Store?

This was fun. What are your Groovy 2009 highlights and 2010 predictions?

Tuesday, August 4, 2009

IntelliJ IDEA 9 OSGi Support Explored

IntelliJ IDEA 9 (Maia) purports to support OSGi bundles... so I dug in the weekend to find out just what this means.

This blog posts provides a quick start guide for two things: 1) getting the IDEA 9 EAP to publish your library as an OSGi bundle, and 2) getting a second bundle published and running to test your library.

General Impressions
The IDEA 9 OSGi support is a port/conversion of the Osmorc plugin which was available in version 8. In general, the functionality seems stable but sparsely documented. I could find neither a discussion group nor documentation for Osmorc. A lot of the configuration was a process of trial and error. But it does all seem to work, and after investing a few hours it has started to seem straight-forward in hindsight. You'll have to judge for yourself how it compares to Eclipse (that's next on my list!). Osmorc tries to do a lot of auto-magic generation for you, and when I stepped outside the norm (like including Groovy as a test-only dependency) I was confronted with hard to fix failures. However, this may not be a fair criticism. For any serious project, you will want to write a bnd script, not simply use an IDE, and IDEA lets you use a bnd script to drive the OSGi configuration. So at points where the config wizard started to get difficult, I really should have stepped back and created a bnd script.

Getting a Bundle Published
While Eclipse seems to be focused on creating a Plugin (ie Bundle) from scratch using a wizard, IDEA is more focused on including OSGi support on one of your existing libraries using an OSGi facet. There is no "Create OSGi Project" wizard. You simply need to add an OSGi facet to one of your projects. I find this approach more reasonable. But let's not get too far before describing the basics of publishing a bundle:

1. Installing IntelliJ IDEA 9 and OSGi

  • Download and install the Maia EAP
  • Download and install an OSGi SDK (not just the framework jar). I had trouble with Eclipse Equinox, but KnopplerFish worked just fine
2. Configuring IntelliJ IDEA for OSGi
The next step is to tell IDEA about your OSGi SDK. In Settings (Ctrl+Alt+S), go to OSGi->IDE Settings->Framework Definitions and add your framework:
Now tell IDEA to use the framework you just registered. In Settings (Ctrl+Alt+S), go to OSGi->Project Settings and select your framework in the dropdown:

Done!

3. Publishing Your Library
Now let's publish your Java library as an OSGi bundle. In this example, I'm using my filter4osgi library that provides a nice API for LDAP style filters (shameless plug: I'll pay you for bug reports). This step will create the OSGi .jar file and required manifests.
  • Open an existing IDEA project... the fewer dependencies the easier it will be to publish
  • Add the OSGi facet to the project module. Clicking the little plus sign and picking OSGi should do the trick.
A note about the OSGi facet... currently, you're not able to add more than one OSGi facet to a module. For me, this forced me to create a multi-module project in order to produce several OSGi bundles from the same codebase. This seems like a considerable limitation to me but maybe my projects are structured strangely.

The Manifest Generation tab allows you to specify the exported packages for the bundle. I needed to manually add the package I wanted to export, Osmorc did not seem to discover this for me. Again, using bnd is probably the best option here.


There are plenty of other options, but they aren't as important right now. And note, I didn't add an Activator, because my bundle is just a library.

To verify that you published your library correctly, rebuild the application. The jar file should be written to disk. The manifest file with the OSGi headers is pretty simple:
Manifest-Version: 1.0
Export-Package: org.filter4osgi.builder;version="0.0.1"
Bundle-Version: 0.0.1
Tool: Bnd-0.0.337
Bnd-LastModified: 1249412068156
Bundle-Name: filter4osgi
Bundle-ManifestVersion: 2
Created-By: 1.6.0_12 (Sun Microsystems Inc.)
Import-Package: org.filter4osgi.builder;version="0.0"
Bundle-SymbolicName: filter4osgi
Include-Resource: ..\Filter4osgi
4. Running Your Bundle
Running the bundle is simple. Create a new Run/Debug Configuration using the little plus sign:
Just use the Add button to specify your bundle. You can also specify dependent bundles too.
On the Parameters tab, you'll need to specify the OSGi framework to run within:

Now just click Run, and your console output window should have something like this written to it:
Knopflerfish OSGi framework, version 4.1.7
Copyright 2003-2009 Knopflerfish. All Rights Reserved.

See http://www.knopflerfish.org for more information.
Failed to remove existing fwdir C:\Documents and Settings\hdarcy\.IntelliJIdea90\system\osmorc\runtmp1249413066328
Framework launched
Installed: file:///D:/dev/filter4osgi/out/production/Filter4osgi.jar (id#1)
Started: file:///D:/dev/filter4osgi/out/production/Filter4osgi.jar (id#1)
It worked! (Although I have no idea why there is a failure removing "fwdir", whatever that means). Alternately, you can load the jar file into any other container and interact with it that way. One feature that is missing is the ability to interact with the container from IDEA. You cannot issue the stop or uninstall commands. In fact, the only way I found to stop the container is with the big red Stop button. It would be better if you could issue text commands to the container. This doesn't seem like it would be difficult to add.

5. Testing Your Bundle with an OSGi Test Harness
There are a few test utilities for OSGi, such as Pax Exam and the Knopflerfish Junit Support, but all I wanted to do was write a bundle that imported filter4osgi and made sure the classes were available. So I simply added a new module to my project called "filter4osgiIntegrationTest". To this I added the Knopflerfish framework.jar since I needed to create an Activator. Take note, the prior example of exposing a library as a bundle required zero design or runtime dependencies on any OSGi implementation.

Without adding the OSGi facet, I created a new Java class that implemented BundleActivator. IDEA flagged me with a missing facet error and asked if I'd like to create a facet, which I did. Nice!

The Manifest Generation tab was mostly filled in, but again I needed to hand edit the MANIFEST.MF data so that it imported the package from the original filter4osgi bundle and added the root '.' to the bundle classpath (otherwise there were ClassNotFound exceptions).

Now I just implemented the activator to construct a new filter object:
public class ActivatorForTesting implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
FilterBuilder filter = or(
and(
eq("mailbox", "default"),
eq("lang", "EN_US")
),
and(
eq("mailbox", "dflt"),
eq("lang", "EN_CA")
)
);
assert filter.toString().equals("(|(&(mailbox=default) (lang=EN_US)) (&(mailbox=dflt) (lang=EN_CA)))");
}

@Override
public void stop(BundleContext context) throws Exception { }
}
Hey, that's not a bad API for working with LDAP filters, is it?

And now it's time to create the Run/Debug Configuration, which was probably the hardest step in all this. In the Run Config, I needed to specify that both the filter4osgi and filter4osgiIntegrationTest need to be started up, and that the filter4osgi must be started first. You do this in the Bundles tab, and ordering is done by indicating a Start Level:


Now, when I run the config, I should see that both bundles were started. And if I don't get a ClassNotFound error then I know that the filter4osgi exports lined up correctly with the filter4osgiIntegrationTest imports. Which they do:
Knopflerfish OSGi framework, version 4.1.7
Copyright 2003-2009 Knopflerfish. All Rights Reserved.

See http://www.knopflerfish.org for more information.
Failed to remove existing fwdir C:\Documents and Settings\hdarcy\.IntelliJIdea90\system\osmorc\runtmp1249414635312
Framework launched
Installed: file:///D:/dev/filter4osgi/out/production/Filter4osgi.jar (id#1)
Started: file:///D:/dev/filter4osgi/out/production/Filter4osgi.jar (id#1)
Installed: file:///D:/dev/filter4osgi/out/production/filter4osgiIntegrationTest.jar (id#2)
Started: file:///D:/dev/filter4osgi/out/production/filter4osgiIntegrationTest.jar (id#2)
Perfect!

All in all, the support was quite usable. I think starting with a bnd file would have made things easier for me, as well as if IDEA had let me interact directly with the container.Definitely looking forward to the official release!

Wednesday, July 29, 2009

IntelliJ IDEA 8 - The Good Parts

I keep getting asked if the upgrade from IDEA 7 to IDEA 8 is worth the cost.

While all the new features are listed on the IDEA site, these are my favorite 5 features of IDEA 8, listed in the order I like 'em best.

Database Support
The new SQL Console means you now get code completion, syntax highlighting, and error highlighting in your SQL scripts. Plus, no more launching a 2nd application to run queries. Very useful, but does seem to work better in MySQL than MS-SQL.

7 new Java Refactorings
The most useful of the new rafactorings are Extract Method Object, which allows you to extract method on blocks with more than one result type, and "Introduce Parameter Object" to compact long parameter lists. Use with care, you may not end up with a meaningless abstraction in your object model. Also, Introduce Constant got a big upgrade that lets you extract just parts of big static strings. Nice!

UML Diagrams
You can create diagrams right in the IDE now. I think there were some plugins in the past that allowed this, but now a nice version of the feature is available in IDEA. You can generate diagrams, and can also create new entities, refactor, and navigate directly to source code. The diagrams look great; I've used them in some presentation already.

Groovy & Grails Support
Improved Groovy support adds a couple notable improvements: better code completion, more inspections, two new refactorings including "Convert method parameter to map-parameter entry", debugger support for Gant(!), and a whole bunch of Grails stuff.

Debugger for Flex (and Javascript)
We're using FlexBuilder for official Flex development at work, but for me, who does mostly Java, I've found it useful to use the IDEA Flex debugger when I don't feel like launching a 2nd huge application on my workstation. We evaluated IDEA 8 as a replacement for FlexBuilder and decided not to, but we'll take another look at IDEA 9 Flex support and maybe switch then. There's also a Javascript debugger but I haven't touched that language in a year or so.

Honorable Mentions

Dataflow to This - Shows you how a certain variable got the value it did. Think of it as a better call stack window.

Thread Dump Analyzer - The new window is way easier on the eyes than scanning through text thread dumps. Nice.

Spring 2.5 support - Use it every day so that some of the new Spring annotations are recognizable and navigable.

IDE Settings Synchronization - Share all your IDE settings between several workstations.

Those are the things I use the most... there is, of course, way more new than that. If you know me and want a 60 day trial license (normally they are only 30) then drop me an email!

Or check out the IDEA 9 EAP.

Sunday, February 8, 2009

IntelliJ IDEA 8 Groovy Intentions in 2:45

The Groovy plugin within IntelliJ 8 offers Alt+Enter triggered intentions to simpily, modify, and groovify your code.


The full list of intentions is on the JeyGroovy wiki, but here is a 2 minute 45 second video demonstration for those too lazy to read:








Trying to make this screencast has been a nightmare: bought microphone, doesn't work; upgrade IDEA, license expired; bought firewire card, out of PCI Ports; record screencast, can't add audio track; format to .swf, text illegible; pour huge glass of gin, no tonic. It can't get any worse.


All these IDEA posts are preparation for the Groovy IDE Shootout at Groovy.MN this Tuesday. Stop by and say Hi!

Wednesday, February 4, 2009

Groovy + IDEA Debugging Tip: Skip Stepping into GDK Classes

Debugging Groovy code in IDEA can be a hassle because you spend more time stepping into and out of classes in the Groovy language rather than your own classes. Nothing like stepping through a whole bunch of "invokeMethod" reflection layers.

You can fix this by telling IDEA not to step into the Groovy framework classes. Open up the Settings, and go to the Debugger->Stepping panel. Using the "Add Pattern..." button, add the patterns "groovy.*" and "org.codehaus.groovy.*" This screenshot is from IDEA 8, but this works fine on 7 too:




February 10, 2009 is the Groovy IDEA shootout at Groovy.MN... please stop by. And, of course, check out the IDEA Refcardz if you haven't yet.

Groovy Dynamic Method Support in IDEA

When IDEA 8 was announced, the press release simply said "Dynamic properties and methods". Uh, okay. I never understood what that meant until I stumbled upon a discussion board post for them.


Here's the explanation:

The JetGroovy plugin underlines expressions in Groovy code that it doesn't recognize. So misspelling a variable or referencing a missing class gives you a visual cue:


Notice how "mystring" is underlined (it is mis-capitalized). But frequently these are valid expressions that will resolve at runtime... for instance, Grails GORM methods. You know these methods will exist so the underlining is annoying. Accepting the Alt+Enter quick-fix on these properties and methods for "Add dynamic property" will add the expression to your list of dynamic expressions. You can view this dynamic expressions in the Dynamic properties panel.


Notice how the "".greetings is not underlined, whereas before it would have been. Also, the expression is now available for code completion:


To remove an expression just select it in the list and press delete on the keyboard.


That's not such a bad feature.

February 10, 2009 is the Groovy IDEA shootout at Groovy.MN... please stop by. And, of course, check out the IDEA Refcardz if you haven't yet.