Skip to content

Make javax.annotation-api dependency optional #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@
<version>1</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
20 changes: 15 additions & 5 deletions inject/src/main/java/io/avaje/inject/core/DBeanContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Priority;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -233,10 +233,20 @@ private static class SortBean<T> implements Comparable<SortBean<T>> {
}

int initPriority() {
final Priority ann = bean.getClass().getAnnotation(Priority.class);
if (ann != null) {
priorityDefined = true;
return ann.value();
// Avoid adding hard dependency on javax.annotation-api by using reflection to find @Priority
try {
Class<? extends Annotation> type = (Class<? extends Annotation>) Class.forName("javax.annotation.Priority");
Annotation ann = bean.getClass().getAnnotation(type);
if (ann != null) {
int priority = (Integer) type.getMethod("value").invoke(ann);
priorityDefined = true;
return priority;
}
} catch (ClassNotFoundException ignore) {
// @Priority not available, so just use default priority
} catch (ReflectiveOperationException | SecurityException | IllegalArgumentException | ExceptionInInitializerError | ClassCastException e) {
// If this happens, something has gone very wrong since a non-confirming @Priority was found...
throw new UnsupportedOperationException("Problem instantiating @Priority", e);
}
// Default priority as per javax.ws.rs.Priorities.USER
// User-level filter/interceptor priority
Expand Down