Changeset 4081


Ignore:
Timestamp:
Dec 17, 2010, 9:32:28 AM (12 years ago)
Author:
olle
Message:

Refs #668. Class/file plugins/RunMsInspectPlugin.java in plugin/ updated with progress information during msInspect feature finding:

  1. Private inner class StreamGobbler updated with new instance variable ProgressReporter myProgress, initially set to null. New constructor StreamGobbler(InputStream is, String type, OutputStream redirect, ProgressReporter progress) added, that takes a ProgressReporter argument and sets the value of instance variable myProgress to this. Public method void run() updated to call new private method void updateProgressInformation(ProgressReporter progress, String line) with the value of instance variable myProgress and the string read from the input stream.
  1. Private method void msInspectSearchLocal(Request request, Response response, ProgressReporter progress, ...) updated to call new StreamGobbler constructor for the error input stream, and setting the ProgressReporter argument to the value of local variable progress.
  1. New private method void updateProgressInformation(ProgressReporter progress, String line) added. It updates the progress reporter information with data parsed from the input string.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugin/src/org/proteios/plugins/RunMsInspectPlugin.java

    r4080 r4081  
    7777    OutputStream os;
    7878    String content = null;
     79    ProgressReporter myProgress = null;
    7980
    8081
     
    9091      this.type = type;
    9192      this.os = redirect;
     93    }
     94
     95
     96    StreamGobbler(InputStream is, String type, OutputStream redirect, ProgressReporter progress)
     97    {
     98      this.is = is;
     99      this.type = type;
     100      this.os = redirect;
     101      this.myProgress = progress;
    92102    }
    93103
     
    133143            content = content + "\n" + line;
    134144          }
     145          // Parse output for progress report
     146          updateProgressInformation(myProgress, line);
    135147        }
    136148        if (pw != null)
     
    455467      Runtime rt = Runtime.getRuntime();
    456468      Process proc = rt.exec(cmd);
     469      /*
    457470      // any error message?
    458471      StreamGobbler errorGobbler = new StreamGobbler(proc
    459472        .getErrorStream(), "ERR");
     473      */
     474      // Parse error stream for progress info
     475      // any error message?
     476      StreamGobbler errorGobbler = new StreamGobbler(proc
     477        .getErrorStream(), "ERR", null, progress);
    460478      // any output?
    461479      StreamGobbler outputGobbler = new StreamGobbler(proc
     
    713731
    714732  /**
     733   * Updates progress reporter information.
     734   *
     735   * @param progress ProgressReporter The progress reporter instance to use.
     736   * @param line String The information string to parse for progress information
     737   */
     738  private void updateProgressInformation(ProgressReporter progress, String line)
     739  {
     740    // Parse output for progress report
     741    if (progress != null)
     742    {
     743      if (line.contains("complete"))
     744      {
     745        // msInspect typically outputs a line like "16 Dec 2010 11:02:02,965 INFO  ApplicationContext: 12.043658% complete."
     746        String testStr = new String("ApplicationContext: ");
     747        int index = line.indexOf(testStr);
     748        if (index >= 0)
     749        {
     750          // Cut off start of string including testStr
     751          String percentStr = line.substring(index + testStr.length());
     752          /*
     753          System.out
     754            .println(this.getClass().getSimpleName() + ": percentStr (1) = \"" + percentStr + "\"");
     755          */
     756          testStr = new String(".");
     757          index = percentStr.indexOf(testStr);
     758          if (index >= 0)
     759          {
     760            // Cut off end of string starting with testStr
     761            percentStr = percentStr.substring(0, index);
     762            /*
     763            System.out
     764              .println(this.getClass().getSimpleName() + ": percentStr (2) = \"" + percentStr + "\"");
     765            */
     766            // Convert percent string to int
     767            int percentCompleted = 0;
     768            try
     769            {
     770              percentCompleted = Integer.parseInt(percentStr);
     771            }
     772            catch (NumberFormatException e)
     773            {}
     774            // Total progress includes more than msInspect analysis
     775            if (percentCompleted > 99)
     776            {
     777              percentCompleted = 99;
     778            }
     779            progress.display(percentCompleted, "% completed");
     780          }
     781        }
     782      }
     783    }
     784  }
     785
     786
     787  /**
    715788   * Update command line with new option and value,
    716789   * provided that the value differs from null and
Note: See TracChangeset for help on using the changeset viewer.