diff options
Diffstat (limited to 'csarvalidation/src/main')
-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; } |