From 8f430d7df0e80e6231c2e1bc9e14fd61da7dc003 Mon Sep 17 00:00:00 2001 From: Gabriel Martinez Date: Sat, 15 Jun 2024 06:51:38 -0500 Subject: [PATCH] fix(ca validation): moved dep search into gradle task to avoid ConcurentModificationExceptions --- .../architecture/ArchitectureValidation.java | 13 ------------- .../bancolombia/task/ValidateStructureTask.java | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/co/com/bancolombia/factory/validations/architecture/ArchitectureValidation.java b/src/main/java/co/com/bancolombia/factory/validations/architecture/ArchitectureValidation.java index 473e4c79..8b82b639 100644 --- a/src/main/java/co/com/bancolombia/factory/validations/architecture/ArchitectureValidation.java +++ b/src/main/java/co/com/bancolombia/factory/validations/architecture/ArchitectureValidation.java @@ -9,7 +9,6 @@ import lombok.NoArgsConstructor; import lombok.SneakyThrows; import org.gradle.api.Project; -import org.gradle.api.artifacts.Configuration; @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ArchitectureValidation { @@ -37,21 +36,9 @@ private static String toOSPath(String os, File projectDir) { return projectDir.toString(); } - private static void prepareParams(Project project, Project appService, ModuleBuilder builder) { - boolean hasSpringWeb = - appService.getConfigurations().stream() - .map(Configuration::getIncoming) - .flatMap(d -> d.getDependencies().stream()) - .map(d -> d.getGroup() + ":" + d.getName()) - .anyMatch(dep -> dep.equals("org.springframework:spring-web")); - project.getLogger().debug("hasSpringWeb: {}", hasSpringWeb); - builder.addParam("hasSpringWeb", hasSpringWeb); - } - @SneakyThrows private static void generateArchUnitFiles( Project project, Project appService, ModuleBuilder builder) { - prepareParams(project, appService, builder); project .getLogger() .lifecycle("Injecting ArchitectureTest in module {}", appService.getProjectDir().getName()); diff --git a/src/main/java/co/com/bancolombia/task/ValidateStructureTask.java b/src/main/java/co/com/bancolombia/task/ValidateStructureTask.java index 3e274f45..ed756fdd 100644 --- a/src/main/java/co/com/bancolombia/task/ValidateStructureTask.java +++ b/src/main/java/co/com/bancolombia/task/ValidateStructureTask.java @@ -19,6 +19,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.Dependency; import org.gradle.api.artifacts.DependencySet; +import org.gradle.api.artifacts.UnknownConfigurationException; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; @@ -47,7 +48,7 @@ public void execute() throws IOException, CleanException { logger.lifecycle("Clean Architecture plugin version: {}", Utils.getVersionPlugin()); getModules().forEach(d -> logger.lifecycle("Submodules: " + d.getKey())); logger.lifecycle("Project Package: {}", packageName); - + checkForSpringWebDependency(); ArchitectureValidation.inject(getProject(), builder); if (!validateModelLayer()) { @@ -62,6 +63,20 @@ public void execute() throws IOException, CleanException { logger.lifecycle("The project is valid"); } + private void checkForSpringWebDependency() { + boolean hasSpringWeb = false; + try { + hasSpringWeb = + getProject().getChildProjects().get(APP_SERVICE).getConfigurations() + .getByName("testImplementation").getDependencies().stream() + .anyMatch(d -> d.getName().equals("spring-web")); + } catch (UnknownConfigurationException e) { + logger.warn("configuration testImplementation not present"); + } + logger.lifecycle("has spring-web dependency to run validations: {}", hasSpringWeb); + builder.addParam("hasSpringWeb", hasSpringWeb); + } + private boolean validateModelLayer() { if (validateExistingModule(MODEL_MODULE)) { logger.lifecycle("Validating Model Module");