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

jvergara
23.56.2007 fd724f1439c50c1d9dcf076d42c1bff6de2482d3
Fix for issue 2494.

Add a scriptFriendly option so that the output of the status panel is easier to parse.
2 files modified
88 ■■■■■ changed files
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java 66 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java 22 ●●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/statuspanel/StatusCli.java
@@ -578,33 +578,50 @@
        INFO_JAVA_VERSION_LABEL.get()
      };
    int labelWidth = 0;
    Message title = INFO_SERVER_STATUS_TITLE.get();
    if (!isScriptFriendly())
    {
    for (int i=0; i<labels.length; i++)
    {
      labelWidth = Math.max(labelWidth, labels[i].length());
    }
    out.println();
    Message title = INFO_SERVER_STATUS_TITLE.get();
    out.println(centerTitle(title));
    }
    writeStatusContents(desc, labelWidth);
    writeCurrentConnectionContents(desc, labelWidth);
    if (!isScriptFriendly())
    {
    out.println();
    }
    title = INFO_SERVER_DETAILS_TITLE.get();
    if (!isScriptFriendly())
    {
    out.println(centerTitle(title));
    }
    writeHostnameContents(desc, labelWidth);
    writeAdministrativeUserContents(desc, labelWidth);
    writeInstallPathContents(desc, labelWidth);
    writeVersionContents(desc, labelWidth);
    writeJavaVersionContents(desc, labelWidth);
    if (!isScriptFriendly())
    {
    out.println();
    }
    writeListenerContents(desc);
    if (!isScriptFriendly())
    {
    out.println();
    }
    writeDatabaseContents(desc);
    writeErrorContents(desc);
    if (!isScriptFriendly())
    {
    if (displayMustStartLegend)
    {
      out.println();
@@ -616,6 +633,7 @@
      out.println(
          wrap(INFO_NOT_AVAILABLE_AUTHENTICATION_REQUIRED_CLI_LEGEND.get()));
    }
    }
    out.println();
  }
@@ -830,8 +848,11 @@
   */
  private void writeListenerContents(ServerStatusDescriptor desc)
  {
    if (!isScriptFriendly())
    {
    Message title = INFO_LISTENERS_TITLE.get();
    out.println(centerTitle(title));
    }
    Set<ListenerDescriptor> allListeners = desc.getListeners();
@@ -879,7 +900,10 @@
  private void writeDatabaseContents(ServerStatusDescriptor desc)
  {
    Message title = INFO_DATABASES_TITLE.get();
    if (!isScriptFriendly())
    {
    out.println(centerTitle(title));
    }
    Set<DatabaseDescriptor> databases = desc.getDatabases();
@@ -1039,6 +1063,8 @@
        headerLine.append(" ");
      }
    }
    if (!isScriptFriendly())
    {
    out.println(wrap(headerLine.toMessage()));
    MessageBuilder t = new MessageBuilder();
    for (int i=0; i<headerLine.length(); i++)
@@ -1046,12 +1072,21 @@
      t.append("=");
    }
    out.println(wrap(t.toMessage()));
    }
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      if (isScriptFriendly())
      {
        out.println("-");
      }
      MessageBuilder line = new MessageBuilder();
      for (int j=0; j<tableModel.getColumnCount(); j++)
      {
        if (isScriptFriendly())
        {
          line.append(tableModel.getColumnName(j)+": ");
        }
        int extra = maxWidths[j];
        Object v = tableModel.getValueAt(i, j);
        if (v != null)
@@ -1085,16 +1120,26 @@
          {
            throw new IllegalStateException("Unknown object type: "+v);
          }
          if (isScriptFriendly())
          {
            out.println(wrap(line.toMessage()));
            line = new MessageBuilder();
        }
        }
        if (!isScriptFriendly())
        {
        for (int k=0; k<extra; k++)
        {
          line.append(" ");
        }
      }
      }
      if (!isScriptFriendly())
      {
      out.println(wrap(line.toMessage()));
    }
  }
  }
  /**
   * Writes the contents of the provided database table model.  Every base DN
@@ -1128,7 +1173,11 @@
    Message replicatedLabel = INFO_BASEDN_REPLICATED_LABEL.get();
    for (int i=0; i<tableModel.getRowCount(); i++)
    {
      if (i > 0)
      if (isScriptFriendly())
      {
        out.println("-");
      }
      else if (i > 0)
      {
        out.println();
      }
@@ -1254,4 +1303,15 @@
  {
    return argParser.getTrustManager();
  }
  /**
   * Tells whether the user specified to have a script-friendly output or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have a script-friendly
   * output and <CODE>false</CODE> otherwise.
   */
  private boolean isScriptFriendly()
  {
    return argParser.isScriptFriendly();
  }
}
opends/src/guitools/org/opends/guitools/statuspanel/StatusCliArgumentParser.java
@@ -49,6 +49,11 @@
  private BooleanArgument noPromptArg;
  /**
   * The 'scriptFriendly' argument.
   */
  private BooleanArgument scriptFriendlyArg;
  /**
   * Creates a new instance of this argument parser with no arguments.
   *
   * @param mainClassName
@@ -86,6 +91,12 @@
        ToolConstants.OPTION_LONG_NO_PROMPT,
        INFO_DESCRIPTION_NO_PROMPT.get());
    defaultArgs.add(0, noPromptArg);
    scriptFriendlyArg = new BooleanArgument(
        "script-friendly",
        's',
        "script-friendly",
        INFO_DESCRIPTION_SCRIPT_FRIENDLY.get());
    defaultArgs.add(1, scriptFriendlyArg);
    initializeGlobalArguments(defaultArgs);
  }
@@ -101,6 +112,17 @@
  }
  /**
   * Tells whether the user specified to have a script-friendly output or not.
   * This method must be called after calling parseArguments.
   * @return <CODE>true</CODE> if the user specified to have a script-friendly
   * output and <CODE>false</CODE> otherwise.
   */
  public boolean isScriptFriendly()
  {
    return scriptFriendlyArg.isPresent();
  }
  /**
   * Returns the first server bind dn explicitly provided in the enable
   * replication subcommand.
   * @return the first server bind dn explicitly provided in the enable