From 540304eeec51e9279675e2f3028d044f958f11a0 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Tue, 20 Mar 2007 15:39:55 +0000
Subject: [PATCH] Updated various issues related to the debug logging framework: - Fixed a bug where debug logs are not included on unit test failures. - Weaving is only enabled for targets that run unit-tests (all, weekly, nightly, test, testall, testwithcoverage, testallwithcoverage). - Weaving is disabled for test targets that use test.methods, test.classes, or test.packages properties to specify a smaller set of tests to run. - Weaving is now controlled by the WEAVE_ENABLED property on build instead of DEBUG_BUILD. Use this property to override the default weaving behaviour for any target. - Added package-info.java to the server.loggers.debug package. - Fixed a bug where logger is not enabled when configured with an enabled configuration. - Added supress warning annotations to debug advices. No more advice not matched warnings when weaving.

---
 opends/build.xml                                                               |   83 +++++++++++++++++++++++----
 opends/src/server/org/opends/server/loggers/debug/DebugConfiguration.java      |    2 
 opends/src/server/org/opends/server/loggers/debug/Tracer.java                  |   19 ++++++
 opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java |    1 
 opends/src/server/org/opends/server/loggers/Logger.java                        |    2 
 opends/src/server/org/opends/server/loggers/debug/package-info.java            |   42 ++++++++++++++
 opends/resource/DynamicConstants.java.stubs                                    |    6 ++
 7 files changed, 140 insertions(+), 15 deletions(-)

diff --git a/opends/build.xml b/opends/build.xml
index 2533079..ce9d877 100644
--- a/opends/build.xml
+++ b/opends/build.xml
@@ -187,14 +187,16 @@
       <format property="timestamp" pattern="yyyyMMddHHmmss" />
     </tstamp>
 
-    <condition property="DEBUG_BUILD" value="true">
+    <condition property="DEBUG_BUILD" value="false">
       <not>
         <isset property="DEBUG_BUILD" />
       </not>
     </condition>
 
-    <condition property="weave.enabled" value="true">
-      <equals arg1="${DEBUG_BUILD}" arg2="true" />
+    <condition property="WEAVE_ENABLED" value="false">
+      <not>
+        <isset property="WEAVE_ENABLED" />
+      </not>
     </condition>
 
     <condition property="MEM" value="128M">
@@ -247,7 +249,8 @@
       Be warned that the .stubs file references the following properties
       PRODUCT_NAME, SHORT_NAME, MAJOR_VERSION, MINOR_VERSION, POINT_VERSION,
       VERSION_QUALIFIER, FIX_IDS, timestamp, user.name, java.version,
-      java.vendor, java.vm.version, JVM_VENDOR, DEBUG_BUILD, REVISION_NUMBER
+      java.vendor, java.vm.version, JVM_VENDOR, DEBUG_BUILD, REVISION_NUMBER,
+      WEAVE_ENABLED
       If you change the name of any of those properties in this build.xml
       you'll need to relfect the same change in the .stubs file
     -->
@@ -383,7 +386,7 @@
 
   <!-- Compile the Directory Server source files. -->
   <target name="cleancompile"
-       depends="cleaninit,compilequicksetup,weave,compilestatuspanel"
+       depends="cleaninit,compilequicksetup,compile,compilestatuspanel"
        description="Recompile the Directory Server source files.">
   </target>
 
@@ -409,7 +412,15 @@
     </javac>
   </target>
 
-  <target name="weave" if="weave.enabled" depends="compile">
+  <target name="prepweave">
+    <condition property="weave.enabled" value="true">
+      <and>
+        <equals arg1="${WEAVE_ENABLED}" arg2="true" />
+      </and>
+    </condition>
+  </target>
+
+  <target name="weave" if="weave.enabled" depends="compile, prepweave">
     <taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
       <classpath>
         <pathelement location="${aj.lib.dir}/aspectjtools.jar" />
@@ -843,7 +854,7 @@
 
 
   <!-- Prepare to execute the Directory Server TestNG unit tests. -->
-  <target name="testinit" depends="buildtools,weave"
+  <target name="testinit" depends="buildtools,compile, weave"
          description="Prepare to execute the Directory Server TestNG unit tests.">
 
     <!-- If we are to perform coverage tests, then set that up. -->
@@ -1027,7 +1038,7 @@
 
   <!-- Execute the Directory Server TestNG unit tests in text mode. -->
   <target name="test"
-          depends="testinit,runtests"
+          depends="prepdefaulttest,testinit,runtests"
           description="Execute the Directory Server TestNG unit tests in text mode.  Set '-Dorg.opends.test.suppressOutput=false' to see the output from the unit tests.  Set '-Dtest.failures=true' to run only the tests that failed previously.">
   </target>
 
@@ -1057,7 +1068,7 @@
     <echo message="  -Dtest.failed=true"/>
     <echo message="      runs only the tests that failed last time"/>
     <echo message=""/>
-    <echo message="  -DDEBUG_BUILD=false" />
+    <echo message="  -DWEAVE_ENABLED=false" />
     <echo message="      builds the server without the debug logging facility." />
     <echo message="      No debug logging messages will be included on test failures." />
     <echo message=""/>
@@ -1073,17 +1084,17 @@
     <echo message="  -Dtest.packages=org.opends.server.api"/>
     <echo message="      for example runs only the tests in the api package"/>
     <echo message="      For multiple packages, separate them with a ',' and "/>
-    <echo message="      quote the entire value"/>
+    <echo message="      quote the entire value. Debug logging is disabled."/>
     <echo message=""/>
     <echo message="  -Dtest.classes=org.opends.server.types.TestDN"/>
     <echo message="      for example only runs the TestDN class"/>
     <echo message="      For multiple classes, separate them with a ',' and "/>
-    <echo message="      quote the entire value"/>
+    <echo message="      quote the entire value. Debug logging is disabled."/>
     <echo message=""/>
     <echo message="  -Dtest.methods=org.opends.server.types.TestDN.testGetRDN"/>
     <echo message="      for example only runs the testGetRDN method"/>
     <echo message="      For multiple methods, separate them with a ',' and "/>
-    <echo message="      quote the entire value"/>
+    <echo message="      quote the entire value. Debug logging is disabled."/>
     <echo message=""/>
     <echo message="  -Dtest.diff.srcpath=src/server/org/opends/server/core"/>
     <echo message="      for example includes only the classes in"/>
@@ -1206,7 +1217,53 @@
   </target>
 
   <target name="prepdefaultalltest">
-    <property name="test.groups" value="" />
+    <condition property="WEAVE_ENABLED" value="true">
+      <not>
+        <or>
+          <isset property="WEAVE_ENABLED" />
+          <isset property="test.groups" />
+          <isset property="test.packages" />
+          <isset property="test.classes" />
+          <isset property="test.methods" />
+        </or>
+      </not>
+    </condition>
+
+    <condition property="test.groups" value="">
+      <not>
+        <or>
+          <isset property="test.groups" />
+          <isset property="test.packages" />
+          <isset property="test.classes" />
+          <isset property="test.methods" />
+        </or>
+      </not>
+    </condition>
+  </target>
+
+  <target name="prepdefaulttest">
+   <condition property="WEAVE_ENABLED" value="true">
+      <not>
+        <or>
+          <isset property="WEAVE_ENABLED" />
+          <isset property="test.groups" />
+          <isset property="test.packages" />
+          <isset property="test.classes" />
+          <isset property="test.methods" />
+        </or>
+      </not>
+    </condition>
+
+    <condition property="test.groups" value="exclude=slow">
+      <not>
+        <or>
+          <isset property="test.groups" />
+          <isset property="test.packages" />
+          <isset property="test.classes" />
+          <isset property="test.methods" />
+        </or>
+      </not>
+    </condition>
   </target>
 
   <target name="testreport"
diff --git a/opends/resource/DynamicConstants.java.stubs b/opends/resource/DynamicConstants.java.stubs
index 7d29305..c254d3d 100644
--- a/opends/resource/DynamicConstants.java.stubs
+++ b/opends/resource/DynamicConstants.java.stubs
@@ -117,6 +117,12 @@
   public static final long REVISION_NUMBER = ${REVISION_NUMBER};
 
   /**
+   * Indicates wheater this build includes AspectJ weaving for the debug logging
+   * framework.
+   */
+  public static final boolean WEAVE_ENABLED = ${WEAVE_ENABLED};
+
+  /**
    * A compact version string for this product, suitable for use in path
    * names and similar cases.
    */
diff --git a/opends/src/server/org/opends/server/loggers/Logger.java b/opends/src/server/org/opends/server/loggers/Logger.java
index b30383f..c399cb8 100644
--- a/opends/src/server/org/opends/server/loggers/Logger.java
+++ b/opends/src/server/org/opends/server/loggers/Logger.java
@@ -113,5 +113,7 @@
       this.publishers = config.getPublishers();
       this.handler = config.getErrorHandler();
     }
+
+    enabled = newEnabled;
   }
 }
diff --git a/opends/src/server/org/opends/server/loggers/debug/DebugConfiguration.java b/opends/src/server/org/opends/server/loggers/debug/DebugConfiguration.java
index 5672d0c..cc51bc1 100644
--- a/opends/src/server/org/opends/server/loggers/debug/DebugConfiguration.java
+++ b/opends/src/server/org/opends/server/loggers/debug/DebugConfiguration.java
@@ -227,7 +227,7 @@
   {
 
     String enabledProp = System.getProperty(PROPERTY_DEBUG_ENABLED);
-    if(DynamicConstants.DEBUG_BUILD && (enabledProp != null &&
+    if(DynamicConstants.WEAVE_ENABLED && (enabledProp != null &&
         (enabledProp.startsWith("T") || enabledProp.startsWith("t") ||
             enabledProp.startsWith("Y") || enabledProp.startsWith("y"))))
     {
diff --git a/opends/src/server/org/opends/server/loggers/debug/Tracer.java b/opends/src/server/org/opends/server/loggers/debug/Tracer.java
index c3f5183..a6e672d 100644
--- a/opends/src/server/org/opends/server/loggers/debug/Tracer.java
+++ b/opends/src/server/org/opends/server/loggers/debug/Tracer.java
@@ -405,6 +405,7 @@
    * @param thisJoinPointStaticPart the JoinPoint reflection object.
    * @param ex the exception thrown.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @AfterThrowing(pointcut = "shouldTrace() && tracedThrownMethod()",
                  throwing = "ex")
   public void traceThrown(JoinPoint.StaticPart thisJoinPointStaticPart,
@@ -432,6 +433,7 @@
    * @param thisJoinPointStaticPart the JoinPoint reflection object.
    * @param msg message to format and log.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logVerboseMethod() && args(msg)")
   public void traceVerbose(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -462,6 +464,7 @@
    * @param msg message to format and log.
    * @param msgArgs arguments to place into the format string.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logVerboseMethod() && args(msg, msgArgs)")
   public void traceVerbose(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -491,6 +494,7 @@
    * @param thisJoinPointStaticPart the JoinPoint reflection object.
    * @param msg message to format and log.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logInfoMethod() && args(msg)")
   public void traceInfo(JoinPoint.EnclosingStaticPart
                           thisEnclosingJoinPointStaticPart,
@@ -521,6 +525,7 @@
    * @param msg message to format and log.
    * @param msgArgs arguments to place into the format string.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logInfoMethod() && args(msg, msgArgs)")
   public void traceInfo(JoinPoint.EnclosingStaticPart
                           thisEnclosingJoinPointStaticPart,
@@ -550,6 +555,7 @@
    * @param thisJoinPointStaticPart the JoinPoint reflection object.
    * @param msg message to format and log.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logWarningMethod() && args(msg)")
   public void traceWarning(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -581,6 +587,7 @@
    * @param msg message to format and log.
    * @param msgArgs arguments to place into the format string.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logWarningMethod() && args(msg, msgArgs)")
   public void traceWarning(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -610,6 +617,7 @@
    * @param thisJoinPointStaticPart the JoinPoint reflection object.
    * @param msg message to format and log.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logErrorMethod() && args(msg)")
   public void traceError(JoinPoint.EnclosingStaticPart
                            thisEnclosingJoinPointStaticPart,
@@ -641,6 +649,7 @@
    * @param msg message to format and log.
    * @param msgArgs arguments to place into the format string.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logErrorMethod() && args(msg, msgArgs)")
   public void traceError(JoinPoint.EnclosingStaticPart
                            thisEnclosingJoinPointStaticPart,
@@ -671,6 +680,7 @@
    * @param level the level of the log message.
    * @param msg message to format and log.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logMessageMethod() && args(level, msg)")
   public void traceMessage(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -701,6 +711,7 @@
    * @param msg message to format and log.
    * @param msgArgs arguments to place into the format string.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logMessageMethod() && args(level, msg, msgArgs)")
   public void traceMessage(JoinPoint.EnclosingStaticPart
                              thisEnclosingJoinPointStaticPart,
@@ -730,6 +741,7 @@
    * @param level the level of the log message.
    * @param ex the exception thrown.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logThrownMethod() && args(level, ex)")
   public void traceThrown(JoinPoint.EnclosingStaticPart
                             thisEnclosingJoinPointStaticPart,
@@ -759,6 +771,7 @@
    * @param level the level of the log message.
    * @param ex the exception caught.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logCaughtMethod() && args(level, ex)")
   public void traceCaught(JoinPoint.EnclosingStaticPart
                             thisEnclosingJoinPointStaticPart,
@@ -792,6 +805,7 @@
    * @param key  the key to dump.
    * @param data the data to dump.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logJEAccessMethod() && args(level, status, " +
       "database, txn, key, data)")
   public void traceJEAccess(JoinPoint.EnclosingStaticPart
@@ -877,6 +891,7 @@
    * @param level the level of the log message.
    * @param data the data to dump.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logDataMethod() && args(level, data)")
   public void traceData(JoinPoint.EnclosingStaticPart
                           thisEnclosingJoinPointStaticPart,
@@ -917,6 +932,7 @@
    * @param level the level of the log message.
    * @param element the protocol element to dump.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logProtocolElementMethod() && args(level, element)")
   public void traceProtocolElement(JoinPoint.EnclosingStaticPart
                                      thisEnclosingJoinPointStaticPart,
@@ -953,6 +969,7 @@
    * @param level the level of the log message.
    * @param buffer the data to dump.
    */
+  @SuppressAjWarnings({"adviceDidNotMatch"})
   @Around("shouldTrace() && logDataMethod() && args(level, buffer)")
   public void traceData(JoinPoint.EnclosingStaticPart
                           thisEnclosingJoinPointStaticPart,
@@ -1212,7 +1229,7 @@
   public @interface NoExitDebugTracing {}
 
   /**
-   * Methods annotated with @TraceThrown will not be weaved by AspectJ with
+   * Methods annotated with @TraceThrown will be weaved by AspectJ with
    * debug logging statements when an exception is thrown from the method.
    */
   public @interface TraceThrown {}
diff --git a/opends/src/server/org/opends/server/loggers/debug/package-info.java b/opends/src/server/org/opends/server/loggers/debug/package-info.java
new file mode 100644
index 0000000..f35a8aa
--- /dev/null
+++ b/opends/src/server/org/opends/server/loggers/debug/package-info.java
@@ -0,0 +1,42 @@
+/*
+ * 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/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * 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/opends/resource/legal-notices/OpenDS.LICENSE.  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
+ *
+ *
+ *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
+ */
+
+
+
+/**
+ * Contains implementation of the debug logger for the Directory Server.
+ * Static methods are included in the DebugLogger class to log a debug message.
+ * The debug logging framework uses AspectJ AOP to crosscut certain logging
+ * concerns across server code base at weave time during the build process. If
+ * the weaving step is skipped, the debug logging framework is disabled.
+ * The AspectJ aspect defined in the Tracer class is used to automatically trace
+ * method entry and exit events and generate the appropreate debug messages. It
+ * also keeps track of the source location of debug message calls so information
+ * about the class, method, line number, and threads are automatically included
+ * in the debug message.
+ */
+package org.opends.server.loggers.debug;
\ No newline at end of file
diff --git a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
index f9bd769..9fc5e7c 100644
--- a/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
+++ b/opends/tests/unit-tests-testng/src/server/org/opends/server/TestCaseUtils.java
@@ -153,6 +153,7 @@
     String debugTarget = System.getProperty("org.opends.test.debug.target");
     if(debugTarget != null)
     {
+      System.setProperty("org.opends.server.debug.enabled", "true");
       System.setProperty("org.opends.server.debug.target.1", debugTarget);
     }
     DebugConfiguration testDebugConfig =

--
Gitblit v1.10.0