mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
26.04.2013 709f2e00aace14c87d65a8a382337eff43b81186
OPENDJ-1032 RPM package should be built in a different way for more visibility.
1 files deleted
4 files added
2 files modified
1055 ■■■■ changed files
opends/build.xml 76 ●●●●● patch | view | raw | blame | history
opends/resource/rpm/excludedFiles 26 ●●●●● patch | view | raw | blame | history
opends/resource/rpm/files 26 ●●●●● patch | view | raw | blame | history
opends/resource/rpm/specFile 206 ●●●●● patch | view | raw | blame | history
opends/src/build-tools/org/opends/build/tools/GenerateRpm.java 458 ●●●●● patch | view | raw | blame | history
opends/src/build-tools/org/opends/build/tools/ProcessFilesForPackages.java 262 ●●●●● patch | view | raw | blame | history
opends/src/build-tools/org/opends/build/tools/Utilities.java 1 ●●●● patch | view | raw | blame | history
opends/build.xml
@@ -1336,47 +1336,71 @@
    <property name="prefix"    value="/opt/opendj"/>
    <property name="release"   value="1"/>
    <taskdef name="genrpm"
             classname="org.opends.build.tools.GenerateRpm">
    <mkdir dir="${build.dir}/rpm/BUILD" />
    <mkdir dir="${build.dir}/rpm/RPMS" />
    <mkdir dir="${build.dir}/rpm/SOURCES" />
    <mkdir dir="${build.dir}/rpm/SPECS" />
    <mkdir dir="${build.dir}/rpm/SRPMS" />
    <condition property="rpmRelease" value="${release}" else="${release}.${pkg_version_qualifier}">
        <or>
            <not>
                <isset property="pkg_version_qualifier"/>
            </not>
            <equals arg1="${pkg_version_qualifier}" arg2="" />
        </or>
    </condition>
    <copy todir="${build.dir}/rpm/SPECS">
      <fileset file="resource/rpm/specFile"/>
      <filterset begintoken="[[ " endtoken=" ]]">
        <filter token="topDir" value="${build.dir}/rpm"/>
        <filter token="prefix" value="${prefix}"/>
        <filter token="pre" value="${SHORT_NAME}-${VERSION_NUMBER_STRING}"/>
        <filter token="productName" value="${PRODUCT_NAME}"/>
        <filter token="shortName" value="${SHORT_NAME}"/>
        <filter token="pkgName" value="${PKG_NAME}"/>
        <filter token="referenceURL" value="${DOC_REFERENCE_HOME}"/>
        <filter token="sourceDirName" value="${package.dir}/${SHORT_NAME}-${VERSION_NUMBER_STRING}"/>
        <filter token="specFileName" value="${build.dir}/rpm/SPECS/specFile"/>
        <filter token="version" value="${pkg_version_string}"/>
        <filter token="release" value="${rpmRelease}" />
      </filterset>
    </copy>
    <taskdef name="processFilesForPackages"
                     classname="org.opends.build.tools.ProcessFilesForPackages">
      <classpath>
        <fileset dir="${build.dir}/build-tools">
          <include name="*.jar" />
        </fileset>
      </classpath>
    </taskdef>
    <mkdir dir="${build.dir}/rpm/BUILD" />
    <mkdir dir="${build.dir}/rpm/RPMS" />
    <mkdir dir="${build.dir}/rpm/SOURCES" />
    <mkdir dir="${build.dir}/rpm/SPECS" />
    <mkdir dir="${build.dir}/rpm/SRPMS" />
    <genrpm
        topDir="${build.dir}/rpm"
        prefix="${prefix}"
        productName="${PRODUCT_NAME}"
        shortName="${PKG_NAME}"
        referenceURL="${DOC_REFERENCE_HOME}"
        sourceDirName="${package.dir}/${SHORT_NAME}-${VERSION_NUMBER_STRING}"
        specFileName="${build.dir}/rpm/SPECS/specFile"
        version="${pkg_version_string}"
        release="${release}.${pkg_version_qualifier}"
        overwrite="true">
    </genrpm>
    <processFilesForPackages sourceDirName="${package.dir}/${SHORT_NAME}-${VERSION_NUMBER_STRING}" />
    <copy file="resource/rpm/files" tofile="${build.dir}/rpm/SOURCES/files" />
    <replace file="${build.dir}/rpm/SOURCES/files" token="# [[ listFiles ]]" value="${listRPMFiles}" />
    <replace file="${build.dir}/rpm/SPECS/specFile" token="# [[ docsList ]]" value="${listRPMDocFiles}" />
    <replace file="${build.dir}/rpm/SPECS/specFile" token="# [[ installRpmFiles ]]" value="cp -rf ${package.dir}/${SHORT_NAME}-${VERSION_NUMBER_STRING}/* . ${line.separator}" />
    <copy file="resource/rpm/excludedFiles" tofile="${build.dir}/rpm/SOURCES/excludedFiles" />
    <replace file="${build.dir}/rpm/SOURCES/excludedFiles" token="# [[ excludedListFiles ]]" value="${excludedRPMFiles}" />
    <rpm specfile="specFile"
         topdir="${build.dir}/rpm"
         quiet="true">
         quiet="true"
         removeSpec="false">
    </rpm>
    <mkdir dir="${build.dir}/rpm/RPMS/noarch" />
    <copy todir="${package.dir}">
      <fileset dir="${build.dir}/rpm/RPMS/noarch">
        <include name="*.rpm" />
      </fileset>
    </copy>
  </target>
  <!-- Package the Directory Server for the DEB distribution. -->
  <target name="package-DEB"
          description="Package the Directory Server for DEB distribution.">
opends/resource/rpm/excludedFiles
New file
@@ -0,0 +1,26 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at
# trunk/opendj3/legal-notices/CDDLv1_0.txt
# or http://forgerock.org/license/CDDLv1.0.html.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opendj3/legal-notices/CDDLv1_0.txt.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#      Copyright 2013 ForgeRock AS
#
# [[ excludedListFiles ]]
opends/resource/rpm/files
New file
@@ -0,0 +1,26 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at
# trunk/opendj3/legal-notices/CDDLv1_0.txt
# or http://forgerock.org/license/CDDLv1.0.html.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opendj3/legal-notices/CDDLv1_0.txt.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#      Copyright 2013 ForgeRock AS
#
# [[ listFiles ]]
opends/resource/rpm/specFile
New file
@@ -0,0 +1,206 @@
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License").  You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at
# trunk/opendj3/legal-notices/CDDLv1_0.txt
# or http://forgerock.org/license/CDDLv1.0.html.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at
# trunk/opendj3/legal-notices/CDDLv1_0.txt.  If applicable,
# add the following below this CDDL HEADER, with the fields enclosed
# by brackets "[]" replaced with your own identifying information:
#      Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#      Copyright 2013 ForgeRock AS
#
%define _topdir [[ topDir ]]
%define _arch noarch
%define _prefix [[ prefix ]]
%define _pre [[ pre ]]
%define __os_install_post %{nil}
# =========================
# Header
# =========================
# Short Description
Summary: [[ shortName ]]
# Application Name
Name: [[ pkgName ]]
# Application Version
Version: [[ version ]]
# Packaging Revision
Release: [[ release ]]
# Software Licenced Under
License: CDDL
# RPM Group
Group: Applications/Network
# Link to Application web site
URL: [[ referenceURL ]]
# Distributing Organisation
Vendor: ForgeRock AS
# Build Architecture
BuildArch: noarch
Requires: jre >= 1.6
# Long Description
%Description
OpenDJ LDAP Server
OpenDJ is an LDAPv3 compliant directory service, developed for the Java
platform, providing a high performance, highly available and secure store
for the identities managed by enterprises. Its easy installation process,
combined with the power of the Java platform makes OpenDJ one of the
simplest and fastest directory servers to deploy and manage.
# =========================
# Prepare, Build, Install
# =========================
# %prep
# %build
%install
mkdir -p "$RPM_BUILD_ROOT%{_prefix}"
cd "$RPM_BUILD_ROOT%{_prefix}"
# [[ installRpmFiles ]]
# Remove the excluded files. They shouldn't be a part of this package.
/bin/grep -v '^#' "$RPM_SOURCE_DIR/excludedFiles" | while read excludedFiles
do
    rm -r "$RPM_BUILD_ROOT%{_prefix}$excludedFiles"
done
%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf "${RPM_BUILD_ROOT}"
# =========================
# Pre & Post Install
# =========================
# If the first argument to %pre is 1, the RPM operation is an initial
#  installation. If the argument to %pre is 2, the operation is an upgrade
#  from an existing version to a new one.
# Similarly, the arguments to a %post are 1 and 2 for a new installation
#  and upgrade, respectively. (%pre and %post aren't executed during
#  an uninstallation.)
# -------------------------
# Pre Install
%pre
if [ "$1" == "1" ]; then
    echo "Pre Install - initial install"
else if [ "$1" == "2" ] ; then
# Only if the instance has been configured
    if [ isInstanceConfigured ]
    then
        echo "Pre Install - upgrade install"
# If the server is running before upgrade, creates a file flag
        if [ -f "%{_prefix}"/logs/server.pid ]
        then
            touch "%{_prefix}"/logs/status
        fi
        "%{_prefix}"/bin/./stop-ds
        fi
    fi
fi
# -------------------------
# Post Install
%post
if [ "$1" == "1" ] ; then
    echo "Post Install - initial install"
else if [ "$1" == "2" ] ; then
    echo "Post Install - upgrade install"
# Only if the instance has been configured
    if [ isInstanceConfigured ]
    then
        "%{_prefix}"/./upgrade -n --acceptLicense
# Upgrade ok
        if [ "$?" == "0" ] ; then
# Checks the server status flag for restart.
            if [ -f "%{_prefix}"/logs/status ]
            then
                echo ""
                echo "Restarting server..."
                "%{_prefix}"/./bin/start-ds
                echo ""
                rm -f "%{_prefix}"/logs/status
            fi
        fi
# Upgrade fails, needs user interaction (eg. manual mode)
        if [ "$?" == "2" ] ; then
            exit "0"
        fi
    else
        echo "Instance is not configured. Upgrade aborted."
        exit -1
    fi
    fi
fi
# =========================
# Pre & Post Uninstall
# =========================
# If the first argument to %preun and %postun is 0, the action is
#  uninstallation.
# If the first argument to %preun and %postun is 1, the action is an upgrade.
# -------------------------
# Pre Uninstall
%preun
if [ "$1" == "0" ] ; then
    echo "Pre Uninstall - uninstall"
# Only if the instance has been configured
    if [ isInstanceConfigured ]
    then
    "%{_prefix}"/bin/./stop-ds
    fi
else if [ "$1" == "1" ] ; then
    echo "Pre Uninstall - upgrade uninstall"
    fi
fi
# -------------------------
# Post Uninstall
%postun
if [ "$1" == "0" ] ; then
    echo "Post Uninstall - uninstall"
    echo "OpenDJ successfully removed."
else if [ "$1" == "1" ] ; then
    echo "Post Uninstall - upgrade uninstall"
    fi
fi
# -------------------------
# Returns true/0 if the instance has been configured.
isInstanceConfigured() {
    if [ -f "%{_prefix}"/config/buildinfo ] && [ "$(ls -A "%{_prefix}"/config/archived-configs)" ]
    then
        return 0
    else
        return 1
    fi
}
# =========================
# Files section
# =========================
%files -f "%{_sourcedir}"/files
%defattr(-,root,root)
# [[ docsList ]]
# =========================
# Changelog
# =========================
%changelog
* Thu Jul 18 2013 ForgeRock
- Fixed the sections' order and added a new "clean" section.
- Added '%doc' section.
- Added '%changelog' at the end of the file.
- Added license to header's files.
opends/src/build-tools/org/opends/build/tools/GenerateRpm.java
File was deleted
opends/src/build-tools/org/opends/build/tools/ProcessFilesForPackages.java
New file
@@ -0,0 +1,262 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.build.tools;
import java.io.File;
import java.io.FileFilter;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
/**
 * A utility class for the packaging process. It is used by the build.xml to
 * perform the package construction.
 */
public class ProcessFilesForPackages extends Task
{
  /** The source directory name */
  private String sourceDirName;
  /** Files contained in the package */
  private final List<File> files = new LinkedList<File>();
  /** Files which should be excluded from the package */
  private final List<File> excludedFiles = new LinkedList<File>();
  /** Package documentation files */
  private final List<File> docFiles = new LinkedList<File>();
  /** The end-of-line character for this platform */
  private static String EOL = System.getProperty("line.separator");
  /**
   * Returns the source directory name.
   *
   * @return The source directory name.
   */
  public String getSourceDirName()
  {
    return sourceDirName.replaceAll(" ", "\\\\ ");
  }
  /**
   * Sets the source directory name.
   *
   * @param sourceDirName
   *          The source directory name.
   */
  public void setSourceDirName(String sourceDirName)
  {
    this.sourceDirName = sourceDirName;
  }
  @Override()
  public void execute()
  {
    try
    {
      // Process the filtering of the files contained in the given directory.
      filterFiles(new File(getSourceDirName()));
      // Sorts the list.
      Collections.sort(files);
      Collections.sort(docFiles);
      // Returns the properties which can be used fill data.
      getProject().setNewProperty("listRPMFiles", formatAsFileList(files));
      getProject().setNewProperty("listRPMDocFiles",
          formatAsDocList(docFiles));
      getProject().setNewProperty("excludedRPMFiles",
          formatAsExcludedList(excludedFiles));
    }
    catch (Exception e)
    {
      throw new BuildException(
          "An error occurs during filtering package files", e);
    }
  }
  /**
   * Formats the file list to be supported by RPM.
   *
   * @param fileList
   *          The list of files to be processed.
   * @return A string containing the list of files which should be excluded in
   *         the RPM source.
   */
  private String formatAsExcludedList(final List<File> fileList)
  {
    final StringBuilder sb = new StringBuilder();
    for (final File f : fileList)
    {
      sb.append(relativeToSourceDirName(f)).append(EOL);
    }
    return sb.toString();
  }
  /**
   * Formats the file list to be supported by RPM.
   *
   * @param fileList
   *          The list of files to be processed.
   * @return A string containing the list of files which can be included in the
   *         RPM source.
   */
  private String formatAsFileList(final List<File> fileList)
  {
    final StringBuilder sb = new StringBuilder();
    sb.append("%dir %{_prefix}").append(EOL);
    for (final File f : fileList)
    {
      if (f.isDirectory())
      {
        sb.append("%dir %{_prefix}");
      }
      else
      {
        sb.append("%{_prefix}");
      }
      sb.append(relativeToSourceDirName(f)).append(EOL);
    }
    return sb.toString();
  }
  /**
   * Formats the document list to be supported by RPM.
   *
   * @param fileList
   *          The list of files to be processed.
   * @return A string containing the formatted list doc.
   */
  private String formatAsDocList(final List<File> fileList)
  {
    final StringBuilder sb = new StringBuilder();
    for (final File f : fileList)
    {
      // FIXME If directory is mentioned, files are duplicated in doc directory
      // in us/share/opendj{version} and in the package install opt/opendj/
      if (!f.isDirectory())
      {
        sb.append("%doc $RPM_BUILD_ROOT%{_prefix}").append(
            relativeToSourceDirName(f));
        sb.append(EOL);
      }
    }
    return sb.toString();
  }
  /**
   * Sorts all the files contained in selected directory and fills the
   * appropriate lists.
   *
   * @param dir
   *          The directory where to analyze the files.
   * @throws Exception
   *           If an exception occurs during the process.
   */
  private void filterFiles(final File dir) throws Exception
  {
    final ExcludeFileFilter exFilter = new ExcludeFileFilter();
    final DocFileFilter docFilter = new DocFileFilter();
    for (final File f : dir.listFiles())
    {
      if (f.isDirectory())
      {
        filterFiles(f);
      }
      // Completes the excluded files list.
      if (exFilter.accept(f))
      {
        excludedFiles.add(f);
      }
      else
      {
        files.add(f);
      }
      // Completes the document file list.
      if (docFilter.accept(f))
      {
        docFiles.add(f);
      }
    }
  }
  /**
   * Returns the relative path to given source directory name.
   *
   * @param f
   *          The file we want the relative path.
   * @return A string representing the relative path to the given source
   *         directory name.
   */
  private String relativeToSourceDirName(File f)
  {
    return f.getAbsolutePath().replace(getSourceDirName(), "");
  }
  /**
   * A file filter which excludes all files that belong to other OS.
   */
  static final class ExcludeFileFilter implements FileFilter
  {
    /** {@inheritDoc} */
    public boolean accept(File file)
    {
      final String fileName = file.getName().toLowerCase();
      return (
          fileName.equals("bat")
          || fileName.endsWith(".app")
          || fileName.endsWith(".bat")
          || fileName.endsWith(".exe")
          || file.getAbsolutePath().contains(".app"));
    }
  }
  /**
   * A file filter which accepts only documentation files.
   */
  static final class DocFileFilter implements FileFilter
  {
    /** {@inheritDoc} */
    public boolean accept(File file)
    {
      final String fileName = file.getName().toLowerCase();
      if (file.isDirectory())
      {
        return fileName.equals("legal-notices");
      }
      return (
          !file.getAbsolutePath().contains("/template/")
          && !file.getAbsolutePath().contains("/legals/")
          && (fileName.endsWith(".doc")
          || fileName.endsWith(".txt")
          || fileName.contains("example-plugin")
          || fileName.equals("readme")
          || fileName.equals("opends.license")));
    }
  }
}
opends/src/build-tools/org/opends/build/tools/Utilities.java
@@ -153,5 +153,4 @@
    return buffer.toString();
  }
}