Skip to content
Permalink
Browse files
JSIEVE-112 Replace commons-logging by slf4j
  • Loading branch information
Arsnael authored and chibenwa committed Sep 13, 2019
1 parent 2a729f0 commit 8e52fc171e8e7c0d267ed40a84c90aa415afbb17
Showing 23 changed files with 120 additions and 270 deletions.
@@ -52,8 +52,8 @@
<artifactId>apache-mime4j-core</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
@@ -19,8 +19,6 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;

/**
* Bean based implementation of context.
*/
@@ -38,17 +36,14 @@ public class BaseSieveContext extends SieveContext {

private final TestManager testManager;

private final Log log;

public BaseSieveContext(final CommandManager commandManager,
final ComparatorManager comparatorManager,
final TestManager testManager, final Log log) {
final TestManager testManager) {
this.commandStateManager = new CommandStateManager();
this.conditionManager = new ConditionManager();
this.testManager = testManager;
this.commandManager = commandManager;
this.comparatorManager = comparatorManager;
this.log = log;
}

/**
@@ -69,9 +64,6 @@ public ScriptCoordinate getCoordinate() {
@Override
public void setCoordinate(ScriptCoordinate coordinate) {
this.coordinate = coordinate;
if (coordinate != null) {
coordinate.setLog(getLog());
}
}

/**
@@ -98,14 +90,6 @@ public void setConditionManager(ConditionManager conditionManager) {
this.conditionManager = conditionManager;
}

/**
* @see SieveContext#getLog()
*/
@Override
public Log getLog() {
return log;
}

/**
* @see SieveContext#getComparatorManager()
*/
@@ -19,9 +19,10 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;
import org.apache.jsieve.exception.SieveException;
import org.apache.jsieve.mail.MailAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* <p>
@@ -31,6 +32,7 @@
* <code>command = identifier arguments ( ";" / block )</code>
*/
public class Command implements Executable {
private static final Logger LOGGER = LoggerFactory.getLogger(Command.class);

/** The name of this Command */
private String fieldName;
@@ -143,13 +145,9 @@ protected void setBlock(Block block) {
/**
* @see org.apache.jsieve.Executable#execute(MailAdapter, SieveContext)
*/
public Object execute(MailAdapter mail, SieveContext context)
throws SieveException {
Log log = context.getLog();
if (log.isDebugEnabled()) {
log.debug(toString());
coordinate.debugDiagnostics(log);
}
public Object execute(MailAdapter mail, SieveContext context) throws SieveException {
LOGGER.debug(toString());
coordinate.debugDiagnostics();
// commands are executed after the parsing phase
// recursively from the top level block
// so need to use the coordinate recorded from the parse
@@ -19,17 +19,17 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

/**
* <p>
* <code>ConfigurationManager</code> parses the XML statements
@@ -97,9 +97,7 @@ public class ConfigurationManager {
*/
private int initialConcurrencyLevel = DEFAULT_INITIAL_CONCURRENCY_LEVEL;

private static final Log LOG = LogFactory.getLog("org.apache.jsieve");

private Log log = LOG;
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationManager.class);

/**
* Constructor for ConfigurationManager.
@@ -111,12 +109,10 @@ public ConfigurationManager() throws SieveConfigurationException {
try {
parse();
} catch (SAXException e) {
if (log.isErrorEnabled())
log.error("Exception processing Configuration: ", e);
LOGGER.error("Exception processing Configuration: ", e);
throw new SieveConfigurationException(e);
} catch (IOException e) {
if (log.isErrorEnabled())
log.error("Exception processing Configuration: ", e);
LOGGER.error("Exception processing Configuration: ", e);
throw new SieveConfigurationException(e);
}
}
@@ -284,16 +280,8 @@ public TestManager getTestManager() {
return new TestManagerImpl(fieldTestMap);
}

public Log getLog() {
return log;
}

public void setLog(Log log) {
this.log = log;
}

public SieveFactory build() {
return new SieveFactory(getCommandManager(), getComparatorManager(),
getTestManager(), getLog());
getTestManager());
}
}
@@ -19,16 +19,18 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;
import org.apache.jsieve.exception.CommandException;
import org.apache.jsieve.exception.SyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Specifies the positional extent of an element within the script being
* executed. In other words, this gives the line and column at which the elment
* starts and at which it ends.
*/
public final class ScriptCoordinate {
private static final Logger LOGGER = LoggerFactory.getLogger(ScriptCoordinate.class);

private final int startLineNumber;

@@ -38,8 +40,6 @@ public final class ScriptCoordinate {

private final int endColumnNumber;

private Log log;

public ScriptCoordinate(final int startLineNumber,
final int startColumnNumber, final int endLineNumber,
final int endColumnNumber) {
@@ -50,14 +50,6 @@ public ScriptCoordinate(final int startLineNumber,
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.
*
@@ -99,18 +91,14 @@ public int getStartLineNumber() {
* of the script position. The message should end with a full stop.
*
* @param message
* <code>CharSequence</code> containing the base message, not
* <code>String</code> containing the base message, not
* null
* @return <code>SyntaxException</code> with details of the script
* position appended to the message, not null
*/
public SyntaxException syntaxException(CharSequence message) {
if (log != null) {
if (log.isWarnEnabled()) {
log.warn(message);
}
logDiagnosticsInfo(log);
}
public SyntaxException syntaxException(String message) {
LOGGER.warn(message);
logDiagnosticsInfo();
final String fullMessage = addStartLineAndColumn(message);
return new SyntaxException(fullMessage);
}
@@ -120,18 +108,14 @@ public SyntaxException syntaxException(CharSequence message) {
* of the script position. The message should end with a full stop.
*
* @param message
* <code>CharSequence</code> containing the base message, not
* <code>String</code> containing the base message, not
* null
* @return <code>CommandException</code> with details of the script
* position appended to the message, not null
*/
public CommandException commandException(CharSequence message) {
if (log != null) {
if (log.isWarnEnabled()) {
log.warn(message);
}
logDiagnosticsInfo(log);
}
public CommandException commandException(String message) {
LOGGER.warn(message);
logDiagnosticsInfo();
final String fullMessage = addStartLineAndColumn(message);
return new CommandException(fullMessage);
}
@@ -162,31 +146,17 @@ public String addStartLineAndColumn(CharSequence message) {

/**
* Logs diagnotic information about the script coordinate.
*
* @param logger
* <code>Log</code>, not null
*/
public void logDiagnosticsInfo(Log logger) {
if (logger.isInfoEnabled()) {
logger.info("Expression starts line " + startLineNumber
+ " column " + startColumnNumber);
logger.info("Expression ends line " + endLineNumber + " column "
+ endColumnNumber);
}
public void logDiagnosticsInfo() {
LOGGER.info("Expression starts line {} column {}", startLineNumber, startColumnNumber);
LOGGER.info("Expression ends line {} column {}", endLineNumber, endColumnNumber);
}

/**
* Logs diagnotic information about the script coordinate.
*
* @param logger
* <code>Log</code>, not null
*/
public void debugDiagnostics(Log logger) {
if (logger.isDebugEnabled()) {
logger.debug("Expression starts line " + startLineNumber
+ " column " + startColumnNumber);
logger.debug("Expression ends line " + endLineNumber + " column "
+ endColumnNumber);
}
public void debugDiagnostics() {
LOGGER.debug("Expression starts line {} column {}", startLineNumber, startColumnNumber);
LOGGER.debug("Expression ends line {} column {}", endLineNumber, endColumnNumber);
}
}
@@ -19,8 +19,6 @@

package org.apache.jsieve;

import org.apache.commons.logging.Log;

/**
* Context for sieve operations.
*
@@ -77,10 +75,4 @@ public abstract class SieveContext {
* @return test manager, not null
*/
public abstract TestManager getTestManager();

/**
* Gets the log.
* @return log, not null
*/
public abstract Log getLog();
}

0 comments on commit 8e52fc1

Please sign in to comment.