Skip to content

Commit

Permalink
deprecated OptionHelper.isNullOrEmpty method and replaced by OptionH…
Browse files Browse the repository at this point in the history
…elper.isNullOrEmptyOrAllSpaces

Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Feb 2, 2024
1 parent 5a36133 commit 5782d29
Show file tree
Hide file tree
Showing 35 changed files with 78 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void handle(ModelInterpretationContext mic, Model model) {
}


if (!(OptionHelper.isNullOrEmpty(debugAttrib) || debugAttrib.equalsIgnoreCase(FALSE.toString())
if (!(OptionHelper.isNullOrEmptyOrAllSpaces(debugAttrib) || debugAttrib.equalsIgnoreCase(FALSE.toString())
|| debugAttrib.equalsIgnoreCase(NULL_STR))) {
StatusListenerConfigHelper.addOnConsoleListenerInstance(context, new OnConsoleStatusListener());
}
Expand All @@ -87,7 +87,7 @@ public void handle(ModelInterpretationContext mic, Model model) {

protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) {
String scanStr = mic.subst(configurationModel.getScanStr());
if (!OptionHelper.isNullOrEmpty(scanStr) && !"false".equalsIgnoreCase(scanStr)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) {
addInfo("Skipping ReconfigureOnChangeTask registration");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@
*/
package ch.qos.logback.classic.model.processor;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.ReconfigureOnChangeTask;
import ch.qos.logback.classic.model.ConfigurationModel;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.processor.ModelHandlerBase;
import ch.qos.logback.core.model.processor.ModelHandlerException;
import ch.qos.logback.core.model.processor.ModelInterpretationContext;
import ch.qos.logback.core.spi.ConfigurationEvent;
import ch.qos.logback.core.status.OnConsoleStatusListener;
import ch.qos.logback.core.util.ContextUtil;
import ch.qos.logback.core.util.Duration;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusListenerConfigHelper;

import java.net.URL;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

import static ch.qos.logback.core.model.ModelConstants.DEBUG_SYSTEM_PROPERTY_KEY;
import static ch.qos.logback.core.model.ModelConstants.NULL_STR;
import static java.lang.Boolean.FALSE;

/**
* This is a subclass of {@link ConfigurationModelHandler} offering configuration reloading support.
*
Expand All @@ -57,7 +47,7 @@ static public ModelHandlerBase makeInstance2(Context context, ModelInterpretatio

protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationModel configurationModel) {
String scanStr = mic.subst(configurationModel.getScanStr());
if (!OptionHelper.isNullOrEmpty(scanStr) && !"false".equalsIgnoreCase(scanStr)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanStr) && !"false".equalsIgnoreCase(scanStr)) {

ScheduledExecutorService scheduledExecutorService = context.getScheduledExecutorService();
URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(context);
Expand Down Expand Up @@ -94,7 +84,7 @@ protected void processScanAttrib(ModelInterpretationContext mic, ConfigurationMo
private Duration getDurationOfScanPeriodAttribute(String scanPeriodAttrib, Duration defaultDuration) {
Duration duration = null;

if (!OptionHelper.isNullOrEmpty(scanPeriodAttrib)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(scanPeriodAttrib)) {
try {
duration = Duration.valueOf(scanPeriodAttrib);
} catch (IllegalStateException | IllegalArgumentException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
LoggerContextListenerModel lclModel = (LoggerContextListenerModel) model;

String className = lclModel.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addError("Empty class name for LoggerContextListener");
inError = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
logger = loggerContext.getLogger(finalLoggerName);

String levelStr = mic.subst(loggerModel.getLevel());
if (!OptionHelper.isNullOrEmpty(levelStr)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) {
if (JoranConstants.INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
if(Logger.ROOT_LOGGER_NAME.equalsIgnoreCase(finalLoggerName)) {
addError(ErrorCodes.ROOT_LEVEL_CANNOT_BE_SET_TO_NULL);
Expand All @@ -61,7 +61,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
}

String additivityStr = mic.subst(loggerModel.getAdditivity());
if (!OptionHelper.isNullOrEmpty(additivityStr)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(additivityStr)) {
boolean additive = OptionHelper.toBoolean(additivityStr, true);
addInfo("Setting additivity of logger [" + finalLoggerName + "] to " + additive);
logger.setAdditive(additive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
ReceiverModel receiverModel = (ReceiverModel) model;
String className = receiverModel.getClassName();

if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addError("Missing class name for receiver. ");
inError = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);

String levelStr = mic.subst(rootLoggerModel.getLevel());
if (!OptionHelper.isNullOrEmpty(levelStr)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) {
Level level = Level.toLevel(levelStr);
addInfo("Setting level of ROOT logger to " + level);
root.setLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ boolean isDisabledByConfiguration(ServletContext ctx) {
disableAttributeStr = (String) disableAttribute;
}

if (OptionHelper.isNullOrEmpty(disableAttributeStr)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(disableAttributeStr)) {
disableAttributeStr = OptionHelper.getSystemProperty(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY);
}

if (OptionHelper.isNullOrEmpty(disableAttributeStr)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(disableAttributeStr)) {
disableAttributeStr = OptionHelper.getEnv(DISABLE_SERVLET_CONTAINER_INITIALIZER_KEY);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public String getDiscriminatingValue(ILoggingEvent event) {
@Override
public void start() {
int errors = 0;
if (OptionHelper.isNullOrEmpty(key)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(key)) {
errors++;
addError("The \"Key\" property must be set");
}
if (OptionHelper.isNullOrEmpty(defaultValue)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(defaultValue)) {
errors++;
addError("The \"DefaultValue\" property must be set");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private String extractThreadName(Thread aThread) {
return CoreConstants.NA;
}
String threadName = aThread.getName();
if (threadName != null)
if (threadName != null && !threadName.isEmpty())
return threadName;
Long virtualThreadId = getVirtualThreadId(aThread);
if (virtualThreadId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public void begin(SaxEventInterpretationContext ec, String localName, Attributes
String conversionWord = attributes.getValue(JoranConstants.CONVERSION_WORD_ATTRIBUTE);
String converterClass = attributes.getValue(JoranConstants.CONVERTER_CLASS_ATTRIBUTE);

if (OptionHelper.isNullOrEmpty(conversionWord)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(conversionWord)) {
inError = true;
errorMsg = "No 'conversionWord' attribute in <conversionRule>";
addError(errorMsg);

return;
}

if (OptionHelper.isNullOrEmpty(converterClass)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(converterClass)) {
inError = true;
errorMsg = "No 'converterClass' attribute in <conversionRule>";
ec.addError(errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ private boolean checkAttributes(Attributes attributes) {

int count = 0;

if (!OptionHelper.isNullOrEmpty(fileAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(fileAttribute)) {
count++;
}
if (!OptionHelper.isNullOrEmpty(urlAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(urlAttribute)) {
count++;
}
if (!OptionHelper.isNullOrEmpty(resourceAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(resourceAttribute)) {
count++;
}

Expand Down Expand Up @@ -210,17 +210,17 @@ URL getInputURL(SaxEventInterpretationContext ec, Attributes attributes) {
String urlAttribute = attributes.getValue(URL_ATTR);
String resourceAttribute = attributes.getValue(RESOURCE_ATTR);

if (!OptionHelper.isNullOrEmpty(fileAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(fileAttribute)) {
this.attributeInUse = ec.subst(fileAttribute);
return filePathAsURL(attributeInUse);
}

if (!OptionHelper.isNullOrEmpty(urlAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(urlAttribute)) {
this.attributeInUse = ec.subst(urlAttribute);
return attributeToURL(attributeInUse);
}

if (!OptionHelper.isNullOrEmpty(resourceAttribute)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(resourceAttribute)) {
this.attributeInUse = ec.subst(resourceAttribute);
return resourceAsURL(attributeInUse);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public void begin(SaxEventInterpretationContext ec, String localName, Attributes
String pattern = attributes.getValue(Action.PATTERN_ATTRIBUTE);
String actionClass = attributes.getValue(Action.ACTION_CLASS_ATTRIBUTE);

if (OptionHelper.isNullOrEmpty(pattern)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(pattern)) {
inError = true;
errorMsg = "No 'pattern' attribute in <newRule>";
addError(errorMsg);
return;
}

if (OptionHelper.isNullOrEmpty(actionClass)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(actionClass)) {
inError = true;
errorMsg = "No 'actionClass' attribute in <newRule>";
addError(errorMsg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public PreconditionValidator validateRefAttribute() {

public PreconditionValidator generic(String attributeName) {
String attributeValue = attributes.getValue(attributeName);
if (OptionHelper.isNullOrEmpty(attributeValue)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(attributeValue)) {
addError("Missing attribute [" + attributeName + "] in element [" + tag + "] near line "
+ Action.getLineNumber(intercon));
this.valid = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class StatusListenerAction extends BaseModelAction {
protected boolean validPreconditions(SaxEventInterpretationContext interpretationContext, String name,
Attributes attributes) {
String className = attributes.getValue(CLASS_ATTRIBUTE);
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addError("Missing class name for statusListener. Near [" + name + "] line "
+ getLineNumber(interpretationContext));
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ protected boolean validPreconditions(SaxEventInterpretationContext interpretatio
Attributes attributes) {
boolean valid = true;
String keyStr = attributes.getValue(KEY_ATTRIBUTE);
if (OptionHelper.isNullOrEmpty(keyStr)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(keyStr)) {
addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty");
valid = false;
}
String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE);
if (OptionHelper.isNullOrEmpty(datePatternStr)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(datePatternStr)) {
addError("Attribute named [" + DATE_PATTERN_ATTRIBUTE + "] cannot be empty");
valid = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ public void handle(ModelInterpretationContext interpretationContext, Model model

scope = ActionUtil.stringToScope(scopeStr);

if (OptionHelper.isNullOrEmpty(propertyName)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(propertyName)) {
addError("Missing property name for property definer. Near [" + model.getTag() + "] line "
+ model.getLineNumber());
inError = true;
}

// read property definer class name
String className = defineModel.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addError("Missing class name for property definer. Near [" + model.getTag() + "] line "
+ model.getLineNumber());
inError = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public void handle(ModelInterpretationContext intercon, Model model) throws Mode
EventEvaluatorModel eem = (EventEvaluatorModel) model;

String className = eem.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
String defaultClassName = defaultClassName(intercon, eem);
if (OptionHelper.isNullOrEmpty(defaultClassName)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(defaultClassName)) {
inError = true;
addError("Mandatory \"" + CLASS_ATTRIBUTE + "\" attribute missing for <evaluator>");
addError("No default classname could be found.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void doComplex(ModelInterpretationContext interpretationContext, Componen
Class<?> componentClass = null;
try {

if (!OptionHelper.isNullOrEmpty(fqcn)) {
if (!OptionHelper.isNullOrEmptyOrAllSpaces(fqcn)) {
componentClass = Loader.loadClass(fqcn, context);
} else {
// guess class name via implicit rules
Expand All @@ -146,7 +146,7 @@ public void doComplex(ModelInterpretationContext interpretationContext, Componen
return;
}

if (OptionHelper.isNullOrEmpty(fqcn)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(fqcn)) {
addInfo("Assuming default type [" + componentClass.getName() + "] for [" + componentModel.getTag()
+ "] property");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void handle(ModelInterpretationContext intercon, Model model) throws Mode
ImportModel importModel = (ImportModel) model;

String className = importModel.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addWarn("Empty className not allowed");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand

String envEntryValue;

if (OptionHelper.isNullOrEmpty(envEntryName)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(envEntryName)) {
addError("[" + InsertFromJNDIModel.ENV_ENTRY_NAME_ATTR + "] missing");
errorCount++;
}

if (OptionHelper.isNullOrEmpty(asKey)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(asKey)) {
addError("[" + InsertFromJNDIModel.AS_ATTR + "] missing");
errorCount++;
}
Expand All @@ -57,7 +57,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand
try {
javax.naming.Context ctx = JNDIUtil.getInitialContext();
envEntryValue = JNDIUtil.lookupString(ctx, envEntryName);
if (OptionHelper.isNullOrEmpty(envEntryValue)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(envEntryValue)) {
addError("[" + envEntryName + "] has null or empty value");
} else {
addInfo("Setting variable [" + asKey + "] to [" + envEntryValue + "] in [" + scope + "] scope");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import ch.qos.logback.core.model.Model;
import ch.qos.logback.core.model.ModelUtil;
import ch.qos.logback.core.model.PropertyModel;
import ch.qos.logback.core.pattern.util.RegularEscapeUtil;
import ch.qos.logback.core.util.Loader;
import ch.qos.logback.core.util.OptionHelper;

Expand Down Expand Up @@ -93,8 +92,8 @@ boolean checkFileAttributeSanity(PropertyModel propertyModel) {
String value = propertyModel.getValue();
String resource = propertyModel.getResource();

return !(OptionHelper.isNullOrEmpty(file)) && (OptionHelper.isNullOrEmpty(name)
&& OptionHelper.isNullOrEmpty(value) && OptionHelper.isNullOrEmpty(resource));
return !(OptionHelper.isNullOrEmptyOrAllSpaces(file)) && (OptionHelper.isNullOrEmptyOrAllSpaces(name)
&& OptionHelper.isNullOrEmptyOrAllSpaces(value) && OptionHelper.isNullOrEmptyOrAllSpaces(resource));
}

boolean checkResourceAttributeSanity(PropertyModel propertyModel) {
Expand All @@ -103,17 +102,17 @@ boolean checkResourceAttributeSanity(PropertyModel propertyModel) {
String value = propertyModel.getValue();
String resource = propertyModel.getResource();

return !(OptionHelper.isNullOrEmpty(resource)) && (OptionHelper.isNullOrEmpty(name)
&& OptionHelper.isNullOrEmpty(value) && OptionHelper.isNullOrEmpty(file));
return !(OptionHelper.isNullOrEmptyOrAllSpaces(resource)) && (OptionHelper.isNullOrEmptyOrAllSpaces(name)
&& OptionHelper.isNullOrEmptyOrAllSpaces(value) && OptionHelper.isNullOrEmptyOrAllSpaces(file));
}

boolean checkValueNameAttributesSanity(PropertyModel propertyModel) {
String file = propertyModel.getFile();
String name = propertyModel.getName();
String value = propertyModel.getValue();
String resource = propertyModel.getResource();
return (!(OptionHelper.isNullOrEmpty(name) || OptionHelper.isNullOrEmpty(value))
&& (OptionHelper.isNullOrEmpty(file) && OptionHelper.isNullOrEmpty(resource)));
return (!(OptionHelper.isNullOrEmptyOrAllSpaces(name) || OptionHelper.isNullOrEmptyOrAllSpaces(value))
&& (OptionHelper.isNullOrEmptyOrAllSpaces(file) && OptionHelper.isNullOrEmptyOrAllSpaces(resource)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void handle(ModelInterpretationContext mic, Model model) throws ModelHand

SequenceNumberGeneratorModel sequenceNumberGeneratorModel = (SequenceNumberGeneratorModel) model;
String className = sequenceNumberGeneratorModel.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
addWarn("Missing className. This should have been caught earlier.");
inError = true;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void handle(ModelInterpretationContext mic, Model model) {
ShutdownHookModel shutdownHookModel = (ShutdownHookModel) model;

String className = shutdownHookModel.getClassName();
if (OptionHelper.isNullOrEmpty(className)) {
if (OptionHelper.isNullOrEmptyOrAllSpaces(className)) {
className = DEFAULT_SHUTDOWN_HOOK_CLASSNAME;
addInfo("Assuming className [" + className + "]");
} else {
Expand Down
Loading

0 comments on commit 5782d29

Please sign in to comment.