Skip to content

Commit

Permalink
GH-406 - Improving the detection of Spring AOT classes.
Browse files Browse the repository at this point in the history
We now inspect the classes for the newly introduced Spring AOT @generated annotation instead of a name containing a double underscore.
  • Loading branch information
odrotbohm committed Dec 8, 2023
1 parent 4043b2e commit c1f5630
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.tngtech.archunit.base.DescribedPredicate.*;
import static com.tngtech.archunit.core.domain.JavaClass.Predicates.*;
import static com.tngtech.archunit.core.domain.properties.CanBeAnnotated.Predicates.*;
import static com.tngtech.archunit.core.domain.properties.HasName.Predicates.*;
import static java.util.stream.Collectors.*;

Expand All @@ -33,6 +34,7 @@
import org.jgrapht.graph.DefaultEdge;
import org.jgrapht.traverse.TopologicalOrderIterator;
import org.jmolecules.archunit.JMoleculesDddRules;
import org.springframework.aot.generate.Generated;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.lang.Nullable;
Expand All @@ -44,6 +46,7 @@
import com.tngtech.archunit.base.DescribedPredicate;
import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.domain.properties.CanBeAnnotated;
import com.tngtech.archunit.core.domain.properties.HasName;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
Expand All @@ -64,8 +67,8 @@ public class ApplicationModules implements Iterable<ApplicationModule> {
private static final ImportOption IMPORT_OPTION = new ImportOption.DoNotIncludeTests();
private static final boolean JGRAPHT_PRESENT = ClassUtils.isPresent("org.jgrapht.Graph",
ApplicationModules.class.getClassLoader());
private static final DescribedPredicate<HasName> IS_AOT_TYPE = nameContaining("__")
.or(nameContaining("$$SpringCGLIB$$"));
private static final DescribedPredicate<CanBeAnnotated> IS_AOT_TYPE = annotatedWith(Generated.class);
private static final DescribedPredicate<HasName> IS_SPRING_CGLIB_PROXY = nameContaining("$$SpringCGLIB$$");

static {

Expand Down Expand Up @@ -101,7 +104,7 @@ protected ApplicationModules(ModulithMetadata metadata, Collection<String> packa
this.allClasses = new ClassFileImporter() //
.withImportOption(option) //
.importPackages(packages) //
.that(not(ignored.or(IS_AOT_TYPE)));
.that(not(ignored.or(IS_AOT_TYPE).or(IS_SPRING_CGLIB_PROXY)));

Classes classes = Classes.of(allClasses);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package com.acme.myproject.aot;

import org.springframework.aot.generate.Generated;

/**
*
* @author Oliver Drotbohm
*/
@Generated
public class Spring__Aot {

}

0 comments on commit c1f5630

Please sign in to comment.