Jump to: navigation, search

Headless entrypoints (Buckminster)

Revision as of 09:31, 21 September 2006 by Henrik.lindberg.puppet.com (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Below are various possibilities of running a Buckminster command. Note that in all cases, this has the same benefits and drawbacks as running any command line app; detecting errors is up to checking exit codes, you may have to parse text etc. On the other hand it's really simple. If you need more control than this you must write an Eclipse plugin and interface to the 'real' Buckminster API's available.

The buckminster 'binary'

A key desire is that Buckminster headless commands are reachable and work just as any other command line application on your system. This not only includes being able to type 'buckminster' from the command line - it should also be able to easily reach such an entry point from a scripting environment. Yes, Buckminster is a Java application, but having to type

java -cp ...

also suffers from the problems with a plain batch script.

For these reasons we provide a buckminster 'binary'. However, due to various systems idosyncrasies this is not necessarily simple.

  • On Unix/Linux systems it is reasonably straightforward. We can pretty much count on having /bin/sh available, and with a very simple shell script with a suitable shebang line, it works pretty much like we want.
  • On Windows however, it is slightly different. A regular cmd.exe 'batch' file is not sufficient as trying to invoke 'buckminster.bat' from a scripting environment won't necessarily work without explicitly using something like
cmd /c buckminster

So, on Windows we provide a very simple buckminster.exe file - this is essentially just a 'packaged' command line.

From Java — command line

The 'binary' described above is thus really nothing more than a wrapper around a Java command line. If you wish to call it yourself that way this is what you need:

java -classpath /some/path/buckminster_startup.jar org.eclipse.buckminster.headless.startup.Main [the rest of the command line]

From Java — code

As is evident from above, all you really need is to call the entry point in the buckminster_startup.jar and pass in the 'command line' directly. Sample dynamic code:

URLClassLoader cl = new URLClassLoader(new URL[] { new File("/some/path/buckminster_startup.jar").toURI().toURL() });
Class<?> c = cl.loadClass("org.eclipse.buckminster.headless.startup.Main");
Method m = c.getMethod("run", new Class[] { String[].class });
Integer exitCode = (Integer)m.invoke(c.newInstance(), new Object[] {new String[] { "lscmd", "--style", "short" }});

From Ant

There are no specific Ant tasks (unless you write them yourself), but calling the commands from Ant is fairly simple as it follows from the able code sample:

<target name="sample">
       <arg value="lscmd"/>
       <arg value="--style"/>
       <arg value="short"/>

Note the use of 'fork'. At this time using a fork value of false is not supported.