[ImageJ-devel] Migrating an ImageJ1 plugin (Git, Ant etc.) to ImageJ2 (Git, Maven)
Johannes Schindelin
Johannes.Schindelin at gmx.de
Mon Jul 30 12:35:24 CDT 2012
Hi Michael,
On Sun, 29 Jul 2012, Michael Doube wrote:
> In a new thread because it's a broad but different issue than the
> others: How to move an active ImageJ1 plugin project to an ImageJ2
> project?
>
> The scenario:
> I have an active ImageJ1 plugin project, which I want to move to Image2.
> The old plugin needs to stay active with bugfixes and for archival
> reasons. Currently, releases are tracked on the master branch of a Git
> repository, the IDE is Eclipse and Ant is the builder. I'd like to keep
> the whole project (IJ1 and IJ2 plugins) in the same Git repository.
>
> The plan at the moment is to:
> Keep releasing the old plugin on the master branch
> Work on the new plugin on a version branch
> When the new plugin is stable, send the old plugin to a legacy branch
> and merge the new plugin to master
Personally, I would actually develop them in the same branch, in different
subdirectories, for the time being. And if at all possible, I would try to
re-use code all the time.
Ideally, however, you would really provide the very same .jar file (and
likewise have really just one project) for both the IJ1 and IJ2 plugin. If
you wrap the ImagePlus into an ImgLib2 structure in the IJ1-specific part,
you should be able to use the exact same code to perform the actual
computation from both IJ1 and IJ2.
> Because the two plugins use different build systems, I've set them up as
> two separate Eclipse projects, one with the old style (Ant,
> plugins.config) and one with the new style (Maven, annotations). The two
> projects work on different branches of the same Git repository, so I can
> work on both of them simultaneously in the same instance of Eclipse.
If you have a look at, say,
https://github.com/fiji/fiji/tree/master/src-plugins/Arrow_ you will see
that it is quite doable to use Maven to build IJ1 plugins without any
hassle.
> To do that I branched the new plugin off, cloned it locally into a new
> Eclipse project (Import...) then 'Mavenized' the new project. The
> pom.xml-related chatter from me lately has been a result of this
> process. The new branch has the old directory structure:
> workspace/src/org/bonej/MyPlugin.java but Maven expects something else
> by convention.
Yep, that is right, the convention is that your sources live in the
src/main/java/ sub-directory of your project root directory. In your case,
it would be:
BoneJ/src/main/java/org/bonej/MyPlugin.java
Also, I would strongly advise to keep the sources outside of the Eclipse
workspace. We had a lot of "fun" with Eclipse that was solved simply by
moving the project files outside of the workspace.
> The big question is, is this going to work at all or should I start
> again in a different way?
I'll not suggest to throw away all your hard work. If you want to follow
my advice above, you can do that without re-starting the whole thing.
For example, to get the IJ1 and IJ2 plugin reconciled into one branch, you
could first change things in the IJ1 branch to use ImgLib2 and to use
Maven, and then you could simply merge the IJ2 branch.
> I am asking all this because processing of annotations doesn't work in
> my setup, so the new plugin's menu items aren't added to ImageJ2
> (solution is to use the Ant build.xml and Sun javac to do the release
> build, as we developed at the last Fiji Hackathon).
Yes, the annotation processing is a little hairy. Our solution in ImageJ2
is to force certain settings by tracking the .factorypath and
.settings/org.eclipse.jdt.apt.core.prefs as part of our source code. This
tells Eclipse to adher to the standard mandated by the Java specifications
which demand that annotation processors present in the classpath when
compiling Java sources be run.
I have ticket in the ImageJ2 ticket system to make it easier to start
developing a plugin in Eclipse, by providing a File>New Plugin (Eclipse)
menu entry. I fully intend to write out the two files mentioned above
together with a pom.xml file from there.
Also note that starting with ImageJ2 beta3, Eclipse setups should be
supported much better even when the annotation processors failed to be
called: if you start ImageJ2 from within Eclipse, it should now detect
that situation and run the annotation processors manually.
> Do you see any disasters looming, or propose another streamlined
> approach that will work? Maven is impressive so far, so I'd like to
> continue with it, I just have to organise things so that it behaves
> correctly.
Right, the problem is however not so much Maven as Eclipse's Maven
emulation. One other thing I would strongly suggest to do is to make the
scijava pom.xml the parent of your top-level pom.xml. That way, you not
only get the ImageJ2 versions for free, but you also get some settings
fixing issues in particular with Eclipse that at least yours truly
struggled with for extended amounts of time. Just as an example: at some
stage, Eclipse's Maven emulation stopped running the buildnumber plugin
(which embeds the current commit into your .jar file's manifest,
super-useful). After hours of research I finally found how to force it
back to normal.
And yes, you probably guessed it, the pom.xml which File>New Plugin
(Eclipse) will write out will have the scijava pom as parent.
Ciao,
Dscho
More information about the ImageJ-devel
mailing list