From bcdab6d3104e368c131bf63d91866fec130c4481 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 26 Mar 2007 18:22:27 +0000
Subject: [PATCH] Fix for issue 1432 (Uninstall fails on windows due to lock on activation.jar).

---
 opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java             |  112 +++++++++++++++++++++++++++-
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java     |    1 
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java |  109 +--------------------------
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java  |   18 ++--
 4 files changed, 120 insertions(+), 120 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java
index ad381d4..ffc2e89 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java
@@ -253,7 +253,6 @@
     }
     catch (Throwable t)
     {
-      t.printStackTrace();
       // Assume that if we cannot acquire the lock file the server is
       // running.
       isServerRunning = true;
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java
index ccf858b..1bb7875 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java
@@ -27,9 +27,9 @@
 
 package org.opends.quicksetup.uninstaller;
 
-import java.io.BufferedReader;
+
 import java.io.ByteArrayOutputStream;
-import java.io.FileReader;
+
 import java.util.ArrayList;
 import java.util.Set;
 
@@ -288,34 +288,7 @@
     return response;
   }
 
-  /**
-   * Interactively prompts (on standard output) the user to provide a string
-   * value.  Any non-empty string will be allowed (the empty string will
-   * indicate that the default should be used).
-   *
-   * @param  prompt        The prompt to present to the user.
-   * @param  defaultValue  The default value returned if the user clicks enter.
-   *
-   * @return  The string value read from the user.
-   */
-  private String promptForString(String prompt, String defaultValue)
-  {
-    System.out.println();
 
-    String response = null;
-    String msg = getMsg("cli-uninstall-string-prompt",
-        new String[] {prompt, defaultValue});
-
-    System.out.print(msg);
-    System.out.flush();
-
-    response = readLine();
-    if (response.equals(""))
-    {
-      response = defaultValue;
-    }
-    return response;
-  }
 
   /**
    * Reads a line of text from standard input.
@@ -577,7 +550,7 @@
   {
     boolean cancelled = false;
 
-    if (installStatus.isServerRunning())
+    if (CurrentInstallStatus.isServerRunning())
     {
         if (!silentUninstall)
         {
@@ -588,7 +561,7 @@
         if (!cancelled)
         {
             /* During all the confirmations, the server might be stopped. */
-            userData.setStopServer(installStatus.isServerRunning());
+            userData.setStopServer(CurrentInstallStatus.isServerRunning());
         }
     }
     else
@@ -636,9 +609,6 @@
   private void validateArguments(UserUninstallData userData,
       String[] args) throws UserUninstallDataException
   {
-    String directoryManagerPwd = null;
-    String directoryManagerPwdFile = null;
-
     ArrayList<String> errors = new ArrayList<String>();
 
     for (int i=0; i<args.length; i++)
@@ -667,77 +637,6 @@
   }
 
   /**
-   * Interactively prompts (on standard output) the user to provide a string
-   * value.
-   *
-   * @param  prompt  The prompt to present to the user.
-   *
-   * @return  The string value read from the user.
-   */
-  private String promptForPassword(String prompt)
-  {
-    char[] password = null;
-    while ((password == null) || (password.length == 0))
-    {
-      System.out.println();
-      System.out.print(prompt);
-      System.out.flush();
-
-      password = org.opends.server.util.PasswordReader.readPassword();
-    }
-
-    return new String(password);
-  }
-
-  /**
-   * Returns the password stored in a file.  Returns <CODE>null</CODE> if no
-   * password is found.
-   * @param path the path of the file containing the password.
-   * @return the password stored in a file.  Returns <CODE>null</CODE> if no
-   * password is found.
-   */
-  private String readPwdFromFile(String path)
-  {
-    String pwd = null;
-    BufferedReader reader = null;
-    try
-    {
-      reader = new BufferedReader(new FileReader(path));
-      pwd = reader.readLine();
-    }
-    catch (Exception e)
-    {
-    }
-    finally
-    {
-      try
-      {
-        if (reader != null)
-        {
-          reader.close();
-        }
-      } catch (Exception e) {}
-    }
-    return pwd;
-  }
-
-  /**
-   * Method used to know if we can connect as administrator in a server with a
-   * given password and dn.
-   * @param ldapUrl the ldap URL of the server.
-   * @param dn the dn to be used.
-   * @param pwd the password to be used.
-   * @return <CODE>true</CODE> if we can connect and read the configuration and
-   * <CODE>false</CODE> otherwise.
-   */
-  private boolean canConnectAsAdministrativeUser(String ldapUrl, String dn,
-      String pwd)
-  {
-    return Utils.canConnectAsAdministrativeUser(ldapUrl, dn, pwd);
-  }
-
-
-  /**
    *  Ask for confirmation to stop server.
    *  @return <CODE>true</CODE> if the user wants to continue and stop the
    *  server.  <CODE>false</CODE> otherwise.
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
index 53ea429..ba76a6e 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
@@ -527,6 +527,10 @@
       if (isWindowsServiceEnabled())
       {
         status = UninstallProgressStep.DISABLING_WINDOWS_SERVICE;
+        if (displaySeparator)
+        {
+          notifyListeners(getTaskSeparator());
+        }
         disableWindowsService();
         displaySeparator = true;
       }
@@ -943,14 +947,7 @@
     return Utils.getPath(getLibrariesPath(), "OpenDS.jar");
   }
 
-  /**
-   * Returns the path to the aspectj jar file.
-   * @return the path to the aspectj jar file.
-   */
-  private String getAspectJJarPath()
-  {
-    return Utils.getPath(getLibrariesPath(), "aspectjrt.jar");
-  }
+
 
 
   /**
@@ -1183,7 +1180,7 @@
             String line = reader.readLine();
             while (line != null)
             {
-              StringBuffer buf = new StringBuffer();
+              StringBuilder buf = new StringBuilder();
               if (!isFirstLine)
               {
                 buf.append(formatter.getLineBreak());
@@ -1257,7 +1254,7 @@
 
      boolean accept =
           !installationPath.equals(file)
-              && !librariesFile.equals(file)
+              && !equalsOrDescendant(file, librariesFile)
               && !quicksetupFile.equals(file)
               && !openDSFile.equals(file);
 
@@ -1434,3 +1431,4 @@
     }
   }
 }
+
diff --git a/opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java b/opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java
index b332d1b..e8b3b25 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java
@@ -138,10 +138,11 @@
 
 
       // Open the file for reading and get the corresponding file channel.
-      FileChannel channel;
+      FileChannel channel = null;
+      RandomAccessFile raf = null;
       try
       {
-        RandomAccessFile raf = new RandomAccessFile(lockFile, "r");
+        raf = new RandomAccessFile(lockFile, "r");
         channel = raf.getChannel();
       }
       catch (Exception e)
@@ -154,6 +155,17 @@
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_OPEN;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -174,6 +186,26 @@
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_LOCK;
         failureReason.append(getMessage(msgID,
                                         stackTraceToSingleLineString(e)));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -184,6 +216,26 @@
       {
         int msgID = MSGID_FILELOCKER_LOCK_SHARED_NOT_GRANTED;
         failureReason.append(getMessage(msgID, lockFile));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
       else
@@ -263,10 +315,11 @@
 
 
       // Open the file read+write and get the corresponding file channel.
-      FileChannel channel;
+      FileChannel channel = null;
+      RandomAccessFile raf = null;
       try
       {
-        RandomAccessFile raf = new RandomAccessFile(lockFile, "rw");
+        raf = new RandomAccessFile(lockFile, "rw");
         channel = raf.getChannel();
       }
       catch (Exception e)
@@ -279,6 +332,16 @@
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
 
@@ -299,6 +362,27 @@
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK;
         failureReason.append(getMessage(msgID, lockFile,
                                         stackTraceToSingleLineString(e)));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+
         return false;
       }
 
@@ -309,6 +393,26 @@
       {
         int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_NOT_GRANTED;
         failureReason.append(getMessage(msgID, lockFile));
+        if (channel != null)
+        {
+          try
+          {
+            channel.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
+        if (raf != null)
+        {
+          try
+          {
+            raf.close();
+          }
+          catch (Throwable t)
+          {
+          }
+        }
         return false;
       }
       else

--
Gitblit v1.10.0