简体   繁体   中英

How to develop Eclipse plugins in clojure?

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.

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". EG 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, eg 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

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM