diff options
author | Jan Srnicek <jsrnicek@cisco.com> | 2017-08-31 09:51:39 +0200 |
---|---|---|
committer | Marek Gradzki <mgradzki@cisco.com> | 2017-09-05 15:39:31 +0000 |
commit | 2c390365f13f5aa8d92672254cee6fae16ba823a (patch) | |
tree | 02dc033e610ae375c57c4c94e7462ebad86997a9 /common | |
parent | bb9141c63012d0305ac65da763af3fb0c427076f (diff) |
HONEYCOMB-389 - Restconf whitelist
Change-Id: I4c60d0ea569e85b23a9d0127ef496545fc475a61
Signed-off-by: Jan Srnicek <jsrnicek@cisco.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/common-scripts/pom.xml | 5 | ||||
-rw-r--r-- | common/common-scripts/src/main/groovy/io/fd/honeycomb/common/scripts/ModuleYangIndexGenerator.groovy | 58 |
2 files changed, 43 insertions, 20 deletions
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 @@ <artifactId>commons-io</artifactId> <version>${commons-io.version}</version> </dependency> + <dependency> + <groupId>io.fd.honeycomb.yang</groupId> + <artifactId>yang-whitelist-impl</artifactId> + <version>1.17.10-SNAPSHOT</version> + </dependency> </dependencies> </project>
\ 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() |