Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apache commons-configuration2 #315

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions agent/http_client_5/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<!-- Locations used for informational purposes only. -->
<locations>
<location displayName="Unspecified" name="unspecified"/>
<location displayName="San Diego\, CA" name="san_diego"/>
<location displayName="San Diego, CA" name="san_diego"/>
</locations>
<!-- mail configuration for notifications -->
<mail>
Expand Down Expand Up @@ -387,7 +387,7 @@ function toJsonObj(text) {

function toJsonString(jsonObj) {
try {
return JSON.stringify(jsonObj\, null\, '\t');
return JSON.stringify(jsonObj, null, '\t');
} catch(e) {
error("Error converting json to string json: " + e);
}
Expand Down Expand Up @@ -458,8 +458,8 @@ function getVariable(key) {
* @param value
* the value to set it to
*/
function setVariable(key\, value) {
ioBean.getInput("variables").addVariable(key\, value);
function setVariable(key, value) {
ioBean.getInput("variables").addVariable(key, value);
}

//######## Result functions ##########
Expand All @@ -468,7 +468,7 @@ function setVariable(key\, value) {
* jump to a group within the script with the specified name.
*
* @param groupName
* the name of the group to go to. if the group does not exist\, it
* the name of the group to go to. if the group does not exist, it
* skips to next script.
*/
function gotoGroup(groupName) {
Expand Down Expand Up @@ -517,7 +517,7 @@ function terminateUser() {
* sets the action in the output.
*/
function setAction(action) {
ioBean.setOutput("action"\, action);
ioBean.setOutput("action", action);
}

]]>
Expand Down
10 changes: 5 additions & 5 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
</dependency>

<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<groupId>org.apache.commons</groupId>
<artifactId>commons-configuration2</artifactId>
</dependency>

<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
* #L%
*/

import java.io.File;
import java.io.Serializable;
import java.io.*;
import java.net.URL;
import java.util.List;

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
import org.apache.commons.configuration.tree.ExpressionEngine;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.XMLConfiguration;
import org.apache.commons.configuration2.builder.ReloadingFileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.reloading.ReloadingController;
import org.apache.commons.configuration2.tree.ExpressionEngine;
import org.apache.commons.configuration2.tree.xpath.XPathExpressionEngine;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -40,20 +41,18 @@ public abstract class BaseCommonsXmlConfig implements Serializable {

private static final Logger LOG = LogManager.getLogger(BaseCommonsXmlConfig.class);

protected XMLConfiguration config;
protected XMLConfiguration XMLConfig;

protected File configFile;

/**
* Constructor pulls file out of the jar or reads from disk and sets up refresh policy.
*
* @param expressionEngine
* the expression engine to use. Null results in default expression engine
*
*/
protected void readConfig() {
try {
ExpressionEngine expressionEngine = new XPathExpressionEngine();
String configPath = getConfigName();
FileChangedReloadingStrategy reloadingStrategy = new FileChangedReloadingStrategy();

File dataDirConfigFile = new File(configPath);
// LOG.info("Reading settings from " + dataDirConfigFile.getAbsolutePath());
Expand All @@ -67,33 +66,38 @@ protected void readConfig() {
throw new RuntimeException("unable to load resource: " + configPath);
}

XMLConfiguration tmpConfig = new XMLConfiguration(configResourceUrl);
XMLConfiguration tmpConfig = new ReloadingFileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
.configure(new Parameters().xml().setURL(configResourceUrl))
.getConfiguration();

// Copy over a default configuration since none exists:
// Ensure data dir location exists:
if (dataDirConfigFile.getParentFile() != null && !dataDirConfigFile.getParentFile().exists()
&& !dataDirConfigFile.getParentFile().mkdirs()) {
throw new RuntimeException("could not create directories.");
}
tmpConfig.save(dataDirConfigFile);
tmpConfig.write(new FileWriter(dataDirConfigFile));
LOG.info("Saving settings file to " + dataDirConfigFile.getAbsolutePath());
}

if (dataDirConfigFile.exists()) {
config = new XMLConfiguration(dataDirConfigFile);
XMLConfig = new ReloadingFileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class)
.configure(new Parameters().xml().setFile(dataDirConfigFile))
.getConfiguration();
} else {
// extract from jar and write to
throw new IllegalStateException("Config file does not exist or cannot be created");
}
if (expressionEngine != null) {
config.setExpressionEngine(expressionEngine);
XMLConfig.setExpressionEngine(expressionEngine);
}
configFile = dataDirConfigFile;
// reload at most once per thirty seconds on configuration queries.
config.setReloadingStrategy(reloadingStrategy);
initConfig(config);
initConfig(XMLConfig);
} catch (ConfigurationException e) {
LOG.error("Error reading settings file: " + e, e);
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Expand All @@ -119,8 +123,7 @@ public static HierarchicalConfiguration getChildConfigurationAt(HierarchicalConf
* @return the config
*/
protected XMLConfiguration getConfig() {
checkReload();
return config;
return XMLConfig;
}

/**
Expand All @@ -138,25 +141,4 @@ protected XMLConfiguration getConfig() {
*/
protected abstract void initConfig(@Nonnull XMLConfiguration configuration);

/**
* checks if the config needs to be reloaded and calls initConfig on it. should be called if parsing of the config
* is needed.
*/
protected synchronized void checkReload() {
if (config == null) {
readConfig();
} else if (config.getReloadingStrategy().reloadingRequired()) {
config.reload();
initConfig(config);
config.getReloadingStrategy().reloadingPerformed();
}
}

/**
* checks if the config needs to be reloaded.
*/
public boolean needsReload() {
return (config == null || config.getReloadingStrategy().reloadingRequired());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* #L%
*/

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.lang3.StringUtils;

import com.intuit.tank.harness.AmazonUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.List;
import java.util.Set;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* #L%
*/

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

import com.intuit.tank.vm.api.enumerated.VMImageType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.List;
import java.util.stream.Collectors;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* InstanceDescription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* ProductConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* <logic-step> <insert-before></insert-before> <append-after></append-after> </logic-step>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* MailConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import jakarta.enterprise.context.ApplicationScoped;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.XMLConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.configuration2.XMLConfiguration;
import org.apache.commons.configuration2.tree.ImmutableNode;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -91,7 +92,6 @@ public MailMessageConfig() {
}

public MailMessage getMailMessage(String event) {
checkReload();
MailMessage mailMessage = messages.get(event);
if (mailMessage == null) {
mailMessage = messages.get(MailMessageConfig.DEFAULT);
Expand All @@ -100,22 +100,21 @@ public MailMessage getMailMessage(String event) {
}

public Collection<MailMessage> getAllMessages() {
checkReload();
return messages.values();
}

/**
* @return the footer
*/
public String getFooter() {
return config
return XMLConfig
.getString(
KEY_FOOTER,
"<p class=\"footer\">This message automatically generated by Tank (<a href=\"{tankBaseUrl}\">{tankBaseUrl}</a>). </p>");
}

public String getStyle() {
return config.getString(KEY_CSS, "");
return XMLConfig.getString(KEY_CSS, "");
}

/**
Expand All @@ -132,10 +131,9 @@ protected String getConfigName() {
@Override
protected void initConfig(XMLConfiguration configuration) {
messages.clear();
if (config != null) {
if (XMLConfig != null) {
String style = getStyle();
@SuppressWarnings("unchecked") List<HierarchicalConfiguration> msgConfigs = config
.configurationsAt(KEY_MESSAGE_NODE);
List<HierarchicalConfiguration<ImmutableNode>> msgConfigs = XMLConfig.configurationsAt(KEY_MESSAGE_NODE);
for (HierarchicalConfiguration msgConfig : msgConfigs) {
String event = msgConfig.getString(KEY_EVENT);
String subject = msgConfig.getString(KEY_SUBJECT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.intuit.tank.vm.settings;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* OidcSsoConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;

/**
* ProductConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import java.io.Serializable;
import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration.SubnodeConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -55,7 +54,7 @@ public String getReporterClass() {
String ret = DEFAULT_REPORTER;
if (config != null) {
try {
SubnodeConfiguration configurationAt = config.configurationAt(KEY_REPORTER);
HierarchicalConfiguration configurationAt = config.configurationAt(KEY_REPORTER);
String string = configurationAt.getString("");
if (StringUtils.isNotBlank(string)) {
ret = string;
Expand All @@ -76,7 +75,7 @@ public String getReaderClass() {
String ret = DEFAULT_READER;
if (config != null) {
try {
SubnodeConfiguration configurationAt = config.configurationAt(KEY_READER);
HierarchicalConfiguration configurationAt = config.configurationAt(KEY_READER);
String string = configurationAt.getString("");
if (StringUtils.isNotBlank(string)) {
ret = string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* #L%
*/

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.intuit.tank.vm.api.enumerated.VMRegion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import jakarta.annotation.Nonnull;

import org.apache.commons.configuration.HierarchicalConfiguration;
import org.apache.commons.configuration2.HierarchicalConfiguration;
import org.apache.commons.lang3.StringUtils;

public class SearchConfig {
Expand Down
Loading