use of org.tomlj.TomlTable in project ANNIS by korpling.
the class ServiceStarterDesktop method unpackToml.
protected static Map<String, Object> unpackToml(TomlTable orig) {
LinkedHashMap<String, Object> result = new LinkedHashMap<>();
for (Map.Entry<String, Object> e : orig.toMap().entrySet()) {
if (e.getValue() instanceof TomlArray) {
TomlArray tomlArray = (TomlArray) e.getValue();
result.put(e.getKey(), unpackToml(tomlArray));
} else if (e.getValue() instanceof TomlTable) {
TomlTable tomlTable = (TomlTable) e.getValue();
result.put(e.getKey(), unpackToml(tomlTable));
} else {
result.put(e.getKey(), e.getValue());
}
}
return result;
}
use of org.tomlj.TomlTable in project synopsys-detect by blackducksoftware.
the class PoetryLockParser method parseDependencies.
private DependencyGraph parseDependencies(TomlArray lockPackages) {
DependencyGraph graph = new BasicDependencyGraph();
Set<String> rootPackages = determineRootPackages(lockPackages);
for (String rootPackage : rootPackages) {
graph.addChildToRoot(packageMap.get(rootPackage));
}
for (int i = 0; i < lockPackages.size(); i++) {
TomlTable lockPackage = lockPackages.getTable(i);
List<String> dependencies = extractFromDependencyList(lockPackage.getTable(DEPENDENCIES_KEY));
if (dependencies.isEmpty()) {
continue;
}
for (String dependency : dependencies) {
Dependency child = packageMap.get(dependency);
Dependency parent = packageMap.get(lockPackage.getString(NAME_KEY));
if (child != null && parent != null) {
graph.addChildWithParent(child, parent);
}
}
}
return graph;
}
use of org.tomlj.TomlTable in project ANNIS by korpling.
the class ServiceStarter method getServiceConfig.
protected File getServiceConfig() throws IOException {
File result = new File(config.getWebserviceConfig());
if (!result.exists()) {
File parentDir = result.getParentFile();
if (!parentDir.mkdirs()) {
log.error("Could not create directory {}", parentDir.getAbsolutePath());
}
if (!result.createNewFile()) {
log.error("Could not create new file {}", result.getAbsolutePath());
}
}
// Set to a default data folder and SQLite file
TomlParseResult configToml = Toml.parse(result.toPath());
Map<String, Object> config = configToml.toMap();
TomlTable databaseTable = configToml.getTable("database");
Map<String, Object> databaseConfig;
if (databaseTable == null) {
// Create a new map instead of re-using the existing one
databaseConfig = new LinkedHashMap<>();
config.put("database", databaseConfig);
} else {
databaseConfig = databaseTable.toMap();
}
// Add the graphannis data and sqlite location of not existing yet
Object previousDatabase = databaseConfig.putIfAbsent("graphannis", Paths.get(System.getProperty("user.home"), ".annis", "v4").toAbsolutePath().toString());
Object previousSqlite = databaseConfig.putIfAbsent("sqlite", Paths.get(System.getProperty("user.home"), ".annis", "v4", "service_data.sqlite3").toAbsolutePath().toString());
// Change service debug level if ANNIS itself is in debug mode
Map<String, Object> loggingConfig;
if (configToml.isTable(LOGGING_SECTION)) {
loggingConfig = configToml.getTable(LOGGING_SECTION).toMap();
} else {
loggingConfig = new LinkedHashMap<>();
config.put(LOGGING_SECTION, loggingConfig);
}
Object previousDebugConfig = loggingConfig.put("debug", log.isDebugEnabled());
if (previousDatabase == null || previousSqlite == null || previousDebugConfig == null) {
// Write updated configuration to file
TomlWriter writer = new TomlWriter();
writer.write(config, result);
}
return result;
}
use of org.tomlj.TomlTable in project ANNIS by korpling.
the class ServiceStarterDesktop method unpackToml.
protected static List<Object> unpackToml(TomlArray orig) {
ArrayList<Object> result = new ArrayList<>(orig.size());
for (Object o : orig.toList()) {
if (o instanceof TomlArray) {
TomlArray tomlArray = (TomlArray) o;
result.add(unpackToml(tomlArray));
} else if (o instanceof TomlTable) {
TomlTable tomlTable = (TomlTable) o;
result.add(unpackToml(tomlTable));
} else {
result.add(o);
}
}
return result;
}
use of org.tomlj.TomlTable in project synopsys-detect by blackducksoftware.
the class PoetryLockParser method determineRootPackages.
private Set<String> determineRootPackages(TomlArray lockPackages) {
Set<String> rootPackages = new HashSet<>();
Set<String> dependencyPackages = new HashSet<>();
for (int i = 0; i < lockPackages.size(); i++) {
TomlTable lockPackage = lockPackages.getTable(i);
if (lockPackage != null) {
String projectName = lockPackage.getString(NAME_KEY);
String projectVersion = lockPackage.getString(VERSION_KEY);
packageMap.put(projectName, Dependency.FACTORY.createNameVersionDependency(Forge.PYPI, projectName, projectVersion));
rootPackages.add(projectName);
if (lockPackage.getTable(DEPENDENCIES_KEY) != null) {
List<String> dependencies = extractFromDependencyList(lockPackage.getTable(DEPENDENCIES_KEY));
dependencyPackages.addAll(dependencies);
}
}
}
rootPackages.removeAll(dependencyPackages);
return rootPackages;
}
Aggregations