Skip to content

Commit

Permalink
GH-406 - Ignore Spring AOT generated types in architecture model.
Browse files Browse the repository at this point in the history
We now explicitly exclude classes generated by Spring AOT in the architectural model. For technical reasons, they might introduce dependencies to application components considered module internals otherwise. Also, proxies generated do not need to be considered either.
  • Loading branch information
odrotbohm committed Dec 6, 2023
1 parent da43c72 commit e7b531e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
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.HasName.Predicates.*;
import static java.util.stream.Collectors.*;

import java.util.*;
Expand All @@ -43,6 +44,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.HasName;
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption;
import com.tngtech.archunit.lang.EvaluationResult;
Expand All @@ -62,6 +64,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$$"));

static {

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

Classes classes = Classes.of(allClasses);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.acme.myproject.aot;

/**
*
* @author Oliver Drotbohm
*/
public class Some$$SpringCGLIB$$Proxy {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.acme.myproject.aot;

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package com.acme.myproject.aot;
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.junit.jupiter.api.Test;

import com.acme.myproject.Application;
import com.acme.myproject.aot.Some$$SpringCGLIB$$Proxy;
import com.acme.myproject.aot.Spring__Aot;
import com.acme.myproject.complex.internal.FirstTypeBasedPort;
import com.acme.myproject.complex.internal.SecondTypeBasePort;
import com.acme.myproject.moduleA.ServiceComponentA;
Expand Down Expand Up @@ -185,6 +187,15 @@ void explicitEmptyAllowedModulesResultsInAllDependenciesRejected() {
assertThat(third.getDeclaredDependencies(modules).isAllowedDependency(Fourth.class)).isTrue();
}

@Test // GH-406
void excludesSpringAOTGeneratedTypes() {

assertThat(modules.getModuleByName("aot")).hasValueSatisfying(it -> {
assertThat(it.contains(Spring__Aot.class)).isFalse();
assertThat(it.contains(Some$$SpringCGLIB$$Proxy.class)).isFalse();
});
}

private static void verifyNamedInterfaces(NamedInterfaces interfaces, String name, Class<?>... types) {

Stream.of(types).forEach(type -> {
Expand Down

0 comments on commit e7b531e

Please sign in to comment.