API for jEdit Plugin Developers

Antelope can be used from other jEdit plugins that may desire to run Ant targets. The public API is described here, plus some examples of how to use this API from other plugins. You can also use this API from a beanshell macro, see the FAQ section.

public static File getBuildFile(View view);

This method returns a reference to the current build file.

public static String[] getTargetList(File buildFile);

This method returns a list of the target names in the given build file.

public static void executeTarget( View view, File buildFile, String target );

This method executes a target. Since the execution is through Antelope, output will be to the Console plugin and errors will be displayed in the ErrorList plugin. The AntelopePlugin will attempt to find an instance of Antelope for the given view, then execute the target. The target must exist in the given build file.

public static void setBuildFile(View view, File buildFile);

This method sets the current build file for the Antelope instance in the given view. Antelope will reload itself to reflect the new build file.

Following are some examples of calling these methods from your plugin. Notice that you do not need the Antelope source or classes to compile or run your plugin, so you do not need to make Antelope a dependency for the PluginManager. The examples only work if Antelope is actually installed as a jEdit plugin and do nothing otherwise. The best place to put these examples is in your plugin's Plugin class. These examples are suitable for copy and paste into your plugin's source code. You will need to import: org.gjt.sp.jedit.EditPlugin, org.gjt.sp.jedit.jEdit, org.gjt.sp.jedit.View, and java.io.File.

This simply returns "true" if Antelope is installed. It is convenient to call this method prior to calling the others.

public static boolean isAntelopeAvailable() {
   EditPlugin ep = jEdit.getPlugin( "ise.antelope.plugin.AntelopePlugin" );
   return ep != null;
}

This method returns a reference to the current build file or null if Antelope is not installed or on any other error.

   public static File getBuildFile(View view) {
      if (view == null){
         return null;
      }
      if ( !isAntelopeAvailable() ) {
         return null;
      }
      EditPlugin ep = jEdit.getPlugin( "ise.antelope.plugin.AntelopePlugin" );
      try {
         Class c = ep.getClass();
         java.lang.reflect.Method m = c.getDeclaredMethod( "getBuildFile",
               new Class[]{View.class} );
         if ( m == null ) {
            return null;
         }
         return (File)m.invoke( null, new Object[]{view} );
      }
      catch ( Throwable e ) {
      }
      return null;
   }

This method returns a list of targets in the given build file or null if Antelope is not installed or on any other error.

   public static String[] getTargetList(File buildFile) {
      if (buildFile == null || !buildFile.exists()){
         return null;
      }
      if ( !isAntelopeAvailable() ) {
         return null;
      }
      EditPlugin ep = jEdit.getPlugin( "ise.antelope.plugin.AntelopePlugin" );
      try {
         Class c = ep.getClass();
         java.lang.reflect.Method m = c.getDeclaredMethod( "getTargetList",
               new Class[]{File.class} );
         if ( m == null ) {
            return null;
         }
         return (String[])m.invoke( null, new Object[]{buildFile} );
      }
      catch ( Throwable e ) {
      }
      return null;
   }

This method will execute an Ant target via Antelope.

   public static void executeAntTarget(View view, File buildFile, String target) {
      if (view == null || buildFile == null || target == null)
         return;
      if ( !isAntelopeAvailable() ) {
         return;
      }
      EditPlugin ep = jEdit.getPlugin( "ise.antelope.plugin.AntelopePlugin" );
      try {
         Class c = ep.getClass();
         java.lang.reflect.Method m = c.getDeclaredMethod( "executeTarget",
               new Class[]{View.class, File.class, String.class} );
         if ( m == null ) {
            return;
         }
         m.invoke( null, new Object[]{view, buildFile, target} );
      }
      catch ( Throwable e ) {
      }
   }

This method will cause Antelope to load the given build file.

   public static void setAntelopeBuildFile(View view, File buildFile) {
      if (buildFile == null || !buildFile.exists()){
         return;
      }
      if ( !isAntelopeAvailable() ) {
         return;
      }
      EditPlugin ep = jEdit.getPlugin( "ise.antelope.plugin.AntelopePlugin" );
      try {
         Class c = ep.getClass();
         java.lang.reflect.Method m = c.getDeclaredMethod( "setBuildFile",
               new Class[]{View.class, File.class} );
         if ( m == null ) {
            return;
         }
         m.invoke( null, new Object[]{view, buildFile} );
      }
      catch ( Throwable e ) {
      }
   }