Search in sources :

Example 1 with TomlTable

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;
}
Also used : TomlTable(org.tomlj.TomlTable) TomlArray(org.tomlj.TomlArray) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with TomlTable

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;
}
Also used : TomlTable(org.tomlj.TomlTable) DependencyGraph(com.synopsys.integration.bdio.graph.DependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) BasicDependencyGraph(com.synopsys.integration.bdio.graph.BasicDependencyGraph) Dependency(com.synopsys.integration.bdio.model.dependency.Dependency)

Example 3 with TomlTable

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;
}
Also used : TomlTable(org.tomlj.TomlTable) File(java.io.File) TomlWriter(com.moandjiezana.toml.TomlWriter) TomlParseResult(org.tomlj.TomlParseResult)

Example 4 with TomlTable

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;
}
Also used : TomlTable(org.tomlj.TomlTable) ArrayList(java.util.ArrayList) TomlArray(org.tomlj.TomlArray)

Example 5 with TomlTable

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;
}
Also used : TomlTable(org.tomlj.TomlTable) HashSet(java.util.HashSet)

Aggregations

TomlTable (org.tomlj.TomlTable)6 TomlArray (org.tomlj.TomlArray)2 TomlParseResult (org.tomlj.TomlParseResult)2 Sets (com.google.common.collect.Sets)1 TomlWriter (com.moandjiezana.toml.TomlWriter)1 BasicDependencyGraph (com.synopsys.integration.bdio.graph.BasicDependencyGraph)1 DependencyGraph (com.synopsys.integration.bdio.graph.DependencyGraph)1 Dependency (com.synopsys.integration.bdio.model.dependency.Dependency)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1