From 48d3983dd2c841ff2610a5bf57faa1f7c95b8631 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Fri, 13 Jun 2008 11:03:18 +0000
Subject: [PATCH] Fix for 3338 (upgrade breaks the java_home parameter)

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java         |   39 +++++++++++++++++++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java |   13 ++++++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Installation.java              |   11 +++++
 3 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Installation.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Installation.java
index c1bfe55..a002478 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Installation.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Installation.java
@@ -518,6 +518,17 @@
   }
 
   /**
+   * Returns the path to the set-java-home file.
+   *
+   * @return the path to the set-java-home file.
+   */
+  public File getSetJavaHomeFile() {
+    return new File(getLibrariesDirectory(),
+        Utils.isWindows()?SET_JAVA_PROPERTIES_FILE_WINDOWS :
+          SET_JAVA_PROPERTIES_FILE_UNIX);
+  }
+
+  /**
    * Creates a File object representing config/upgrade/schema.ldif.current
    * which the server creates the first time it starts if there are schema
    * customizations.
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java
index 5678928..244da2c 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java
@@ -77,6 +77,7 @@
   private File backupDir;
   private UserInteraction ui;
   private boolean isSchemaCustomized;
+  private boolean mustRunDSJavaProperties;
 
   /**
    * Creates a new parameterized instance.
@@ -164,6 +165,7 @@
       throw ApplicationException.createFileSystemException(
               INFO_ERROR_DETERMINING_CUSTOM_CONFIG.get(), e);
     }
+    mustRunDSJavaProperties = installation.getSetJavaHomeFile().exists();
   }
 
   /**
@@ -228,6 +230,17 @@
   }
 
   /**
+   * Tells whether a set-java-home file exists and so if we have to run
+   * dsjavaproperties to regenerate it.
+   * @return <CODE>true</CODE> if the set-java-home file exists and
+   * <CODE>false</CODE> otherwise.
+   */
+  public boolean mustRunDSJavaProperties()
+  {
+    return mustRunDSJavaProperties;
+  }
+
+  /**
    * Migrates the tools properties file.
    * @param newPropertiesFile the new properties file.
    * @throws ApplicationException if there is an error copying the new
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index 3aca262..5c5e070 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -69,6 +69,7 @@
 import org.opends.quicksetup.ui.FieldName;
 import org.opends.quicksetup.upgrader.ui.UpgraderReviewPanel;
 import org.opends.quicksetup.upgrader.ui.WelcomePanel;
+import org.opends.server.tools.JavaPropertiesTool;
 
 import java.awt.event.WindowEvent;
 import java.io.File;
@@ -709,6 +710,9 @@
 
       checkAbort();
 
+      getUserData().setStartServer(
+          getInstallation().getStatus().isServerRunning());
+
       try {
         LOG.log(Level.INFO, "initializing upgrade");
         setCurrentProgressStep(UpgradeProgressStep.INITIALIZING);
@@ -903,6 +907,41 @@
           }
         }
 
+        if (migration.mustRunDSJavaProperties())
+        {
+          try {
+            LOG.log(Level.INFO, "Upgrading script with java properties");
+//          Launch the script
+            String propertiesFile = new File(
+                getInstallation().getConfigurationDirectory(),
+                Installation.DEFAULT_JAVA_PROPERTIES_FILE).getAbsolutePath();
+            String setJavaFile =
+              getInstallation().getSetJavaHomeFile().getAbsolutePath();
+            String[] args =
+            {
+                "--propertiesFile", propertiesFile,
+                "--destinationFile", setJavaFile,
+                "--quiet"
+            };
+
+            int returnValue = JavaPropertiesTool.mainCLI(args);
+
+            if ((returnValue !=
+              JavaPropertiesTool.ErrorReturnCode.SUCCESSFUL.getReturnCode()) &&
+              returnValue !=
+              JavaPropertiesTool.ErrorReturnCode.SUCCESSFUL_NOP.getReturnCode())
+            {
+              throw new ApplicationException(ReturnCode.APPLICATION_ERROR,
+              ERR_ERROR_CREATING_JAVA_HOME_SCRIPTS.get(returnValue), null);
+            }
+            LOG.log(Level.INFO, "scripts successfully upgraded");
+          } catch (ApplicationException e) {
+            LOG.log(Level.INFO,
+                "Error upgrading scripts", e);
+            throw e;
+          }
+        }
+
         checkAbort();
 
         try {

--
Gitblit v1.10.0