From 94146a7d114384a521d36077f4f97c8e07b524c1 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 28 Feb 2007 11:35:55 +0000
Subject: [PATCH] Fix for issue 1285.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java |  135 ++-------------------------------------------
 1 files changed, 6 insertions(+), 129 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
index ce0a509..e722310 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/Utils.java
@@ -31,7 +31,6 @@
 import java.awt.Toolkit;
 import java.awt.Window;
 import java.io.BufferedOutputStream;
-import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
@@ -39,11 +38,7 @@
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.io.RandomAccessFile;
-import java.io.Writer;
 import java.net.ConnectException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -62,6 +57,7 @@
 import org.opends.quicksetup.CurrentInstallStatus;
 import org.opends.quicksetup.i18n.ResourceProvider;
 import org.opends.quicksetup.installer.webstart.JnlpProperties;
+import org.opends.server.util.SetupUtils;
 
 
 /**
@@ -229,51 +225,7 @@
    */
   public static boolean canUseAsPort(int port)
   {
-    boolean canUseAsPort = false;
-    ServerSocket serverSocket = null;
-    try
-    {
-      InetSocketAddress socketAddress = new InetSocketAddress(port);
-      serverSocket = new ServerSocket();
-      if (!isWindows())
-      {
-        serverSocket.setReuseAddress(true);
-      }
-      serverSocket.bind(socketAddress);
-      canUseAsPort = true;
-
-      serverSocket.close();
-
-      /* Try to create a socket because sometimes even if we can create a server
-       * socket there is already someone listening to the port (is the case
-       * of products as Sun DS 6.0).
-       */
-      try
-      {
-        new Socket("localhost", port);
-        canUseAsPort = false;
-
-      } catch (IOException ioe)
-      {
-      }
-
-    } catch (IOException ex)
-    {
-      canUseAsPort = false;
-    } finally
-    {
-      try
-      {
-        if (serverSocket != null)
-        {
-          serverSocket.close();
-        }
-      } catch (Exception ex)
-      {
-      }
-    }
-
-    return canUseAsPort;
+    return SetupUtils.canUseAsPort(port);
   }
 
   /**
@@ -285,7 +237,7 @@
    */
   public static boolean isPriviledgedPort(int port)
   {
-    return (port <= 1024) && !isWindows();
+    return SetupUtils.isPriviledgedPort(port);
   }
 
   /**
@@ -369,7 +321,7 @@
    */
   public static boolean isWindows()
   {
-    return containsOsProperty("windows");
+    return SetupUtils.isWindows();
   }
 
   /**
@@ -380,7 +332,7 @@
    */
   public static boolean isMacOS()
   {
-    return containsOsProperty("mac os");
+    return SetupUtils.isMacOS();
   }
 
   /**
@@ -391,7 +343,7 @@
    */
   public static boolean isUnix()
   {
-    return !isWindows();
+    return SetupUtils.isUnix();
   }
 
   /**
@@ -773,25 +725,6 @@
   }
 
   /**
-   * Commodity method to help identifying the OS we are running on.
-   * @param s the String that represents an OS.
-   * @return <CODE>true</CODE> if there is os java property exists and contains
-   * the value specified in s, <CODE>false</CODE> otherwise.
-   */
-  private static boolean containsOsProperty(String s)
-  {
-    boolean containsOsProperty = false;
-
-    String osName = System.getProperty("os.name");
-    if (osName != null)
-    {
-      containsOsProperty = osName.toLowerCase().indexOf(s) != -1;
-    }
-
-    return containsOsProperty;
-  }
-
-  /**
    * Sets the permissions of the provided paths with the provided permission
    * String.
    * @param paths the paths to set permissions on.
@@ -1362,62 +1295,6 @@
   }
 
   /**
-   * Returns if the server is running on the given path.
-   * @param serverPath the installation path of the server.
-   * @return <CODE>true</CODE> if the server is running and <CODE>false</CODE>
-   * otherwise.
-   */
-  public static boolean isServerRunning(String serverPath)
-  {
-    boolean isServerRunning;
-    if (isWindows())
-    {
-      String testPath = serverPath+File.separator+
-      "locks"+File.separator+"server.lock";
-      File testFile = new File(testPath);
-
-      boolean canWriteFile = false;
-      Writer output = null;
-      try {
-        //use buffering
-        //FileWriter always assumes default encoding is OK!
-        output = new BufferedWriter( new FileWriter(testFile) );
-        output.write("test");
-        output.close();
-        output = new BufferedWriter( new FileWriter(testFile) );
-        output.write("");
-        output.close();
-
-        canWriteFile = true;
-
-      }
-      catch (Throwable t)
-      {
-      }
-      finally
-      {
-        if (output != null)
-        {
-          try
-          {
-            output.close();
-          }
-          catch (Throwable t)
-          {
-          }
-        }
-      }
-      isServerRunning = !canWriteFile;
-    }
-    else
-    {
-      isServerRunning = fileExists(serverPath+File.separator+
-          "logs"+File.separator+"server.pid");
-    }
-    return isServerRunning;
-  }
-
-  /**
    * This is just a commodity method used to try to get an InitialLdapContext.
    * @param t the Thread to be used to create the InitialLdapContext.
    * @param pair an Object[] array that contains the InitialLdapContext and the

--
Gitblit v1.10.0