private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) { if (this.environment == null) { return false; } String[] profileNames = StringUtils.trimArrayElements(StringUtils .commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE))); if (profileNames.length == 0) { return false; } for (int i = 0; i < profileNames.length; i++) { profileNames[i] = OptionHelper.substVars(profileNames[i], ic, this.context); } return this.environment.acceptsProfiles(Profiles.of(profileNames)); }
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) { ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.patterns.getProperty("logging.pattern.console", CONSOLE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext())); config.start(encoder); appender.setEncoder(encoder); config.appender("CONSOLE", appender); return appender; }
public String subst(String value) { if (value == null) { return null; } return OptionHelper.substVars(value, this, context); }
/** * @see #substVars(String, PropertyContainer, PropertyContainer) */ public static String substVars(String val, PropertyContainer pc1) { return substVars(val, pc1, null); }
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String logFile) { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.patterns.getProperty("logging.pattern.file", FILE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext())); appender.setEncoder(encoder); config.start(encoder); appender.setFile(logFile); setRollingPolicy(appender, config, logFile); config.appender("FILE", appender); return appender; }
conditionAttribute = OptionHelper.substVars(conditionAttribute, ic, context); PropertyEvalScriptBuilder pesb = new PropertyEvalScriptBuilder(ic); pesb.setContext(context);
/** * @see #substVars(String, PropertyContainer, PropertyContainer) * @param val string to be evaluated * @param pc1 property container * @return the substituted string */ public static String substVars(String val, PropertyContainer pc1) { return substVars(val, pc1, null); }
public String subst(String value) { if (value == null) { return null; } return OptionHelper.substVars(value, this, context); }
@Test public void testSubstVarsSystemProperties() { System.setProperty("v1", "if"); System.setProperty("v2", "works"); String result = OptionHelper.substVars(text, context); assertEquals(expected, result); System.clearProperty("v1"); System.clearProperty("v2"); }
@Test public void testUndefinedValues() { String withUndefinedValues = "${axyz}"; String result = OptionHelper.substVars(withUndefinedValues, context); assertEquals("axyz"+OptionHelper._IS_UNDEFINED, result); }
@Test public void jackrabbit_standalone() { String r = OptionHelper.substVars("${jackrabbit.log:-${repo:-jackrabbit}/log/jackrabbit.log}", context); assertEquals("jackrabbit/log/jackrabbit.log", r); }
@Test public void defaultValueReferencingAVariable() { context.putProperty("v1", "k1"); String result = OptionHelper.substVars("${undef:-${v1}}", context); assertEquals("k1", result); }
@Test public void trailingColon_LOGBACK_1140() { String prefix = "c:"; String suffix = "/tmp"; context.putProperty("var", prefix); String r = OptionHelper.substVars("${var}" + suffix, context); assertEquals(prefix + suffix, r); }
@Test public void replaceNewline() { String pattern = "%replace(A\nB){'\n', '\n\t'}"; String substPattern = OptionHelper.substVars(pattern, null, lc); assertEquals(pattern, substPattern); pl.setPattern(substPattern); pl.start(); StatusPrinter.print(lc); String val = pl.doLayout(makeLoggingEvent("", null)); assertEquals("A\n\tB", val); }
@Test(timeout = 1000) public void detectCircularReferences1() { context.putProperty("A", "${A}a"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${A} --> ${A}]"); OptionHelper.substVars("${A}", context); }
@Test(timeout = 1000) public void detectCircularReferences0() { context.putProperty("A", "${A}"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${A} --> ${A}]"); OptionHelper.substVars("${A}", context); }
@Test public void detectCircularReferences5() { context.putProperty("A", "${B} and ${C}"); context.putProperty("B", "${B1}"); context.putProperty("B1", "B1-value"); context.putProperty("C", "${C1}"); context.putProperty("C1", "here's the loop: ${A}"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${A} --> ${C} --> ${C1} --> ${A}]"); String result = OptionHelper.substVars("${A}", context); System.err.println(result); }
@Test(timeout = 1000) public void detectCircularReferences4() { context.putProperty("A", "${B}"); context.putProperty("B", "${C}"); context.putProperty("C", "${A}"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${C} --> ${A} --> ${B} --> ${C}]"); OptionHelper.substVars("${C} and ${A}", context); }
@Test(timeout = 1000) public void stubstVarsShouldNotGoIntoInfiniteLoop() { context.putProperty("v1", "if"); context.putProperty("v2", "${v3}"); context.putProperty("v3", "${v4}"); context.putProperty("v4", "${v2}c"); expectedException.expect(Exception.class); OptionHelper.substVars(text, context); }
@Test(timeout = 1000) public void detectCircularReferences3() { context.putProperty("A", "${B}"); context.putProperty("B", "${C}"); context.putProperty("C", "${A}"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${B} --> ${C} --> ${A} --> ${B}]"); OptionHelper.substVars("${B} ", context); }