aboutsummaryrefslogtreecommitdiffstats
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/pom.xml6
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java3
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java9
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java37
5 files changed, 37 insertions, 21 deletions
diff --git a/framework/pom.xml b/framework/pom.xml
index 6d60d8b2..9878cd84 100644
--- a/framework/pom.xml
+++ b/framework/pom.xml
@@ -49,9 +49,9 @@
<version>5.0.3-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.yaml</groupId>
- <artifactId>snakeyaml</artifactId>
- <version>1.18</version>
+ <groupId>com.esotericsoftware.yamlbeans</groupId>
+ <artifactId>yamlbeans</artifactId>
+ <version>1.13</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
index d0788c16..10d9c448 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapProductsListCommand.java
@@ -28,7 +28,6 @@ import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cli.fw.schema.OnapCommandSchemaInfo;
import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
-import org.yaml.snakeyaml.Yaml;
/**
* Product list.
@@ -58,7 +57,7 @@ public class OnapProductsListCommand extends OnapCommand {
"/" + product + OnapCommandConstants.PRODUCT_REGISTRY_YAML);
if (stream != null) {
- Map<String, ?> map = (Map<String, ?>) new Yaml().load(stream);
+ Map<String, ?> map = OnapCommandDiscoveryUtils.loadYaml(stream);
Map<String, String> productMap = (Map<String, String>) map.get("product");
String description = (String) productMap.get(OnapCommandConstants.DESCRIPTION);
this.getResult().getRecordsMap().get("description").getValues().add(description.trim());
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
index fa4f60b9..880f83ea 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/product/OnapServiceListCommand.java
@@ -29,7 +29,6 @@ import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cli.fw.schema.OnapCommandSchemaInfo;
import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
-import org.yaml.snakeyaml.Yaml;
/**
* Service list.
@@ -62,7 +61,7 @@ public class OnapServiceListCommand extends OnapCommand {
Map<String, String> serviceDescs = new HashMap<>();
if (stream != null) {
- Map<String, ?> map = (Map<String, ?>) new Yaml().load(stream);
+ Map<String, ?> map = OnapCommandDiscoveryUtils.loadYaml(stream);
if (map.containsKey("services")) {
List<Map<String, String>> services = (List) map.get("services");
diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
index a1a14745..41be2332 100644
--- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
+++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaLoader.java
@@ -88,7 +88,6 @@ import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
import org.onap.cli.fw.utils.OnapCommandDiscoveryUtils;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.springframework.core.io.Resource;
-import org.yaml.snakeyaml.Yaml;
public class OnapCommandSchemaLoader {
@@ -541,13 +540,7 @@ public class OnapCommandSchemaLoader {
* exception
*/
public static Map<String, ?> loadSchema(InputStream stream, String schemaName) throws OnapCommandInvalidSchema {
- Map<String, ?> values = null;
- try {
- values = (Map<String, ?>) new Yaml().load(stream);
- } catch (Exception e) {
- throw new OnapCommandInvalidSchema(schemaName, e);
- }
+ return OnapCommandDiscoveryUtils.loadYaml(stream);
- return values;
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index 105f68dc..23c825e2 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -56,7 +56,8 @@ import org.onap.cli.fw.schema.OnapCommandSchemaInfo;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
-import org.yaml.snakeyaml.Yaml;
+import com.esotericsoftware.yamlbeans.YamlReader;
+import com.esotericsoftware.yamlbeans.YamlException;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -64,7 +65,9 @@ import com.google.gson.stream.JsonReader;
import java.io.FileReader;
import java.io.Writer;
import java.io.FileWriter;
-
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.FileInputStream;
public class OnapCommandDiscoveryUtils {
private static Gson gson = new GsonBuilder().serializeNulls().create();
@@ -216,7 +219,7 @@ public class OnapCommandDiscoveryUtils {
public static Map<String, ?> loadSchema(Resource resource) throws OnapCommandInvalidSchema {
Map<String, ?> values = null;
try {
- values = (Map<String, ?>) new Yaml().load(resource.getInputStream());
+ values = loadYaml(resource.getInputStream());
} catch (Exception e) {
throw new OnapCommandInvalidSchema(resource.getFilename(), e);
}
@@ -306,7 +309,7 @@ public class OnapCommandDiscoveryUtils {
if (deafultResourceMap.containsKey(PARAMETERS)) {
List<Object> params = new ArrayList<>();
for (Map<String, ?> p: (List<Map<String, ?>>) deafultResourceMap.get(PARAMETERS)) {
- if (p.keySet().contains(IS_DEFAULT_PARAM) && !((Boolean) p.get(IS_DEFAULT_PARAM))) {
+ if (p.keySet().contains(IS_DEFAULT_PARAM) && ! (Boolean.getBoolean(String.valueOf(p.get(IS_DEFAULT_PARAM))))) {
params.add(p);
}
}
@@ -542,7 +545,7 @@ public class OnapCommandDiscoveryUtils {
public static Map<String, ?> loadYaml(Resource resource) throws OnapCommandInvalidSchema {
Map<String, ?> values = null;
try {
- values = (Map<String, ?>) new Yaml().load(resource.getInputStream());
+ values = loadYaml(resource.getInputStream());
} catch (Exception e) {
throw new OnapCommandInvalidSchema(resource.getFilename(), e);
}
@@ -560,11 +563,33 @@ public class OnapCommandDiscoveryUtils {
public static Map<String, ?> loadYaml(String filePath) throws OnapCommandInvalidSchema {
Map<String, ?> values = null;
try {
- values = (Map<String, Object>) new Yaml().load(FileUtils.readFileToString(new File(filePath)));
+ values = loadYaml(new FileInputStream(new File(filePath)));
} catch (Exception e) {
throw new OnapCommandInvalidSchema(filePath, e);
}
return values;
}
+
+
+ /**
+ * Get schema map.
+ *
+ * @param inputStream
+ * @return map
+ * @throws OnapCommandInvalidSchema
+ * exception
+ */
+ public static Map<String, ?> loadYaml(InputStream inputStream) throws OnapCommandInvalidSchema {
+ Map<String, ?> values = null;
+ try(InputStreamReader inputStreamReader = new InputStreamReader(inputStream);){
+ YamlReader reader = new YamlReader(inputStreamReader);
+ values = (Map<String, ?>) reader.read();
+ } catch (YamlException e) {
+ throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage());
+ } catch (IOException e) {
+ throw new OnapCommandInvalidSchema(inputStream.getClass().getName(),e.getMessage());
+ }
+ return values;
+ }
}