net.maizegenetics.plugindef.ParameterCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tassel Show documentation
Show all versions of tassel Show documentation
TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage
disequilibrium.
The newest version!
package net.maizegenetics.plugindef;
import net.maizegenetics.util.Utils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.io.BufferedReader;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
/**
* This class is for storing a cache of parameters retrieved from a {@link java.util.Properties} file that is available
* to all plugins on the command line. This is used when run_pipeline.pl -configParameters config.txt... is used.
*
* config.txt example entries as follow... First five are using by GetDBConnectionPlugin -config config.txt but that
* should be refactored to individual PluginParameters. Then entry example would be GetDBConnectionPlugin.DBType=sqlite
* KinshipPlugin.method=TYPE is the standard. PLUGIN_NAME.COMMAND_LINE_NAME=VALUE
*
* host=localHost user=sqlite password=sqlite DB=/tempFileDir/outputDir/phgTestDB.db DBtype=sqlite
* KinshipPlugin.method=Normalized_IBS
*
* @author Terry Casstevens Created January 05, 2018
*/
public class ParameterCache {
private static final Logger myLogger = LogManager.getLogger(ParameterCache.class);
private static Properties CACHE = null;
private ParameterCache() {
}
/**
* Loads the parameter cache with the values in the given {@link java.util.Properties} file.
*
* @param filename file name
*/
public static void load(String filename) {
if (filename == null || filename.trim().isEmpty()) {
CACHE = null;
return;
}
myLogger.info("load: loading parameter cache with: " + filename);
CACHE = new Properties();
try (BufferedReader reader = Utils.getBufferedReader(filename)) {
CACHE.load(reader);
CACHE.put("configFile", filename);
} catch (Exception e) {
CACHE = null;
myLogger.debug(e.getMessage(), e);
throw new IllegalArgumentException("ParameterCache: load: problem reading properties file: " + filename + "\n" + e.getMessage());
}
for (String key : CACHE.stringPropertyNames()) {
if (key.toLowerCase().contains("password") || key.toLowerCase().contains("passwd")) {
myLogger.info("ParameterCache: key: " + key + " value: ********");
} else {
myLogger.info("ParameterCache: key: " + key + " value: " + CACHE.getProperty(key));
}
}
verify(filename);
}
/**
* Verifies specified parameters exist on given plugin
*/
private static void verify(String filename) {
for (Map.Entry