From 71543ba27dd6b7addc25a5e3f19018e7debd1bb1 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 01 Mar 2013 09:52:32 +0000
Subject: [PATCH] OPENDJ-777 ldapcompare should exit with different values w.r.t comparison is successful or not

---
 opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java         |   12 ++----
 opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java |   25 +++++++-----
 opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java         |   20 +++++-----
 opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java           |   14 ++-----
 4 files changed, 33 insertions(+), 38 deletions(-)

diff --git a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java
index 4294e84..98e0b0b 100755
--- a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java
+++ b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/ConsoleApplication.java
@@ -22,7 +22,7 @@
  *
  *
  *      Copyright 2008-2009 Sun Microsystems, Inc.
- *      Portions copyright 2011-2012 ForgeRock AS
+ *      Portions copyright 2011-2013 ForgeRock AS
  *      Portions copyright 2011 Nemanja Lukić
  */
 package com.forgerock.opendj.ldap.tools;
@@ -67,17 +67,22 @@
     }
 
     /**
-     * Closes the provided {@code Closeable} if it is not {@code null}.
+     * Closes the provided {@code Closeable}s if they are not {@code null}.
      *
-     * @param closeable
-     *            The closeable to be closed.
+     * @param closeables
+     *          The closeables to be closed.
      */
-    final void closeIfNotNull(Closeable closeable) {
-        if (closeable != null) {
-            try {
-                closeable.close();
-            } catch (Exception ignored) {
-                // Do nothing.
+    final void closeIfNotNull(Closeable... closeables) {
+        if (closeables == null) {
+            return;
+        }
+        for (Closeable closeable : closeables) {
+            if (closeable != null) {
+                try {
+                    closeable.close();
+                } catch (Exception ignored) {
+                    // Do nothing.
+                }
             }
         }
     }
diff --git a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
index bb22123..31e5567 100644
--- a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
+++ b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFDiff.java
@@ -21,7 +21,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2012 ForgeRock AS
+ *      Copyright 2012-2013 ForgeRock AS
  */
 
 package com.forgerock.opendj.ldap.tools;
@@ -60,7 +60,6 @@
      * @param args
      *            The command-line arguments provided to this program.
      */
-
     public static void main(final String[] args) {
         final int retCode = new LDIFDiff().run(args);
         System.exit(filterExitCode(retCode));
@@ -109,7 +108,7 @@
             // If we should just display usage or version information,
             // then print it and exit.
             if (argParser.usageOrVersionDisplayed()) {
-                return 0;
+                return ResultCode.SUCCESS.intValue();
             }
         } catch (final ArgumentException ae) {
             final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
@@ -200,13 +199,8 @@
             }
             return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue();
         } finally {
-            closeIfNotNull(sourceReader);
-            closeIfNotNull(targetReader);
-            closeIfNotNull(outputWriter);
-
-            closeIfNotNull(sourceInputStream);
-            closeIfNotNull(targetInputStream);
-            closeIfNotNull(outputStream);
+            closeIfNotNull(sourceReader, targetReader, outputWriter);
+            closeIfNotNull(sourceInputStream, targetInputStream, outputStream);
         }
 
         return ResultCode.SUCCESS.intValue();
diff --git a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
index a4ac2dc..e3fe2f6 100644
--- a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
+++ b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFModify.java
@@ -21,7 +21,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2012 ForgeRock AS
+ *      Copyright 2012-2013 ForgeRock AS
  */
 
 package com.forgerock.opendj.ldap.tools;
@@ -68,7 +68,6 @@
      * @param args
      *            The command-line arguments provided to this program.
      */
-
     public static void main(final String[] args) {
         final int retCode = new LDIFModify().run(args);
         System.exit(filterExitCode(retCode));
@@ -124,7 +123,7 @@
             // If we should just display usage or version information,
             // then print it and exit.
             if (argParser.usageOrVersionDisplayed()) {
-                return 0;
+                return ResultCode.SUCCESS.intValue();
             }
         } catch (final ArgumentException ae) {
             final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
@@ -209,6 +208,7 @@
             outputWriter = new LDIFEntryWriter(outputStream);
 
             final RejectedChangeRecordListener listener = new RejectedChangeRecordListener() {
+                @Override
                 public Entry handleDuplicateEntry(final AddRequest change, final Entry existingEntry)
                         throws DecodeException {
                     try {
@@ -220,6 +220,7 @@
                     return change;
                 }
 
+                @Override
                 public Entry handleDuplicateEntry(final ModifyDNRequest change,
                         final Entry existingEntry, final Entry renamedEntry) throws DecodeException {
                     try {
@@ -231,6 +232,7 @@
                     return renamedEntry;
                 }
 
+                @Override
                 public void handleRejectedChangeRecord(final AddRequest change,
                         final LocalizableMessage reason) throws DecodeException {
                     try {
@@ -241,6 +243,7 @@
                     }
                 }
 
+                @Override
                 public void handleRejectedChangeRecord(final DeleteRequest change,
                         final LocalizableMessage reason) throws DecodeException {
                     try {
@@ -251,6 +254,7 @@
                     }
                 }
 
+                @Override
                 public void handleRejectedChangeRecord(final ModifyDNRequest change,
                         final LocalizableMessage reason) throws DecodeException {
                     try {
@@ -261,6 +265,7 @@
                     }
                 }
 
+                @Override
                 public void handleRejectedChangeRecord(final ModifyRequest change,
                         final LocalizableMessage reason) throws DecodeException {
                     try {
@@ -290,13 +295,8 @@
             }
             return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue();
         } finally {
-            closeIfNotNull(sourceReader);
-            closeIfNotNull(changesReader);
-            closeIfNotNull(outputWriter);
-
-            closeIfNotNull(sourceInputStream);
-            closeIfNotNull(changesInputStream);
-            closeIfNotNull(outputStream);
+            closeIfNotNull(sourceReader, changesReader, outputWriter);
+            closeIfNotNull(sourceInputStream, changesInputStream, outputStream);
         }
 
         return ResultCode.SUCCESS.intValue();
diff --git a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
index f5bfca9..edfacb8 100644
--- a/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
+++ b/opendj-sdk/opendj3/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/LDIFSearch.java
@@ -21,7 +21,7 @@
  * CDDL HEADER END
  *
  *
- *      Copyright 2012 ForgeRock AS
+ *      Copyright 2012-2013 ForgeRock AS
  */
 
 package com.forgerock.opendj.ldap.tools;
@@ -66,7 +66,6 @@
      * @param args
      *            The command-line arguments provided to this program.
      */
-
     public static void main(final String[] args) {
         final int retCode = new LDIFSearch().run(args);
         System.exit(filterExitCode(retCode));
@@ -163,7 +162,7 @@
             // If we should just display usage or version information,
             // then print it and exit.
             if (argParser.usageOrVersionDisplayed()) {
-                return 0;
+                return ResultCode.SUCCESS.intValue();
             }
         } catch (final ArgumentException ae) {
             final LocalizableMessage message = ERR_ERROR_PARSING_ARGS.get(ae.getMessage());
@@ -300,11 +299,8 @@
             }
             return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue();
         } finally {
-            closeIfNotNull(sourceReader);
-            closeIfNotNull(outputWriter);
-
-            closeIfNotNull(sourceInputStream);
-            closeIfNotNull(outputStream);
+            closeIfNotNull(sourceReader, outputWriter);
+            closeIfNotNull(sourceInputStream, outputStream);
         }
 
         return ResultCode.SUCCESS.intValue();

--
Gitblit v1.10.0