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

Jean-Noel Rouvignac
17.58.2013 508d3949e86d0fd27885d1b825889a80d7a46ee7
OPENDJ-842 (CR-1699) On Windows, the setup command hangs when the length of the install path is too long


In order to avoid getting errors like "The input line is too long" on windows, a common way to fix this is to provide a "bootstrap" empty jar which contains only a MANIFEST.MF file listing all the application's jars in the "Class-Path" attribute.
This URL describes well enough the problem: http://ant.apache.org/manual/Tasks/manifestclasspath.html


build.xml:
In "prepackage" target, build bootstrap.jar.

_script-util.bat, _script-util.sh:
Replaced appending all the jars under libs with just the bootstrap jar.

Utilities.java, Utils.java, UpgradeUtils.java:
In getInstallPathFromClasspath(), extracted getInstallPath() and simplified its code a lot.

Installation.java, Installation.java:
Changed OPEN_DS_JAR_RELATIVE_PATHS into OPEN_DJ_BOOTSTRAP_JAR_RELATIVE_PATH.
8 files modified
252 ■■■■ changed files
opends/build.xml 18 ●●●●● patch | view | raw | blame | history
opends/resource/bin/_script-util.bat 2 ●●● patch | view | raw | blame | history
opends/resource/bin/_script-util.sh 5 ●●●● patch | view | raw | blame | history
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java 59 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/Installation.java 19 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java 48 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/Installation.java 9 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java 92 ●●●●● patch | view | raw | blame | history
opends/build.xml
@@ -1136,7 +1136,23 @@
    </copy>
    <antcall target="package-snmp" />
    <!-- Build the bootstrap jar that avoids getting the error message "The input line is too long" on Windows -->
    <manifestclasspath property="manifest.classpath"
                       jarfile="${pdir}/lib/bootstrap.jar">
      <classpath>
        <fileset dir="${pdir}/lib">
          <include name="*.jar" />
        </fileset>
      </classpath>
    </manifestclasspath>
    <jar jarfile="${pdir}/lib/bootstrap.jar">
      <manifest>
        <attribute name="Built-By" value="${user.name}" />
        <attribute name="Class-Path" value="${manifest.classpath}" />
      </manifest>
    </jar>
    <!-- Create buildinfo files -->
    <echo message="${MAJOR_VERSION}.${MINOR_VERSION}.${POINT_VERSION}.${REVISION_NUMBER}"
          file="${pdir}/template/config/buildinfo" />
opends/resource/bin/_script-util.bat
@@ -61,7 +61,7 @@
rem it also helps comparing the two paths
FOR /F %%i IN ("%INSTALL_ROOT%")  DO set INSTALL_ROOT=%%~dpnxi
FOR /F %%i IN ("%INSTANCE_ROOT%") DO set INSTANCE_ROOT=%%~dpnxi
FOR %%x in ("%INSTALL_ROOT%\lib\*.jar") DO call "%INSTALL_ROOT%\lib\setcp.bat" %%x
call "%INSTALL_ROOT%\lib\setcp.bat" "%INSTALL_ROOT%\lib\bootstrap.jar"
FOR %%x in ("%INSTALL_ROOT%\resources\*.jar") DO call "%INSTALL_ROOT%\lib\setcp.bat" %%x
set CLASSPATH=%INSTANCE_ROOT%\classes;%CLASSPATH%
if "%INSTALL_ROOT%" == "%INSTANCE_ROOT%" goto setClassPathDone
opends/resource/bin/_script-util.sh
@@ -258,10 +258,7 @@
  do
    CLASSPATH=${CLASSPATH}:${JAR}
  done
  for JAR in "${INSTALL_ROOT}/lib/"*.jar
  do
    CLASSPATH=${CLASSPATH}:${JAR}
  done
  CLASSPATH="${CLASSPATH}:${INSTALL_ROOT}/lib/bootstrap.jar"
  if [ "${INSTALL_ROOT}" != "${INSTANCE_ROOT}" ]
  then
    for JAR in "${INSTANCE_ROOT}/lib/"*.jar
opends/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -113,6 +113,7 @@
import org.opends.guitools.controlpanel.ui.renderer.
 AccessibleTableHeaderRenderer;
import org.opends.messages.Message;
import org.opends.quicksetup.Installation;
import org.opends.quicksetup.ui.UIFactory;
import org.opends.quicksetup.util.Utils;
import org.opends.server.api.AttributeSyntax;
@@ -1115,19 +1116,15 @@
          inTag = false;
          String tag = s.substring(lastOpenTag, i+1);
          lastOpenTag = -1;
          lastLine.append(c);
          if (isLineBreakTag(tag))
          {
            lastLine.append(c);
            sb.append(lastLine);
            lastLine.delete(0, lastLine.length());
            lastLineLength = 0;
            lastSpace = -1;
            lastLineLengthInLastSpace = 0;
          }
          else
          {
            lastLine.append(c);
          }
        }
        else
        {
@@ -1142,8 +1139,8 @@
      {
        if (s.length() >= i + HTML_SPACE.length())
        {
          if (s.substring(i, i + HTML_SPACE.length()).equalsIgnoreCase(
              HTML_SPACE))
          if (HTML_SPACE.equalsIgnoreCase(s.substring(i, i
              + HTML_SPACE.length())))
          {
            if (lastLineLength < nCols)
            {
@@ -1243,11 +1240,11 @@
  private static boolean isLineBreakTag(String tag)
  {
    return tag.equalsIgnoreCase("<br>") ||
    tag.equalsIgnoreCase("</br>") ||
    tag.equalsIgnoreCase("</div>") ||
    tag.equalsIgnoreCase("<p>") ||
    tag.equalsIgnoreCase("</p>");
    return "<br>".equalsIgnoreCase(tag) ||
    "</br>".equalsIgnoreCase(tag) ||
    "</div>".equalsIgnoreCase(tag) ||
    "<p>".equalsIgnoreCase(tag) ||
    "</p>".equalsIgnoreCase(tag);
  }
  /**
@@ -1340,7 +1337,7 @@
    Component parent = comp;
    while (parent != null)
    {
      if ((parent instanceof JDialog) || (parent instanceof JFrame))
      if (parent instanceof JDialog || parent instanceof JFrame)
      {
        return (Window)parent;
      }
@@ -1750,7 +1747,7 @@
      buf.append("<br><br>")
      .append(applyFont(details.toString(), detailsFont));
    }
    return "<form>"+buf.toString()+"</form>";
    return "<form>" + buf + "</form>";
  }
@@ -1954,21 +1951,7 @@
    /* Get the install path from the Class Path */
    String sep = System.getProperty("path.separator");
    String[] classPaths = System.getProperty("java.class.path").split(sep);
    String path = null;
    for (int i = 0; i < classPaths.length && (path == null); i++)
    {
      for (int j = 0; j < org.opends.quicksetup.Installation.
      OPEN_DS_JAR_RELATIVE_PATHS.length &&
      (path == null); j++)
      {
        String normPath = classPaths[i].replace(File.separatorChar, '/');
        if (normPath.endsWith(
            org.opends.quicksetup.Installation.OPEN_DS_JAR_RELATIVE_PATHS[j]))
        {
          path = classPaths[i];
        }
      }
    }
    String path = getInstallPath(classPaths);
    if (path != null) {
      File f = new File(path).getAbsoluteFile();
      File librariesDir = f.getParentFile();
@@ -1990,6 +1973,19 @@
    return installPath;
  }
  private static String getInstallPath(String[] classPaths)
  {
    for (String classPath : classPaths)
    {
      String normPath = classPath.replace(File.separatorChar, '/');
      if (normPath.endsWith(Installation.OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH))
      {
        return classPath;
      }
    }
    return null;
  }
  /**
   * Returns <CODE>true</CODE> if the server located in the provided path
   * is running and <CODE>false</CODE> otherwise.
@@ -2002,8 +1998,7 @@
    boolean isServerRunning;
    String lockFileName = ServerConstants.SERVER_LOCK_FILE_NAME +
    ServerConstants.LOCK_FILE_SUFFIX;
    String lockPathRelative =
      org.opends.quicksetup.Installation.LOCKS_PATH_RELATIVE;
    String lockPathRelative = Installation.LOCKS_PATH_RELATIVE;
    File locksPath = new File(serverRootDirectory, lockPathRelative);
    String lockFile = new File(locksPath, lockFileName).getAbsolutePath();
    StringBuilder failureReason = new StringBuilder();
@@ -2266,7 +2261,7 @@
  {
    boolean hasImageSyntax = false;
    attrName = Utilities.getAttributeNameWithoutOptions(attrName).toLowerCase();
    if (attrName.equals("photo"))
    if ("photo".equals(attrName))
    {
      hasImageSyntax = true;
    }
opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -25,22 +25,19 @@
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.quicksetup;
import org.opends.messages.Message;
import static org.opends.messages.QuickSetupMessages.*;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.concurrent.FutureTask;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.opends.messages.Message;
import org.opends.quicksetup.util.Utils;
import org.opends.server.util.SetupUtils;
@@ -54,11 +51,9 @@
public final class Installation
{
  /**
   * Relative path to OpenDJ jar files.
   */
  public static final String[] OPEN_DS_JAR_RELATIVE_PATHS = {
      "lib/quicksetup.jar", "lib/OpenDJ.jar", "lib/je.jar" };
  /** Relative path to bootstrap OpenDJ jar file. */
  public static final String OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH =
      "lib/bootstrap.jar";
  /**
   * The relative path where all the Windows binaries (batch files) are.
opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -27,7 +27,6 @@
 */
package org.opends.quicksetup.util;
import org.opends.messages.Message;
import static org.opends.messages.QuickSetupMessages.*;
import java.io.BufferedOutputStream;
@@ -68,16 +67,16 @@
import org.opends.admin.ads.SuffixDescriptor;
import org.opends.admin.ads.TopologyCacheException;
import org.opends.admin.ads.util.ConnectionUtils;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
import org.opends.messages.MessageDescriptor;
import org.opends.quicksetup.*;
import org.opends.quicksetup.installer.AuthenticationData;
import org.opends.quicksetup.installer.DataReplicationOptions;
import org.opends.quicksetup.installer.NewSuffixOptions;
import org.opends.quicksetup.installer.SuffixesToReplicateOptions;
import org.opends.quicksetup.ui.UIFactory;
import org.opends.server.util.SetupUtils;
import org.opends.messages.MessageBuilder;
import org.opends.messages.MessageDescriptor;
/**
@@ -197,6 +196,7 @@
            // in the logger and then kill the process.
            Thread t = new Thread(new Runnable()
            {
              @Override
              public void run()
              {
                try
@@ -1107,19 +1107,7 @@
    /* Get the install path from the Class Path */
    String sep = System.getProperty("path.separator");
    String[] classPaths = System.getProperty("java.class.path").split(sep);
    String path = null;
    for (int i = 0; i < classPaths.length && (path == null); i++)
    {
      for (int j = 0; j < Installation.OPEN_DS_JAR_RELATIVE_PATHS.length &&
      (path == null); j++)
      {
        String normPath = classPaths[i].replace(File.separatorChar, '/');
        if (normPath.endsWith(Installation.OPEN_DS_JAR_RELATIVE_PATHS[j]))
        {
          path = classPaths[i];
        }
      }
    }
    String path = getInstallPath(classPaths);
    if (path != null) {
      File f = new File(path).getAbsoluteFile();
      File librariesDir = f.getParentFile();
@@ -1141,6 +1129,19 @@
    return installPath;
  }
  private static String getInstallPath(final String[] classPaths)
  {
    for (String classPath : classPaths)
    {
      final String normPath = classPath.replace(File.separatorChar, '/');
      if (normPath.endsWith(Installation.OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH))
      {
        return classPath;
      }
    }
    return null;
  }
  /**
   * Returns the path of the installation of the directory server.  Note that
   * this method assumes that this code is being run locally.
@@ -1455,9 +1456,7 @@
   * @return true if the string contains HTML
   */
  static public boolean containsHtml(String text) {
    return (text != null &&
            text.indexOf('<') != -1 &&
            text.indexOf('>') != -1);
    return text != null && text.indexOf('<') != -1 && text.indexOf('>') != -1;
  }
  private static EmptyPrintStream emptyStream = new EmptyPrintStream();
@@ -1941,13 +1940,9 @@
    builder.append(formatter.getFormattedProgress(Message.raw(cmd.get(0))));
    int initialIndex = 1;
    StringBuilder sbSeparator = new StringBuilder();
    if (Utils.isWindows())
    sbSeparator.append(formatter.getSpace());
    if (!Utils.isWindows())
    {
      sbSeparator.append(formatter.getSpace());
    }
    else
    {
      sbSeparator.append(formatter.getSpace());
      sbSeparator.append("\\");
      sbSeparator.append(formatter.getLineBreak());
      for (int i=0 ; i < 10 ; i++)
@@ -2576,6 +2571,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public void println(String msg)
  {
    LOG.log(Level.INFO, "EmptyStream msg: "+msg);
opends/src/server/org/opends/server/tools/upgrade/Installation.java
@@ -25,7 +25,6 @@
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011-2013 ForgeRock AS
 */
package org.opends.server.tools.upgrade;
/**
@@ -36,11 +35,9 @@
public final class Installation
{
  /**
   * Relative path to OpenDJ jar files.
   */
  public static final String[] OPEN_DS_JAR_RELATIVE_PATHS = {
      "lib/quicksetup.jar", "lib/OpenDJ.jar", "lib/je.jar" };
  /** Relative path to bootstrap OpenDJ jar file. */
  public static final String OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH =
      "lib/bootstrap.jar";
  /**
   * The relative path where all the Windows binaries (batch files) are.
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -24,15 +24,13 @@
 *
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.server.tools.upgrade;
import static org.opends.messages.ConfigMessages.*;
import static org.opends.messages.ToolMessages.*;
import static org.opends.messages.ConfigMessages.INFO_CONFIG_FILE_HEADER;
import static org.opends.server.tools.upgrade.FileManager.deleteRecursively;
import static org.opends.server.tools.upgrade.FileManager.rename;
import static org.opends.server.tools.upgrade.FileManager.*;
import static org.opends.server.tools.upgrade.Installation.*;
import static org.opends.server.util.ServerConstants.EOL;
import static org.opends.server.util.ServerConstants.*;
import java.io.BufferedReader;
import java.io.File;
@@ -82,21 +80,21 @@
  private final static Logger LOG = Logger
      .getLogger(UpgradeCli.class.getName());
  // The config folder of the current installation.
  /** The config folder of the current installation. */
  static final File configDirectory = new File(getInstallationPath(),
      Installation.CONFIG_PATH_RELATIVE);
  // The config/schema folder of the current installation.
  /** The config/schema folder of the current installation. */
  static final File configSchemaDirectory = new File(getInstallationPath(),
      Installation.CONFIG_PATH_RELATIVE + File.separator
          + Installation.SCHEMA_PATH_RELATIVE);
  // The template folder of the current installation.
  /** The template folder of the current installation. */
  static final File templateDirectory = new File(getInstallationPath(),
      Installation.CONFIG_PATH_RELATIVE + File.separator
          + Installation.TEMPLATE_RELATIVE_PATH);
  // The template/config/schema folder of the current installation.
  /** The template/config/schema folder of the current installation. */
  static final File templateConfigSchemaDirectory = new File(
      getInstallationPath(), Installation.TEMPLATE_RELATIVE_PATH
          + File.separator + Installation.CONFIG_PATH_RELATIVE + File.separator
@@ -120,19 +118,7 @@
    final String sep = System.getProperty("path.separator");
    final String[] classPaths =
        System.getProperty("java.class.path").split(sep);
    String path = null;
    for (int i = 0; i < classPaths.length && (path == null); i++)
    {
      for (int j = 0; j < Installation.OPEN_DS_JAR_RELATIVE_PATHS.length
          && (path == null); j++)
      {
        final String normPath = classPaths[i].replace(File.separatorChar, '/');
        if (normPath.endsWith(Installation.OPEN_DS_JAR_RELATIVE_PATHS[j]))
        {
          path = classPaths[i];
        }
      }
    }
    String path = getInstallPath(classPaths);
    if (path != null)
    {
      final File f = new File(path).getAbsoluteFile();
@@ -155,6 +141,19 @@
    return installPath;
  }
  private static String getInstallPath(final String[] classPaths)
  {
    for (String classPath : classPaths)
    {
      final String normPath = classPath.replace(File.separatorChar, '/');
      if (normPath.endsWith(Installation.OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH))
      {
        return classPath;
      }
    }
    return null;
  }
  /**
   * Returns the path of the installation of the directory server. Note that
   * this method assumes that this code is being run locally.
@@ -505,15 +504,12 @@
            LOG.log(Level.SEVERE, ex.getMessage());
          }
        }
        if (filter == null && changeType == PersistentSearchChangeType.ADD)
        if (filter == null && changeType == PersistentSearchChangeType.ADD
            && (entry.getName() + "dn: ").equals(lines[0]))
        {
          if (new StringBuilder("dn: ").append(entry.getName().toString())
              .toString().equals(lines[0]))
          {
            LOG.log(Level.INFO, String.format("Entry %s found", entry.getName()
                .toString()));
            alreadyExist = true;
          }
          LOG.log(Level.INFO, String.format("Entry %s found", entry.getName()
              .toString()));
          alreadyExist = true;
        }
        writer.writeEntry(entry);
      }
@@ -589,7 +585,7 @@
    {
      reader = new LDIFEntryReader(new FileInputStream(templateFile));
      LinkedList<String> definitionsList = new LinkedList<String>();
      final LinkedList<String> definitionsList = new LinkedList<String>();
      final Entry schemaEntry = reader.readEntry();
      Schema schema = null;
@@ -604,8 +600,7 @@
          try
          {
            final String definition =
                new StringBuilder("attributeTypes: ").append(
                    schema.getAttributeType(att).toString()).toString();
                schema.getAttributeType(att) + "attributeTypes: ";
            definitionsList.add(definition);
            LOG.log(Level.INFO, String.format("Added : %s", definition));
          }
@@ -623,8 +618,8 @@
        {
          try
          {
            final String definition = new StringBuilder("objectClasses: ")
            .append(schema.getObjectClass(oc).toString()).toString();
            final String definition =
                schema.getObjectClass(oc) + "objectClasses: ";
            definitionsList.add(definition);
            LOG.log(Level.INFO, String.format("Added : %s", definition));
          }
@@ -640,23 +635,19 @@
      br = new BufferedReader(new FileReader(destination));
      fw = new FileWriter(copy);
      String line = null;
      if (definitionsList != null)
      String line = br.readLine();
      while (line != null && !"".equals(line))
      {
        fw.write(line + EOL);
        line = br.readLine();
        while (line != null && !line.equals(""))
        {
          fw.write(line + EOL);
          line = br.readLine();
        }
        for (final String definition : definitionsList)
        {
          writeLine(fw, definition, 80);
          changeCount++;
        }
        // Must be ended with a blank line
        fw.write(EOL);
      }
      for (final String definition : definitionsList)
      {
        writeLine(fw, definition, 80);
        changeCount++;
      }
      // Must be ended with a blank line
      fw.write(EOL);
    }
    finally
    {
@@ -759,8 +750,7 @@
    int index = 0;
    if (changeType == PersistentSearchChangeType.MODIFY)
    {
      modifiedLines[0] =
          new StringBuilder("dn: ").append(dn.toString()).toString();
      modifiedLines[0] = dn + "dn: ";
      modifiedLines[1] = "changetype: modify";
      index = 2;
    }