From 4b7eb7058b8fe46bbe7bf630bffa535119ccd8e8 Mon Sep 17 00:00:00 2001
From: Gaetan Boismal <gaetan.boismal@forgerock.com>
Date: Wed, 17 Jun 2015 09:48:31 +0000
Subject: [PATCH] OPENDJ-2144 Update license files and folder location

---
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/LicenseFile.java |   98 ++++++++++++++++++++++++++++---------------------
 opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/LicenseFile.java           |    4 +-
 opendj-sdk/opendj-server-legacy/build.xml                                                      |    6 +-
 opendj-sdk/opendj-server-legacy/resource/webstart/create-webstart-standalone.sh                |    6 +-
 opendj-sdk/opendj-server-legacy/src/main/docbkx/reference/appendix-file-layout.xml             |    4 +-
 5 files changed, 66 insertions(+), 52 deletions(-)

diff --git a/opendj-sdk/opendj-server-legacy/build.xml b/opendj-sdk/opendj-server-legacy/build.xml
index c51f7f0..995f0df 100644
--- a/opendj-sdk/opendj-server-legacy/build.xml
+++ b/opendj-sdk/opendj-server-legacy/build.xml
@@ -1048,7 +1048,7 @@
        This target should only be called from targets which have defined the
        pdir property, such as prepackage and rebuild.
 
-       The license file will be copied to ${pdir}/Legal/license_to_accept.txt.
+       The license file will be copied to ${pdir}/legal-notices/Forgerock_License.txt.
        This file location is hard-coded in the following classes:
 
        org.opends.server.tools.upgrade.LicenseFile
@@ -1057,8 +1057,8 @@
        Care must be taken to keep these filenames synchronized.
   -->
   <target name="copylicense" if="include.license.file" >
-    <mkdir dir="${pdir}/Legal" />
-    <copy tofile="${pdir}/Legal/license_to_accept.txt" file="${license.file}" />
+    <mkdir dir="${pdir}/legal-notices" />
+    <copy tofile="${pdir}/legal-notices/Forgerock_License.txt" file="${license.file}" />
   </target>
 
   <!-- Populate the Directory Server package, but don't zip it up. -->
diff --git a/opendj-sdk/opendj-server-legacy/resource/webstart/create-webstart-standalone.sh b/opendj-sdk/opendj-server-legacy/resource/webstart/create-webstart-standalone.sh
index af56876..9f3aaa7 100755
--- a/opendj-sdk/opendj-server-legacy/resource/webstart/create-webstart-standalone.sh
+++ b/opendj-sdk/opendj-server-legacy/resource/webstart/create-webstart-standalone.sh
@@ -175,12 +175,12 @@
 done
 
 # Create and sign the licence.jar file if exists.
-if [ -d ${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/Legal ]
+if [ -d ${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/legal-notices ]
 then
 echo "Creating license.jar ..."
-cp "${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/Legal" "${INSTALL_DIR}/lib"
+cp "${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/legal-notices" "${INSTALL_DIR}/lib"
 cd "${BUILD_DIR}/package"
-"${JAR}" -cf "${INSTALL_DIR}/lib/license.jar" -C "${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/" "Legal"
+"${JAR}" -cf "${INSTALL_DIR}/lib/license.jar" -C "${BUILD_DIR}/package/${ZIP_FILENAME_BASE}/" "legal-notices"
 cd "${INSTALL_DIR}/lib"
 echo "Signing license.jar ..."
 "${JARSIGNER}" -keystore "${CERT_KEYSTORE}" -keypass "${CERT_KEYSTORE_PIN}" \
diff --git a/opendj-sdk/opendj-server-legacy/src/main/docbkx/reference/appendix-file-layout.xml b/opendj-sdk/opendj-server-legacy/src/main/docbkx/reference/appendix-file-layout.xml
index 7c8d49a..dc0a8f8 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/docbkx/reference/appendix-file-layout.xml
+++ b/opendj-sdk/opendj-server-legacy/src/main/docbkx/reference/appendix-file-layout.xml
@@ -21,7 +21,7 @@
   ! CCPL HEADER END
   !
   !      Copyright 2011-2015 ForgeRock AS.
-  !    
+  !
 -->
 <appendix xml:id='appendix-file-layout'
           xmlns='http://docbook.org/ns/docbook' version='5.0' xml:lang='en'
@@ -38,7 +38,7 @@
  <indexterm><primary>Installed files</primary></indexterm>
  <variablelist>
   <varlistentry>
-   <term><filename>Legal</filename></term>
+   <term><filename>legal-notices</filename></term>
    <listitem>
     <para>
      License information
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/LicenseFile.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/LicenseFile.java
index 5d0b124..3247350 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/LicenseFile.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/quicksetup/LicenseFile.java
@@ -51,12 +51,12 @@
   /**
    * The license file name in Legal directory.
    */
-  private static final String LICENSE_FILE_NAME = "license_to_accept.txt";
+  private static final String LICENSE_FILE_NAME = "Forgerock_License.txt";
 
   /**
    * The Legal folder which contains license file.
    */
-  private static final String LEGAL_FOLDER_NAME = "Legal";
+  private static final String LEGAL_FOLDER_NAME = "legal-notices";
 
   /**
    * The accepted license file name.
diff --git a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/LicenseFile.java b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/LicenseFile.java
index a3d29cb..f897bdc 100644
--- a/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/LicenseFile.java
+++ b/opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/LicenseFile.java
@@ -41,24 +41,48 @@
  */
 class LicenseFile
 {
+  private static final String INSTALL_ROOT_SYSTEM_PROPERTY = "INSTALL_ROOT";
+
   /**
-   * Get the directory in which legal files are stored.
+   * The license file name in Legal directory.
    */
+  private static final String LICENSE_FILE_NAME = "Forgerock_License.txt";
+
+  /**
+   * The Legal folder which contains license file.
+   */
+  private static final String LEGAL_FOLDER_NAME = "legal-notices";
+
+  /** List of possible folder of the accepted license file. */
+  private static final String[] ACCEPTED_LICENSE_FOLDER_NAMES = new String[] { LEGAL_FOLDER_NAME, "Legal" };
+
+  /**
+   * The accepted license file name.
+   */
+  private static final String ACCEPTED_LICENSE_FILE_NAME = "licenseAccepted";
+
+  /**
+   * Try to find the local instance path from system property or environment. If
+   * both are null, return the provided fallback value.
+   */
+  private static String getInstanceRootPathFromSystem(final String fallBackValue)
+  {
+    final String[] possibleValues = new String[] {
+      System.getProperty(INSTALL_ROOT_SYSTEM_PROPERTY), System.getenv(INSTALL_ROOT_SYSTEM_PROPERTY) };
+    for (final String value : possibleValues )
+    {
+      if (value != null)
+      {
+        return value;
+      }
+    }
+    return fallBackValue;
+  }
+
+  /** Get the directory in which legal files are stored. */
   private static String getLegalDirectory()
   {
-    String installRootFromSystem = System.getProperty("INSTALL_ROOT");
-
-    if (installRootFromSystem == null)
-    {
-      installRootFromSystem = System.getenv("INSTALL_ROOT");
-    }
-
-    if (installRootFromSystem == null)
-    {
-      installRootFromSystem = "";
-    }
-
-    return installRootFromSystem + File.separatorChar + "Legal";
+    return getInstanceRootPathFromSystem("") + File.separatorChar + LEGAL_FOLDER_NAME;
   }
 
   /**
@@ -66,30 +90,14 @@
    */
   private static String getInstanceLegalDirectory()
   {
-    String installDirName = System.getProperty("INSTALL_ROOT");
-
-    if (installDirName == null)
-    {
-      installDirName = System.getenv("INSTALL_ROOT");
-    }
-
-    if (installDirName == null)
-    {
-      installDirName = ".";
-    }
-
-    final String instanceDirname =
-        UpgradeUtils.getInstancePathFromInstallPath(installDirName);
-    StringBuilder instanceLegalDirName =
-        new StringBuilder(instanceDirname).append(File.separator).append(
-            "Legal");
-    final File instanceLegalDir = new File(instanceLegalDirName.toString());
+    final String instanceDirname = UpgradeUtils.getInstancePathFromInstallPath(getInstanceRootPathFromSystem("."));
+    final String instanceLegalDirName = instanceDirname + File.separator + LEGAL_FOLDER_NAME;
+    final File instanceLegalDir = new File(instanceLegalDirName);
     if (!instanceLegalDir.exists())
     {
       instanceLegalDir.mkdir();
     }
-
-    return instanceLegalDirName.toString();
+    return instanceLegalDirName;
   }
 
   /**
@@ -107,7 +115,7 @@
    */
   private static String getName()
   {
-    return getLegalDirectory() + File.separatorChar + "license_to_accept.txt";
+    return getLegalDirectory() + File.separatorChar + LICENSE_FILE_NAME;
   }
 
   /**
@@ -126,7 +134,7 @@
   /**
    * Checks if the license file exists.
    *
-   * @return <CODE>true</CODE> a license file license_to_accept.txt exists in
+   * @return <CODE>true</CODE> a license file exists in
    *         the Legal directory in the top level installation directory
    *         <CODE>false</CODE> otherwise.
    */
@@ -205,7 +213,7 @@
       try
       {
         new File(getInstanceLegalDirectory() + File.separatorChar
-            + "licenseAccepted").createNewFile();
+            + ACCEPTED_LICENSE_FILE_NAME).createNewFile();
       }
       catch (IOException e)
       {
@@ -219,12 +227,18 @@
    * @return <CODE>true</CODE> if the license had already been approved by the
    *         user <CODE>false</CODE> otherwise.
    */
-  static boolean isAlreadyApproved()
+  public static boolean isAlreadyApproved()
   {
-    File f =
-        new File(getInstanceLegalDirectory() + File.separatorChar
-            + "licenseAccepted");
-    return f.exists();
+    for (final String folderName : ACCEPTED_LICENSE_FOLDER_NAMES)
+    {
+      final File f = new File(getInstanceRootPathFromSystem(".") + File.separatorChar + folderName
+          + File.separatorChar + ACCEPTED_LICENSE_FILE_NAME);
+      if (f.exists())
+      {
+        return true;
+      }
+    }
+    return false;
   }
 
 }

--
Gitblit v1.10.0