From 2c390365f13f5aa8d92672254cee6fae16ba823a Mon Sep 17 00:00:00 2001 From: Jan Srnicek Date: Thu, 31 Aug 2017 09:51:39 +0200 Subject: HONEYCOMB-389 - Restconf whitelist Change-Id: I4c60d0ea569e85b23a9d0127ef496545fc475a61 Signed-off-by: Jan Srnicek --- common/common-scripts/pom.xml | 5 ++ .../common/scripts/ModuleYangIndexGenerator.groovy | 58 ++++++++++++++-------- 2 files changed, 43 insertions(+), 20 deletions(-) (limited to 'common') diff --git a/common/common-scripts/pom.xml b/common/common-scripts/pom.xml index 5469efd69..78768741e 100644 --- a/common/common-scripts/pom.xml +++ b/common/common-scripts/pom.xml @@ -94,6 +94,11 @@ commons-io ${commons-io.version} + + io.fd.honeycomb.yang + yang-whitelist-impl + 1.17.10-SNAPSHOT + \ No newline at end of file diff --git a/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy index 8e4c38824..8061d5825 100644 --- a/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy +++ b/common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy @@ -18,6 +18,7 @@ package io.fd.honeycomb.common.scripts import com.google.common.base.Strings import com.google.common.io.Files +import io.fd.honeycomb.yang.YangModuleWhitelistReader import org.apache.commons.io.FileUtils import org.opendaylight.yangtools.yang.binding.YangModelBindingProvider @@ -56,32 +57,50 @@ class ModuleYangIndexGenerator { return } - log.info "Checking module providers for project ${project.getName()}" - // checks module provides from dependencies - // folder with extracted libs - def libsFolder = Paths.get(project.getBuild().getDirectory(), "lib") - if (!libsFolder.toFile().exists()) { - // Plugin for collecting dependencies is executed from parent project, - // therefore it will run also for parent, that does not have any depedencies(just dep management) - // so lib folder wont be created - log.info "Folder ${libsFolder} does not exist - No dependencies to process" - return + String whitelist = project.getProperties().get("yang.modules.whitelist") + String yangModules; + if (whitelist != null) { + log.info "Using whitelist configuration for project ${project.getName()}" + def whiteListPath = Paths.get(whitelist) + if (!whiteListPath.toFile().exists()) { + throw new IllegalStateException(format("Whitelist file on path %s does not exist", whitelist)); + } + + def reader = new YangModuleWhitelistReader() + def yangModuleWhitelist = reader.read(whiteListPath); + yangModules = yangModuleWhitelist.getModules().stream() + .map { module -> module.getBindingProviderName().trim()} + .collect() + .join(MODULES_DELIMITER) + } else { + log.info "Checking module providers for project ${project.getName()}" + // checks module provides from dependencies + // folder with extracted libs + def libsFolder = Paths.get(project.getBuild().getDirectory(), "lib") + if (!libsFolder.toFile().exists()) { + // Plugin for collecting dependencies is executed from parent project, + // therefore it will run also for parent, that does not have any depedencies(just dep management) + // so lib folder wont be created + log.info "Folder ${libsFolder} does not exist - No dependencies to process" + return + } + + yangModules = java.nio.file.Files.walk(libsFolder) + .map { path -> path.toFile() } + .filter { file -> file.isFile() } + .filter { file -> file.getName().endsWith(".jar") } + .map { file -> getModuleProviderContentFromApiJar(new JarFile(file), log) } + .filter { content -> !Strings.isNullOrEmpty(content.trim()) } + .collect().join(MODULES_DELIMITER) } - String yangModules = java.nio.file.Files.walk(libsFolder) - .map { path -> path.toFile() } - .filter { file -> file.isFile() } - .filter { file -> file.getName().endsWith(".jar") } - .map { file -> getModuleProviderContentFromApiJar(new JarFile(file), log) } - .filter { content -> !Strings.isNullOrEmpty(content.trim()) } - .collect().join(MODULES_DELIMITER) - log.info "Yang yangModules found : $yangModules" + log.info "Yang modules found : $yangModules" def outputDir = Paths.get(project.getBuild().getOutputDirectory(), YANG_MODULES_FOLDER).toFile() outputDir.mkdirs() def outputFile = Paths.get(outputDir.getPath(), YANG_MODULES_FILE_NAME).toFile() outputFile.createNewFile() Files.write(yangModules, outputFile, StandardCharsets.UTF_8) - log.info "Yang yangModules configuration successfully written to ${outputFile.getPath()}" + log.info "Yang modules configuration successfully written to ${outputFile.getPath()}" } /** @@ -101,7 +120,6 @@ class ModuleYangIndexGenerator { log.info "Pairing against dependencies" // The rest of the modules is looked up in dependencies pairAgainsDependencyArtifacts(project, modules, log, moduleToYangModulesIndex) - // for ex.: /target/honeycomb-minimal-resources/yang-mapping def yangMappingFolder = Paths.get(project.getBuild().getOutputDirectory(), StartupScriptGenerator.MINIMAL_RESOURCES_FOLDER, YANG_MAPPING_FOLDER).toFile() -- cgit 1.2.3-korg