vmassol 01/11/16 14:09:54
Modified: build build-servletapi.xml build.xml
conf/sample/build/servlet22 build.properties.sample
build.xml
conf/sample/build/servlet23 build.properties.sample
build.xml
docs/framework/xdocs changes.xml
src/framework/share/org/apache/cactus AbstractTestCase.java
Added: src/framework/share/org/apache/cactus/util/log
LogAspect.java LogManagerAspect.java
Log:
now internally using aspectJ (still with Log4j) for logging entries and exits of
methods
Revision Changes Path
1.28 +26 -13 jakarta-cactus/build/build-servletapi.xml
Index: build-servletapi.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/build/build-servletapi.xml,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- build-servletapi.xml 2001/09/21 21:25:34 1.27
+++ build-servletapi.xml 2001/11/16 22:09:54 1.28
@@ -202,6 +202,13 @@
</classpath>
</taskdef>
+ <!-- AspectJ task definition -->
+ <taskdef name="ajc" classname="org.aspectj.tools.ant.taskdefs.Ajc" >
+ <classpath>
+ <pathelement path="${java.class.path}"/>
+ </classpath>
+ </taskdef>
+
</target>
<!--
@@ -236,9 +243,6 @@
<mkdir dir="${out.src.dir}"/>
- <!-- Copy all source files to destination dir. Apply the filters in
- order to replace the tokens for the copyright year and the
- version -->
<copy todir="${out.src.dir}" filtering="on">
<fileset dir="${src.java.share.dir}">
<patternset refid="all.src.files"/>
@@ -263,24 +267,26 @@
<mkdir dir="${out.classes.dir}"/>
+ <!-- Only run the ajc task if at least one of the source file has been
+ modified. -->
+ <uptodate property="ajc.notrequired" targetfile="${final.jar.name}">
+ <srcfiles dir="${out.src.dir}">
+ <patternset refid="all.src.files"/>
+ </srcfiles>
+ </uptodate>
+
</target>
<!-- Run the java compilation -->
- <target name="compile" depends="prepare-compile">
+ <target name="compile" depends="prepare-compile" unless="ajc.notrequired">
- <javac srcdir="${out.src.dir}"
+ <ajc srcdir="${out.src.dir}"
destdir="${out.classes.dir}"
- debug="${debug}"
deprecation="${deprecation}"
optimize="${optimize}">
- <!-- Exclude all files that are not .java source files -->
-
- <!-- All doc files -->
<exclude name="**/package.html"/>
<exclude name="**/overview.html"/>
-
- <!-- All conf files (including test files) -->
<exclude name="**/*.txt"/>
<exclude name="**/*.xml"/>
<exclude name="**/*.properties"/>
@@ -291,10 +297,11 @@
<pathelement location="${log4j.jar}"/>
<pathelement location="${httpclient.jar}"/>
<pathelement location="${junit.jar}"/>
+ <pathelement location="${aspectjrt.jar}"/>
<pathelement path="${java.class.path}"/>
</classpath>
- </javac>
+ </ajc>
<!-- Copies non java files that need to be in the classes directory -->
<copy todir="${out.classes.dir}">
@@ -543,7 +550,7 @@
of the sample application and will be exercised there
========================================================================
-->
- <target name="tests-unit" depends="compile">
+ <target name="tests-unit" depends="jar">
<junit printsummary="yes" haltonfailure="yes" fork="yes">
@@ -551,6 +558,7 @@
<pathelement location="${servlet.jar}"/>
<pathelement location="${httpunit.jar}"/>
<pathelement location="${httpclient.jar}"/>
+ <pathelement location="${aspectjrt.jar}"/>
<pathelement location="${out.classes.dir}"/>
<pathelement path="${junit.jar}"/>
<pathelement path="${java.class.path}"/>
@@ -593,6 +601,8 @@
<arg value="-Djunit.jar=${junit.jar}"/>
<arg value="-Dlog4j.jar=${log4j.jar}"/>
<arg value="-Dhttpclient.jar=${httpclient.jar}"/>
+ <arg value="-Daspectjrt.jar=${aspectjrt.jar}"/>
+ <arg value="-Dhttpunit.jar=${httpunit.jar}"/>
<!-- Pass all servlet engine properties -->
<arg line="${test22.args.list}"/>
@@ -627,6 +637,8 @@
<arg value="-Djunit.jar=${junit.jar}"/>
<arg value="-Dlog4j.jar=${log4j.jar}"/>
<arg value="-Dhttpclient.jar=${httpclient.jar}"/>
+ <arg value="-Daspectjrt.jar=${aspectjrt.jar}"/>
+ <arg value="-Dhttpunit.jar=${httpunit.jar}"/>
<!-- Pass all servlet engine properties -->
<arg line="${test23.args.list}"/>
@@ -676,6 +688,7 @@
<copy todir="${out.lib.dir}" file="${log4j.jar}"/>
<copy todir="${out.lib.dir}" file="${junit.jar}"/>
<copy todir="${out.lib.dir}" file="${httpclient.jar}"/>
+ <copy todir="${out.lib.dir}" file="${aspectjrt.jar}"/>
<!-- Copy the dist directory for the current Servlet API to the
dist.dir directory -->
1.30 +3 -0 jakarta-cactus/build/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/build/build.xml,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- build.xml 2001/09/25 10:12:18 1.29
+++ build.xml 2001/11/16 22:09:54 1.30
@@ -41,6 +41,9 @@
Required for bundling it in the distribution
(used in build-servletapi.xml).
+ aspectjrt.jar [REQUIRED] The path to the AspectJ runtime jar. It is
used by Cactus
+ for logging entries and exit of methods,
configuration checking, ...)
+
dist.dir [OPTIONAL] The directories where distributable
files will be copied with version number
postfixed. Required for the dist target only.
1.18 +3 -0
jakarta-cactus/conf/sample/build/servlet22/build.properties.sample
Index: build.properties.sample
===================================================================
RCS file:
/home/cvs/jakarta-cactus/conf/sample/build/servlet22/build.properties.sample,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- build.properties.sample 2001/11/16 19:45:43 1.17
+++ build.properties.sample 2001/11/16 22:09:54 1.18
@@ -15,6 +15,9 @@
# Commons HttpClient class (needed by Cactus)
httpclient.jar=../lib/httpclient.jar
+# AspectJ runtime jar (used by Cactus for logging, configuration checking, ...)
+aspectjrt.jar=../lib/aspectjrt.jar
+
# You have 2 options. Define a property named "log4j.jar" and point it to the
# log4j jar file. In that case, Cactus will generate log files (named
# cactus_server.log and cactus_client.log). the second option is not to define
1.10 +7 -0 jakarta-cactus/conf/sample/build/servlet22/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/conf/sample/build/servlet22/build.xml,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- build.xml 2001/09/15 12:40:41 1.9
+++ build.xml 2001/11/16 22:09:54 1.10
@@ -39,6 +39,13 @@
httpclient.jar [REQUIRED] The Commons HttpClient jar file
+ aspectjrt.jar [REQUIRED] The path to the AspectJ runtime jar. It is
used by Cactus
+ for logging entries and exit of methods,
configuration checking, ...)
+
+ httpunit.jar [REQUIRED] The path to the HttpUnit jar file.
+ Required for compiling and running the unit
+ tests.
+
cactus.ant.jar [REQUIRED] The path to the Cactus custom Ant
tasks jar file
1.17 +3 -0
jakarta-cactus/conf/sample/build/servlet23/build.properties.sample
Index: build.properties.sample
===================================================================
RCS file:
/home/cvs/jakarta-cactus/conf/sample/build/servlet23/build.properties.sample,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- build.properties.sample 2001/11/16 19:45:43 1.16
+++ build.properties.sample 2001/11/16 22:09:54 1.17
@@ -15,6 +15,9 @@
# Commons HttpClient class (needed by Cactus)
httpclient.jar=../lib/commons-httpclient.jar
+# AspectJ runtime jar (used by Cactus for logging, configuration checking, ...)
+aspectjrt.jar=../lib/aspectjrt.jar
+
# You have 2 options. Define a property named "log4j.jar" and point it to the
# log4j jar file. In that case, Cactus will generate log files (named
# cactus_server.log and cactus_client.log). the second option is not to define
1.8 +7 -0 jakarta-cactus/conf/sample/build/servlet23/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/conf/sample/build/servlet23/build.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- build.xml 2001/09/15 12:40:42 1.7
+++ build.xml 2001/11/16 22:09:54 1.8
@@ -36,6 +36,13 @@
httpclient.jar [REQUIRED] The Commons HttpClient jar file
+ aspectjrt.jar [REQUIRED] The path to the AspectJ runtime jar. It is
used by Cactus
+ for logging entries and exit of methods,
configuration checking, ...)
+
+ httpunit.jar [REQUIRED] The path to the HttpUnit jar file.
+ Required for compiling and running the unit
+ tests.
+
cactus.ant.jar [REQUIRED] The path to the Cactus custom Ant
tasks jar file
1.66 +8 -0 jakarta-cactus/docs/framework/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/docs/framework/xdocs/changes.xml,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- changes.xml 2001/11/16 19:17:06 1.65
+++ changes.xml 2001/11/16 22:09:54 1.66
@@ -128,6 +128,14 @@
<release version="1.3 in CVS">
<action dev="VMA" type="add">
+ Cactus is now using AspectJ under the hood to provide automatic logging of
entries and
+ exits of methods (for debugging purpose) and to automatically initialise
the logging
+ subsystem. The next step is to add automatic configuration checking using
AspectJ. The
+ consequence for end users if that they now need to include the
<code>aspectjrt.jar</code>
+ jar in their classpaths (both client side and server side). It is a small
jar (25ko) that
+ is packaged in the cactus distribution.
+ </action>
+ <action dev="VMA" type="add">
Added new java property "<code>cactus.config</code>" to specify location of
cactus
properties file (you pass it on the command line, ex:
"<code>java -Dcactus.property=conf/mycactus.properties</code>"). If not
specified,
1.16 +1 -21
jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java
Index: AbstractTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/AbstractTestCase.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- AbstractTestCase.java 2001/10/28 11:27:36 1.15
+++ AbstractTestCase.java 2001/11/16 22:09:54 1.16
@@ -72,7 +72,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: AbstractTestCase.java,v 1.15 2001/10/28 11:27:36 vmassol Exp $
+ * @version $Id: AbstractTestCase.java,v 1.16 2001/11/16 22:09:54 vmassol Exp $
*/
public abstract class AbstractTestCase extends TestCase
{
@@ -363,14 +363,6 @@
ClientConfigurationChecker.getInstance().checkHttpClient();
ClientConfigurationChecker.getInstance().checkLog4j();
- // Initialize the logging system. As this class is instanciated both
- // on the server side and on the client side, we need to differentiate
- // the logging initialisation. This method is only called on the client
- // side, so we instanciate the log for client side here.
- if (!LogService.getInstance().isInitialized()) {
- LogService.getInstance().init("/" + AbstractTestCase.LOG_CLIENT_CONFIG);
- }
-
// We make sure we reinitialize the logger with the name of the
// current class (that's why the logged instance is not static).
this.logger =
@@ -404,8 +396,6 @@
protected void runGenericTest(AbstractHttpClient theHttpClient)
throws Throwable
{
- logger.entry("runGenericTest(...)");
-
// Log the test name
logger.debug("Test case = " + currentTestMethod);
@@ -443,8 +433,6 @@
// Close the intput stream (just in the case the user has not done it
// in it's endXXX method (or if he has no endXXX method) ....
connection.getInputStream().close();
-
- logger.exit("runGenericTest");
}
// Methods below are only called by the Cactus redirector on the server
@@ -465,8 +453,6 @@
LogService.getInstance().getLog(this.getClass().getName());
}
- logger.entry("runBareServerTest()");
-
setUp();
try {
runServerTest();
@@ -474,8 +460,6 @@
finally {
tearDown();
}
-
- logger.exit("runBareServerTest");
}
/**
@@ -483,8 +467,6 @@
*/
protected void runServerTest() throws Throwable
{
- logger.entry("runServerTest()");
-
Method runMethod= null;
try {
// use getMethod to get all public inherited
@@ -514,8 +496,6 @@
e.fillInStackTrace();
throw e;
}
-
- logger.exit("runServerTest");
}
}
1.1
jakarta-cactus/src/framework/share/org/apache/cactus/util/log/LogAspect.java
Index: LogAspect.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.cactus.util.log;
import org.aspectj.lang.reflect.*;
import org.aspectj.lang.*;
/**
* Log every entry and exit of methods.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
* @version $Id: LogAspect.java,v 1.1 2001/11/16 22:09:54 vmassol Exp $
*/
public aspect LogAspect
{
/**
* Saves the call depth to print indented logs
* TODO: move this feature to the log4j wrapper so that all other log
* message in the code will benefit from it.
*/
protected static int callDepth = 0;
/**
* All calls that take longer than this default duration will have their
* exact duration logged. Value is in ms.
*/
protected static long duration = 200;
/**
* Log all entries and exits of methods. Also logs returned values when
* concerned method returns a value.
*/
Object around() :
!within(org.apache.cactus.util.log.*) && target(org.apache.cactus.*) &&
call(* *(..))
{
// The class name that uses the method that has been called
String targetName = thisJoinPoint.getTarget().getClass().getName();
// The class name that declares the method called (can be different from the
class that
// uses the method - think inheritance).
String declaringName =
thisJoinPoint.getSignature().getDeclaringType().getName();
Class declaringReturnType =
((MethodSignature)(thisJoinPoint.getSignature())).getReturnType();
Object result;
// Only log methods that belong to the cactus codebase
if (declaringName.startsWith("org.apache.cactus")) {
Log log = LogService.getInstance().getLog(targetName);
log.entry(getIndentations() + getFullSignature(thisJoinPoint));
callDepth++;
long entryTime = System.currentTimeMillis();
// Execute the method
result = proceed();
long exitTime = System.currentTimeMillis();
callDepth--;
// Compute the exit string to print
StringBuffer exitString = new StringBuffer(getIndentations());
exitString.append(getFullSignature(thisJoinPoint));
// Log the result if the declaring method is returning a value
if (declaringReturnType != Void.TYPE) {
exitString.append(" = [" + result + "]");
}
// Add the time if > default duration
if ((exitTime - entryTime) >= duration) {
exitString.append(", duration = " + (exitTime - entryTime) + "ms");
}
log.exit(exitString.toString());
} else {
result = proceed();
}
return result;
}
/**
* @return the full signature of a method
*/
private String getFullSignature(JoinPoint jp)
{
StringBuffer buffer = new StringBuffer();
buffer.append(jp.getSignature().getName());
buffer.append('(');
Object[] objs = jp.getArgs();
if (objs.length > 0) {
for (int i = 0; i < objs.length - 1; i++) {
buffer.append('[');
buffer.append(objs[i]);
buffer.append(']');
buffer.append(',');
buffer.append(' ');
}
buffer.append('[');
buffer.append(objs[objs.length - 1]);
buffer.append(']');
}
buffer.append(')');
return buffer.toString();
}
/**
* Prints spaces for log indentation.
*/
private static String getIndentations()
{
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < callDepth; i++) {
buffer.append(' ');
buffer.append(' ');
}
return buffer.toString();
}
}
1.1
jakarta-cactus/src/framework/share/org/apache/cactus/util/log/LogManagerAspect.java
Index: LogManagerAspect.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Cactus", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.cactus.util.log;
/**
* Manage logging subsystem initialisation.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
* @version $Id: LogManagerAspect.java,v 1.1 2001/11/16 22:09:54 vmassol Exp $
*/
public aspect LogManagerAspect dominates LogAspect
{
/**
* Name of properties file to initialize logging subsystem on the client
* side.
*/
public final static String LOG_CLIENT_CONFIG = "log_client.properties";
/**
* Initialise logging subsystem for the client side (client JVM)
*/
before() :
call(void *.runBare())
{
if (!LogService.getInstance().isInitialized()) {
LogService.getInstance().init("/" + LogManagerAspect.LOG_CLIENT_CONFIG);
}
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>