Build, Debugging and Unit test setup

This page overlaps with the Getting started page, but goes into more detail.

All of the following processes should be trivial if you use Maven 2 with ShapeLogic:

  • Build
  • Debugging
  • Running unit test from within the IDE or command line

Building ShapeLogic

ShapeLogic uses http://maven.apache.org for building.

This is very simple to learn and makes the build process trivial.

Install Maven 2.

Download ShapeLogic and unpack it.

After these initial steps the build process only contains 2 steps:

Step 1: Go into the shapelogic dir and run this command:

mvn package  

This will run all unit tests and if there are no errors, build the jar file.

Step 2: When the build is successful moved shapelogic/target/shapelogic_-1.6.jar to ImageJ/plugin/shapelogic dir, this will make it available in ImageJ.

Details to the build process

The latest jar file is called shapelogic_-1.6.jar.

It has to have an underscore in the name in order for ImageJ to treat it as a plugin.

Creating PlugInFilter

All the files that are PlugInFilter needs to be placed in the default package dir: shapelogic/src/main/java, and they need to have a name that is ending in a underscore e.g. MaxDistanceVectorizerTest_.java.

In ShapeLogic the source files that live there are thin wrappers around the real classes that live under other packages, e.g.: shapelogic/src/main/java/org/shapelogic/imageprocessing/MaxDistanceVectorizerTest.java

Depending jar file

In order to run ShapeLogic you need to place all the jar files that it depends on in the ImageJ/plugin director:

These jar file can be found in:

  shapelogicplugin1.6.zip       ShapeLogic 1.0 plugin for ImageJ with all dependent jar files  

Steps to install:

  • Download shapelogicplugin1.6.zip
  • Unzip it
  • This will create a directory named shapelogicplugin1.6/shapelogicplugin
  • Inside this there are 2 dirs: ShapeLogic and ShapeLogicOld and 6 jar files
  • Take these 2 dirs and all the jar files from this directory and copy it into ./ImageJ/plugins/

Debugging

Just start the debugger from Eclipse, with these setting:

Debugging class: ij.ImageJ (main ImageJ class)
Start directory:  ImageJ directory:
VM setting: -Xmx50m

Unit tests

The test classes open an image from a file and directly calls the Processor on it directly.

See the AbstractImageProcessingTests.java. Here is the main setup part:

static public ImageProcessor runPluginFilterOnImage(String fileName, PlugInFilter plugInFilter) {
        Opener opener = new Opener();
        ImagePlus image = opener.openImage(fileName);
        ImageProcessor ip = image.getProcessor();
        plugInFilter.setup("", image);
        plugInFilter.run(ip);
        return ip;
}

Handling libraries that are not in Maven repository

ShapeLogic is mainly only using libraries that are in Maven repository. Maven downloads them automatically when running mvn test or mvn package.

It is a little harder to work with libraries that are not in the Maven repository.

There are only 2 of those: Scripting engines and ImageJ 1.40.

Installing Groovy or other Scripting engines for JSR 223

This is one thing that does not work directly with Maven

In other to get it to work you have to download jsr223-engines.zip from https://scripting.dev.java.net/servlets/ProjectDocumentList

After that you have to unpack it, and install it into the Maven repository:

Installing ImageJ jar, source and doc into local Maven repository

Download jar, source and doc from ImageJ download.

mvn install:install-file -Dfile=groovy-engine.jar -DgeneratePom=true -DgroupId=org.codehaus.groovy -DartifactId=groovy-engine -Dversion=1.5.1 -Dpackaging=jar

Installing ImageJ into local Maven repository:

mvn install:install-file -Dfile=ij.jar -DgeneratePom=true -DgroupId=imagej -DartifactId=imagej -Dversion=1.41 -Dpackaging=jar

Installing ImageJ sources into local Maven repository:

mvn install:install-file -Dfile=ij141o-src.zip -DgeneratePom=true -DgroupId=imagej -DartifactId=imagej -Dversion=1.41 -Dclassifier=sources -Dpackaging=jar

Installing ImageJ javadoc into local Maven repository:

mvn install:install-file -Dfile=api.zip -DgeneratePom=true -DgroupId=imagej -DartifactId=imagej -Dversion=1.41 -Dclassifier=javadoc -Dpackaging=jar

How ShapeLogic was set up for Maven and Eclipse

You will not need to do this, since ShapeLogic is already setup when down loaded.

This useful if you are setting your own ImageJ project up and you want to use similar simple build, debug and unit test processes.

Here is a good description of setting up Maven 2 in five minutes.

mvn archetype:create -DgroupId=org.shapelogic -DartifactId=shapelogic_

Generating Eclipse project

Install the the Maven 2 plugin for Eclipse: http://m2eclipse.codehaus.org/update

To generate the Eclipse project file for ShapeLogic run this command:

mvn eclipse:eclipse  

Open Eclipse and import the project.

That is all there was to it.

Generating IntelliJ project

To create a project for IntelliJ instead run this command:

mvn idea:idea  

How to run ShapeLogic from NetBeans

  • In NetBeans download the Maven plugin.
  • Checkout ShapeLogic from Google Code into your NetBeansProjects dir:
    cd NetBeansProjects
    svn checkout http://shapelogic.googlecode.com/svn/trunk/ shapelogic-read-only
  • In NetBeans create a new project of type Maven, Maven from existing POM

Maven gloals can be run directly from NetBeans. Just rigthclick on shapelogic project, select Custom, Goals. Type the name of the goal, e.g. package. This comes with word compleation.

The site goals could not be run from NetBeans because of a Maven version conflict, but ran fine from command line:

cd NetBeansProjects/shapelogic
mvn site  

This was tested with NetBeans 6.0, 6.1 and 6.5.

Platforms and IDE

ShapeLogic is pure Java and should run under most platforms and IDEs. ShapeLogic development has taken place under Linux, Windows, Eclipse and NetBeans. All works fine. And each has some advantages.

Eclipse 3.3 advantages

  • Better integration with Maven, especially for selecting dependent libraries and for debugger
  • Bigger community, and more plugins
  • Spell checker for comments and documentation files

NetBeans 6.1 and 6.5 advantages

  • Less dependencies more stability, Eclipse would break under some Linux AMD64 distributions
  • There is only one way of doing normal things that seems better integrated
  • More lightweight than Eclipse

Eclipse 3.4 problems

There seems to be some problems with debugging under Eclipse 3.4.

They are related to the 2 directories for compiled class files:

  • shapelogic/target
  • shapelogic/target-eclipse

Maven will create class files in shapelogic/target while Eclipse 3.4 will create class files in shapelogic/eclipse-target. However when you start to run or debug, it will first find the class files in shapelogic/target. You can override this when you are debugging something, but it appear that you have to do it each time.