Skip to content

Commit

Permalink
Merge pull request #2315 from DamnClin/arch-unit-module
Browse files Browse the repository at this point in the history
Migrate arch unit module
  • Loading branch information
pascalgrimaud authored Jun 30, 2022
2 parents 89d092d + 74bff80 commit fc3681b
Show file tree
Hide file tree
Showing 19 changed files with 177 additions and 412 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ private GeneratorAction() {}

public static final String MONGOCK = "mongock";

public static final String JAVA_ARCHUNIT = "java-archunit";

public static final String MARIADB = "mariadb";

public static final String MONGODB = "mongodb";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package tech.jhipster.lite.generator.server.javatool.arch.application;

import org.springframework.stereotype.Service;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.server.javatool.arch.domain.JavaArchUnitService;
import tech.jhipster.lite.generator.server.javatool.arch.domain.ArchUnitModuleFactory;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

@Service
public class JavaArchUnitApplicationService {

private final JavaArchUnitService javaArchUnitService;
private final ArchUnitModuleFactory factory;

public JavaArchUnitApplicationService(JavaArchUnitService javaArchUnitService) {
this.javaArchUnitService = javaArchUnitService;
public JavaArchUnitApplicationService() {
factory = new ArchUnitModuleFactory();
}

public void init(Project project) {
javaArchUnitService.init(project);
public JHipsterModule buildModule(JHipsterModuleProperties properties) {
return factory.buildModule(properties);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package tech.jhipster.lite.generator.server.javatool.arch.domain;

import static tech.jhipster.lite.module.domain.JHipsterModule.*;

import java.util.stream.Collectors;
import java.util.stream.Stream;
import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.module.domain.JHipsterDestination;
import tech.jhipster.lite.module.domain.JHipsterModule;
import tech.jhipster.lite.module.domain.JHipsterSource;
import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
import tech.jhipster.lite.module.domain.javadependency.JavaDependencyScope;
import tech.jhipster.lite.module.domain.properties.JHipsterBasePackage;
import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;

public class ArchUnitModuleFactory {

private static final String QUOTE = "\"";
private static final JHipsterSource SOURCE = from("server/javatool/arch");

public JHipsterModule buildModule(JHipsterModuleProperties properties) {
Assert.notNull("properties", properties);

JHipsterDestination testDestination = toSrcTestJava().append(properties.basePackage().path());

//@formatter:off
return moduleBuilder(properties)
.context()
.put("packageWalkPath", packageWalkPath(properties.basePackage()))
.and()
.files()
.add(SOURCE.template("archunit.properties"), to("src/test/resources/archunit.properties"))
.add(SOURCE.template("HexagonalArchTest.java"), testDestination.append("HexagonalArchTest.java"))
.and()
.javaDependencies()
.add(archUnitDependency())
.and()
.optionalReplacements()
.in("src/test/resources/logback.xml")
.add(justLineBefore(text("<!-- jhipster-needle-logback-add-log -->")), "<logger name=\"com.tngtech.archunit\" level=\"WARN\" />")
.and()
.and()
.build();
//@formatter:on
}

private String packageWalkPath(JHipsterBasePackage basePackage) {
return Stream.of(basePackage.path().split("/")).map(folder -> QUOTE + folder + QUOTE).collect(Collectors.joining(", "));
}

private JavaDependency archUnitDependency() {
return javaDependency()
.groupId("com.tngtech.archunit")
.artifactId("archunit-junit5-api")
.versionSlug("archunit-junit5.version")
.scope(JavaDependencyScope.TEST)
.build();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package tech.jhipster.lite.generator.server.javatool.arch.infrastructure.primary;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import tech.jhipster.lite.generator.server.javatool.arch.application.JavaArchUnitApplicationService;
import tech.jhipster.lite.module.domain.properties.JHipsterModulePropertiesDefinition;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleApiDoc;
import tech.jhipster.lite.module.infrastructure.primary.JHipsterModuleResource;

@Configuration
class ArchUnitModuleConfiguration {

@Bean
JHipsterModuleResource archUnitModule(JavaArchUnitApplicationService archUnit) {
return JHipsterModuleResource
.builder()
.legacyUrl("/api/servers/java/arch")
.slug("java-archunit")
.propertiesDefinition(JHipsterModulePropertiesDefinition.builder().addBasePackage().build())
.apiDoc(new JHipsterModuleApiDoc("Java", "Add Hexagonal Arch classes to project"))
.factory(archUnit::buildModule);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HexagonalArchTest {
private static Collection<String> getPackageAnnotatedBy(Class<? extends Annotation> annotationClass) throws AssertionError {
try {
return Files
.walk(Paths.get("src", "main", "java", {{{packageWalkPath}}}))
.walk(Paths.get("src", "main", "java", {{ packageWalkPath }}))
.filter(path -> path.toString().endsWith("package-info.java"))
.map(toPackageName())
.map(path -> path.replaceAll("[\\/]", "."))
Expand Down
7 changes: 7 additions & 0 deletions src/test/features/arch-unit.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Feature: Arch Unit

Scenario: Should apply arch unit module
When I apply "java-archunit" module to default project with maven file
| packageName | tech.jhipster.chips |
Then I should have files in "src/test/java/tech/jhipster/chips"
| HexagonalArchTest.java |

This file was deleted.

Loading

0 comments on commit fc3681b

Please sign in to comment.