Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit a224485

Browse files
committed
Support conditions involving AbstractNestedCondition
Fixes #719
1 parent 496b425 commit a224485

File tree

6 files changed

+52
-3
lines changed

6 files changed

+52
-3
lines changed

samples/features/src/main/java/com/example/commandlinerunner/Application.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import elsewhere.FooBeanFactory;
88

99
@SpringBootApplication
10-
// 1. Importing configuration
11-
@Import(FooBeanFactory.class)
10+
@Import({FooBeanFactory.class,ConditionalConfig.class})
1211
public class Application {
1312

1413
public static void main(String[] args) throws InterruptedException {

samples/features/src/main/java/com/example/commandlinerunner/CLR.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ SomeComponent someComponent() {
2020
return new SomeComponent();
2121
}
2222

23+
@Autowired
24+
SomeBean someBean;
25+
2326
@Autowired
2427
ApplicationContext env;
2528

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.example.commandlinerunner;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Conditional;
5+
6+
@Conditional(TrickyCondition.class)
7+
public class ConditionalConfig {
8+
9+
@Bean
10+
SomeBean getBean() {
11+
return new SomeBean();
12+
}
13+
14+
}
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.example.commandlinerunner;
2+
3+
public class SomeBean {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.example.commandlinerunner;
2+
3+
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
4+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
5+
6+
public class TrickyCondition extends AnyNestedCondition {
7+
private TrickyCondition() {
8+
super(ConfigurationPhase.REGISTER_BEAN);
9+
}
10+
11+
@ConditionalOnClass(String.class)
12+
static class Inner {
13+
Inner() {
14+
15+
}
16+
17+
}
18+
19+
20+
}

spring-aot/src/main/java/org/springframework/nativex/support/ResourcesHandler.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ enum ReachedBy {
10521052
NestedReference, // This was discovered as a nested type within some type currently being processed
10531053
HierarchyProcessing, // This was discovered whilst going up the hierarchy from some type currently being processed
10541054
Inferred, // This type was 'inferred' whilst processing a hint (e.g. the class in a @COC usage)
1055-
Specific // This type was explicitly listed in a hint that was processed
1055+
Specific, // This type was explicitly listed in a hint that was processed
1056+
InnerOfNestedCondition // it is the inner type of a class implementing AbstractNestedCondition
10561057
}
10571058

10581059
private boolean checkJmxConstraint(Type type, ProcessingContext pc) {
@@ -1496,6 +1497,12 @@ private boolean processImplicitTypeReferencesFromHint(ProcessingContext pc,
14961497
logger.debug("will follow " + t);
14971498
ReachedBy reason = isImportHint(hint)?ReachedBy.Import:ReachedBy.Inferred;
14981499
toFollow.put(t,reason);
1500+
} else if (t.isAbstractNestedCondition()) {
1501+
// The inner types are hosting conditions
1502+
logger.debug("will follow inner types inside this nested condition type " + t);
1503+
for (Type inner : t.getNestedTypes()) {
1504+
toFollow.put(inner, ReachedBy.InnerOfNestedCondition);
1505+
}
14991506
}
15001507
} else if (hint.isSkipIfTypesMissing() && (pc.depth() == 1 || isNestedConfiguration(type) /*|| reachedBy==ReachedBy.Specific*/ || pc.peekReachedBy()==ReachedBy.Import)) {
15011508
if (pc.depth()>1) {

0 commit comments

Comments
 (0)