From d42b15e420478dc45785fff6e00b863cc1f8a0f9 Mon Sep 17 00:00:00 2001
From: lutoff <lutoff@localhost>
Date: Thu, 18 Sep 2008 10:14:53 +0000
Subject: [PATCH] These changes are separating the current delivery into  an "Install Layout" (the binaries) and an "Instance Layout" (the user data).

---
 opends/src/quicksetup/org/opends/quicksetup/util/Utils.java |   86 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 1 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index b2f49d4..8f007fc 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -34,6 +34,7 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
@@ -82,6 +83,27 @@
   }
 
   /**
+   * Enumeration that specify if the operation applies to the install directory
+   * only, to the instance directory only, or both.
+   */
+  public static enum  Dir {
+    /**
+     * all directories.
+     */
+    ALL,
+
+    /**
+     * The install directory.
+     */
+    INSTALL,
+
+    /***
+     * The instance directory.
+     */
+    INSTANCE;
+  }
+
+  /**
    * Returns <CODE>true</CODE> if the provided port is free and we can use it,
    * <CODE>false</CODE> otherwise.
    * @param port the port we are analyzing.
@@ -1093,6 +1115,7 @@
     return ConnectionUtils.getDefaultLDAPTimeout();
   }
 
+
   /**
    * Returns the path of the installation of the directory server.  Note that
    * this method assumes that this code is being run locally.
@@ -1100,7 +1123,11 @@
    */
   public static String getInstallPathFromClasspath()
   {
-    String installPath = null;
+    String installPath = System.getProperty("org.opends.quicksetup.Root");
+    if (installPath != null)
+    {
+      return installPath;
+    }
 
     /* Get the install path from the Class Path */
     String sep = System.getProperty("path.separator");
@@ -1140,6 +1167,63 @@
   }
 
   /**
+   * Returns the path of the installation of the directory server.  Note that
+   * this method assumes that this code is being run locally.
+   * @param installPath The installation path
+   * @return the path of the installation of the directory server.
+   */
+  public static String getInstancePathFromClasspath(String installPath)
+  {
+    String instancePathFileName = installPath + File.separator + "instance.loc";
+
+    // look for <installPath>/instance.loc
+    File f = new File(instancePathFileName);
+    if (! f.exists())
+    {
+      return installPath;
+    }
+
+    BufferedReader reader;
+    try
+    {
+      reader = new BufferedReader(new FileReader(instancePathFileName));
+    }
+    catch (Exception e)
+    {
+      return installPath;
+    }
+
+
+    // Read the first line and close the file.
+    String line;
+    try
+    {
+      line = reader.readLine();
+      File instanceLoc =  new File (line);
+      if (instanceLoc.isAbsolute())
+      {
+        return instanceLoc.getAbsolutePath();
+      }
+      else
+      {
+        return new File(installPath + File.separator + instanceLoc.getPath())
+            .getAbsolutePath();
+      }
+    }
+    catch (Exception e)
+    {
+      return installPath;
+    }
+    finally
+    {
+      try
+      {
+        reader.close();
+      } catch (Exception e) {}
+    }
+  }
+
+  /**
 
    * Returns the max size in character of a line to be displayed in the command
    * line.

--
Gitblit v1.10.0