mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
14.23.2014 0ca9288cef37a2821dc9a95057a86589c58b2e87
Backport fix for OPENDJ-1292 Upgrade display is "broken" when a task has a message longer than 71 chars.
2 files modified
62 ■■■■ changed files
opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java 56 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -21,7 +21,7 @@
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS
 *      Copyright 2013-2014 ForgeRock AS
 */
package org.opends.server.tools.upgrade;
@@ -391,9 +391,7 @@
      {
        final ProgressNotificationCallback pnc =
            (ProgressNotificationCallback) c;
        final Message msg = Message.raw("  " + pnc.getMessage());
        printProgress(msg);
        printProgressBar(msg.length(), pnc.getProgress());
        printProgressBar(pnc.getMessage(), pnc.getProgress(), 2);
      }
      else if (c instanceof FormattedNotificationCallback)
      {
opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -22,7 +22,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2012-2013 ForgeRock AS
 *      Portions Copyright 2012-2014 ForgeRock AS
 */
package org.opends.server.util.cli;
@@ -75,6 +75,7 @@
public abstract class ConsoleApplication
{
  private static final int PROGRESS_LINE = 70;
  /**
   * A null reader.
   */
@@ -139,6 +140,8 @@
  // The output stream which this application should use.
  private final PrintStream out;
  private boolean isProgressSuite;
  /**
   * The maximum number of times we try to confirm.
   */
@@ -513,7 +516,7 @@
   * @param progress
   *          The current percentage progress to print.
   */
  public final void printProgressBar(final int linePos, final int progress)
  private final void printProgressBar(final int linePos, final int progress)
  {
    if (!isQuiet())
    {
@@ -521,9 +524,10 @@
      StringBuilder bar = new StringBuilder();
      if (progress != 0)
      {
        for (int i = 0; i < 50; i++)
        for (int i = 0; i < PROGRESS_LINE; i++)
        {
          if ((i < (Math.abs(progress) / 2)) && (bar.length() < spacesLeft))
          if (i < (Math.abs(progress) * spacesLeft) / 100
              && bar.length() < spacesLeft)
          {
            bar.append(".");
          }
@@ -537,6 +541,7 @@
      else
      {
        bar.append("FAIL");
        isProgressSuite = false;
      }
      final int endBuilder = linePos + bar.length();
      for (int i = 0; i < endBuilder; i++)
@@ -546,11 +551,54 @@
      if (progress >= 100 || progress < 0)
      {
        bar.append(EOL);
        isProgressSuite = false;
      }
      out.print(bar.toString());
    }
  }
  /**
   * Prints a progress bar on the same output stream line if not in quiet mode.
   * If the line's length is upper than the limit, the message is wrapped and
   * the progress bar is affected to the last one. e.g.
   *
   * <pre>
   *   Changing matching rule for 'userCertificate' and 'caCertificate' to
   *   CertificateExactMatch...........................................  100%
   * </pre>
   *
   * @param msg
   *          The message to display before the progress line.
   * @param progress
   *          The current percentage progress to print.
   * @param indent
   *          Indentation of the message.
   */
  public final void printProgressBar(String msg, final int progress,
      final int indent)
  {
    if (!isQuiet())
    {
      String msgToDisplay = wrapText(msg, PROGRESS_LINE, indent);
      if (msgToDisplay.length() > PROGRESS_LINE)
      {
        final String[] msgWrapped = msgToDisplay.split(EOL);
        if (!isProgressSuite)
        {
          for (int pos = 0; pos < msgWrapped.length - 1; pos++)
          {
            println(Message.raw(msgWrapped[pos]));
          }
          isProgressSuite = true;
        }
        msgToDisplay = msgWrapped[msgWrapped.length - 1];
      }
      print(Message.raw(msgToDisplay));
      printProgressBar(msgToDisplay.length(), progress);
    }
  }
  /**
   * Display the batch progress string to the error stream, if we are not in
   * quiet mode.