Jump to: navigation, search

Difference between revisions of "Headless entrypoints (Buckminster)"

 
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
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.
 
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==
 
==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:
+
If you wish to invoke Buckminster directly using Java, this is what you type:
 
<pre>
 
<pre>
java -classpath /some/path/buckminster_startup.jar org.eclipse.buckminster.headless.startup.Main [the rest of the command line]
+
java -jar startup.jar [the rest of the command line]
 
</pre>
 
</pre>
 +
 +
==The buckminster 'binary'==
 +
Invoking using the java binary is sometimes tedious. Buckminster therefore provides a script that does this for you. Please note that calling scripts from other executables might be less then trivial. Should problems arise, the fall-back is to call the java binary directly.
  
 
==From Java &mdash; code==
 
==From Java &mdash; code==
Line 22: Line 14:
 
<pre>
 
<pre>
 
...
 
...
URLClassLoader cl = new URLClassLoader(new URL[] { new File("/some/path/buckminster_startup.jar").toURI().toURL() });
+
URLClassLoader cl = new URLClassLoader(new URL[] { new File("/some/path/startup.jar").toURI().toURL() });
Class<?> c = cl.loadClass("org.eclipse.buckminster.headless.startup.Main");
+
Class<?> c = cl.loadClass("org.eclipse.core.launcher.Main");
 
Method m = c.getMethod("run", new Class[] { String[].class });
 
Method m = c.getMethod("run", new Class[] { String[].class });
 
Integer exitCode = (Integer)m.invoke(c.newInstance(), new Object[] {new String[] { "lscmd", "--style", "short" }});
 
Integer exitCode = (Integer)m.invoke(c.newInstance(), new Object[] {new String[] { "lscmd", "--style", "short" }});
Line 34: Line 26:
 
<target name="sample">
 
<target name="sample">
 
   ...
 
   ...
   <java
+
   <java jar="startup.jar" fork="true">
      classname="org.eclipse.buckminster.headless.startup.Main"
+
      classpath="buckminster_startup.jar"
+
      fork="true"
+
      >
+
 
       <arg value="lscmd"/>
 
       <arg value="lscmd"/>
 
       <arg value="--style"/>
 
       <arg value="--style"/>
Line 48: Line 36:
  
 
Note the use of 'fork'. At this time using a fork value of false is not supported.
 
Note the use of 'fork'. At this time using a fork value of false is not supported.
[[Category:Buckminster]]
+
 
[[Category:Buckminster Documentation]]
+
 
[[Category:Buckminster Examples]]
+
 
[[Category:Buckminster Headless]]
 
[[Category:Buckminster Headless]]

Latest revision as of 10:26, 19 July 2007

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.

From Java — command line

If you wish to invoke Buckminster directly using Java, this is what you type:

java -jar startup.jar [the rest of the command line]

The buckminster 'binary'

Invoking using the java binary is sometimes tedious. Buckminster therefore provides a script that does this for you. Please note that calling scripts from other executables might be less then trivial. Should problems arise, the fall-back is to call the java binary directly.

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/startup.jar").toURI().toURL() });
Class<?> c = cl.loadClass("org.eclipse.core.launcher.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">
   ...
   <java jar="startup.jar" fork="true">
       <arg value="lscmd"/>
       <arg value="--style"/>
       <arg value="short"/>
   </java>
   ...
</target>

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