From 3bbbadc34cb19b20209a84ec36453fd4b3a73bd1 Mon Sep 17 00:00:00 2001 From: AvinashS Date: Thu, 2 Nov 2017 11:31:34 +0000 Subject: Validate against as per defined attributes Fix CSIT with runtime context path check. Change-Id: Ie5210606bddf589d93608f25eb04856b1a3b7517 Issue-Id: VNFSDK-118 Signed-off-by: AvinashS --- .../validation/csar/ValidatorSchemaLoader.java | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) (limited to 'csarvalidation') 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 215700d..7d9c8c1 100644 --- a/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java +++ b/csarvalidation/src/main/java/org/onap/validation/csar/ValidatorSchemaLoader.java @@ -26,6 +26,9 @@ import java.util.*; import org.apache.commons.io.FilenameUtils; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.scanner.ScannerException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.Path; public class ValidatorSchemaLoader { @@ -62,22 +65,14 @@ public class ValidatorSchemaLoader { private boolean loadResources() throws FileNotFoundException { 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()); + String schema_folder = getClass().getResource("../../../../schema").getPath(); + + Files.walk(Paths.get(schema_folder)) + .filter(Files::isRegularFile) + .forEach((Path e) -> { + + File file = e.toFile(); + if (!file.isDirectory() && ( FilenameUtils.isExtension(file.getName(), "yaml") || FilenameUtils.isExtension(file.getName(), "mf") || @@ -116,10 +111,11 @@ public class ValidatorSchemaLoader { break; } } - schemaFileList.add(e); + schemaFileList.add(e.toAbsolutePath().toString()); }); - } catch (NullPointerException e) { - LOG.error("Schema files/folder access error"+e); + + } catch (NullPointerException | IOException err) { + LOG.error("Schema files/folder access error"+err); } return true; -- cgit 1.2.3-korg