Skip to content

Commit

Permalink
Add clientCode and parentComponent (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamaradeRoman committed Jan 24, 2024
1 parent b985b6e commit 89d5032
Show file tree
Hide file tree
Showing 11 changed files with 246 additions and 158 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package org.octopusden.octopus.escrow.configuration.model

import org.octopusden.octopus.escrow.BuildSystem
import org.octopusden.octopus.escrow.configuration.loader.VCSSettingsWrapper
import org.octopusden.octopus.escrow.model.BuildParameters
import org.octopusden.octopus.escrow.model.Distribution
import org.octopusden.octopus.releng.dto.JiraComponent
import groovy.transform.AutoClone
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.transform.TupleConstructor
import groovy.transform.TypeChecked
import org.octopusden.octopus.escrow.BuildSystem
import org.octopusden.octopus.escrow.configuration.loader.VCSSettingsWrapper
import org.octopusden.octopus.escrow.model.BuildParameters
import org.octopusden.octopus.escrow.model.Distribution
import org.octopusden.octopus.releng.dto.JiraComponent

@TupleConstructor
@EqualsAndHashCode
Expand All @@ -26,7 +26,7 @@ class DefaultConfigParameters {

String artifactIdPattern

String groupIdPattern;
String groupIdPattern

JiraComponent jiraComponent

Expand All @@ -46,6 +46,10 @@ class DefaultConfigParameters {

String system

String clientCode

String parentComponent

String octopusVersion
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.octopusden.octopus.escrow.configuration.model

import groovy.transform.AutoClone
import groovy.transform.AutoCloneStyle
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.transform.TupleConstructor
import org.octopusden.octopus.components.registry.api.VersionedComponentConfiguration
import org.octopusden.octopus.components.registry.api.beans.VersionedComponentConfigurationBean
import org.octopusden.octopus.components.registry.api.enums.ProductTypes
Expand All @@ -11,17 +16,13 @@ import org.octopusden.octopus.escrow.model.BuildParameters
import org.octopusden.octopus.escrow.model.Distribution
import org.octopusden.octopus.escrow.model.VCSSettings
import org.octopusden.octopus.releng.dto.JiraComponent
import groovy.transform.AutoClone
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.transform.TupleConstructor
import groovy.transform.AutoCloneStyle

@TupleConstructor
@AutoClone(style = AutoCloneStyle.CLONE)
@EqualsAndHashCode(includeFields = true, includes = ["buildSystem", "artifactIdPattern", "groupIdPattern",// "versionRange",
"buildFilePath", "jiraConfiguration", "buildConfiguration", "deprecated", "vcsSettings",
"distribution", "componentDisplayName", "componentOwner", "releaseManager", "securityChampion", "system", "octopusVersion", "escrow", "productType"])
"buildFilePath", "jiraConfiguration", "buildConfiguration", "deprecated", "vcsSettings",
"distribution", "componentDisplayName", "componentOwner", "releaseManager", "securityChampion", "system",
"clientCode", "parentComponent", "octopusVersion", "escrow", "productType"])
@ToString(includeFields = true)
class EscrowModuleConfig {
private BuildSystem buildSystem
Expand Down Expand Up @@ -54,6 +55,10 @@ class EscrowModuleConfig {

private String system

private String clientCode

private String parentComponent

private String octopusVersion

Escrow escrow
Expand Down Expand Up @@ -116,6 +121,14 @@ class EscrowModuleConfig {
return system
}

String getClientCode() {
return clientCode
}

String getParentComponent() {
return parentComponent
}

String getComponentDisplayName() {
return componentDisplayName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ package org.octopusden.octopus.escrow.configuration.validation

import groovy.transform.TupleConstructor
import groovy.transform.TypeChecked
import java.util.function.BinaryOperator
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
import java.util.stream.Stream
import kotlin.Pair
import org.apache.commons.lang3.StringUtils
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.octopusden.octopus.escrow.BuildSystem
import org.octopusden.octopus.escrow.MavenArtifactMatcher
import org.octopusden.octopus.escrow.RepositoryType
import org.octopusden.octopus.escrow.configuration.loader.EscrowConfigurationLoader
import org.octopusden.octopus.escrow.configuration.model.EscrowConfiguration
import org.octopusden.octopus.escrow.configuration.model.EscrowModule
Expand All @@ -20,11 +23,6 @@ import org.octopusden.releng.versions.VersionNames
import org.octopusden.releng.versions.VersionRange
import org.octopusden.releng.versions.VersionRangeFactory

import java.util.function.BinaryOperator
import java.util.regex.Pattern
import java.util.regex.PatternSyntaxException
import java.util.stream.Stream

@TypeChecked
class EscrowConfigValidator {

Expand All @@ -33,6 +31,7 @@ class EscrowConfigValidator {

private static final Logger LOG = LogManager.getLogger(EscrowConfigValidator.class)
public static final String SPLIT_PATTERN = "[,|\\s]+"
private static final Pattern CLIENT_CODE_PATTERN = Pattern.compile("[A-Z_0-9]+")

private List<String> supportedGroupIds
private List<String> supportedSystems
Expand Down Expand Up @@ -82,31 +81,31 @@ class EscrowConfigValidator {

boolean validateEscrowConfiguration(EscrowConfiguration configuration) {
LOG.info("Validate of escrow configuration started")
def modules = configuration.getEscrowModules()
for (String component : modules.keySet()) {
EscrowModule escrowModule = configuration.getEscrowModules().get(component)
configuration.escrowModules.each { String componentName, EscrowModule escrowModule ->
def configurations = escrowModule.getModuleConfigurations()
if (configurations.isEmpty()) {
registerError("No configurations in module $component")
registerError("No configurations in module $componentName")
}
for (EscrowModuleConfig moduleConfig : configurations) {
validateMandatoryFields(moduleConfig, component)
validateBuildSystem(moduleConfig.getBuildSystem(), component)
validateArtifactId(moduleConfig.getArtifactIdPattern(), component)
validateGroupId(moduleConfig, component)
validateVcsSettings(moduleConfig, component)
validateVersionRange(moduleConfig, component)
validateJiraParams(moduleConfig, component)
validateExplicitExternalComponent(moduleConfig, component)
validateSystem(moduleConfig, component)
validateMandatoryFields(moduleConfig, componentName)
validateBuildSystem(moduleConfig.getBuildSystem(), componentName)
validateArtifactId(moduleConfig.getArtifactIdPattern(), componentName)
validateGroupId(moduleConfig, componentName)
validateVcsSettings(moduleConfig, componentName)
validateVersionRange(moduleConfig, componentName)
validateJiraParams(moduleConfig, componentName)
validateExplicitExternalComponent(moduleConfig, componentName)
validateSystem(moduleConfig, componentName)
validateClientCode(moduleConfig, componentName)
}
}
if (!hasErrors()) {
validateVersionConflicts(configuration)
validateGroupIdAndVersionIdIntersections(configuration)
validateComponentParent(configuration)
validateArchivedComponents(configuration)
} else {
LOG.warn("Validating version conflicts is skipped due to the previous errors")
LOG.warn("Composite validations are skipped due to the previous errors")
}
LOG.info("Validate of escrow configuration completed")
return hasErrors()
Expand Down Expand Up @@ -171,6 +170,25 @@ class EscrowConfigValidator {
}
}

def validateComponentParent(EscrowConfiguration configuration) {
configuration.escrowModules.each { String componentName, EscrowModule escrowModule ->
escrowModule.moduleConfigurations.each { moduleConfiguration ->
if (moduleConfiguration.parentComponent != null) {
def parentEscrowModule = configuration.escrowModules[moduleConfiguration.parentComponent]
if (parentEscrowModule == null) {
registerError("parentComponent '${moduleConfiguration.parentComponent}' is not found for '$componentName'")
} else {
parentEscrowModule.moduleConfigurations.find { parentComponentConfiguration ->
parentComponentConfiguration.parentComponent != null
}?.with {
registerError("Component '${moduleConfiguration.parentComponent}' having parentComponent specified is set as parentComponent for '$componentName'")
}
}
}
}
}
}

/**
* Validate archived component.
* Check distribution section of the component.
Expand Down Expand Up @@ -223,7 +241,6 @@ class EscrowConfigValidator {
}
def versionRangeFactory = new VersionRangeFactory(escrowConfiguration.versionNames)
map.each { it ->
def mavenArtifact = it.key
List<EscrowModuleConfig> configs = it.value
if (configs.size() > 1) {
for (int i = 0; i < configs.size() - 1; i++) {
Expand All @@ -233,7 +250,7 @@ class EscrowConfigValidator {
def vr1 = versionRangeFactory.create(config1.getVersionRangeString())
def vr2 = versionRangeFactory.create(config2.getVersionRangeString())
if (versionRangeHelper.hasIntersection(vr1, vr2)) {
registerError("More than one configuration matches $mavenArtifact. " +
registerError("More than one configuration matches ${it.key}. " +
"Intersection of version ranges ${config1.getVersionRangeString()} with ${config2.getVersionRangeString()}.")
}
}
Expand Down Expand Up @@ -370,6 +387,13 @@ class EscrowConfigValidator {
}
}

def validateClientCode(EscrowModuleConfig moduleConfig, String component) {
def clientCode = moduleConfig.getClientCode()
if (clientCode != null && !CLIENT_CODE_PATTERN.matcher(clientCode).matches()) {
registerError("clientCode is not matched '${CLIENT_CODE_PATTERN.pattern()}' in '$component'")
}
}

/**
* Validate component name.
* @param componentName component name
Expand Down
Loading

0 comments on commit 89d5032

Please sign in to comment.