Changeset 890


Ignore:
Timestamp:
Dec 7, 2008, 12:57:18 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Added debug code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/base2/net.sf.basedb.pluginutilities/trunk/src/net/sf/basedb/plugins/AbstractRunBinaryPlugin.java

    r862 r890  
    4848
    4949import java.io.IOException;
     50import java.io.PrintStream;
    5051
    5152import java.util.ArrayList;
     
    6869
    6970   @author Jari Hakkinen
    70    @version MAKESUBSTOFVERSIONNUMBER
    7171   @since BASE 2.9
    7272   @base.modified $Date$
     
    7878{
    7979
    80   protected AbstractRunBinaryPlugin() {}
     80  protected AbstractRunBinaryPlugin() {
     81    if (debug_output)
     82      try
     83      {
     84        System.setErr(new PrintStream(debug_outputfile));
     85        System.err.println("Initializing super class");
     86      }
     87      catch (IOException e) {
     88        e.printStackTrace();
     89      }
     90  }
    8191
    8292  @SuppressWarnings("unchecked")
    8393  public void configure(GuiContext context, Request request, Response response)
    8494  {
     95    if (debug_output) System.err.println("Configuring");
    8596    try
    8697    {
     
    122133      response.setError(e.getMessage(), Arrays.asList(e));
    123134    }
     135    if (debug_output) System.err.println("Configuring done");
    124136  }
    125137
     
    128140    throws InterruptedException, IOException
    129141  {
     142    if (debug_output) System.err.println("execute");
    130143    percentDone+=1;
    131144    progress.display(percentDone,"Running " + about.getName());
     
    134147    int status=p.exitValue();
    135148    if (status>0)
     149    {
     150      if (debug_output) System.err.println("execute failed");
    136151      throw new IOException("Unexpected exit of " + about.getName() +
    137152                            "WeNNI sub-process. Return value: " + status);
     153    }
     154    if (debug_output) System.err.println("execute end succesfully reached");
    138155  }
    139156
     
    147164  protected String getBinaryPath(Class cls, String binaryname)
    148165  {
    149     if (BinaryPath == null) {
     166    if (debug_output) System.err.println("Acquiring binary path");
     167    if (binaryPath == null) {
    150168      DbControl dc = sc.newDbControl();
    151169      try {
     
    155173        while ((pos>0) && (jarpath.charAt(pos-1)!=java.io.File.separatorChar))
    156174          --pos;
    157         BinaryPath=jarpath.substring(0, pos) + binaryname;
     175        binaryPath=jarpath.substring(0, pos) + binaryname;
    158176      }
    159177      finally {
     
    162180      }
    163181    }
    164     return BinaryPath;
     182    if (debug_output) System.err.println("Got binary path " + binaryPath );
     183    return binaryPath;
    165184  }
    166185
     
    187206  protected java.io.File getExecDirectory()
    188207  {
     208    if (debug_output) System.err.println("Acquiring exec direcotry");
    189209    if (execDirectory == null) {
    190210      execDirectory = new java.io.File
     
    193213      execDirectory.mkdirs();
    194214    }
     215    if (debug_output) System.err.println("Got exec direcotry " + execDirectory);
    195216    return execDirectory;
    196217  }
     
    228249  public void run(Request request, Response response, ProgressReporter progress)
    229250  {
     251    if (debug_output) System.err.println("run");
    230252    DbControl dc=sc.newDbControl();
    231253    try {
     
    248270    }
    249271    catch (Throwable e) {
     272      if (debug_output) System.err.println("run failed: " + e.getMessage());
    250273      response.setError(e.getMessage(), Arrays.asList(e));
    251274    }
    252275    finally {
    253       // clean up
    254       java.io.File[] files=getExecDirectory().listFiles();
    255       for (java.io.File f : files)
    256         f.delete();
    257       getExecDirectory().delete();
     276      if (!debug_output) {
     277        // clean up
     278        java.io.File[] files=getExecDirectory().listFiles();
     279        for (java.io.File f : files)
     280          f.delete();
     281        getExecDirectory().delete();
     282      }
     283      else
     284      {
     285        System.err.println("exec directory NOT removed");
     286      }
    258287      if (dc != null)
    259288        dc.close();
    260289    }
     290    if (debug_output) System.err.println("run end");
    261291  }
    262292
     
    283313  protected Plugin.MainType plugin_maintype=null;
    284314
    285   private String BinaryPath=null;
     315  private String binaryPath=null;
    286316  private RequestInformation configureJob = null;
    287317  private java.io.File execDirectory;
    288318  private int percentDone=0;
     319
     320  // debug options. Note, if debug information is on, the exec
     321  // directory is not removed after plug-in execution.
     322  protected Boolean debug_output=true;
     323  private String debug_outputfile="/tmp/base_debug.txt";
    289324}
Note: See TracChangeset for help on using the changeset viewer.