Skip to content

Commit 825e0b3

Browse files
authored
Merge branch 'master' into feature/bump-bte-buddy
2 parents ef8f4b6 + d632f95 commit 825e0b3

File tree

22 files changed

+202
-92
lines changed

22 files changed

+202
-92
lines changed

.github/workflows/dependabot-merge.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ jobs:
2121
PR_URL: ${{github.event.pull_request.html_url}}
2222
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
2323
# Enable for automerge
24-
# - name: Enable auto-merge for Dependabot PRs
25-
# if: ${{contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'}}
26-
# run: gh pr merge --auto --merge "$PR_URL"
27-
# env:
28-
# PR_URL: ${{github.event.pull_request.html_url}}
29-
# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
24+
- name: Enable auto-merge for Dependabot PRs
25+
run: gh pr merge --auto --merge "$PR_URL"
26+
env:
27+
PR_URL: ${{github.event.pull_request.html_url}}
28+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

blackbox-aspect/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>avaje-inject-parent</artifactId>
77
<groupId>io.avaje</groupId>
8-
<version>9.8-RC1</version>
8+
<version>9.9-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

blackbox-other/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>avaje-inject-parent</artifactId>
88
<groupId>io.avaje</groupId>
9-
<version>9.8-RC1</version>
9+
<version>9.9-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>blackbox-other</artifactId>

blackbox-test-inject/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>avaje-inject-parent</artifactId>
77
<groupId>io.avaje</groupId>
8-
<version>9.8-RC1</version>
8+
<version>9.9-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>io.avaje</groupId>
4141
<artifactId>avaje-config</artifactId>
42-
<version>3.8</version>
42+
<version>3.9</version>
4343
</dependency>
4444

4545
<dependency>
@@ -57,7 +57,7 @@
5757
<dependency>
5858
<groupId>io.github.resilience4j</groupId>
5959
<artifactId>resilience4j-annotations</artifactId>
60-
<version>1.7.1</version>
60+
<version>2.1.0</version>
6161
</dependency>
6262

6363
<!-- annotation processor -->
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.example.myapp.conditional;
2+
3+
import io.avaje.inject.Component;
4+
import io.avaje.inject.RequiresProperty;
5+
import org.example.myapp.aspect.MyAround;
6+
7+
@Component
8+
@RequiresProperty(value = "factory")
9+
public class WithAspectConditional {
10+
11+
@MyAround
12+
void test(String str) {
13+
// does nothing
14+
}
15+
}

blackbox-test-inject/src/main/java/org/example/myapp/config/AFactory.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.avaje.inject.Bean;
44
import io.avaje.inject.Factory;
55

6+
import java.io.IOException;
7+
68
@Factory
79
class AFactory {
810

@@ -27,10 +29,19 @@ void ad(A0.Builder b1, A1.Builder b2) {
2729
b2.hashCode();
2830
}
2931

32+
@Bean
33+
AFoo buildAfoo() throws IOException {
34+
return new AFoo();
35+
}
36+
3037
static class I0 implements A0.Builder {
3138

3239
}
3340
static class I1 implements A1.Builder {
3441

3542
}
43+
44+
static class AFoo {
45+
46+
}
3647
}

blackbox-test-inject/src/test/java/org/example/myapp/conditional/ConditionalTests.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ConditionalTests {
2121

2222
@BeforeEach
2323
void clearConfig() {
24-
2524
Config.eventBuilder("")
2625
.remove("secondary")
2726
.remove("factory")
@@ -32,15 +31,14 @@ void clearConfig() {
3231
}
3332

3433
@Test
35-
void basic() throws IOException {
34+
void basic() {
3635
// just wire everything with no test scope, mocks etc
3736
final BeanScope beanScope = BeanScope.builder().build();
3837
assertTrue(beanScope.getOptional(Bird.class).isEmpty());
3938
}
4039

4140
@Test
42-
void jay() throws IOException {
43-
41+
void jay() {
4442
Config.setProperty("factory", "bird");
4543

4644
final BeanScope beanScope = BeanScope.builder().build();
@@ -51,8 +49,7 @@ void jay() throws IOException {
5149
}
5250

5351
@Test
54-
void birdWatch() throws IOException {
55-
52+
void birdWatch() {
5653
Config.setProperty("factory", "bird");
5754
Config.setProperty("watcher", "bird");
5855

@@ -62,8 +59,7 @@ void birdWatch() throws IOException {
6259
}
6360

6461
@Test
65-
void missingBeans() throws IOException {
66-
62+
void missingBeans() {
6763
Config.setProperty("watcher", "bird");
6864

6965
final BeanScope beanScope = BeanScope.builder().build();
@@ -72,34 +68,33 @@ void missingBeans() throws IOException {
7268
}
7369

7470
@Test
75-
void noFactory() throws IOException {
76-
71+
void noFactory() {
7772
Config.setProperty("kiwi", "somethin");
7873
Config.setProperty("watcher", "bird");
7974

8075
final BeanScope beanScope = BeanScope.builder().build();
8176

77+
assertTrue(beanScope.getOptional(WithAspectConditional.class).isEmpty());
8278
assertTrue(beanScope.getOptional(BirdFactory.class).isEmpty());
8379
assertTrue(beanScope.getOptional(BlueJay.class).isEmpty());
8480
assertTrue(beanScope.getOptional(BirdWatcher.class).isPresent());
8581
assertEquals("Kiwi", beanScope.get(Bird.class).toString());
8682
}
8783

8884
@Test
89-
void factoryKiwiOverride() throws IOException {
90-
85+
void factoryKiwiOverride() {
9186
Config.setProperty("kiwi", "somethin");
9287
Config.setProperty("factory", "bird");
9388
Config.setProperty("watcher", "bird");
9489

9590
final BeanScope beanScope = BeanScope.builder().build();
9691
assertTrue(beanScope.getOptional(BirdWatcher.class).isPresent());
92+
assertTrue(beanScope.getOptional(WithAspectConditional.class).isPresent());
9793
assertEquals("Kiwi", beanScope.get(Bird.class).toString());
9894
}
9995

10096
@Test
101-
void factorySecondaryOverride() throws IOException {
102-
97+
void factorySecondaryOverride() {
10398
Config.setProperty("secondary", "somethin");
10499
Config.setProperty("factory", "bird");
105100
Config.setProperty("watcher", "bird");
@@ -110,16 +105,14 @@ void factorySecondaryOverride() throws IOException {
110105
}
111106

112107
@Test
113-
void qualifierTest() throws IOException {
114-
108+
void qualifierTest() {
115109
final BeanScope beanScope =
116110
BeanScope.builder().bean("finch", Bird.class, new StrawberryFinch()).build();
117111
assertTrue(beanScope.getOptional(QualifiedBirdWatcher.class).isPresent());
118112
}
119113

120114
@Test
121-
void metaMetaAnnotationTest() throws IOException {
122-
115+
void metaMetaAnnotationTest() {
123116
Config.setProperty("finch-time", "somethin");
124117
Config.setProperty("factory", "bird");
125118
Config.setProperty("watcher", "bird");

inject-generator/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<parent>
77
<groupId>io.avaje</groupId>
88
<artifactId>avaje-inject-parent</artifactId>
9-
<version>9.8-RC1</version>
9+
<version>9.9-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>avaje-inject-generator</artifactId>
1313
<name>avaje inject generator</name>
1414
<description>annotation processor generating source code for avaje-inject dependency injection</description>
1515
<properties>
16-
<avaje.prisms.version>1.14</avaje.prisms.version>
16+
<avaje.prisms.version>1.16</avaje.prisms.version>
1717
</properties>
1818
<dependencies>
1919

inject-generator/src/main/java/io/avaje/inject/generator/Append.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,29 @@ final class Append {
1212
private final Writer writer;
1313
private int nameIndex;
1414
private boolean comma;
15+
private String extraIndent;
1516

1617
Append(Writer writer) {
1718
this.writer = writer;
1819
}
1920

21+
Append setExtraIndent(String extraIndent) {
22+
this.extraIndent = extraIndent;
23+
return this;
24+
}
25+
26+
Append indent(String content) {
27+
try {
28+
if (extraIndent != null) {
29+
writer.append(extraIndent);
30+
}
31+
writer.append(content);
32+
return this;
33+
} catch (IOException e) {
34+
throw new UncheckedIOException(e);
35+
}
36+
}
37+
2038
Append append(String content) {
2139
try {
2240
writer.append(content);

inject-generator/src/main/java/io/avaje/inject/generator/BeanReader.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,10 @@ final class BeanReader {
4444
this.prototype = PrototypePrism.isPresent(beanType);
4545
this.primary = PrimaryPrism.isPresent(beanType);
4646
this.secondary = !primary && SecondaryPrism.isPresent(beanType);
47-
this.proxy = ProxyPrism.isPresent(beanType);
4847
this.typeReader = new TypeReader(GenericType.parse(type), beanType, importTypes, factory);
4948

50-
conditions.readAll(beanType);
51-
5249
typeReader.process();
50+
5351
this.requestParams = new BeanRequestParams(type);
5452
this.name = typeReader.name();
5553
this.aspects = typeReader.hasAspects();
@@ -61,6 +59,18 @@ final class BeanReader {
6159
this.preDestroyPriority = typeReader.preDestroyPriority();
6260
this.constructor = typeReader.constructor();
6361
this.importedComponent = importedComponent && (constructor != null && constructor.isPublic());
62+
63+
var proxyPrism = ProxyPrism.getInstanceOn(beanType);
64+
if (proxyPrism != null) {
65+
this.proxy = true;
66+
var proxyMirror = proxyPrism.value();
67+
if (!"Void".equals(proxyMirror.toString())) {
68+
conditions.readAll(APContext.asTypeElement(proxyMirror));
69+
}
70+
} else {
71+
conditions.readAll(beanType);
72+
this.proxy = false;
73+
}
6474
}
6575

6676
@Override
@@ -111,7 +121,7 @@ List<Dependency> dependsOn() {
111121
for (MethodReader.MethodParam param : constructor.params()) {
112122
Dependency dependsOn = param.dependsOn();
113123
// BeanScope is always injectable with no impact on injection ordering
114-
if (!dependsOn.dependsOn().equals(Constants.BEANSCOPE)) {
124+
if (!Constants.BEANSCOPE.equals(dependsOn.dependsOn())) {
115125
list.add(dependsOn);
116126
}
117127
}
@@ -230,7 +240,7 @@ void buildRegister(Append writer) {
230240
if (prototype) {
231241
return;
232242
}
233-
writer.append(" ");
243+
writer.indent(" ");
234244
if (isExtraInjectionRequired() || hasLifecycleMethods()) {
235245
writer.append("var $bean = ");
236246
}
@@ -245,14 +255,14 @@ void buildRegister(Append writer) {
245255

246256
void addLifecycleCallbacks(Append writer, String indent) {
247257
if (postConstructMethod != null && !prototype) {
248-
writer.append("%s builder.addPostConstruct($bean::%s);", indent, postConstructMethod.getSimpleName()).eol();
258+
writer.indent(indent).append(" builder.addPostConstruct($bean::%s);", postConstructMethod.getSimpleName()).eol();
249259
}
250260
if (preDestroyMethod != null) {
251261
prototypeNotSupported("@PreDestroy");
252262
var priority = preDestroyPriority == null || preDestroyPriority == 1000 ? "" : ", " + preDestroyPriority;
253-
writer.append("%s builder.addPreDestroy($bean::%s%s);", indent, preDestroyMethod.getSimpleName(), priority).eol();
263+
writer.indent(indent).append(" builder.addPreDestroy($bean::%s%s);", preDestroyMethod.getSimpleName(), priority).eol();
254264
} else if (typeReader.isClosable() && !prototype) {
255-
writer.append("%s builder.addPreDestroy($bean);", indent).eol();
265+
writer.indent(indent).append(" builder.addPreDestroy($bean);").eol();
256266
}
257267
}
258268

@@ -438,4 +448,13 @@ private String beanPackageName() {
438448
private String beanQualifiedName() {
439449
return beanType.getQualifiedName().toString();
440450
}
451+
452+
boolean needsTryForMethodInjection() {
453+
for (MethodReader injectMethod : injectMethods) {
454+
if (injectMethod.methodThrows()) {
455+
return true;
456+
}
457+
}
458+
return false;
459+
}
441460
}

0 commit comments

Comments
 (0)