The Object Teams Blog

Everthing Object Teams - adding team spirit to your objects.

Archive for June, 2011

A use case for Java 7

with 10 comments

Recent stress tests have revealed a few issues in the Eclipse platform where leaking file handles could cause “Too many open files”-style failures.

Until now that kind of issue was notoriously difficult to analyze, and a lot of luck was involved when I spotted one of those bugs by mere code inspection.

However, chances are that this particular kind of bug will soon be a curiosity from the past. How? Java 7 brings a new feature that should be used in exactly this kind of situation: by the new try-with-resources construct leaking of any resources can be safely avoided.

Now, current code certainly doesn’t use try-with-resources, how can we efficiently migrate existing code to using this new feature? As one step I just filed this RFE for a new warning where try-with-resources should probably be used but is not. At this point I can’t promise that we’ll be able to implement the new warning in a useful way, i.e., without too many false positives, but it sounds like a promising task, doesn’t it?

Here’s a mockup of what I’m thinking of:

Warning: potential resource leak

And this is what the quickfix would create:
After applying the quickfix

Sounds cool?

Written by stephan

June 14th, 2011 at 5:11 pm

Posted in Eclipse

Tagged with , , ,

Between the Times

with 2 comments

This week is (supposed to be) “quiet week” at Eclipse: Release Candidate 4 is in place and more testing is being done before the final Indigo Release. Time to speak of s.t. that the Object Teams project has neglected a bit in the past: compiling / building with Maven.

Compiling OT/J with Maven

In the days of Maven2, pluging-in a non-standard compiler required fiddling with the nexus compiler plugin, which was buggy and all that. With the recent development around Maven3 and Tycho things became easier. The following pom-snippet is all you need to tell Maven to use the OT/J compiler:

<build>
    <pluginManagement>
	<plugins>
	    <plugin>
		<!-- Use compiler plugin with tycho as the adapter to the OT/J compiler. -->
		<artifactId>maven-compiler-plugin</artifactId>
		<configuration>
		    <source>1.6</source>
		    <target>1.6</target>
		    <compilerId>jdt</compilerId>
		</configuration>
		<dependencies>
		    <!-- This dependency provides the implementation of compiler "jdt": -->
		    <dependency>
			<groupId>org.sonatype.tycho</groupId>
			<artifactId>tycho-compiler-jdt</artifactId>
			<version>${tycho.version}</version>
			<exclusions>
			    <!-- Exclude the original JDT/Core to be replaced by the OT/J variant: -->
			    <exclusion>
				<groupId>org.sonatype.tycho</groupId>
				<artifactId>org.eclipse.jdt.core</artifactId>
			    </exclusion>
			</exclusions>
		    </dependency>
		    <dependency>
			<!-- plug the OT/J compiler into the tycho-compiler-jdt plug-in: -->
			<groupId>org.eclipse</groupId>
			<artifactId>objectteams-otj-compiler</artifactId>
			<version>${otj.version}</version>
		    </dependency>
		</dependencies>
	    </plugin>
	</plugins>
    </pluginManagement>
</build>

This relies on the fact, that the OT/J compiler is compatible with the JDT compiler, good.

To make things go smooth in various build phases a few more bits are required:

  • provide the OT/J runtime jar and its dependency (bcel)
  • tell surefire about required command line arguments for running OT/J programs

These basics are collected in a parent pom so that all you need are these two snippets:

<repositories>
    <repository>
	<id>ObjectTeamsRepository</id>
	<name>Object Teams Repository</name>
	<url>http://download.eclipse.org/objectteams/maven/3/repository</url>
    </repository>
</repositories>
<parent>
    <groupId>org.eclipse</groupId>
    <artifactId>objectteams-parent-pom</artifactId>
    <version>2.0.0</version>
</parent>

This converts any Java project into an OT/J project, simply enough, huh?

At least compiling and testing works out-of-the box. Let me know what additional sophistication you need and if adjustments to other build phases are needed.

OT/J over m2e

Well, I’m not much of a Maven expert, but I’m an Eclipse enthusiast, so, how can we use the above inside the IDE?

The bad news: the m2e plug-in has hardcoded its support for the compiler plugin to use “javac” as the compiler. Naive attempts to use tycho-compiler-jdt have failed with the infamous "Plugin execution not covered by lifecycle configuration".

The good news: By writing a tiny OT/Equinox plug-in I was able to remedy those issues. If you have the m2e plug-in installed (Indigo version), the normal “Update Project Configuration” action will suffice:
Update Project Configuration

After that, the project is recognized as an OT/J project, both by the IDE …

… and also by maven …
Running mvn test

Where to get it?

The mentioned plug-in is brand-new and as such it is not part of the regular OTDT distribution. OTOH, the plug-in is so simple, I don’t expect a lot of changes needed. So, if you have an Indigo-ish Eclipse just add this update site:

Then install “Maven Integration for Object Teams (Early Access)”:
Install the Maven Integration for Object Teams

Don’t forget the <repository> and <parent> definitions from above and you should be ready to go! Yesss, sometimes it pays off that OT/J is a kind of Java, a lot of the tooling can just piggy-back on what’s already there for Java :)

Written by stephan

June 14th, 2011 at 2:56 pm

Posted in Eclipse, Object Teams

Tagged with , , ,