From 821363de13b07538ad455424ee4cd142c5bd1a6d Mon Sep 17 00:00:00 2001 From: AvinashS Date: Fri, 27 Oct 2017 13:41:03 +0000 Subject: Schema validator change for windows Schema validator change with windows UT support. Change-Id: Ic86007d23edb83ab9e817d6b097192533a8c43bc Issue-Id: VNFSDK-118 Signed-off-by: AvinashS --- .../validation/csar/ValidatorSchemaLoader.java | 115 +++++++++++---------- 1 file changed, 63 insertions(+), 52 deletions(-) (limited to 'csarvalidation/src/main') 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 optionOneSchema; static HashMap 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) 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) 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) 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) 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) 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) 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) 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) 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; } -- cgit 1.2.3-korg