From cfb5767d9216efaf0c1738b5ce1ae243630fd8f5 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 30 Apr 2007 21:31:38 +0000
Subject: [PATCH] This commit is mainly intended to prevent the sort of false positives that occur when the upgrader assumes the server has been upgraded properly but leaves the server in a corrupt state (see issues 1546 and 1559).  The following changes are introduced:

---
 opends/src/quicksetup/org/opends/quicksetup/Installation.java |   83 +++++++++++------------------------------
 1 files changed, 22 insertions(+), 61 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/Installation.java b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
index 5a79706..b78276a 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Installation.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -29,8 +29,6 @@
 
 import java.io.*;
 import java.util.*;
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
 
 import org.opends.quicksetup.util.Utils;
 
@@ -209,7 +207,9 @@
           throws IllegalArgumentException {
     // TODO:  i18n
     String failureReason = null;
-    if (!rootDirectory.exists()) {
+    if (rootDirectory == null) {
+      failureReason = "root directory is null";
+    } else if (!rootDirectory.exists()) {
       failureReason = "is not a directory";
     } else if (!rootDirectory.isDirectory()) {
       failureReason = "does not exist";
@@ -230,7 +230,7 @@
     }
     if (failureReason != null) {
       throw new IllegalArgumentException("Install root '" +
-              Utils.getPath(rootDirectory) +
+              (rootDirectory != null ? Utils.getPath(rootDirectory) : "null") +
               "' is not an OpenDS installation root: " +
               " " + failureReason);
     }
@@ -244,7 +244,7 @@
 
   private Configuration baseConfiguration;
 
-  private String buildId;
+  private BuildInformation buildInformation;
 
   /**
    * Creates a new instance from a root directory specified as a string.
@@ -278,14 +278,10 @@
    * Sets the root directory of this installation.
    *
    * @param rootDirectory File of this installation
-   * @throws NullPointerException if root directory is null
    */
-  public void setRootDirectory(File rootDirectory) throws NullPointerException {
-    if (rootDirectory == null) {
-      throw new NullPointerException("Install root cannot be null");
-    }
+  public void setRootDirectory(File rootDirectory) {
 
-    // Hold off on doing more validation of rootDirectory since
+    // Hold off on doing validation of rootDirectory since
     // some applications (like the Installer) create an Installation
     // before the actual bits have been laid down on the filesyste.
 
@@ -456,46 +452,6 @@
   }
 
   /**
-   * Gets the build ID which is the 14 digit number code like 20070420110336.
-   * @return String representing the build ID
-   * @throws ApplicationException if something goes wrong
-   */
-  public String getBuildId() throws ApplicationException {
-    if (buildId == null) {
-      List<String> args = new ArrayList<String>();
-      args.add(Utils.getPath(getServerStartCommandFile()));
-      args.add("-V"); // verbose
-      ProcessBuilder pb = new ProcessBuilder(args);
-      InputStream is = null;
-      try {
-        Process process = pb.start();
-        is = process.getInputStream();
-        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
-        String line = null;
-        Pattern p = Pattern.compile("(Build )(\\d{14})");
-        while (null != (line = reader.readLine())) {
-          Matcher m = p.matcher(line);
-          if (m.matches()) {
-            buildId = line.substring(m.start(2), m.end(2));
-          }
-        }
-      } catch (IOException e) {
-        throw new ApplicationException(ApplicationException.Type.START_ERROR,
-                "Error attempting to determine build ID", e);
-      } finally {
-        if (is != null) {
-          try {
-            is.close();
-          } catch (IOException e) {
-            // ignore;
-          }
-        }
-      }
-    }
-    return buildId;
-  }
-
-  /**
    * Returns the path to the configuration file of the directory server.  Note
    * that this method assumes that this code is being run locally.
    *
@@ -542,15 +498,6 @@
   }
 
   /**
-   * Returns the path to the LDIF files under the install path.
-   *
-   * @return the path to the LDIF files under the install path.
-   */
-  public File geLdifDirectory() {
-    return new File(getRootDirectory(), LDIFS_PATH_RELATIVE);
-  }
-
-  /**
    * Returns the path to the config files under the install path.
    *
    * @return the path to the config files under the install path.
@@ -725,4 +672,18 @@
     }
     return statusPanelCommandFile;
   }
-}
+
+  /**
+   * Gets information about the build that was used to produce the bits
+   * for this installation.
+   * @return BuildInformation object describing this installation
+   * @throws ApplicationException if there is a problem obtaining the
+   * build information
+   */
+  public BuildInformation getBuildInformation() throws ApplicationException {
+    if (buildInformation == null) {
+      buildInformation = BuildInformation.create(this);
+    }
+    return buildInformation;
+  }
+}
\ No newline at end of file

--
Gitblit v1.10.0