public void addProperties(Properties props) { if (props == null) { return; } Iterator i = props.keySet().iterator(); while (i.hasNext()) { String key = (String) i.next(); context.putProperty(key, props.getProperty(key)); } }
private LoggerContext configureLogging(final String workerName, final String logDirectory) throws EngineException { final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory(); if (iLoggerFactory instanceof Context) { final Context context = (Context) iLoggerFactory; final LoggerContext result = (LoggerContext) iLoggerFactory; final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); context.putProperty("WORKER_NAME", workerName); context.putProperty("LOG_DIRECTORY", logDirectory); try { configurator.doConfigure(GrinderProcess.class.getResource("/logback-worker.xml")); } catch (final JoranException e) { throw new EngineException("Could not initialise logger", e); } return result; } else { m_terminalLogger.warn("Logback not found; grinder log configuration will be ignored.\n" + "Consider adding logback-classic to the start of the CLASSPATH."); return null; } }
static public void setProperty(InterpretationContext ic, String key, String value, Scope scope) { switch (scope) { case LOCAL: ic.addSubstitutionProperty(key, value); break; case CONTEXT: ic.getContext().putProperty(key, value); break; case SYSTEM: OptionHelper.setSystemProperty(ic, key, value); } }
private void configureLogging() { File logDirectory = getHome().getLogDirectory(); String level = "INFO"; if (getCommonProperties().getPropertyBoolean(PROP_COMMON_VERBOSE)) { level = "TRACE"; } if (isSilentMode()) { level = "ERROR"; } final Context context = (Context) LoggerFactory.getILoggerFactory(); final JoranConfigurator configurator = new JoranConfigurator(); configurator.setContext(context); context.putProperty("LOG_LEVEL", level); context.putProperty("LOG_DIRECTORY", logDirectory.getAbsolutePath()); try { configurator.doConfigure(getClass().getResource("/logback-agent.xml")); } catch (JoranException e) { LOGGER.error("Error while configuring logger", e); } }
/** * Add the local host's name as a property */ public void addHostNameAsProperty() { try { String localhostName = getLocalHostName(); context.putProperty(CoreConstants.HOSTNAME_KEY, localhostName); } catch (UnknownHostException e) { addError("Failed to get local hostname", e); } catch (SocketException e) { addError("Failed to get local hostname", e); } catch (SecurityException e) { addError("Failed to get local hostname", e); } }
/** * Add the local host's name as a property */ public void addHostNameAsProperty() { context.putProperty(CoreConstants.HOSTNAME_KEY, "localhost"); }
@Test public void testSubstVarsTwoLevelsDeep() { context.putProperty("v1", "if"); context.putProperty("v2", "${v3}"); context.putProperty("v3", "${v4}"); context.putProperty("v4", "works"); String result = OptionHelper.substVars(text, context); assertEquals(expected, result); }
@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); }
/** * Instantiates an layout of the given class and sets its name. * */ public void begin(InterpretationContext ec, String name, Attributes attributes) { String str = "Hello "+attributes.getValue("name")+"."; ec.getContext().putProperty(PROPERTY_KEY, str); }
@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); }
@Test(timeout = 1000) public void detectCircularReferences2() { 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 [${A} --> ${B} --> ${C} --> ${A}]"); OptionHelper.substVars("${A}", context); }
@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 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 testSubstVarsWithDefault() { context.putProperty("v1", "if"); String textWithDefault = "Testing ${v1} variable substitution ${v2:-toto}"; String resultWithDefault = "Testing if variable substitution toto"; String result = OptionHelper.substVars(textWithDefault, context); assertEquals(resultWithDefault, result); }
@Test public void defaultValueReferencingAVariable() { context.putProperty("v1", "k1"); String result = OptionHelper.substVars("${undef:-${v1}}", context); assertEquals("k1", result); }
@Test public void testLoadFileWithPrerequisiteSubsitution() { context.putProperty("STEM", CoreTestConstants.TEST_DIR_PREFIX + "input/joran"); atts.setValue("file", "${STEM}/propertyActionTest.properties"); propertyAction.begin(ec, null, atts); assertEquals("tata", ec.getProperty("v1")); assertEquals("toto", ec.getProperty("v2")); }
@Test public void nameValuePairWithPrerequisiteSubsitution() { context.putProperty("w", "wor"); atts.setValue("name", "v1"); atts.setValue("value", "${w}k"); propertyAction.begin(ec, null, atts); assertEquals("work", ec.getProperty("v1")); }
@Test public void detectCircularReferencesInDefault() { context.putProperty("A", "${B:-${A}}"); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Circular variable reference detected while parsing input [${A} --> ${B} --> ${A}]"); OptionHelper.substVars("${A}", context); }
@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); }