use of org.apache.commons.configuration2.PropertiesConfiguration in project winery by eclipse.
the class CsarImporter method importNamespacePrefixes.
/**
* Import namespace prefixes. This is kind of a quick hack. TODO: during the import, the prefixes should be
* extracted using JAXB and stored in the NamespacesResource
*
* @param rootPath the root path of the extracted CSAR
*/
private void importNamespacePrefixes(Path rootPath) {
NamespaceManager namespaceManager = targetRepository.getNamespaceManager();
Path properties = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_PROPERTIES);
Path json = rootPath.resolve(CsarExporter.PATH_TO_NAMESPACES_JSON);
if (Files.exists(properties) || Files.exists(json)) {
NamespaceManager localNamespaceManager;
if (Files.exists(properties)) {
PropertiesConfiguration pconf = new PropertiesConfiguration();
try (final BufferedReader propertyReader = Files.newBufferedReader(properties)) {
pconf.read(propertyReader);
localNamespaceManager = new ConfigurationBasedNamespaceManager(pconf);
} catch (IOException | ConfigurationException e) {
CsarImporter.LOGGER.debug(e.getMessage(), e);
return;
}
} else {
localNamespaceManager = new JsonBasedNamespaceManager(json.toFile());
}
for (String s : localNamespaceManager.getAllNamespaces().keySet()) {
boolean addToStorage = false;
String namespace = s;
if (namespaceManager.hasPermanentProperties(namespace)) {
String storedPrefix = namespaceManager.getPrefix(namespace);
// QUICK HACK to check whether the prefix is a generated one
// We assume we know the internal generation routine
Matcher m = CsarImporter.GENERATED_PREFIX_PATTERN.matcher(storedPrefix);
if (m.matches()) {
// the stored prefix is a generated one
// replace it by the one stored in the exported properties
addToStorage = true;
}
} else {
addToStorage = true;
}
if (addToStorage) {
String prefix = localNamespaceManager.getPrefix(namespace);
namespaceManager.setNamespaceProperties(namespace, new NamespaceProperties(namespace, prefix));
}
}
}
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.
the class JanusGraphFactory method getLocalConfiguration.
/**
* Load a properties file containing a JanusGraph graph configuration.
* <p>
* <ol>
* <li>Load the file contents into a {@link org.apache.commons.configuration2.PropertiesConfiguration}</li>
* <li>For each key that points to a configuration object that is either a directory
* or local file, check
* whether the associated value is a non-null, non-absolute path. If so,
* then prepend the absolute path of the parent directory of the provided configuration {@code file}.
* This has the effect of making non-absolute backend
* paths relative to the config file's directory rather than the JVM's
* working directory.
* <li>Return the {@link ReadConfiguration} for the prepared configuration file</li>
* </ol>
* <p>
*
* @param file A properties file to load
* @return A configuration derived from {@code file}
*/
private static ReadConfiguration getLocalConfiguration(File file) {
Preconditions.checkNotNull(file);
Preconditions.checkArgument(file.exists() && file.isFile() && file.canRead(), "Need to specify a readable configuration file, but was given: %s", file.toString());
try {
PropertiesConfiguration configuration = ConfigurationUtil.loadPropertiesConfig(file);
final File tmpParent = file.getParentFile();
final File configParent;
if (null == tmpParent) {
/*
* null usually means we were given a JanusGraph config file path
* string like "foo.properties" that refers to the current
* working directory of the process.
*/
configParent = new File(System.getProperty("user.dir"));
} else {
configParent = tmpParent;
}
Preconditions.checkNotNull(configParent);
Preconditions.checkArgument(configParent.isDirectory());
// TODO this mangling logic is a relic from the hardcoded string days; it should be deleted and rewritten as a setting on ConfigOption
final Pattern p = Pattern.compile("(" + Pattern.quote(STORAGE_NS.getName()) + "\\..*" + "(" + Pattern.quote(STORAGE_DIRECTORY.getName()) + "|" + Pattern.quote(STORAGE_CONF_FILE.getName()) + ")" + "|" + Pattern.quote(INDEX_NS.getName()) + "\\..*" + "(" + Pattern.quote(INDEX_DIRECTORY.getName()) + "|" + Pattern.quote(INDEX_CONF_FILE.getName()) + ")" + ")");
final List<String> keysToMangle = StreamSupport.stream(Spliterators.spliteratorUnknownSize(configuration.getKeys(), 0), false).filter(key -> null != key && p.matcher(key).matches()).collect(Collectors.toList());
for (String k : keysToMangle) {
Preconditions.checkNotNull(k);
final String s = configuration.getString(k);
Preconditions.checkArgument(StringUtils.isNotBlank(s), "Invalid Configuration: key %s has null empty value", k);
configuration.setProperty(k, getAbsolutePath(configParent, s));
}
return new CommonsConfiguration(configuration);
} catch (ConfigurationException e) {
throw new IllegalArgumentException("Could not load configuration at: " + file, e);
}
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.
the class ConfigurationUtil method loadPropertiesConfig.
private static PropertiesConfiguration loadPropertiesConfig(PropertiesBuilderParameters params, boolean setCommaDelimiterHandler) throws ConfigurationException {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class);
PropertiesBuilderParameters newParams = params;
if (setCommaDelimiterHandler) {
newParams = newParams.setListDelimiterHandler(COMMA_DELIMITER_HANDLER);
}
return builder.configure(newParams).getConfiguration();
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.
the class HBaseSnapshotInputFormatIT method getGraph.
protected Graph getGraph() throws IOException, ConfigurationException {
final PropertiesConfiguration config = ConfigurationUtil.loadPropertiesConfig("target/test-classes/hbase-read-snapshot.properties", false);
Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
baseOutDir.toFile().mkdirs();
String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
config.setProperty("gremlin.hadoop.outputLocation", outDir);
// Set the hbase.rootdir property. This is needed by HBaseSnapshotInputFormat.
config.setProperty("janusgraphmr.ioformat.conf.storage.hbase.ext.hbase.rootdir", hBaseContainer.getHBaseRootDir().toString());
return GraphFactory.open(config);
}
use of org.apache.commons.configuration2.PropertiesConfiguration in project janusgraph by JanusGraph.
the class HBaseInputFormatIT method getGraph.
protected Graph getGraph() throws IOException, ConfigurationException {
final PropertiesConfiguration config = ConfigurationUtil.loadPropertiesConfig("target/test-classes/hbase-read.properties", false);
Path baseOutDir = Paths.get((String) config.getProperty("gremlin.hadoop.outputLocation"));
baseOutDir.toFile().mkdirs();
String outDir = Files.createTempDirectory(baseOutDir, null).toAbsolutePath().toString();
config.setProperty("gremlin.hadoop.outputLocation", outDir);
return GraphFactory.open(config);
}
Aggregations