Skip to content

Commit 2227272

Browse files
authored
Tweaks for PostConstruct/PreDestory changes (#75)
* Allow PostConstruct/PreDestory annotations from other packages. * Remove javax.annotation-api dependency since it is no longer strictly required.
1 parent 468c23b commit 2227272

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

inject-generator/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@
1919
<version>2.1-SNAPSHOT</version>
2020
</dependency>
2121

22-
<dependency>
23-
<groupId>javax.annotation</groupId>
24-
<artifactId>javax.annotation-api</artifactId>
25-
<version>1.3.2</version>
26-
</dependency>
27-
2822
<!-- test dependencies -->
2923
<dependency>
3024
<groupId>org.avaje.composite</groupId>

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,12 @@ private void readMethod(Element element, boolean factory) {
264264
}
265265
}
266266

267-
if (context.isPostConstructAvailable()) {
268-
if (hasAnnotationWithName(element, "PostConstruct")) {
269-
postConstructMethod = element;
270-
}
267+
if (hasAnnotationWithName(element, "PostConstruct")) {
268+
postConstructMethod = element;
269+
}
271270

272-
if (hasAnnotationWithName(element, "PreDestroy")) {
273-
preDestroyMethod = element;
274-
}
271+
if (hasAnnotationWithName(element, "PreDestroy")) {
272+
preDestroyMethod = element;
275273
}
276274
}
277275

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class Constants {
55
static final String KOTLIN_METADATA = "kotlin.Metadata";
66
static final String GENERATED_9 = "javax.annotation.processing.Generated";
77

8-
static final String POSTCONSTRUCT = "javax.annotation.PostConstruct";
98
static final String PROVIDER = "javax.inject.Provider";
109

1110
static final String PATH = "io.avaje.http.api.Path";

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
class IncludeAnnotations {
77

8-
private static final String[] EXCLUDED_PREFIX = {"javax.annotation.", "javax.inject.", "io.avaje.inject.", "lombok."};
8+
private static final String[] EXCLUDED_PREFIX = {"javax.annotation.", "javax.inject.", "jakarta.annotation.", "jakarta.inject.", "io.avaje.inject.", "lombok."};
9+
private static final String[] EXCLUDED_SUFFIX = {".PostConstruct", ".PreDestory"};
910

1011
/**
1112
* Annotations that we don't bother registering lists for.
@@ -26,6 +27,11 @@ static boolean include(String annotationType) {
2627
return false;
2728
}
2829
}
30+
for (String suffix : EXCLUDED_SUFFIX) {
31+
if (annotationType.endsWith(suffix)) {
32+
return false;
33+
}
34+
}
2935
return !EXCLUDED_ANNOTATIONS.contains(annotationType);
3036
}
3137
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ private boolean isTypeAvailable(String canonicalName) {
6060
return null != elementUtils.getTypeElement(canonicalName);
6161
}
6262

63-
boolean isPostConstructAvailable() {
64-
return isTypeAvailable(Constants.POSTCONSTRUCT);
65-
}
66-
6763
boolean isGeneratedAvailable() {
6864
return generatedAnnotation != null;
6965
}

inject-test/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
</dependency>
2626

2727
<!-- test dependencies -->
28+
<dependency>
29+
<groupId>javax.annotation</groupId>
30+
<artifactId>javax.annotation-api</artifactId>
31+
<version>1.3.2</version>
32+
</dependency>
33+
2834
<dependency>
2935
<groupId>io.avaje</groupId>
3036
<artifactId>avaje-http-api</artifactId>

0 commit comments

Comments
 (0)