james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r690766 - in /james/jsieve/trunk/src: main/java/org/apache/jsieve/ main/java/org/apache/jsieve/commands/extensions/ main/java/org/apache/jsieve/tests/ test/java/org/apache/jsieve/ test/java/org/apache/jsieve/junit/ test/java/org/apache/jsie...
Date Sun, 31 Aug 2008 19:29:58 GMT
Author: rdonkin
Date: Sun Aug 31 12:29:57 2008
New Revision: 690766

URL: http://svn.apache.org/viewvc?rev=690766&view=rev
Log:
JSIEVE-30 Inject Log rather than call singleton

Removed:
    james/jsieve/trunk/src/main/java/org/apache/jsieve/Logger.java
Modified:
    james/jsieve/trunk/src/main/java/org/apache/jsieve/BaseSieveContext.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/commands/extensions/Log.java
    james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java
    james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/SieveMailAdapter.java

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/BaseSieveContext.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/BaseSieveContext.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/BaseSieveContext.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/BaseSieveContext.java Sun Aug 31 12:29:57
2008
@@ -19,6 +19,7 @@
 
 package org.apache.jsieve;
 
+import org.apache.commons.logging.Log;
 import org.apache.jsieve.comparators.Comparator;
 import org.apache.jsieve.exception.LookupException;
 import org.apache.jsieve.tests.ExecutableTest;
@@ -36,15 +37,17 @@
     private final CommandManager commandManager;
     private final ComparatorManager comparatorManager;
     private final TestManager testManager;
+    private final Log log;
     
     public BaseSieveContext(final CommandManager commandManager, final ComparatorManager
comparatorManager,
-            final TestManager testManager) 
+            final TestManager testManager, final Log log) 
     {
         this.commandStateManager = new CommandStateManager();
         this.conditionManager = new ConditionManager();
         this.testManager = testManager;
         this.commandManager = commandManager;
         this.comparatorManager = comparatorManager;
+        this.log = log;
     }
     
     /**
@@ -64,6 +67,9 @@
      */
     public void setCoordinate(ScriptCoordinate coordinate) {
         this.coordinate = coordinate;
+        if (coordinate != null) {
+            coordinate.setLog(getLog());
+        }
     }
     
     public CommandStateManager getCommandStateManager()
@@ -90,4 +96,8 @@
     public ExecutableTest getExecutableTest(String name) throws LookupException {
         return testManager.newInstance(name);
     }
+
+    public Log getLog() {
+        return log;
+    }
 }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/Command.java Sun Aug 31 12:29:57 2008
@@ -144,7 +144,7 @@
      * @see org.apache.jsieve.Executable#execute(MailAdapter, SieveContext)
      */
     public Object execute(MailAdapter mail, SieveContext context) throws SieveException {
-        Log log = Logger.getLog();
+        Log log = context.getLog();
         if (log.isDebugEnabled()) {
             log.debug(toString());
             coordinate.debugDiagnostics(log);

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/ConfigurationManager.java Sun Aug 31
12:29:57 2008
@@ -27,6 +27,7 @@
 import java.util.Properties;
 
 import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.SAXException;
 
 /**
@@ -71,6 +72,10 @@
      */
     private Map fieldComparatorMap;
 
+    //TODO: Temporary fix to allow Logger to be deleted
+    //TODO: inject
+    public static final Log log = LogFactory.getLog(ConditionManager.class);
+    
     /**
      * Constructor for ConfigurationManager.
      * 
@@ -78,7 +83,6 @@
      */
     private ConfigurationManager() throws SieveConfigurationException {
         super();
-        Log log = Logger.getLog();
         try {
             parse();
         } catch (SAXException e) {

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/ScriptCoordinate.java Sun Aug 31 12:29:57
2008
@@ -37,6 +37,8 @@
     private final int endLineNumber;
 
     private final int endColumnNumber;
+    
+    private Log log;
 
     public ScriptCoordinate(final int startLineNumber,
             final int startColumnNumber, final int endLineNumber,
@@ -48,6 +50,15 @@
         this.endColumnNumber = endColumnNumber;
     }
 
+    
+    public Log getLog() {
+        return log;
+    }
+
+    public void setLog(Log logger) {
+        this.log = logger;
+    }
+
     /**
      * Gets the number of the column where the elements ends.
      * 
@@ -95,11 +106,12 @@
      *         position appended to the message, not null
      */
     public SyntaxException syntaxException(CharSequence message) {
-        final Log logger = Logger.getLog();
-        if (logger.isWarnEnabled()) {
-            logger.warn(message);
+        if (log != null) {
+            if (log.isWarnEnabled()) {
+                log.warn(message);
+            }
+            logDiagnosticsInfo(log);
         }
-        logDiagnosticsInfo(logger);
         final String fullMessage = addStartLineAndColumn(message);
         final SyntaxException result = new SyntaxException(fullMessage);
         return result;
@@ -116,11 +128,12 @@
      *         position appended to the message, not null
      */
     public CommandException commandException(CharSequence message) {
-        final Log logger = Logger.getLog();
-        if (logger.isWarnEnabled()) {
-            logger.warn(message);
+        if (log != null) {
+            if (log.isWarnEnabled()) {
+                log.warn(message);
+            }
+            logDiagnosticsInfo(log);
         }
-        logDiagnosticsInfo(logger);
         final String fullMessage = addStartLineAndColumn(message);
         final CommandException result = new CommandException(fullMessage);
         return result;

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveContext.java Sun Aug 31 12:29:57
2008
@@ -19,6 +19,7 @@
 
 package org.apache.jsieve;
 
+import org.apache.commons.logging.Log;
 import org.apache.jsieve.comparators.Comparator;
 import org.apache.jsieve.exception.LookupException;
 import org.apache.jsieve.tests.ExecutableTest;
@@ -57,4 +58,6 @@
     public abstract Comparator getComparator(String name) throws LookupException;
     //TODO: consider whether API can be consolidated
     public abstract ExecutableTest getExecutableTest(String name) throws LookupException;
+    
+    public abstract Log getLog();
 }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/SieveFactory.java Sun Aug 31 12:29:57
2008
@@ -91,14 +91,14 @@
             node.jjtAccept(visitor, null);
             return node;
         } catch (ParseException ex) {
-            Log log = Logger.getLog();
+            Log log = ConfigurationManager.log;
             if (log.isErrorEnabled())
                 log.error("Parse failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())
                 log.debug("Parse failed.", ex);
             throw ex;
         } catch (SieveException ex) {
-            Log log = Logger.getLog();
+            Log log = ConfigurationManager.log;
             if (log.isErrorEnabled())
                 log.error("Parse failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())
@@ -132,7 +132,8 @@
         final CommandManager commandManager = CommandManager.getInstance();
         final ComparatorManager comparatorManager = ComparatorManager.getInstance();
         final TestManager testManager = TestManager.getInstance();
-        SieveContext context = new BaseSieveContext(commandManager, comparatorManager, testManager);
+        final Log log = ConfigurationManager.log;
+        SieveContext context = new BaseSieveContext(commandManager, comparatorManager, testManager,
log);
         SieveParserVisitor visitor = new SieveParserVisitorImpl(context);
         try {
             // Evaluate the Nodes
@@ -141,7 +142,6 @@
         } catch (StopException ex) {
             // Stop is OK
         } catch (SieveException ex) {
-            Log log = Logger.getLog();
             if (log.isErrorEnabled())
                 log.error("Evaluation failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())
@@ -159,7 +159,6 @@
         try {
             mail.executeActions();
         } catch (SieveException ex) {
-            Log log = Logger.getLog();
             if (log.isErrorEnabled())
                 log.error("Evaluation failed. Reason: " + ex.getMessage());
             if (log.isDebugEnabled())

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/Test.java Sun Aug 31 12:29:57 2008
@@ -44,7 +44,7 @@
      * @see org.apache.jsieve.Executable#execute(MailAdapter, SieveContext)
      */
     public Object execute(MailAdapter mail, SieveContext context) throws SieveException {
-        Log log = Logger.getLog();
+        Log log = context.getLog();
         if (log.isDebugEnabled()) {
             log.debug(toString());
         }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/commands/extensions/Log.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/commands/extensions/Log.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/commands/extensions/Log.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/commands/extensions/Log.java Sun Aug
31 12:29:57 2008
@@ -24,7 +24,6 @@
 
 import org.apache.jsieve.Arguments;
 import org.apache.jsieve.Block;
-import org.apache.jsieve.Logger;
 import org.apache.jsieve.SieveContext;
 import org.apache.jsieve.StringListArgument;
 import org.apache.jsieve.TagArgument;
@@ -121,17 +120,17 @@
     protected void log(String logLevel, String message, SieveContext context)
             throws SyntaxException {
         if (logLevel.equals(INFO_TAG))
-            logInfo(message);
+            logInfo(message, context);
         else if (logLevel.equals(ERROR_TAG))
-            logError(message);
+            logError(message, context);
         else if (logLevel.equals(WARN_TAG))
-            logWarn(message);
+            logWarn(message, context);
         else if (logLevel.equals(DEBUG_TAG))
-            logDebug(message);
+            logDebug(message, context);
         else if (logLevel.equals(FATAL_TAG))
-            logFatal(message);
+            logFatal(message, context);
         else if (logLevel.equals(TRACE_TAG))
-            logTrace(message);
+            logTrace(message, context);
         else
             throw context.getCoordinate().syntaxException(
                     "Unsupported logging level: " + logLevel);
@@ -141,9 +140,10 @@
      * Method logFatal.
      * 
      * @param message
+     * @param sieveContext TODO
      */
-    protected void logFatal(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logFatal(String message, SieveContext sieveContext) {
+        org.apache.commons.logging.Log log = sieveContext.getLog();
         if (log.isFatalEnabled())
             log.fatal(message);
     }
@@ -152,9 +152,10 @@
      * Method logWarn.
      * 
      * @param message
+     * @param context TODO
      */
-    protected void logWarn(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logWarn(String message, SieveContext context) {
+        org.apache.commons.logging.Log log = context.getLog();
         if (log.isWarnEnabled())
             log.warn(message);
     }
@@ -163,9 +164,10 @@
      * Method logInfo.
      * 
      * @param message
+     * @param context TODO
      */
-    protected void logInfo(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logInfo(String message, SieveContext context) {
+        org.apache.commons.logging.Log log = context.getLog();
         if (log.isInfoEnabled())
             log.info(message);
     }
@@ -174,9 +176,10 @@
      * Method logDebug.
      * 
      * @param message
+     * @param context TODO
      */
-    protected void logDebug(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logDebug(String message, SieveContext context) {
+        org.apache.commons.logging.Log log = context.getLog();
         if (log.isDebugEnabled())
             log.debug(message);
     }
@@ -185,9 +188,10 @@
      * Method logTrace.
      * 
      * @param message
+     * @param context TODO
      */
-    protected void logTrace(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logTrace(String message, SieveContext context) {
+        org.apache.commons.logging.Log log = context.getLog();
         if (log.isTraceEnabled())
             log.trace(message);
     }
@@ -196,9 +200,10 @@
      * Method logError.
      * 
      * @param message
+     * @param context TODO
      */
-    protected void logError(String message) {
-        org.apache.commons.logging.Log log = Logger.getLog();
+    protected void logError(String message, SieveContext context) {
+        org.apache.commons.logging.Log log = context.getLog();
         if (log.isErrorEnabled())
             log.error(message);
     }

Modified: james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractTest.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractTest.java (original)
+++ james/jsieve/trunk/src/main/java/org/apache/jsieve/tests/AbstractTest.java Sun Aug 31
12:29:57 2008
@@ -21,7 +21,6 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.jsieve.Arguments;
-import org.apache.jsieve.Logger;
 import org.apache.jsieve.SieveContext;
 import org.apache.jsieve.exception.SieveException;
 import org.apache.jsieve.exception.SyntaxException;
@@ -95,7 +94,7 @@
     protected void validateArguments(Arguments arguments, SieveContext context)
             throws SieveException {
         if (!arguments.getArgumentList().isEmpty()) {
-            final Log logger = Logger.getLog();
+            final Log logger = context.getLog();
             if (logger.isWarnEnabled()) {
                 logger.warn("Unexpected arguments for " + getClass().getName());
             }

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
(original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/SieveParserVisitorImplQuoteTest.java
Sun Aug 31 12:29:57 2008
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.logging.LogFactory;
 import org.apache.jsieve.parser.generated.ASTstring;
 
 public class SieveParserVisitorImplQuoteTest extends TestCase {
@@ -35,7 +36,7 @@
     protected void setUp() throws Exception {
         super.setUp();
         visitor = new SieveParserVisitorImpl(new BaseSieveContext(CommandManager.getInstance(),
ComparatorManager.getInstance(),
-                TestManager.getInstance()));
+                TestManager.getInstance(), LogFactory.getLog(SieveParserVisitorImplQuoteTest.class)));
         data = new ArrayList();
         node = new ASTstring(100);
     }

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/AddressParseTest.java Sun Aug
31 12:29:57 2008
@@ -21,6 +21,7 @@
 
 import junit.framework.TestCase;
 
+import org.apache.commons.logging.LogFactory;
 import org.apache.jsieve.BaseSieveContext;
 import org.apache.jsieve.CommandManager;
 import org.apache.jsieve.ComparatorManager;
@@ -41,7 +42,8 @@
 
     protected void setUp() throws Exception {
         super.setUp();
-        context = new BaseSieveContext(CommandManager.getInstance(), ComparatorManager.getInstance(),
TestManager.getInstance());
+        context = new BaseSieveContext(CommandManager.getInstance(), ComparatorManager.getInstance(),
TestManager.getInstance(),
+                LogFactory.getLog(AddressParseTest.class));
         mail = (SieveMailAdapter) JUnitUtils.createMail();
         address = new OpenedAddress();
     }

Modified: james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/SieveMailAdapter.java
URL: http://svn.apache.org/viewvc/james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/SieveMailAdapter.java?rev=690766&r1=690765&r2=690766&view=diff
==============================================================================
--- james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/SieveMailAdapter.java (original)
+++ james/jsieve/trunk/src/test/java/org/apache/jsieve/junit/utils/SieveMailAdapter.java Sun
Aug 31 12:29:57 2008
@@ -35,7 +35,7 @@
 import javax.mail.internet.MimeMessage;
 
 import org.apache.commons.logging.Log;
-import org.apache.jsieve.Logger;
+import org.apache.commons.logging.LogFactory;
 import org.apache.jsieve.exception.SieveException;
 import org.apache.jsieve.mail.Action;
 import org.apache.jsieve.mail.MailAdapter;
@@ -53,7 +53,9 @@
  */
 public class SieveMailAdapter implements MailAdapter
 {
-    /*
+    private Log log = LogFactory.getLog(SieveMailAdapter.class);
+    
+    /**
      * The message being adapted.
      */ 
     private MimeMessage fieldMessage;
@@ -146,7 +148,6 @@
      */
     public void executeActions() throws SieveException
     {
-        Log log = Logger.getLog();
         boolean isDebugEnabled = log.isDebugEnabled();
         ListIterator actionsIter = getActionsIterator();
         while (actionsIter.hasNext())



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message