Search in sources :

Example 11 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project streamline by hortonworks.

the class ConfigFileWriter method writeConfigToYamlTypeFile.

private void writeConfigToYamlTypeFile(Map<String, String> configuration, File destPath) throws IOException {
    ObjectMapper objectMapper = new YAMLMapper();
    objectMapper.writeValue(destPath, configuration);
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project service-proxy by membrane.

the class ApiManagementConfiguration method parseAndConstructConfiguration.

private void parseAndConstructConfiguration(InputStream is) throws IOException {
    String yamlSource = null;
    try {
        yamlSource = IOUtils.toString(is);
    } catch (IOException e) {
        log.warn("Could not read stream");
        return;
    }
    YAMLMapper mapper = new YAMLMapper();
    Map<String, Object> yaml = null;
    try {
        yaml = mapper.readValue(yamlSource, Map.class);
    } catch (IOException e) {
        log.warn("Could not parse yaml");
        return;
    }
    setPolicies(parsePolicies(yaml));
    setKeys(parsePoliciesForKeys(yaml));
    is.close();
    log.info("Configuration loaded. Notifying observers");
    notifyConfigChangeObservers();
}
Also used : YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ResolverMap(com.predic8.membrane.core.resolver.ResolverMap)

Example 13 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project hub-detect by blackducksoftware.

the class CocoapodsPackager method extractDependencyGraph.

public DependencyGraph extractDependencyGraph(final String podLockText) throws IOException {
    YAMLMapper mapper = new YAMLMapper();
    PodfileLock podfileLock = mapper.readValue(podLockText, PodfileLock.class);
    NameVersionNode root = new NameVersionNode();
    root.setName(String.format("detectRootNode - %s", UUID.randomUUID()));
    final SubcomponentNodeBuilder builder = new SubcomponentNodeBuilder(root);
    for (Pod pod : podfileLock.getPods()) {
        buildNameVersionNode(builder, pod);
    }
    ;
    for (Pod dependency : podfileLock.getDependencies()) {
        NameVersionNode child = new NameVersionNode();
        child.setName(cleanPodName(dependency.getName()));
        builder.addChildNodeToParent(child, root);
    }
    ;
    if (null != podfileLock.getExternalSources() && !podfileLock.getExternalSources().getSources().isEmpty()) {
        for (PodSource podSource : podfileLock.getExternalSources().getSources()) {
            NodeMetadata nodeMetadata = createMetadata(builder, podSource.getName());
            if (null != podSource.getGit() && podSource.getGit().contains("github")) {
                // Change the forge to GitHub when there is better KB support
                nodeMetadata.setForge(Forge.COCOAPODS);
            } else if (null != podSource.getPath() && podSource.getPath().contains("node_modules")) {
                nodeMetadata.setForge(Forge.NPM);
            }
        }
    }
    MutableDependencyGraph graph = new MutableMapDependencyGraph();
    for (NameVersionNode nameVersionNode : builder.build().getChildren()) {
        Dependency childDependency = nameVersionNodeTransformer.addNameVersionNodeToDependencyGraph(graph, Forge.COCOAPODS, nameVersionNode);
        graph.addChildToRoot(childDependency);
    }
    return graph;
}
Also used : NodeMetadata(com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata) MutableDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph) SubcomponentNodeBuilder(com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder) NameVersionNode(com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) MutableMapDependencyGraph(com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph) Dependency(com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)

Example 14 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project logging-log4j2 by apache.

the class StackTraceElementYamlMixInTest method testFromYamlWithSimpleModule.

@Test
public void testFromYamlWithSimpleModule() throws Exception {
    final ObjectMapper mapper = new YAMLMapper();
    final SimpleModule module = new SimpleModule();
    module.addDeserializer(StackTraceElement.class, new Log4jStackTraceElementDeserializer());
    mapper.registerModule(module);
    final StackTraceElement expected = new StackTraceElement("package.SomeClass", "someMethod", "SomeClass.java", 123);
    final StackTraceElement actual = mapper.readValue("---\nclass: package.SomeClass\nmethod: someMethod\nfile: SomeClass.java\nline: 123\n...", StackTraceElement.class);
    Assert.assertEquals(expected, actual);
}
Also used : Log4jStackTraceElementDeserializer(org.apache.logging.log4j.jackson.Log4jStackTraceElementDeserializer) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule) Test(org.junit.Test)

Example 15 with YAMLMapper

use of com.fasterxml.jackson.dataformat.yaml.YAMLMapper in project fess by codelibs.

the class PluginHelper method loadArtifactsFromRepository.

protected List<Artifact> loadArtifactsFromRepository(final String url) {
    final String content = getRepositoryContent(url);
    final ObjectMapper objectMapper = new YAMLMapper();
    try {
        @SuppressWarnings("unchecked") final List<Map<?, ?>> result = objectMapper.readValue(content, List.class);
        if (result != null) {
            return result.stream().map(o -> new Artifact((String) o.get("name"), (String) o.get("version"), (String) o.get("url"))).collect(Collectors.toList());
        }
        return Collections.emptyList();
    } catch (final Exception e) {
        throw new PluginException("Failed to access " + url, e);
    }
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) PluginException(org.codelibs.fess.exception.PluginException) CurlRequest(org.codelibs.curl.CurlRequest) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ResourceUtil(org.codelibs.fess.util.ResourceUtil) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) Proxy(java.net.Proxy) Document(org.w3c.dom.Document) Map(java.util.Map) Node(org.w3c.dom.Node) CopyUtil(org.codelibs.core.io.CopyUtil) XMLConstants(javax.xml.XMLConstants) Path(java.nio.file.Path) NodeList(org.w3c.dom.NodeList) Files(java.nio.file.Files) StringUtil(org.codelibs.core.lang.StringUtil) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) Curl(org.codelibs.curl.Curl) TimeUnit(java.util.concurrent.TimeUnit) CacheLoader(com.google.common.cache.CacheLoader) Constants(org.codelibs.fess.crawler.Constants) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Paths(java.nio.file.Paths) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DocumentBuilder(javax.xml.parsers.DocumentBuilder) SAXException(org.xml.sax.SAXException) Pattern(java.util.regex.Pattern) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) CacheBuilder(com.google.common.cache.CacheBuilder) Comparator(java.util.Comparator) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CurlResponse(org.codelibs.curl.CurlResponse) InputStream(java.io.InputStream) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) PluginException(org.codelibs.fess.exception.PluginException) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PluginException(org.codelibs.fess.exception.PluginException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException)

Aggregations

YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)15 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10 IOException (java.io.IOException)6 InputStream (java.io.InputStream)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 Map (java.util.Map)2 Test (org.junit.Test)2 MutableDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableDependencyGraph)1 MutableMapDependencyGraph (com.blackducksoftware.integration.hub.bdio.graph.MutableMapDependencyGraph)1 Dependency (com.blackducksoftware.integration.hub.bdio.model.dependency.Dependency)1 NameVersionNode (com.blackducksoftware.integration.hub.detect.nameversion.NameVersionNode)1 NodeMetadata (com.blackducksoftware.integration.hub.detect.nameversion.NodeMetadata)1 SubcomponentNodeBuilder (com.blackducksoftware.integration.hub.detect.nameversion.builder.SubcomponentNodeBuilder)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1