From cd3a41a0bd6762b1f63e58c6a65743f9800f5300 Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Wed, 21 Sep 2016 15:15:44 +0000
Subject: [PATCH] OPENDJ-2413 Remove uses of EmbeddedUtils class and deprecate it

---
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java                        |    7 
 opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java                            |   17 ++
 opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java                     |    1 
 opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java    |   54 ++++++--
 opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java                     |    3 
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java                         |    7 
 opendj-server-legacy/src/main/java/org/opends/server/util/EmbeddedUtils.java                       |   13 ++
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java                         |    1 
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java                         |    6 
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java                         |    7 
 opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java           |   21 +++
 opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java |   18 +-
 /dev/null                                                                                          |  119 -------------------
 opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java                        |    2 
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java                 |    7 
 opendj-server-legacy/src/main/java/org/opends/server/tools/ManageAccount.java                      |    6 
 opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/MakeLDIF.java                  |    2 
 opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java             |    7 
 opendj-server-legacy/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java          |   10 -
 opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java                |    1 
 opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java                           |    1 
 21 files changed, 115 insertions(+), 195 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
index 2db79cf..2bff14e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/uninstaller/Uninstaller.java
@@ -137,7 +137,6 @@
      * ConfigureDS) this initialization is done.
      */
     DirectoryServer.bootstrapClient();
-    //  Bootstrap definition classes.
     try
     {
       ConfigurationFramework configFramework = ConfigurationFramework.getInstance();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java b/opendj-server-legacy/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java
index 37380ec..ca8f72a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/admin/doc/ConfigGuideGeneration.java
@@ -24,6 +24,7 @@
 import java.util.Properties;
 import java.util.TreeMap;
 import java.util.TreeSet;
+
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.opendj.config.ACIPropertyDefinition;
 import org.forgerock.opendj.config.AbsoluteInheritedDefaultBehaviorProvider;
@@ -58,7 +59,7 @@
 import org.forgerock.opendj.config.UndefinedDefaultBehaviorProvider;
 import org.forgerock.opendj.config.server.ConfigException;
 import org.forgerock.opendj.server.config.meta.RootCfgDefn;
-import org.opends.server.util.EmbeddedUtils;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.util.DynamicConstants;
 
 /**
@@ -169,8 +170,7 @@
 
     // Enable the client-side class loader to explicitly load classes
     // which are not directly reachable from the root configuration
-    EmbeddedUtils.initializeForClientUse();
-    // Bootstrap definition classes.
+    DirectoryServer.bootstrapClient();
     try {
       ConfigurationFramework.getInstance().initialize();
     } catch (ConfigException e) {
@@ -178,10 +178,6 @@
       e.printStackTrace();
       System.exit(1);
     }
-    // Switch off class name validation in client.
-//    ClassPropertyDefinition.setAllowClassValidation(false);
-    // Switch off attribute type name validation in client.
-//    AttributeTypePropertyDefinition.setCheckSchema(false);
 
     // Build a sorted list of top managed objects
     TopCfgDefn topCfg = TopCfgDefn.getInstance();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
index 118a269..cf90034 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -1263,7 +1263,6 @@
 
     logger.debug(INFO_DIRECTORY_BOOTSTRAPPING);
 
-    // Perform all the bootstrapping that is shared with the client-side processing.
     bootstrapClient();
 
     // Initialize the variables that will be used for connection tracking.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
index 1b97c6b..ce70149 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ConfigureDS.java
@@ -548,8 +548,6 @@
       }
     }
 
-    // Initialize the Directory Server configuration handler using the
-    // information that was provided.
     final DirectoryServer directoryServer = DirectoryServer.getInstance();
     DirectoryServer.bootstrapClient();
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
index fd533df..3b15ccc 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/CreateRCScript.java
@@ -36,7 +36,6 @@
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.types.FilePermission;
 import org.opends.server.types.NullOutputStream;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.SetupUtils;
 
 import com.forgerock.opendj.cli.ArgumentException;
@@ -162,7 +161,7 @@
       return 0;
     }
 
-    EmbeddedUtils.initializeForClientUse();
+    DirectoryServer.bootstrapClient();
     File serverRoot = DirectoryServer.getEnvironmentConfig().getServerRoot();
     if (serverRoot == null)
     {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java
index fc14693..46c1dcd 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPCompare.java
@@ -20,7 +20,6 @@
 import static com.forgerock.opendj.cli.CliMessages.INFO_DESCRIPTION_BINDPASSWORDFILE;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
 import static org.opends.server.util.cli.LDAPConnectionArgumentParser.*;
@@ -41,6 +40,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.LDAPAssertionRequestControl;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.CompareRequestProtocolOp;
 import org.opends.server.protocols.ldap.CompareResponseProtocolOp;
@@ -51,8 +51,6 @@
 import org.opends.server.types.LDAPException;
 import org.opends.server.types.NullOutputStream;
 import org.opends.server.util.Base64;
-import org.opends.server.util.EmbeddedUtils;
-
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -830,8 +828,7 @@
     {
       if (initializeServer)
       {
-        // Bootstrap and initialize directory data structures.
-        EmbeddedUtils.initializeForClientUse();
+        DirectoryServer.bootstrapClient();
       }
 
       // Connect to the specified host with the supplied userDN and password.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java
index 53afa96..319dd9c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPDelete.java
@@ -20,7 +20,6 @@
 import static com.forgerock.opendj.cli.CliMessages.INFO_DESCRIPTION_BINDPASSWORDFILE;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
 import static org.opends.server.util.cli.LDAPConnectionArgumentParser.*;
@@ -41,6 +40,7 @@
 import org.forgerock.opendj.ldap.ByteString;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.SubtreeDeleteControl;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.DeleteRequestProtocolOp;
 import org.opends.server.protocols.ldap.DeleteResponseProtocolOp;
@@ -49,8 +49,6 @@
 import org.opends.server.types.Control;
 import org.opends.server.types.LDAPException;
 import org.opends.server.types.NullOutputStream;
-import org.opends.server.util.EmbeddedUtils;
-
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -651,8 +649,7 @@
     {
       if (initializeServer)
       {
-        // Bootstrap and initialize directory data structures.
-        EmbeddedUtils.initializeForClientUse();
+        DirectoryServer.bootstrapClient();
       }
 
       // Connect to the specified host with the supplied userDN and password.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java
index 77379de..1251d6c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPModify.java
@@ -21,7 +21,6 @@
 import static com.forgerock.opendj.cli.CliMessages.INFO_DESCRIPTION_BINDPASSWORDFILE;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
 import static org.opends.server.util.ServerConstants.*;
@@ -43,6 +42,7 @@
 import org.forgerock.opendj.ldap.DecodeException;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.opends.server.controls.*;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.plugins.ChangeNumberControlPlugin;
 import org.opends.server.protocols.ldap.AddRequestProtocolOp;
@@ -63,7 +63,6 @@
 import org.opends.server.types.*;
 import org.opends.server.util.AddChangeRecordEntry;
 import org.opends.server.util.ChangeRecordEntry;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.LDIFException;
 import org.opends.server.util.LDIFReader;
 import org.opends.server.util.ModifyChangeRecordEntry;
@@ -1001,8 +1000,7 @@
     {
       if (initializeServer)
       {
-        // Bootstrap and initialize directory data structures.
-        EmbeddedUtils.initializeForClientUse();
+        DirectoryServer.bootstrapClient();
       }
 
       // Connect to the specified host with the supplied userDN and password.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java
index ba7e6cb..354b08c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPPasswordModify.java
@@ -21,7 +21,6 @@
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
 import static org.opends.server.util.ServerConstants.*;
 import static org.opends.server.util.StaticUtils.*;
-
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
@@ -40,6 +39,7 @@
 import org.opends.server.controls.PasswordPolicyErrorType;
 import org.opends.server.controls.PasswordPolicyResponseControl;
 import org.opends.server.controls.PasswordPolicyWarningType;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
 import org.opends.server.protocols.ldap.ExtendedResponseProtocolOp;
@@ -50,8 +50,6 @@
 import org.opends.server.types.Control;
 import org.forgerock.opendj.ldap.DN;
 import org.opends.server.types.NullOutputStream;
-import org.opends.server.util.EmbeddedUtils;
-
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -412,10 +410,9 @@
       }
     }
 
-    // Perform a basic Directory Server bootstrap if appropriate.
     if (initializeServer)
     {
-      EmbeddedUtils.initializeForClientUse();
+      DirectoryServer.bootstrapClient();
     }
 
     // Establish a connection to the Directory Server.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java
index e4ea846..403bae1 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDAPSearch.java
@@ -19,7 +19,6 @@
 import static com.forgerock.opendj.cli.ArgumentConstants.*;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.protocols.ldap.LDAPConstants.*;
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
@@ -41,12 +40,11 @@
 import org.forgerock.opendj.ldap.DN;
 import org.forgerock.opendj.ldap.DecodeException;
 import org.opends.server.controls.*;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.protocols.ldap.*;
 import org.opends.server.types.*;
 import org.opends.server.util.Base64;
-import org.opends.server.util.EmbeddedUtils;
-
 import com.forgerock.opendj.cli.ArgumentException;
 import com.forgerock.opendj.cli.ArgumentParser;
 import com.forgerock.opendj.cli.BooleanArgument;
@@ -1478,8 +1476,7 @@
     {
       if (initializeServer)
       {
-        // Bootstrap and initialize directory data structures.
-        EmbeddedUtils.initializeForClientUse();
+        DirectoryServer.bootstrapClient();
       }
 
       // Connect to the specified host with the supplied userDN and password.
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java
index 28053e4..e4c41f8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFDiff.java
@@ -268,7 +268,6 @@
     boolean checkSchema = configFile.isPresent() && doCheckSchema.isPresent();
     if (! serverInitialized)
     {
-      // Bootstrap the Directory Server configuration for use as a client.
       DirectoryServer directoryServer = DirectoryServer.getInstance();
       DirectoryServer.bootstrapClient();
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java
index 7c96fe7..4454a80 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/LDIFModify.java
@@ -492,7 +492,6 @@
 
     if (! serverInitialized)
     {
-      // Bootstrap the Directory Server configuration for use as a client.
       DirectoryServer directoryServer = DirectoryServer.getInstance();
       DirectoryServer.bootstrapClient();
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/ManageAccount.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/ManageAccount.java
index 53fab8e..7599229 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/ManageAccount.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/ManageAccount.java
@@ -23,7 +23,6 @@
 import static com.forgerock.opendj.cli.CliMessages.INFO_TRUSTSTORE_PWD_FILE_PLACEHOLDER;
 import static com.forgerock.opendj.cli.Utils.*;
 import static com.forgerock.opendj.cli.CommonArguments.*;
-
 import static org.opends.messages.ToolMessages.*;
 import static org.opends.server.extensions.PasswordPolicyStateExtendedOperation.*;
 import static org.opends.server.protocols.ldap.LDAPResultCode.*;
@@ -46,6 +45,7 @@
 import org.forgerock.opendj.io.ASN1Writer;
 import org.forgerock.opendj.ldap.ByteStringBuilder;
 import org.opends.server.config.AdministrationConnector;
+import org.opends.server.core.DirectoryServer;
 import org.opends.server.core.DirectoryServer.DirectoryServerVersionHandler;
 import org.opends.server.loggers.JDKLogging;
 import org.opends.server.protocols.ldap.ExtendedRequestProtocolOp;
@@ -53,7 +53,6 @@
 import org.opends.server.protocols.ldap.LDAPMessage;
 import org.opends.server.protocols.ldap.LDAPResultCode;
 import org.opends.server.types.NullOutputStream;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.cli.LDAPConnectionArgumentParser;
 
 import com.forgerock.opendj.cli.Argument;
@@ -1233,7 +1232,8 @@
     // Bootstrap and initialize directory data structures.
     if (initServer)
     {
-      EmbeddedUtils.initializeForClientUse();
+      DirectoryServer.getInstance();
+      DirectoryServer.bootstrapClient();
     }
     // Create the LDAP connection options object, which will be used to
     // customize the way that we connect to the server and specify a set of
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java
index e3c9b9c..4617729 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/LocalPurgeHistorical.java
@@ -16,22 +16,20 @@
  */
 package org.opends.server.tools.dsreplication;
 
+import static org.opends.server.util.embedded.ConfigParameters.Builder.configParams;
 import static org.opends.messages.AdminToolMessages.*;
 
-import java.io.File;
-
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.slf4j.LocalizedLogger;
 import org.forgerock.opendj.ldap.DN;
 import org.forgerock.opendj.ldap.ResultCode;
 import org.opends.quicksetup.util.ProgressMessageFormatter;
 import org.opends.server.replication.plugin.LDAPReplicationDomain;
-import org.opends.server.types.DirectoryEnvironmentConfig;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.OpenDsException;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.TimeThread;
 import org.opends.server.util.cli.PointAdder;
+import org.opends.server.util.embedded.EmbeddedDirectoryServer;
 
 import com.forgerock.opendj.cli.ConsoleApplication;
 
@@ -90,12 +88,12 @@
 
     try
     {
-      // Create a configuration for the server.
-      DirectoryEnvironmentConfig environmentConfig =
-        new DirectoryEnvironmentConfig();
-      environmentConfig.setConfigFile(new File(configFile));
-      environmentConfig.setDisableConnectionHandlers(true);
-      EmbeddedUtils.startServer(environmentConfig);
+      EmbeddedDirectoryServer server = EmbeddedDirectoryServer.defineServerForStartStopOperations(
+          configParams()
+            .configurationFile(configFile)
+            .disableConnectionHandlers(true)
+            .build());
+      server.start();
     }
     catch (OpenDsException ode)
     {
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/MakeLDIF.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/MakeLDIF.java
index 8fbad80..b5de130 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/MakeLDIF.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/makeldif/MakeLDIF.java
@@ -237,8 +237,6 @@
 
     if (initializeServer)
     {
-      // Initialize the Directory Server configuration handler using the
-      // information that was provided.
       DirectoryServer directoryServer = DirectoryServer.getInstance();
       DirectoryServer.bootstrapClient();
 
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/EmbeddedUtils.java b/opendj-server-legacy/src/main/java/org/opends/server/util/EmbeddedUtils.java
index 0b642a4..7244732 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/EmbeddedUtils.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/EmbeddedUtils.java
@@ -33,7 +33,10 @@
  * This class provides a number of utility methods for using OpenDS in an
  * embedded manner (i.e., running within the same JVM as another application and
  * controlled by that application).
+ *
+ * @deprecated Use {@code EmbeddedDirectoryServer} class instead
  */
+@Deprecated
 @org.opends.server.types.PublicAPI(
      stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
      mayInstantiate=false,
@@ -46,7 +49,9 @@
    *
    * @return  {@code true} if the server is currently running, or {@code false}
    *          if not.
+   * @deprecated Use {@code EmbeddedDirectoryServer} class instead
    */
+  @Deprecated
   public static boolean isRunning()
   {
     return DirectoryServer.isRunning();
@@ -62,7 +67,9 @@
    * @throws  InitializationException  If the Directory Server is already
    *                                   running, or if an error occurs during
    *                                   server initialization or startup.
+   * @deprecated Use {@code EmbeddedDirectoryServer} class instead
    */
+  @Deprecated
   public static void startServer(DirectoryEnvironmentConfig config)
          throws InitializationException
   {
@@ -90,7 +97,9 @@
    *
    * @param  className  The name of the class that initiated the shutdown.
    * @param  reason     A message explaining the reason for the shutdown.
+   * @deprecated Use {@code EmbeddedDirectoryServer} class instead
    */
+  @Deprecated
   public static void stopServer(String className, LocalizableMessage reason)
   {
     DirectoryServer.shutDown(className, reason);
@@ -107,7 +116,9 @@
    * @param  reason     A message explaining the reason for the retart.
    * @param  config     The environment configuration to use for the new server
    *                    instance.
+   * @deprecated Use {@code EmbeddedDirectoryServer} class instead
    */
+  @Deprecated
   public static void restartServer(String className, LocalizableMessage reason,
                                    DirectoryEnvironmentConfig config)
   {
@@ -122,7 +133,9 @@
    * going to be used without the server running (e.g., to facilitate use in an
    * LDAP client API, for DN processing, etc.).  This will have no effect if the
    * server has already been initialized for client use.
+   * @deprecated Use {@code EmbeddedDirectoryServer} class instead
    */
+  @Deprecated
   public static void initializeForClientUse()
   {
     DirectoryServer.getInstance();
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java b/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java
index 443ce4b..08e2832 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/ConfigParameters.java
@@ -23,6 +23,7 @@
   private String serverRootDirectory;
   private String serverInstanceDirectory;
   private String configurationFile;
+  private boolean disableConnectionHandlers;
 
   private ConfigParameters()
   {
@@ -37,7 +38,7 @@
   String getServerInstanceDirectory()
   {
     // provides the expected default value if not set
-    return serverInstanceDirectory != null ? serverInstanceDirectory : serverRootDirectory;
+    return serverInstanceDirectory;
   }
 
   String getConfigurationFile()
@@ -45,6 +46,11 @@
     return configurationFile;
   }
 
+  boolean isDisableConnectionHandlers()
+  {
+    return disableConnectionHandlers;
+  }
+
   /**
    * Builder for this class.
    */
@@ -123,5 +129,18 @@
       params.configurationFile = file;
       return this;
     }
+
+    /**
+     * Sets the indicator allowing to disable the connection handlers.
+     *
+     * @param disable
+     *          {@code true} to disable the connection handlers
+     * @return this builder
+     */
+    public Builder disableConnectionHandlers(boolean disable)
+    {
+      params.disableConnectionHandlers = disable;
+      return this;
+    }
   }
 }
\ No newline at end of file
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java b/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java
index 355d7f4..e10a13e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/util/embedded/EmbeddedDirectoryServer.java
@@ -44,7 +44,6 @@
 import org.opends.server.types.DirectoryEnvironmentConfig;
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.InitializationException;
-import org.opends.server.util.ServerConstants;
 import org.opends.server.util.StaticUtils;
 
 /**
@@ -94,11 +93,11 @@
         new LDAPConnectionFactory(connectionParams.getHostname(), connectionParams.getLdapPort())
         : null;
 
-    System.setProperty("org.opends.quicksetup.Root", configParams.getServerRootDirectory());
-    System.setProperty(ServerConstants.PROPERTY_SERVER_ROOT, configParams.getServerRootDirectory());
-    System.setProperty(ServerConstants.PROPERTY_INSTANCE_ROOT, configParams.getServerInstanceDirectory());
+    //System.setProperty("org.opends.quicksetup.Root", configParams.getServerRootDirectory());
+    //System.setProperty(ServerConstants.PROPERTY_SERVER_ROOT, configParams.getServerRootDirectory());
+    //System.setProperty(ServerConstants.PROPERTY_INSTANCE_ROOT, configParams.getServerInstanceDirectory());
     // from LicenseFile.java - provided by AM OpenDJUpgrader.java
-    System.setProperty("INSTALL_ROOT", configParams.getServerInstanceDirectory());
+    //System.setProperty("INSTALL_ROOT", configParams.getServerInstanceDirectory());
   }
 
   /**
@@ -156,6 +155,21 @@
   }
 
   /**
+   * Defines an embedded directory server for start/stop operation.
+   * <p>
+   * To be able to perform any operation on the server, use the alternative {@code defineServer()}
+   * method.
+   *
+   * @param configParams
+   *          The basic configuration parameters for the server.
+   * @return the directory server
+   */
+  public static EmbeddedDirectoryServer defineServerForStartStopOperations(ConfigParameters configParams)
+  {
+    return new EmbeddedDirectoryServer(configParams, null, System.out, System.err);
+  }
+
+  /**
    * Displays the replication status on the output stream defined for this server.
    * <p>
    * Displays a list with the basic replication configuration of all base DNs of
@@ -403,7 +417,7 @@
    * @param reason
    *          A message explaining the reason for the restart.
    */
-  public void restartServer(String className, LocalizableMessage reason)
+  public void restart(String className, LocalizableMessage reason)
   {
     DirectoryServer.restart(className, reason, DirectoryServer.getEnvironmentConfig());
   }
@@ -425,13 +439,7 @@
 
     try
     {
-      DirectoryEnvironmentConfig env = new DirectoryEnvironmentConfig();
-      env.setServerRoot(new File(configParams.getServerRootDirectory()));
-      env.setInstanceRoot(new File(configParams.getServerInstanceDirectory()));
-      env.setForceDaemonThreads(true);
-      env.setConfigFile(new File(configParams.getConfigurationFile()));
-
-      DirectoryServer directoryServer = DirectoryServer.reinitialize(env);
+      DirectoryServer directoryServer = DirectoryServer.reinitialize(createEnvironmentConfig());
       directoryServer.startServer();
     }
     catch (InitializationException | ConfigException e)
@@ -441,6 +449,26 @@
     }
   }
 
+  private DirectoryEnvironmentConfig createEnvironmentConfig() throws InitializationException
+  {
+    // If server root directory or instance directory are not defined,
+    // the DirectoryEnvironmentConfig class has several ways to find the values,
+    // including using system properties.
+    DirectoryEnvironmentConfig env = new DirectoryEnvironmentConfig();
+    if (configParams.getServerRootDirectory() != null)
+    {
+      env.setServerRoot(new File(configParams.getServerRootDirectory()));
+    }
+    if (configParams.getServerInstanceDirectory() != null)
+    {
+      env.setInstanceRoot(new File(configParams.getServerInstanceDirectory()));
+    }
+    env.setForceDaemonThreads(true);
+    env.setDisableConnectionHandlers(configParams.isDisableConnectionHandlers());
+    env.setConfigFile(new File(configParams.getConfigurationFile()));
+    return env;
+  }
+
   /**
    * Stops this server.
    *
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java b/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
index 856309c..74f1534 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/TestCaseUtils.java
@@ -104,7 +104,6 @@
 import org.opends.server.types.LDIFImportConfig;
 import org.forgerock.opendj.ldap.schema.Schema;
 import org.opends.server.util.BuildVersion;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.LDIFReader;
 import org.opends.server.util.embedded.EmbeddedDirectoryServer;
 import org.testng.Assert;
@@ -589,9 +588,11 @@
 
       clearLoggersContents();
 
-      EmbeddedUtils.stopServer(null, null);
+      server.stop(TestCaseUtils.class.getSimpleName(), LocalizableMessage.raw("restart server for tests"));
+
       restoreServerConfigLdif();
-      EmbeddedUtils.startServer(DirectoryServer.getEnvironmentConfig());
+
+      server.start();
 
       clearJEBackends();
       initializeTestBackend(true);
@@ -610,6 +611,16 @@
     }
   }
 
+  /**
+   * Returns the embedded server used for tests.
+   *
+   * @return the embedded server.
+   */
+  public static EmbeddedDirectoryServer getServer()
+  {
+    return server;
+  }
+
   private static List<Long> restartTimesMs = new ArrayList<>();
   public static List<Long> getRestartTimesMs() {
     return Collections.unmodifiableList(restartTimesMs);
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
index 6dc4053..7220505 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/crypto/CryptoManagerTestCase.java
@@ -46,7 +46,6 @@
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.Entry;
 import org.opends.server.types.Modification;
-import org.opends.server.util.EmbeddedUtils;
 import org.opends.server.util.StaticUtils;
 import org.opends.server.util.TimeThread;
 import org.testng.annotations.AfterClass;
@@ -334,10 +333,8 @@
     final byte[] cipherText2 = cm.encrypt("RC4", 104,
             secretMessage.getBytes());
 
-    EmbeddedUtils.restartServer(
-            this.getClass().getName(),
-            LocalizableMessage.raw("CryptoManager: testing persistent secret keys."),
-            DirectoryServer.getEnvironmentConfig());
+    TestCaseUtils.getServer().restart(this.getClass().getName(),
+        LocalizableMessage.raw("CryptoManager: testing persistent secret keys."));
 
     byte[] plainText = cm.decrypt(cipherText);
     assertEquals(new String(plainText), secretMessage);
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/util/EmbeddedUtilsTestCase.java b/opendj-server-legacy/src/test/java/org/opends/server/util/EmbeddedUtilsTestCase.java
deleted file mode 100644
index 240d815..0000000
--- a/opendj-server-legacy/src/test/java/org/opends/server/util/EmbeddedUtilsTestCase.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The contents of this file are subject to the terms of the Common Development and
- * Distribution License (the License). You may not use this file except in compliance with the
- * License.
- *
- * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
- * specific language governing permission and limitations under the License.
- *
- * When distributing Covered Software, include this CDDL Header Notice in each file and include
- * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
- * Header, with the fields enclosed by brackets [] replaced by your own identifying
- * information: "Portions Copyright [year] [name of copyright owner]".
- *
- * Copyright 2008 Sun Microsystems, Inc.
- * Portions Copyright 2014-2015 ForgeRock AS.
- */
-package org.opends.server.util;
-
-
-
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import org.forgerock.i18n.LocalizableMessage;
-import org.opends.server.TestCaseUtils;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.DirectoryEnvironmentConfig;
-
-import static org.testng.Assert.*;
-
-
-
-/**
- * A set of generic test cases for the EmbeddedUtils class.
- */
-public class EmbeddedUtilsTestCase
-       extends UtilTestCase
-{
-  /**
-   * Ensures that the Directory Server is running before running any tests.
-   *
-   * @throws  Exception  If an unexpected problem occurs.
-   */
-  @BeforeClass
-  public void setUp()
-         throws Exception
-  {
-    TestCaseUtils.startServer();
-    assertTrue(EmbeddedUtils.isRunning());
-  }
-
-
-
-  /**
-   * Make sure that the server gets restarted by the
-   * {@code TestCaseUtils.restartServer} method because it does a few things to
-   * the server that aren't covered in the out-of-the-box configuration.
-   *
-   * @throws  Exception  If an unexpected problem occurs.
-   */
-  @AfterClass
-  public void cleanUp()
-         throws Exception
-  {
-    TestCaseUtils.restartServer();
-  }
-
-
-
-  /**
-   * Tests the ability to use EmbeddedUtils to restart the server.
-   *
-   * @throws  Exception  If an unexpected problem occurs.
-   */
-  @Test(groups = "slow")
-  public void testRestartServer()
-         throws Exception
-  {
-    assertTrue(EmbeddedUtils.isRunning());
-
-    DirectoryEnvironmentConfig environmentConfig =
-         DirectoryServer.getEnvironmentConfig();
-    assertNotNull(environmentConfig);
-
-    EmbeddedUtils.restartServer(getClass().getName(),
-                                LocalizableMessage.raw("testRestartServer"),
-                                environmentConfig);
-
-    assertTrue(EmbeddedUtils.isRunning());
-  }
-
-
-
-  /**
-   * Tests the ability to use EmbeddedUtils to stop and then subsequently start
-   * the server.
-   *
-   * @throws  Exception  If an unexpected problem occurs.
-   */
-  @Test(groups = "slow")
-  public void testStopAndStartServer()
-         throws Exception
-  {
-    assertTrue(EmbeddedUtils.isRunning());
-
-    DirectoryEnvironmentConfig environmentConfig =
-         DirectoryServer.getEnvironmentConfig();
-    assertNotNull(environmentConfig);
-
-    EmbeddedUtils.stopServer(getClass().getName(),
-                             LocalizableMessage.raw("testStopAndStartServer"));
-    assertFalse(EmbeddedUtils.isRunning());
-
-    EmbeddedUtils.startServer(environmentConfig);
-    assertTrue(EmbeddedUtils.isRunning());
-  }
-}
-

--
Gitblit v1.10.0