Search in sources :

Example 1 with RootClassFolder

use of com.societegenerale.commons.plugin.model.RootClassFolder in project arch-unit-build-plugin-core by societe-generale.

the class RuleInvokerService method invokeConfigurableRules.

private String invokeConfigurableRules(ConfigurableRule rule) {
    if (rule.isSkip()) {
        if (log.isInfoEnabled()) {
            log.info("Skipping rule " + rule.getRule());
        }
        return "";
    }
    InvokableRules invokableRules = InvokableRules.of(rule.getRule(), rule.getChecks(), log);
    String fullPathFromRootTopackage = getPackageNameOnWhichToApplyRules(rule);
    log.info("invoking ConfigurableRule " + rule.toString() + " on " + fullPathFromRootTopackage);
    JavaClasses classes = archUtils.importAllClassesInPackage(new RootClassFolder(""), fullPathFromRootTopackage, excludedPaths);
    InvocationResult result = invokableRules.invokeOn(classes);
    return result.getMessage();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) InvocationResult(com.societegenerale.commons.plugin.service.InvokableRules.InvocationResult) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder)

Example 2 with RootClassFolder

use of com.societegenerale.commons.plugin.model.RootClassFolder in project arch-unit-build-plugin-core by societe-generale.

the class ArchUtilsTest method shouldIgnoreClassesFromConfiguredPaths.

@Test
public void shouldIgnoreClassesFromConfiguredPaths() {
    JavaClasses classes = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "");
    assertThat(classes).isNotEmpty();
    JavaClass classToExclude = classes.stream().filter(c -> c.getSource().get().getUri().toString().contains("ClassToExclude")).findFirst().get();
    assertThat(classToExclude).as("when no exclusion pattern configured, ClassToExclude should be found").isNotNull();
    JavaClasses classesWithTestClassesExclusions = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "", Arrays.asList("test-classes"));
    assertThat(containsClassWithPattern(classesWithTestClassesExclusions, "ClassToExclude")).as("when 'test-classes' pattern configured, ClassToExclude should still be found").isTrue();
    assertThat(classes.size()).as("There should be less classes loaded when we apply the test-classes exclusion").isGreaterThan(classesWithTestClassesExclusions.size());
    JavaClasses classesWithTestClassesAndSpecificExclusions = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target"), "", Arrays.asList("test-classes", "ClassToExclude"));
    assertThat(containsClassWithPattern(classesWithTestClassesAndSpecificExclusions, "ClassToExclude")).as("when 'ClassToExclude' pattern configured, ClassToExclude should not  be found").isFalse();
    assertThat(classesWithTestClassesAndSpecificExclusions.size() + 1).as("with a specific exclusion; we should have one less class than without").isEqualTo(classesWithTestClassesExclusions.size());
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder) Test(org.junit.Test)

Example 3 with RootClassFolder

use of com.societegenerale.commons.plugin.model.RootClassFolder in project arch-unit-build-plugin-core by societe-generale.

the class ArchUtilsTest method shouldLoadAllClassesWhenGivenPakageDoesntExist.

@Test
public void shouldLoadAllClassesWhenGivenPakageDoesntExist() {
    JavaClasses classes = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target/classes"), "someNotExistingFolder");
    long noOfClasses = classes.stream().filter(it -> !it.isNestedClass()).count();
    assertThat(noOfClasses).isEqualTo(36);
}
Also used : ArchUtils(com.societegenerale.commons.plugin.utils.ArchUtils) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SilentLog(com.societegenerale.commons.plugin.SilentLog) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder) JavaClass(com.tngtech.archunit.core.domain.JavaClass) Test(org.junit.Test) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder) Test(org.junit.Test)

Example 4 with RootClassFolder

use of com.societegenerale.commons.plugin.model.RootClassFolder in project arch-unit-build-plugin-core by societe-generale.

the class ArchUtilsTest method shouldLoadClassesFromGivenPackage.

@Test
public void shouldLoadClassesFromGivenPackage() {
    JavaClasses classes = ArchUtils.importAllClassesInPackage(new RootClassFolder("./target/classes/"), "com/societegenerale/commons/plugin/model");
    long noOfClassesInPackage = classes.stream().count();
    assertThat(noOfClassesInPackage).isEqualTo(4);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) RootClassFolder(com.societegenerale.commons.plugin.model.RootClassFolder) Test(org.junit.Test)

Aggregations

RootClassFolder (com.societegenerale.commons.plugin.model.RootClassFolder)4 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)4 Test (org.junit.Test)3 JavaClass (com.tngtech.archunit.core.domain.JavaClass)2 SilentLog (com.societegenerale.commons.plugin.SilentLog)1 InvocationResult (com.societegenerale.commons.plugin.service.InvokableRules.InvocationResult)1 ArchUtils (com.societegenerale.commons.plugin.utils.ArchUtils)1 Arrays (java.util.Arrays)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1