Showing posts with label Mac OS X. Show all posts
Showing posts with label Mac OS X. Show all posts

Sunday, August 21, 2011

Java To OmniGraffle

If you ask developers using Mac OS X about their favorite diagramming tool, you will often get the same answer: OmniGraffle. I also like OmniGraffle very much, and I'm still wondering what makes this tool so much better then all the GEF based editors.

When I have to create diagrams for documenting some Java code, I used to manually draw an UML like class diagram with OmniGraffle. This is an error prone process, and a boring one as well. So, I tried to find a better solution. Since I didn't find any existing tool, I wrote a small Eclipse plugin my self. It automatically generates OmniGraffle class diagrams from existing Java code.

Its usage is very simple: Open or create a drawing in OmniGraffle. Then switch back to Eclipse and select "Create OmniGraffle Diagram" from the context menu of a package in the package explorer, as shown in Figure 1. Configure the output, as shown in Figure 2. The plugin will scan the package and add a class diagram of this package to the front most drawing opened with OmniGraffle. Figure 3 shows the result created by the plugin without any manual changes. It is a visualization of the package "ReverseLookup" of GEF3D.
Fig. 1: Context menu entry

Fig. 2: Configuration Dialog
Fig 3: Created class diagram
At this moment, the plugin can only create class diagrams for a single package. Update: The plugin can create class diagrams for selected types, packages, and sub packages. Besides, the context of selected classes, that is types on which the selected types depend on, can be visualized as well. Attributes are drawn as associations if possible, parameterized collection types are recognized and replaced by 0..* associations. You can configure the output with some switches. Besides filtering members based in their scope, I have added some "filters" I often use when I draw diagrams manually:
  • Getter and setters can be omitted
  • Methods implementing or overriding methods of interfaces or classes already shown in the diagram can be omitted as well
  • In order to better see relations between classes, you can force to draw all associations, even if they would be filtered out by the scope filter.
The newly created shapes are initially drawn using OmniGraffle's hierarchical layout algorithm.

Tip: In order to manually change the diagram, you may want to have a look at my collection of UML shapes at Graffletopia.

You can install the plugin via the update site:

http://jevopi.de/updatesite/de.jevopi.JavaToOmniGraffle
This is an beta alpha version, which will expire 2012. If you find this plugin useful, flattr me! Or leave me a comment below. Depending on the feedback, I will continue developing the plugin -- or not ;-)

In the preferences, you can set the default configuration settings and define the name of your OmniGraffle installation (however, the plugin tries to find the latest installed version automatically).

Last but not least: Of course, this plug is only available on Mac OS X, since OmniGraffle is a native Mac application. The communication between Eclipse and OmniGraffle is done via AppleScript, which is very easy thanks to Peter Friese's blog post.

(At Stackoverflow, someone estimated a tool for creating OmniGraffle diagrams from Eclipse UML2 based models would require 18 months development effort. Well, I needed less then 18 hours. But I only convert Java packages to class diagrams... ;-) ).

Update 2011-11-01:
  1. Besides packages, selected types and sub packages can be visualized.
  2. The context of visualized types can be visualized. That is, types on which the selected types depend on, such as super classes, can be rendered additionally to the selected classes. These context types are rendered in gray.
  3. The default package is now handled as well (see comment by mathpup).

Tuesday, June 1, 2010

Install strictly J2SE-1.4 compatible JRE on Mac OS X Snow Leopard

Today I tried to compile a project requiring J2SE-1.4, i.e. with
Bundle-RequiredExecutionEnvironment: J2SE-1.4
specified in its manifest. On OS X 10.6, JRE 1.4 is no longer installed, instead, version 1.4 points to 1.6. Unfortunately, this JRE is not strictly compatible to J2SE-1.4, as I have learned from this error message:
Build path specifies execution environment J2SE-1.4. 
There are no JREs installed in the workspace that are 
strictly compatible with this environment.
Simply making a selection on the 1.6 JVM in the list compatible JREs in Preferences / Java / Installed JREs / Execution Environment / J2SE-1.4 doesn't help (I tried to clean the projects, but 1.6 is not strictly compatible, thus clean doesn't help here). So, I had to install JDK 1.4, which probably is no problem for Windows and Linux users. However, on OS X, you'll have to follow the hints explained at www.macosxhints.com and repeated here for your convenience:
  1. Remove symbolic links in /System/Library/Frameworks/JavaVM.framework/Versions/ pointing from 1.4.* to 1.6 (otherwise, the 1.6 JDK will be overwritten). E.g, in the terminal (with admin rights):
    > cd /System/Library/Frameworks/JavaVM.framework/Versions/
    > sudo rm 1.4*
  2. Download http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_4. Yeah, it is still available, but Apple doesn't make live easy for Java developers these days: Do not install this package (as it will overwrite your existing Java versions)! See next step instead
  3. Open downloaded pkg with Pacifist (http://www.charlessoft.com/).
  4. Select JDK 1.4 and 1.4.2, and install it to default location via Pacifist's context menu (see screenshot)
Now, JDK 1.4 is installed on OS X 10.6. We only have to let Eclipse (in my case 3.6RC1) know about it: In Eclipse, select Preferences / Java / Installed JREs / Add Standard VM Enter JRE Home: /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home and JRE Name: JVM 1.4 (or whatever) You will have to close Preferences (OK), and reopen it in order to let the newly added JRE to be added to the list of compatible JREs. In Preferences / Java / Installed JREs / Execution Environments / J2SE-1.4 select JVM 1.4 (now marked with "perfect match") in list of compatible JREs. That's it. Ted Wise provides zipped versions of JVM 1.5 and 1.4, and you may install these versions following his description at http://tedwise.com/2009/09/25/using-java-1-5-and-java-1-4-on-snow-leopard/. In that case, you won't need Pacifist.