diff options
author | AvinashS <avinash.s@huawei.com> | 2017-10-27 13:41:03 +0000 |
---|---|---|
committer | AvinashS <avinash.s@huawei.com> | 2017-10-27 14:31:13 +0000 |
commit | 821363de13b07538ad455424ee4cd142c5bd1a6d (patch) | |
tree | ec6bd58f30e25a1a4dd78286aa77dac3c2c62e9d /csarvalidation | |
parent | ebad8195f97ed97498e4c4ddbecf3599380f1e5a (diff) |
Schema validator change for windows
Schema validator change with windows UT
support.
Change-Id: Ic86007d23edb83ab9e817d6b097192533a8c43bc
Issue-Id: VNFSDK-118
Signed-off-by: AvinashS <avinash.s@huawei.com>
Diffstat (limited to 'csarvalidation')
-rw-r--r-- | csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java | 115 |
1 files changed, 63 insertions, 52 deletions
diff --git a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java index 488e151..215700d 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java @@ -16,6 +16,7 @@ package org.onap.validation.csar; +import org.apache.commons.io.FileSystemUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,6 +27,7 @@ import org.apache.commons.io.FilenameUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.scanner.ScannerException; + public class ValidatorSchemaLoader { private static final Logger LOG = LoggerFactory.getLogger(ValidatorSchemaLoader.class); @@ -43,6 +45,7 @@ public class ValidatorSchemaLoader { static HashMap<String, String> optionOneSchema; static HashMap<String, String> optionTwoSchema; + private String schema_folder; public ValidatorSchemaLoader() throws Exception { @@ -57,59 +60,67 @@ public class ValidatorSchemaLoader { @SuppressWarnings("unchecked") private boolean loadResources() throws FileNotFoundException { - - ClassLoader classLoader = getClass().getClassLoader(); - - final InputStream is = classLoader.getResourceAsStream("./schema/"); - final InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); - final BufferedReader br = new BufferedReader(isr); - - - br.lines().filter(Objects::nonNull) - .forEach((String e) -> { - - - File file = new File(getClass().getClassLoader().getResource("schema/"+e.toString()).getFile()); + + try { + if(System.getProperty("os.name").contains("win")) { + schema_folder = "schema\\"; + } + else { + schema_folder = "schema/"; + } + + ClassLoader classLoader = getClass().getClassLoader(); + final InputStream is = classLoader.getResourceAsStream(schema_folder); + final InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8); + final BufferedReader br = new BufferedReader(isr); + + br.lines().filter(Objects::nonNull) + .forEach((String e) -> { + + File file = new File(getClass().getClassLoader().getResource(schema_folder+ e.toString()).getFile()); if (!file.isDirectory() && ( - FilenameUtils.isExtension(file.getName(), "yaml") || - FilenameUtils.isExtension(file.getName(), "mf") || - FilenameUtils.isExtension(file.getName(), "meta"))) { - - Yaml yaml = new Yaml(); - - switch (file.getName()) { - case "TOSCA.meta" : - try { - toscaMeta = (Map<String, ?>) yaml.load(new FileInputStream(file)); - } catch (ScannerException | FileNotFoundException e1) { - LOG.error("Schema files %s format is not as per standard prescribed",file.getName()); - } - break; - case "CSAR.meta" : - try { - csarentryd = (Map<String, ?>) yaml.load(new FileInputStream(file)); - } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed",file.getName()); - } - break; - case "MRF.yaml" : - try { - mrfYaml = (Map<String, ?>) yaml.load(new FileInputStream(file)); - } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed",file.getName()); - } - break; - case "MRF.mf" : - try { - mrfManifest = (Map<String, ?>) yaml.load(new FileInputStream(file)); - } catch (ScannerException | FileNotFoundException e2) { - LOG.error("Schema files %s format is not as per standard prescribed",file.getName()); - } - break; - } - } - schemaFileList.add(e); - }); + FilenameUtils.isExtension(file.getName(), "yaml") || + FilenameUtils.isExtension(file.getName(), "mf") || + FilenameUtils.isExtension(file.getName(), "meta"))) { + + Yaml yaml = new Yaml(); + + switch (file.getName()) { + case "TOSCA.meta": + try { + toscaMeta = (Map<String, ?>) yaml.load(new FileInputStream(file)); + } catch (ScannerException | FileNotFoundException e1) { + LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + } + break; + case "CSAR.meta": + try { + csarentryd = (Map<String, ?>) yaml.load(new FileInputStream(file)); + } catch (ScannerException | FileNotFoundException e2) { + LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + } + break; + case "MRF.yaml": + try { + mrfYaml = (Map<String, ?>) yaml.load(new FileInputStream(file)); + } catch (ScannerException | FileNotFoundException e2) { + LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + } + break; + case "MRF.mf": + try { + mrfManifest = (Map<String, ?>) yaml.load(new FileInputStream(file)); + } catch (ScannerException | FileNotFoundException e2) { + LOG.error("Schema files %s format is not as per standard prescribed", file.getName()); + } + break; + } + } + schemaFileList.add(e); + }); + } catch (NullPointerException e) { + LOG.error("Schema files/folder access error"+e); + } return true; } |