Skip to content

Commit

Permalink
fix(ca validation): moved dep search into gradle task to avoid Concur…
Browse files Browse the repository at this point in the history
…entModificationExceptions
  • Loading branch information
gabheadz committed Jun 15, 2024
1 parent 07463b4 commit 8f430d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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());
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/co/com/bancolombia/task/ValidateStructureTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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");
Expand Down

0 comments on commit 8f430d7

Please sign in to comment.