How to develop Eclipse plugins in clojure?
Asked Answered
R

3

8

I was wondering if there is a way to develop Eclipse plugins in Clojure. To be clear, the question is not about using Eclipse to write Clojure code.

Both Eclipse and Clojure run on the JVM and I feel there should be way to leverage the power of Clojure (and it's libraries) to develop plugins. I was specifically looking at using Korma, but overall I would like to move complete plug-ins to clojure if there is a natural way to do it.

Reorder answered 23/11, 2011 at 10:35 Comment(1)
After thinking about it a bit I had a small brainstorm and searched for OSGI and Clojure and came across this blogpost about running clojure under OSGI and an email thread implying that it is not a good idea. A little confused.Reorder
A
10

Counterclockwise, the Eclipse plugin for Clojure, is written in mixed Java and Clojure. It uses clojure.osgi 1.2.10 yet.

So it is a live proof of concept that it is possible. And AFAIK, Counterclockwise is used successfully by hundreds of people.

There are some constraints, tho: Clojure's namespace is "global" to some "root classloader". E.G. if you package Clojure inside a bundle named, say, myapp.clojure, then you'll probably have a bunch of other bundles which will require myapp.clojure. Say for example myapp.bundle1, myapp.bundle2. When you do so, and, from each bundle, load in memory (require) the bundles namespaces, each one will be loaded from within the right ClassLoader (namespaces of myapp.bundle1 will be loaded within the context classloader of myapp.bundle1, and namespaces of myapp.bundle2 will be loaded within the context classloader of myapp.bundle2). This is great, because it allows java interop to work okay.

But just remember that in the end, namespaces loaded from bundle1 & bundle2 will be held by the "global namespace world" in bundle myapp.clojure.

To be honest, this has not yet proven a problem for Counterclockwise. Because inside the same Feature, having the bundles share one single Clojure instance is almost okay.

The potential drawbacks are:

  • if you use third party libraries, e.g. tools.logging, you will not be able to have namespaces in myapp.bundle1 depend on version X of tools.logging, and at the same time have myapp.bundle2 depend on version Y of tools.logging. That is, inside your feature where you have a shared clojure via bundle myapp.clojure, you work as if OSGi rules did not apply, as webapps work, for example.
  • does not scale well if massively applied: if every Eclipse Feature were to repackage its own version of Clojure, there would be some waste of memory. But this drawback is more theoretical than practical, yet. And this is a problem that can be addressed later, when the need for it emerges.

Note that for an Eclipse RCP Product, as opposed to an Eclipse plugin, these drawbacks vanish.

If you want to see how Counterclockwise has repackaged clojure, and uses clojure.osgi, you can look at its sourcecode:

http://github.com/laurentpetit/ccw.clojure.git http://github.com/laurentpetit/ccw.git

HTH,

-- Laurent

Acidic answered 4/12, 2011 at 20:54 Comment(0)
M
4

It seems it's not available in Eclipse 3.x, but is planned for Eclipse 4, as mentioned in http://wiki.eclipse.org/E4/Languages .

There's also a post here on Stack Overflow asking about development of Eclipse plugins in languages other than Java that may have more information that you'd find useful.

Megilp answered 23/11, 2011 at 10:48 Comment(0)
S
3

It's perfectly possible to write Eclipse plug-ins in Groovy or Scala. Since Clojure produces .class files, it should be no different. However, plugins are normally exported using PDE Build, which only handles Java by default, so you will have to write a customCallback.xml file which can compile Clojure (see http://www.michel-kraemer.com/scala-projects-with-eclipse-pde-build-2 for Scala build).

Shipyard answered 23/11, 2011 at 13:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.