Class YAMLHelper
- java.lang.Object
-
- com.redhat.devtools.intellij.common.utils.YAMLHelper
-
public class YAMLHelper extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description YAMLHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.fasterxml.jackson.databind.JsonNodeaddLabelToResource(java.lang.String yaml, java.lang.String labelKey, java.lang.String labelValue)Add a label to resource metadatastatic com.fasterxml.jackson.databind.JsonNodeeditValueInYAML(java.lang.String yamlAsString, java.lang.String[] fieldnames, java.lang.String value)Edit value of a yaml field and return the update yaml as JsonNodestatic java.lang.StringgetStringValueFromYAML(java.lang.String yamlAsString, java.lang.String[] path)Retrieve value as String from YAML textstatic com.fasterxml.jackson.databind.JsonNodegetValueFromYAML(java.lang.String yamlAsString, java.lang.String[] path)Retrieve value as JsonNode from YAML textstatic java.lang.StringJSONToYAML(com.fasterxml.jackson.databind.JsonNode json)static java.lang.StringJSONToYAML(com.fasterxml.jackson.databind.JsonNode json, boolean minimizeQuotes)static com.fasterxml.jackson.databind.JsonNoderemoveLabelFromResource(java.lang.String yaml, java.lang.String labelKey)Remove a label from resource metadatastatic com.fasterxml.jackson.databind.JsonNodeURLToJSON(java.net.URL file)static com.fasterxml.jackson.databind.JsonNodeYAMLToJsonNode(java.lang.String yaml)
-
-
-
Method Detail
-
getStringValueFromYAML
public static java.lang.String getStringValueFromYAML(java.lang.String yamlAsString, java.lang.String[] path) throws java.io.IOExceptionRetrieve value as String from YAML text- Parameters:
yamlAsString- Full YAML where to search the value frompath- Path to scan to search for the value (e.g to get the resource name `String[] { "metadata", "name" } `)- Returns:
- last field value or null if the YAML doesn't contain any field
- Throws:
java.io.IOException- if erroring during parsing
-
getValueFromYAML
public static com.fasterxml.jackson.databind.JsonNode getValueFromYAML(java.lang.String yamlAsString, java.lang.String[] path) throws java.io.IOExceptionRetrieve value as JsonNode from YAML text- Parameters:
yamlAsString- Full YAML where to search the value frompath- Path to scan to search for the value (e.g to get the resource name `String[] { "metadata", "name" } `)- Returns:
- last field value or null if the YAML doesn't contain any field
- Throws:
java.io.IOException- if erroring during parsing
-
JSONToYAML
public static java.lang.String JSONToYAML(com.fasterxml.jackson.databind.JsonNode json) throws java.io.IOException- Throws:
java.io.IOException
-
JSONToYAML
public static java.lang.String JSONToYAML(com.fasterxml.jackson.databind.JsonNode json, boolean minimizeQuotes) throws java.io.IOException- Throws:
java.io.IOException
-
YAMLToJsonNode
public static com.fasterxml.jackson.databind.JsonNode YAMLToJsonNode(java.lang.String yaml) throws java.io.IOException- Throws:
java.io.IOException
-
URLToJSON
public static com.fasterxml.jackson.databind.JsonNode URLToJSON(java.net.URL file) throws java.io.IOException- Throws:
java.io.IOException
-
editValueInYAML
public static com.fasterxml.jackson.databind.JsonNode editValueInYAML(java.lang.String yamlAsString, java.lang.String[] fieldnames, java.lang.String value) throws java.io.IOExceptionEdit value of a yaml field and return the update yaml as JsonNode- Parameters:
yamlAsString- original yaml to editfieldnames- array of string to define path of field to change (e.g "spec", "template", "containers[0]", "image")value- new value to add to the field- Returns:
- edited yaml as JsonNode or null if unable to update yaml
- Throws:
java.io.IOException- if errored during yaml parsing
-
addLabelToResource
public static com.fasterxml.jackson.databind.JsonNode addLabelToResource(java.lang.String yaml, java.lang.String labelKey, java.lang.String labelValue) throws java.io.IOExceptionAdd a label to resource metadata- Parameters:
yaml- the YAML resource configurationlabelKey- label key to addlabelValue- label value to add- Returns:
- The updated resource with the new label in the metadata
- Throws:
java.io.IOException- if errored during yaml parsing
-
removeLabelFromResource
public static com.fasterxml.jackson.databind.JsonNode removeLabelFromResource(java.lang.String yaml, java.lang.String labelKey) throws java.io.IOExceptionRemove a label from resource metadata- Parameters:
yaml- the YAML resource configurationlabelKey- label key to remove- Returns:
- the updated resource with the label removed
- Throws:
java.io.IOException- if errored during yaml parsing
-
-