From 43ba6d721185f9a810761720fcb05103b31d17b7 Mon Sep 17 00:00:00 2001
From: chebrard <chebrard@localhost>
Date: Wed, 29 Oct 2008 10:39:44 +0000
Subject: [PATCH] Fix 3534: Provide native Solaris packages (fix also 3533: upgrade fails starting server adding entry ds-cfg-key-id)

---
 opends/src/quicksetup/org/opends/quicksetup/Installation.java |  164 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 155 insertions(+), 9 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/Installation.java b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
index e032348..0deca50 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/Installation.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -77,6 +77,11 @@
     SetupUtils.LIBRARIES_PATH_RELATIVE;
 
   /**
+   * The relative path where customer classes are.
+   */
+  public static final String CLASSES_PATH_RELATIVE = "classes";
+
+  /**
    * The relative path where the database files are.
    */
   public static final String DATABASES_PATH_RELATIVE = "db";
@@ -143,10 +148,32 @@
     CONFIG_PATH_RELATIVE+File.separator+"tools.properties";
 
   /**
+   * The path to the default instance.
+   */
+  public static final String DEFAULT_INSTANCE_PATH = "/var/opt/opends";
+
+  /**
    * The relative path to the instance.loc file.
    */
   public static final String INSTANCE_LOCATION_PATH_RELATIVE =
     "instance.loc";
+
+  /**
+   * The path to the instance.loc file.
+   */
+  public static final String INSTANCE_LOCATION_PATH = "/etc/opt/opends/" +
+    INSTANCE_LOCATION_PATH_RELATIVE;
+
+  /**
+   * The relative path to tmpl_instance.
+   */
+  public static final String TMPL_INSTANCE_RELATIVE_PATH = "tmpl_instance";
+
+  /**
+   * The relative path to buildinfo file.
+   */
+  public static final String BUILDINFO_RELATIVE_PATH = "buildinfo";
+
   /**
    * The UNIX setup script file name.
    */
@@ -178,6 +205,11 @@
   public static final String WINDOWS_UPGRADE_FILE_NAME = "upgrade.bat";
 
   /**
+   * The UNIX configure script file name.
+   */
+  public static final String UNIX_CONFIGURE_FILE_NAME = "configure";
+
+  /**
    * Newly upgraded Windows upgrade batch file name.  When the upgrade
    * batch file requires upgrade it is not done during execution of the
    * upgrade utility itself since replacing a running script on Windows
@@ -402,6 +434,8 @@
 
   private BuildInformation buildInformation;
 
+  private BuildInformation instanceInformation;
+
   /**
    * Indicates if the install and instance are in the same directory.
    * @return true if the install and instance are in the same directory.
@@ -469,6 +503,21 @@
   }
 
   /**
+   * Gets the directory of the OpenDS template instance.
+   *
+   * @return File object representing the top level directory of
+   *         and OpenDS installation
+   */
+  public File getTmplInstanceDirectory() {
+    File f = new File(getRootDirectory().getAbsolutePath() +
+             File.separator + TMPL_INSTANCE_RELATIVE_PATH );
+    if (f.exists())
+        return f;
+    else
+        return getInstanceDirectory();
+  }
+
+  /**
    * Sets the root directory of this installation.
    *
    * @param rootDirectory File of this installation
@@ -605,7 +654,7 @@
    * @return the path to the tools properties file.
    */
   public File getToolsPropertiesFile() {
-    return new File(getRootDirectory(), TOOLS_PROPERTIES);
+    return new File(getTmplInstanceDirectory(), TOOLS_PROPERTIES);
   }
 
   /**
@@ -614,7 +663,8 @@
    * @return the path to the set-java-home file.
    */
   public File getSetJavaHomeFile() {
-    return new File(getLibrariesDirectory(),
+    return new File(getInstanceDirectory().getAbsolutePath() + File.separator +
+            LIBRARIES_PATH_RELATIVE,
         Utils.isWindows()?SET_JAVA_PROPERTIES_FILE_WINDOWS :
           SET_JAVA_PROPERTIES_FILE_UNIX);
   }
@@ -642,10 +692,42 @@
    */
   public File getBaseSchemaFile() throws ApplicationException {
     return new File(getConfigurationUpgradeDirectory(),
+                  "schema.ldif." + getInstanceSvnRev().toString());
+  }
+
+  /**
+   * Creates a File object representing
+   * tmpl_instance/config/upgrade/schema.ldif.current.
+   *
+   * @return File object representing
+   *  tmpl_instance/config/upgrade/schema.ldif.current
+   * @throws ApplicationException if there was a problem determining the
+   *                             svn revision number
+   */
+  public File getTemplSchemaFile() throws ApplicationException {
+    return new File(getTmplInstanceDirectory().getAbsolutePath() +
+                  File.separator + CONFIG_PATH_RELATIVE +
+                  File.separator + UPGRADE_PATH,
                   "schema.ldif." + getSvnRev().toString());
   }
 
   /**
+   * Creates a File object representing
+   * tmpl_instance/config/upgrade/config.ldif.current.
+   *
+   * @return File object representing
+   *  tmpl_instance/config/upgrade/config.ldif.current
+   * @throws ApplicationException if there was a problem determining the
+   *                             svn revision number
+   */
+  public File getTemplConfigFile() throws ApplicationException {
+    return new File(getTmplInstanceDirectory().getAbsolutePath() +
+                  File.separator + CONFIG_PATH_RELATIVE +
+                  File.separator + UPGRADE_PATH,
+                  BASE_CONFIG_FILE_PREFIX + getSvnRev().toString());
+  }
+
+  /**
    * Creates a File object representing config/upgrade/schema.ldif.current
    * which the server creates the first time it starts if there are schema
    * customizations.
@@ -656,7 +738,7 @@
    */
   public File getBaseConfigurationFile() throws ApplicationException {
     return new File(getConfigurationUpgradeDirectory(),
-            BASE_CONFIG_FILE_PREFIX + getSvnRev().toString());
+            BASE_CONFIG_FILE_PREFIX + getInstanceSvnRev().toString());
   }
 
   /**
@@ -672,6 +754,18 @@
   }
 
   /**
+   * Gets the SVN revision number of the instance.
+   *
+   * @return Integer representing the svn number
+   * @throws ApplicationException if for some reason the number could not
+   *                             be determined
+   */
+  public Integer getInstanceSvnRev() throws ApplicationException {
+    BuildInformation bi = getInstanceBuildInformation();
+    return bi.getRevisionNumber();
+  }
+
+  /**
    * Returns the path to the configuration file of the directory server.  Note
    * that this method assumes that this code is being run locally.
    *
@@ -688,7 +782,7 @@
    * @return the path of the ADS file of the directory server.
    */
   public File getADSBackendFile() {
-    return new File(getRootDirectory(), ADSContext.getAdminLDIFFile());
+    return new File(getTmplInstanceDirectory(), ADSContext.getAdminLDIFFile());
   }
 
   /**
@@ -737,6 +831,15 @@
   }
 
   /**
+   * Returns the path to the config files under the instance path.
+   *
+   * @return the path to the config files under the instance path.
+   */
+  public File getInstallConfigurationDirectory() {
+    return new File(getRootDirectory(), CONFIG_PATH_RELATIVE);
+  }
+
+  /**
    * Returns the path to the log files under the install path.
    *
    * @return the path to the log files under the install path.
@@ -986,11 +1089,54 @@
   }
 
   /**
-   * {@inheritDoc}
+   * Gets information about the build that was used to produce the
+   * instance.
+   * @return BuildInformation object describing this instance
    */
-  @Override
-  public String toString() {
-    return Utils.getPath(rootDirectory);
+  public BuildInformation getInstanceBuildInformation() {
+    return getInstanceBuildInformation(true);
   }
 
-}
+  /**
+   * Gets information about the build that was used to produce the
+   * instance.
+   * @param useCachedVersion where true indicates that a potentially cached
+   * version of the build information is acceptable for use; false indicates
+   * the build information will be created from scratch which is potentially
+   * time consuming
+   * @return BuildInformation object describing this instance
+   */
+  public BuildInformation
+          getInstanceBuildInformation(boolean useCachedVersion) {
+    if (instanceInformation == null || !useCachedVersion) {
+      try {
+        File bif = new File(getConfigurationDirectory(),
+          BUILDINFO_RELATIVE_PATH);
+
+        if (bif.exists()) {
+          BufferedReader reader = new BufferedReader(new FileReader(bif));
+
+          // Read the first line and close the file.
+          String line;
+          try {
+            line = reader.readLine();
+            instanceInformation = BuildInformation.fromBuildString(line);
+          } finally {
+            try {
+              reader.close();
+            } catch (Exception e) {
+            }
+          }
+        } else {
+          return getBuildInformation();
+        }
+      } catch (Exception e) {
+        LOG.log(Level.SEVERE, "error getting build information for " +
+                "current instance", e);
+      }
+    }
+    return instanceInformation;
+
+  }
+
+  }

--
Gitblit v1.10.0