From 4b4d3492e1b4bddacaff98847c40b27d417e169b Mon Sep 17 00:00:00 2001 From: Philip Gorbachev Date: Mon, 4 Sep 2023 13:31:54 +0400 Subject: [PATCH] Bug/fixtest (#13) * disabled parallel mode for tests * Fixed ComponentsRegistryDSLTest#testProductTypes * refactored setup/init/logging in EscrowConfigurationLoaderTest,BuildToolsResolverTests * improved logging in EscrowConfigurationLoaderTest * added EscrowBean#toString * Improved logging of dsl loading --- build.gradle | 4 +- component-resolver-core/build.gradle | 2 + .../loader/EscrowConfigurationLoader.groovy | 26 ++++++---- .../resolvers/BuildToolsResolver.groovy | 4 +- .../EscrowConfigurationLoaderTest.groovy | 50 ++++++++++++------- .../resolvers/BuildToolResolverTest.groovy | 41 ++++++++++----- .../components/registry/api/beans/ApiBeans.kt | 34 +++++++++---- .../script/ComponentsRegistryScriptRunner.kt | 17 ++++--- .../dsl/test/ComponentsRegistryDSLTest.kt | 25 ++++------ .../registry/dsl/test/DslTestUtilities.kt | 7 +++ 10 files changed, 138 insertions(+), 72 deletions(-) diff --git a/build.gradle b/build.gradle index e9e4ffb..f9ea5e8 100644 --- a/build.gradle +++ b/build.gradle @@ -79,7 +79,9 @@ configure(subprojects) { test { useJUnitPlatform() systemProperties = [ - 'junit.jupiter.execution.parallel.enabled': true + //NOTE: when parallel.enabled = true EscrowConfigurationLoaderTest + BuildToolResolverTest + // can fail sporadically on GH + 'junit.jupiter.execution.parallel.enabled': false ] } diff --git a/component-resolver-core/build.gradle b/component-resolver-core/build.gradle index 916b57e..6251aa9 100644 --- a/component-resolver-core/build.gradle +++ b/component-resolver-core/build.gradle @@ -17,6 +17,8 @@ dependencies { implementation "org.codehaus.groovy.modules.http-builder:http-builder:0.7.1" testImplementation "org.springframework:spring-test:4.1.2.RELEASE" testImplementation group: 'org.assertj', name: 'assertj-core', version: '3.21.0' + testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.7' + testImplementation "org.apache.logging.log4j:log4j-core:${project['log4j2.version']}" } sourceSets { diff --git a/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoader.groovy b/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoader.groovy index 6d4aac2..aeec19a 100644 --- a/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoader.groovy +++ b/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoader.groovy @@ -1,5 +1,13 @@ package org.octopusden.octopus.escrow.configuration.loader +import groovy.transform.TypeChecked +import groovy.transform.TypeCheckingMode +import org.apache.commons.lang3.StringUtils +import org.apache.commons.lang3.Validate +import org.apache.logging.log4j.LogManager +import org.apache.logging.log4j.Logger +import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException +import org.apache.maven.artifact.versioning.VersionRange import org.octopusden.octopus.components.registry.api.Component import org.octopusden.octopus.components.registry.api.SubComponent import org.octopusden.octopus.components.registry.api.VersionedComponentConfiguration @@ -27,21 +35,18 @@ import org.octopusden.octopus.releng.dto.ComponentInfo import org.octopusden.octopus.releng.dto.ComponentVersion import org.octopusden.octopus.releng.dto.JiraComponent import org.octopusden.releng.versions.ComponentVersionFormat -import groovy.transform.TypeChecked -import groovy.transform.TypeCheckingMode -import org.apache.commons.lang3.StringUtils -import org.apache.commons.lang3.Validate -import org.apache.logging.log4j.LogManager -import org.apache.logging.log4j.Logger -import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException -import org.apache.maven.artifact.versioning.VersionRange import org.octopusden.releng.versions.NumericVersionFactory import org.octopusden.releng.versions.VersionNames import org.octopusden.releng.versions.VersionRangeFactory import java.util.stream.Collectors -import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.* +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.BRANCH +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.REPOSITORY_TYPE +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.SECURITY_GROUPS_READ +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.TAG +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.VCS_SETTINGS +import static org.octopusden.octopus.escrow.configuration.validation.GroovySlurperConfigValidator.VCS_URL class EscrowConfigurationLoader { private static final Logger LOG = LogManager.getLogger(EscrowConfigurationLoader.class) @@ -135,7 +140,10 @@ class EscrowConfigurationLoader { LOG.debug("Loading DSL") def dslComponents = configLoader.loadDslDefinedComponents() + LOG.info("Loaded $dslComponents.size DSL components") + dslComponents.forEach {component -> + LOG.debug("processing dsl $component") mergeGroovyAndDslComponent(component, fullConfig) component.subComponents.forEach { name, subComponent -> mergeGroovyAndDslSubComponent(subComponent, fullConfig)} } diff --git a/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/resolvers/BuildToolsResolver.groovy b/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/resolvers/BuildToolsResolver.groovy index fcb60d8..c5033a2 100644 --- a/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/resolvers/BuildToolsResolver.groovy +++ b/component-resolver-core/src/main/groovy/org.octopusden/octopus/escrow/resolvers/BuildToolsResolver.groovy @@ -1,5 +1,7 @@ package org.octopusden.octopus.escrow.resolvers +import groovy.transform.TypeChecked +import groovy.util.logging.Slf4j import org.octopusden.octopus.components.registry.api.beans.PTCProductToolBean import org.octopusden.octopus.components.registry.api.beans.PTKProductToolBean import org.octopusden.octopus.components.registry.api.beans.ProductToolBean @@ -11,9 +13,9 @@ import org.octopusden.octopus.escrow.configuration.model.EscrowConfiguration import org.octopusden.octopus.escrow.dto.DistributionEntity import org.octopusden.octopus.escrow.utilities.DistributionUtilities import org.octopusden.octopus.releng.dto.ComponentVersion -import groovy.transform.TypeChecked @TypeChecked +@Slf4j class BuildToolsResolver implements IBuildToolsResolver { private final EscrowConfiguration configuration diff --git a/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoaderTest.groovy b/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoaderTest.groovy index 51fcc4d..8ba69b0 100644 --- a/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoaderTest.groovy +++ b/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/configuration/loader/EscrowConfigurationLoaderTest.groovy @@ -1,8 +1,18 @@ package org.octopusden.octopus.escrow.configuration.loader +import groovy.util.logging.Slf4j +import org.apache.maven.artifact.DefaultArtifact +import org.apache.maven.artifact.versioning.VersionRange +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.MethodSource import org.octopusden.octopus.components.registry.api.beans.GitVersionControlSystemBean -import org.octopusden.octopus.components.registry.api.beans.PTKProductToolBean import org.octopusden.octopus.components.registry.api.beans.OracleDatabaseToolBean +import org.octopusden.octopus.components.registry.api.beans.PTKProductToolBean import org.octopusden.octopus.components.registry.api.enums.BuildSystemType import org.octopusden.octopus.escrow.RepositoryType import org.octopusden.octopus.escrow.configuration.model.EscrowConfiguration @@ -10,36 +20,32 @@ import org.octopusden.octopus.escrow.configuration.model.EscrowModule import org.octopusden.octopus.escrow.configuration.validation.util.VersionRangeHelper import org.octopusden.octopus.escrow.resolvers.ModuleByArtifactResolver import org.octopusden.octopus.releng.dto.ComponentVersion -import org.apache.maven.artifact.DefaultArtifact -import org.apache.maven.artifact.versioning.VersionRange -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Test -import org.junit.jupiter.params.ParameterizedTest -import org.junit.jupiter.params.provider.Arguments -import org.junit.jupiter.params.provider.MethodSource import org.octopusden.releng.versions.NumericVersionFactory import java.nio.file.Paths import java.util.stream.Stream -import static org.octopusden.octopus.escrow.TestConfigUtils.PRODUCT_TYPES -import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_GROUP_IDS -import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_SYSTEMS import static org.assertj.core.api.AssertionsForClassTypes.assertThat import static org.junit.jupiter.api.Assertions.assertEquals import static org.junit.jupiter.api.Assertions.assertNotNull import static org.junit.jupiter.api.Assertions.assertNull import static org.junit.jupiter.api.Assertions.assertTrue +import static org.octopusden.octopus.escrow.TestConfigUtils.PRODUCT_TYPES +import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_GROUP_IDS +import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_SYSTEMS import static org.octopusden.octopus.escrow.TestConfigUtils.VERSION_NAMES import static org.octopusden.octopus.escrow.TestConfigUtils.VERSION_RANGE_FACTORY +@Slf4j class EscrowConfigurationLoaderTest { - static EscrowConfiguration escrowConfiguration + EscrowConfiguration escrowConfiguration + private static EscrowConfigurationLoader escrowConfigurationLoader - static { + @BeforeAll + static void init() { def aggregatorPath = Paths.get(EscrowConfigurationLoaderTest.class.getResource("/production/Aggregator.groovy").toURI()) - EscrowConfigurationLoader escrowConfigurationLoader = new EscrowConfigurationLoader( + escrowConfigurationLoader = new EscrowConfigurationLoader( new ConfigLoader( ComponentRegistryInfo.createFromFileSystem( aggregatorPath.getParent().toString(), @@ -51,6 +57,10 @@ class EscrowConfigurationLoaderTest { SUPPORTED_SYSTEMS, VERSION_NAMES ) + } + + @BeforeEach + void setUp() { escrowConfiguration = escrowConfigurationLoader.loadFullConfiguration(Collections.emptyMap()) } @@ -154,7 +164,7 @@ class EscrowConfigurationLoaderTest { } else { oracle.version = "11.2" } - assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(oracle)) + assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(oracle), "${moduleConfiguration.buildConfiguration.buildTools} 1sn't contain $oracle escrowModule=$escrowModule") } } @@ -165,7 +175,8 @@ class EscrowConfigurationLoaderTest { assertTrue(moduleConfiguration.escrow.gradle.includeTestConfigurations) assertEquals("build", moduleConfiguration.escrow.buildTask) } else { - assertNull(moduleConfiguration.escrow.buildTask) + log.info("moduleConfiguration=$moduleConfiguration") + assertNull(moduleConfiguration.escrow.buildTask, "${moduleConfiguration.escrow.buildTask} should be empty") } } } @@ -175,7 +186,8 @@ class EscrowConfigurationLoaderTest { getEscrowConfiguration().escrowModules.get("monitoring").moduleConfigurations.forEach { moduleConfiguration -> def kProduct = new PTKProductToolBean() kProduct.version = "03.49" - assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(kProduct)) + log.info("moduleConfiguration=$moduleConfiguration") + assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(kProduct), "${moduleConfiguration.buildConfiguration.buildTools} doesn't contain $kProduct moduleConfiguration=$moduleConfiguration") } } @@ -194,9 +206,9 @@ class EscrowConfigurationLoaderTest { @Test void testEmptyProduct() { - getEscrowConfiguration().escrowModules.get("component_commons").moduleConfigurations.forEach { moduleConfiguration -> + escrowConfiguration.escrowModules.get("component_commons").moduleConfigurations.forEach { moduleConfiguration -> def product = new PTKProductToolBean() - assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(product)) + assertTrue(moduleConfiguration.buildConfiguration.buildTools.contains(product), "$moduleConfiguration.buildConfiguration.buildTools doesn't contain $product") } } diff --git a/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/resolvers/BuildToolResolverTest.groovy b/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/resolvers/BuildToolResolverTest.groovy index fbc72db..31b85c8 100644 --- a/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/resolvers/BuildToolResolverTest.groovy +++ b/component-resolver-core/src/test/groovy/org/octopusden/octopus/escrow/resolvers/BuildToolResolverTest.groovy @@ -1,34 +1,47 @@ package org.octopusden.octopus.escrow.resolvers +import groovy.transform.TypeChecked +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.octopusden.octopus.components.registry.api.beans.OracleDatabaseToolBean import org.octopusden.octopus.components.registry.api.beans.PTCProductToolBean import org.octopusden.octopus.components.registry.api.beans.PTKProductToolBean -import org.octopusden.octopus.components.registry.api.beans.OracleDatabaseToolBean import org.octopusden.octopus.components.registry.api.distribution.entities.MavenArtifactDistributionEntity import org.octopusden.octopus.components.registry.api.enums.ProductTypes import org.octopusden.octopus.escrow.configuration.loader.ComponentRegistryInfo import org.octopusden.octopus.escrow.configuration.loader.ConfigLoader import org.octopusden.octopus.escrow.configuration.loader.EscrowConfigurationLoader import org.octopusden.octopus.releng.dto.ComponentVersion -import groovy.transform.TypeChecked -import org.junit.jupiter.api.Test import java.nio.file.Paths +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertTrue import static org.octopusden.octopus.escrow.TestConfigUtils.PRODUCT_TYPES import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_GROUP_IDS import static org.octopusden.octopus.escrow.TestConfigUtils.SUPPORTED_SYSTEMS -import static org.junit.jupiter.api.Assertions.assertNotNull -import static org.junit.jupiter.api.Assertions.assertTrue -import static org.junit.jupiter.api.Assertions.assertFalse -import static org.junit.jupiter.api.Assertions.assertEquals import static org.octopusden.octopus.escrow.TestConfigUtils.VERSION_NAMES @TypeChecked class BuildToolResolverTest { - static IBuildToolsResolver buildToolsResolver + private IBuildToolsResolver buildToolsResolver + private static EscrowConfigurationLoader escrowConfigurationLoader + + @BeforeAll + static void initBeforeClass() { + escrowConfigurationLoader = initEscrowConfigurationLoader() + } + + @BeforeEach + void setUp() { + buildToolsResolver = initBuildToolResolver(escrowConfigurationLoader) + } - static { + private static EscrowConfigurationLoader initEscrowConfigurationLoader() { def aggregatorPath = Paths.get(EscrowConfigurationLoaderTest.class.getResource("/production/Aggregator.groovy").toURI()) EscrowConfigurationLoader escrowConfigurationLoader = new EscrowConfigurationLoader( new ConfigLoader( @@ -43,7 +56,11 @@ class BuildToolResolverTest { SUPPORTED_SYSTEMS, VERSION_NAMES ) - buildToolsResolver = new BuildToolsResolver(escrowConfigurationLoader.loadFullConfiguration(Collections.emptyMap())) + escrowConfigurationLoader + } + + private static BuildToolsResolver initBuildToolResolver(EscrowConfigurationLoader escrowConfigurationLoader) { + new BuildToolsResolver(escrowConfigurationLoader.loadFullConfiguration(Collections.emptyMap())) } @Test @@ -59,7 +76,7 @@ class BuildToolResolverTest { def tools = buildToolsResolver.getComponentBuildTools(ComponentVersion.create("app", "1.6.1")) def oracle = new OracleDatabaseToolBean() oracle.version = "11.2" - assertTrue(tools.contains(oracle)) + assertTrue(tools.contains(oracle), "$tools doesn't contain $oracle") def ptk = new PTKProductToolBean() ptk.version = "03.49" assertTrue(tools.contains(ptk)) @@ -70,7 +87,7 @@ class BuildToolResolverTest { def tools = buildToolsResolver.getComponentBuildTools(ComponentVersion.create("app", "1.6.1")) def ptk = new PTKProductToolBean() ptk.version = "03.49" - assertTrue(tools.contains(ptk)) + assertTrue(tools.contains(ptk), "$tools doesn't contain $ptk") tools = buildToolsResolver.getComponentBuildTools(ComponentVersion.create("app", "1.6.1"), "03.50.30.45") ptk.version = "03.50.30.45" diff --git a/components-registry-api/src/main/kotlin/org/octopusden/octopus/components/registry/api/beans/ApiBeans.kt b/components-registry-api/src/main/kotlin/org/octopusden/octopus/components/registry/api/beans/ApiBeans.kt index 63e9c3d..752f982 100644 --- a/components-registry-api/src/main/kotlin/org/octopusden/octopus/components/registry/api/beans/ApiBeans.kt +++ b/components-registry-api/src/main/kotlin/org/octopusden/octopus/components/registry/api/beans/ApiBeans.kt @@ -11,15 +11,20 @@ import org.octopusden.octopus.components.registry.api.build.Build import org.octopusden.octopus.components.registry.api.build.BuildSystem import org.octopusden.octopus.components.registry.api.build.tools.BuildTool import org.octopusden.octopus.components.registry.api.build.tools.databases.DatabaseTool -import org.octopusden.octopus.components.registry.api.build.tools.products.ProductTool import org.octopusden.octopus.components.registry.api.build.tools.databases.OracleDatabaseTool import org.octopusden.octopus.components.registry.api.build.tools.oracle.OdbcTool import org.octopusden.octopus.components.registry.api.build.tools.products.PTCProductTool import org.octopusden.octopus.components.registry.api.build.tools.products.PTDDbProductTool import org.octopusden.octopus.components.registry.api.build.tools.products.PTDProductTool import org.octopusden.octopus.components.registry.api.build.tools.products.PTKProductTool +import org.octopusden.octopus.components.registry.api.build.tools.products.ProductTool import org.octopusden.octopus.components.registry.api.distribution.entities.MavenArtifactDistributionEntity -import org.octopusden.octopus.components.registry.api.enums.* +import org.octopusden.octopus.components.registry.api.enums.BuildSystemType +import org.octopusden.octopus.components.registry.api.enums.BuildToolTypes +import org.octopusden.octopus.components.registry.api.enums.DatabaseTypes +import org.octopusden.octopus.components.registry.api.enums.OracleDatabaseEditions +import org.octopusden.octopus.components.registry.api.enums.ProductTypes +import org.octopusden.octopus.components.registry.api.enums.VersionControlSystemType import org.octopusden.octopus.components.registry.api.escrow.Escrow import org.octopusden.octopus.components.registry.api.escrow.GradleBuild import org.octopusden.octopus.components.registry.api.model.Dependencies @@ -30,14 +35,6 @@ import org.octopusden.octopus.components.registry.api.vcs.MultiplyVersionControl import org.octopusden.octopus.components.registry.api.vcs.VersionControlSystem import java.util.* import java.util.regex.Pattern -import org.octopusden.octopus.components.registry.api.enums.BuildSystemType -import org.octopusden.octopus.components.registry.api.enums.BuildToolTypes -import org.octopusden.octopus.components.registry.api.enums.DatabaseTypes -import org.octopusden.octopus.components.registry.api.enums.OracleDatabaseEditions -import org.octopusden.octopus.components.registry.api.enums.ProductTypes -import org.octopusden.octopus.components.registry.api.enums.VersionControlSystemType -import kotlin.collections.ArrayList -import kotlin.collections.HashMap open class OdbcToolBean: OdbcTool { @@ -88,6 +85,11 @@ open class ProductToolBean(private val type: ProductTypes, private var settingsP result = 31 * result + (version?.hashCode() ?: 0) return result } + + override fun toString(): String { + return "ProductToolBean(type=$type, settingsProperty='$settingsProperty', version=$version)" + } + } open class PTCProductToolBean: ProductToolBean(ProductTypes.PT_C, "uscschema"), @@ -159,6 +161,10 @@ class OracleDatabaseToolBean: DatabaseToolBean(DatabaseTypes.ORACLE, "db"), result = 31 * result + (edition?.hashCode() ?: 0) return result } + + override fun toString(): String { + return "OracleDatabaseToolBean(edition=$edition)" + } } open class GradleBuildBean: GradleBuild { @@ -217,6 +223,11 @@ open class EscrowBean: Escrow { fun setReusable(reusable: Boolean) { this.reusable = reusable } + + override fun toString(): String { + return "EscrowBean(buildTask=$buildTask, gradle=$gradle, providedDependencies=$providedDependencies, diskSpaceRequirement=$diskSpaceRequirement, additionalSources=$additionalSources, reusable=$reusable)" + } + } open class BuildBean: Build { @@ -314,6 +325,9 @@ open class ComponentBean: SubComponentBean(), } override fun getSubComponents(): MutableMap = subComponents + override fun toString(): String { + return "Component(productType=$productType, subComponents=$subComponents, displayName=$displayName)" + } } @JsonTypeName("mavenDistribution") diff --git a/components-registry-dsl/src/main/kotlin/org/octopusden/octopus/components/registry/dsl/script/ComponentsRegistryScriptRunner.kt b/components-registry-dsl/src/main/kotlin/org/octopusden/octopus/components/registry/dsl/script/ComponentsRegistryScriptRunner.kt index 95c1dbf..b872c2a 100644 --- a/components-registry-dsl/src/main/kotlin/org/octopusden/octopus/components/registry/dsl/script/ComponentsRegistryScriptRunner.kt +++ b/components-registry-dsl/src/main/kotlin/org/octopusden/octopus/components/registry/dsl/script/ComponentsRegistryScriptRunner.kt @@ -1,15 +1,15 @@ package org.octopusden.octopus.components.registry.dsl.script -import org.octopusden.octopus.components.registry.api.Component import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback +import org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory +import org.octopusden.octopus.components.registry.api.Component +import org.octopusden.octopus.components.registry.api.enums.ProductTypes import java.nio.file.Files import java.nio.file.Path import java.util.logging.Logger -import org.jetbrains.kotlin.script.jsr223.KotlinJsr223JvmLocalScriptEngineFactory -import org.octopusden.octopus.components.registry.api.enums.ProductTypes -import java.util.EnumMap +import java.util.stream.Collectors import kotlin.script.experimental.jsr223.KotlinJsr223DefaultScriptEngineFactory -import kotlin.collections.ArrayList +import kotlin.streams.toList object ComponentsRegistryScriptRunner { private val logger = Logger.getLogger(ComponentsRegistryScriptRunner::class.java.canonicalName) @@ -30,8 +30,11 @@ object ComponentsRegistryScriptRunner { * For boot jar based application System property 'kotlin.script.classpath' has to be set to DSL libraries before call. */ fun loadDSL(basePath: Path, products: Map): Collection { + logger.info("loadDSL from $basePath") val registry = ArrayList() - Files.list(basePath).filter { path -> path.fileName.toString().endsWith(".kts") }.forEach { path -> + val ktsFiles = Files.list(basePath).filter { path -> path.fileName.toString().endsWith(".kts") }.toList() + logger.info("File list = ${ktsFiles.stream().map { it.fileName.toString() }.collect(Collectors.joining(","))}") + ktsFiles.forEach { path -> val loadedComponents = loadDSLFile(path, products) registry.addAll(loadedComponents) } @@ -39,6 +42,7 @@ object ComponentsRegistryScriptRunner { } fun loadDSLFile(dslFilePath: Path, products: Map): Collection { + logger.info("loadDSLFile $dslFilePath") if (productTypeMap.isEmpty()) { products.forEach { k, v -> productTypeMap[v] = k } } @@ -69,4 +73,5 @@ object ComponentsRegistryScriptRunner { } ?: throw IllegalArgumentException("Unknown product type $type") fun getCurrentRegistry() = currentRegistry + fun getProductTypeMap() = productTypeMap } diff --git a/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/ComponentsRegistryDSLTest.kt b/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/ComponentsRegistryDSLTest.kt index 8858716..6e51d3b 100644 --- a/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/ComponentsRegistryDSLTest.kt +++ b/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/ComponentsRegistryDSLTest.kt @@ -1,22 +1,15 @@ package org.octopusden.octopus.components.registry.dsl.test -import org.junit.jupiter.api.Assertions.assertEquals -import org.junit.jupiter.api.Assertions.assertFalse -import org.junit.jupiter.api.Assertions.assertNotNull -import org.junit.jupiter.api.Assertions.assertNull -import org.junit.jupiter.api.Assertions.assertTrue -import org.octopusden.octopus.components.registry.api.build.tools.databases.OracleDatabaseTool -import org.octopusden.octopus.components.registry.api.build.tools.oracle.OdbcTool -import org.octopusden.octopus.components.registry.api.enums.BuildToolTypes -import org.octopusden.octopus.components.registry.api.enums.ProductTypes +import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test import org.junit.jupiter.api.parallel.Execution import org.junit.jupiter.api.parallel.ExecutionMode import org.junit.jupiter.api.parallel.ResourceLock -import org.octopusden.octopus.components.registry.dsl.PT_D -import org.octopusden.octopus.components.registry.dsl.PT_D_DB -import org.octopusden.octopus.components.registry.dsl.PT_K -import org.octopusden.octopus.components.registry.dsl.component +import org.octopusden.octopus.components.registry.api.build.tools.databases.OracleDatabaseTool +import org.octopusden.octopus.components.registry.api.build.tools.oracle.OdbcTool +import org.octopusden.octopus.components.registry.api.enums.BuildToolTypes +import org.octopusden.octopus.components.registry.api.enums.ProductTypes +import org.octopusden.octopus.components.registry.dsl.* /** * Parallel execution is not supported. @@ -61,7 +54,7 @@ class ComponentsRegistryDSLTest { @Test fun testProductTypes() { - val components = registryDsl { + val components = registryDsl (PRODUCT_TYPES_MAP) { component("DDD") { productType = "PT_K" build { @@ -286,4 +279,8 @@ class ComponentsRegistryDSLTest { assertTrue(components.getValue("Z").subComponents.getValue("Z1").build.dependencies.autoUpdate) assertNull(components.getValue("Z").subComponents.getValue("Z2").build) } + + companion object { + val PRODUCT_TYPES_MAP: Map = mapOf("PT_C" to PT_C, "PT_K" to PT_K, "PT_D" to PT_D, "PT_D_DB" to PT_D_DB) + } } \ No newline at end of file diff --git a/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/DslTestUtilities.kt b/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/DslTestUtilities.kt index 16d2b04..2ce36b0 100644 --- a/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/DslTestUtilities.kt +++ b/components-registry-dsl/src/test/kotlin/org/octopusden/octopus/components/registry/dsl/test/DslTestUtilities.kt @@ -1,10 +1,17 @@ package org.octopusden.octopus.components.registry.dsl.test import org.octopusden.octopus.components.registry.api.Component +import org.octopusden.octopus.components.registry.api.enums.ProductTypes import org.octopusden.octopus.components.registry.dsl.script.ComponentsRegistryScriptRunner +import java.util.* fun registryDsl(closure: ()-> Unit): Map { + return registryDsl(Collections.emptyMap(), closure) +} +fun registryDsl(productTypesMap: Map, closure: () -> Unit): Map { ComponentsRegistryScriptRunner.getCurrentRegistry().clear() + ComponentsRegistryScriptRunner.getProductTypeMap().clear() + ComponentsRegistryScriptRunner.getProductTypeMap().putAll(productTypesMap) closure() return ComponentsRegistryScriptRunner.getCurrentRegistry().map { it.name to it }.toMap() } \ No newline at end of file