Skip to content

Commit e378c46

Browse files
committed
jooby-apt: remove JAXRS dependency
Fixes jooby-project#2174
1 parent a11ee80 commit e378c46

File tree

3 files changed

+97
-53
lines changed

3 files changed

+97
-53
lines changed

modules/jooby-apt/pom.xml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@
2626
<optional>true</optional>
2727
</dependency>
2828

29-
<!-- JAXRS -->
30-
<dependency>
31-
<groupId>jakarta.ws.rs</groupId>
32-
<artifactId>jakarta.ws.rs-api</artifactId>
33-
</dependency>
34-
3529
<!-- Test dependencies -->
3630
<dependency>
3731
<groupId>com.google.testing.compile</groupId>
3832
<artifactId>compile-testing</artifactId>
3933
<scope>test</scope>
4034
</dependency>
4135

36+
<!-- JAXRS -->
37+
<dependency>
38+
<groupId>jakarta.ws.rs</groupId>
39+
<artifactId>jakarta.ws.rs-api</artifactId>
40+
<scope>test</scope>
41+
</dependency>
42+
4243
<dependency>
4344
<groupId>com.google.truth</groupId>
4445
<artifactId>truth</artifactId>

modules/jooby-apt/src/main/java/io/jooby/apt/Annotations.java

Lines changed: 64 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@
55
*/
66
package io.jooby.apt;
77

8+
import static java.util.Arrays.asList;
9+
import static java.util.Collections.unmodifiableSet;
10+
11+
import java.util.Arrays;
12+
import java.util.Collections;
13+
import java.util.LinkedHashSet;
14+
import java.util.List;
15+
import java.util.Map;
16+
import java.util.Objects;
17+
import java.util.Set;
18+
import java.util.function.Function;
19+
import java.util.stream.Collectors;
20+
21+
import javax.annotation.Nonnull;
22+
import javax.lang.model.element.AnnotationMirror;
23+
import javax.lang.model.element.AnnotationValue;
24+
import javax.lang.model.element.ExecutableElement;
25+
826
import io.jooby.annotations.CONNECT;
927
import io.jooby.annotations.Consumes;
1028
import io.jooby.annotations.ContextParam;
@@ -27,54 +45,60 @@
2745
import io.jooby.annotations.SessionParam;
2846
import io.jooby.annotations.TRACE;
2947

30-
import javax.annotation.Nonnull;
31-
import javax.lang.model.element.AnnotationMirror;
32-
import javax.lang.model.element.AnnotationValue;
33-
import javax.lang.model.element.ExecutableElement;
34-
import javax.ws.rs.core.Context;
35-
import java.util.Arrays;
36-
import java.util.Collections;
37-
import java.util.LinkedHashSet;
38-
import java.util.List;
39-
import java.util.Map;
40-
import java.util.Objects;
41-
import java.util.Set;
42-
import java.util.function.Function;
43-
import java.util.stream.Collectors;
44-
45-
import static java.util.Arrays.asList;
46-
import static java.util.Collections.unmodifiableSet;
47-
4848
/**
4949
* Annotation constants used by the APT.
5050
*
5151
* @since 2.1.0
5252
*/
5353
public interface Annotations {
54+
/** JAXRS GET. */
55+
String JAXRS_GET = "javax.ws.rs.GET";
56+
/** JAXRS POST. */
57+
String JAXRS_POST = "javax.ws.rs.POST";
58+
/** JAXRS PUT. */
59+
String JAXRS_PUT = "javax.ws.rs.PUT";
60+
/** JAXRS DELETE. */
61+
String JAXRS_DELETE = "javax.ws.rs.DELETE";
62+
/** JAXRS PATCH. */
63+
String JAXRS_PATCH = "javax.ws.rs.PATCH";
64+
/** JAXRS HEAD. */
65+
String JAXRS_HEAD = "javax.ws.rs.HEAD";
66+
/** JAXRS OPTIONS. */
67+
String JAXRS_OPTIONS = "javax.ws.rs.OPTIONS";
68+
/** JAXRS Context. */
69+
String JAXRS_CONTEXT = "javax.ws.rs.core.Context";
70+
/** JAXRS Query Param. */
71+
String JAXRS_QUERY = "javax.ws.rs.QueryParam";
72+
/** JAXRS Cookie Param. */
73+
String JAXRS_COOKIE = "javax.ws.rs.CookieParam";
74+
/** JAXRS Header Param. */
75+
String JAXRS_HEADER = "javax.ws.rs.HeaderParam";
76+
/** JAXRS Form Param. */
77+
String JAXRS_FORM = "javax.ws.rs.FormParam";
78+
/** JAXRS PRODUCES. */
79+
String JAXRS_PRODUCES = "javax.ws.rs.Produces";
80+
/** JAXRS CONSUMES. */
81+
String JAXRS_CONSUMES = "javax.ws.rs.Consumes";
82+
/** JAXRS PATH. */
83+
String JAXRS_PATH = "javax.ws.rs.Path";
84+
5485
/**
5586
* HTTP method supported.
5687
*/
5788
Set<String> HTTP_METHODS = unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
58-
GET.class.getName(),
59-
javax.ws.rs.GET.class.getName(),
89+
GET.class.getName(), JAXRS_GET,
6090

61-
POST.class.getName(),
62-
javax.ws.rs.POST.class.getName(),
91+
POST.class.getName(), JAXRS_POST,
6392

64-
PUT.class.getName(),
65-
javax.ws.rs.PUT.class.getName(),
93+
PUT.class.getName(), JAXRS_PUT,
6694

67-
DELETE.class.getName(),
68-
javax.ws.rs.DELETE.class.getName(),
95+
DELETE.class.getName(), JAXRS_DELETE,
6996

70-
PATCH.class.getName(),
71-
javax.ws.rs.PATCH.class.getName(),
97+
PATCH.class.getName(), JAXRS_PATCH,
7298

73-
HEAD.class.getName(),
74-
javax.ws.rs.HEAD.class.getName(),
99+
HEAD.class.getName(), JAXRS_HEAD,
75100

76-
OPTIONS.class.getName(),
77-
javax.ws.rs.OPTIONS.class.getName(),
101+
OPTIONS.class.getName(), JAXRS_OPTIONS,
78102

79103
CONNECT.class.getName(),
80104

@@ -88,14 +112,13 @@ public interface Annotations {
88112

89113
/** Context params. */
90114
Set<String> CONTEXT_PARAMS = unmodifiableSet(
91-
new LinkedHashSet<>(asList(ContextParam.class.getName(), Context.class.getName())));
115+
new LinkedHashSet<>(asList(ContextParam.class.getName(), JAXRS_CONTEXT)));
92116

93117
/**
94118
* Query parameters.
95119
*/
96120
Set<String> QUERY_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
97-
QueryParam.class.getName(),
98-
javax.ws.rs.QueryParam.class.getName()
121+
QueryParam.class.getName(), JAXRS_QUERY
99122
)));
100123

101124
/**
@@ -109,16 +132,14 @@ public interface Annotations {
109132
* Cookie parameters.
110133
*/
111134
Set<String> COOKIE_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
112-
CookieParam.class.getName(),
113-
javax.ws.rs.CookieParam.class.getName()
135+
CookieParam.class.getName(), JAXRS_COOKIE
114136
)));
115137

116138
/**
117139
* Header parameters.
118140
*/
119141
Set<String> HEADER_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
120-
HeaderParam.class.getName(),
121-
javax.ws.rs.HeaderParam.class.getName()
142+
HeaderParam.class.getName(), JAXRS_HEADER
122143
)));
123144

124145
/**
@@ -131,8 +152,7 @@ public interface Annotations {
131152
* Form parameters.
132153
*/
133154
Set<String> FORM_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
134-
FormParam.class.getName(),
135-
javax.ws.rs.FormParam.class.getName()
155+
FormParam.class.getName(), JAXRS_FORM
136156
)));
137157

138158
/**
@@ -146,24 +166,21 @@ public interface Annotations {
146166
* Produces parameters.
147167
*/
148168
Set<String> PRODUCES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
149-
Produces.class.getName(),
150-
javax.ws.rs.Produces.class.getName()
169+
Produces.class.getName(), JAXRS_PRODUCES
151170
)));
152171

153172
/**
154173
* Consumes parameters.
155174
*/
156175
Set<String> CONSUMES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
157-
Consumes.class.getName(),
158-
javax.ws.rs.Consumes.class.getName()
176+
Consumes.class.getName(), JAXRS_CONSUMES
159177
)));
160178

161179
/**
162180
* Path parameters.
163181
*/
164182
Set<String> PATH = unmodifiableSet(new LinkedHashSet<>(asList(
165-
Path.class.getName(),
166-
javax.ws.rs.Path.class.getName()
183+
Path.class.getName(), JAXRS_PATH
167184
)));
168185

169186
/**
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.jooby.apt;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.List;
6+
import java.util.stream.Collectors;
7+
import java.util.stream.Stream;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import io.jooby.SneakyThrows;
12+
13+
public class JaxrsTest {
14+
15+
@Test
16+
public void shouldValidateJaxRSNames() {
17+
ClassLoader loader = getClass().getClassLoader();
18+
List<String> annotations = Stream.of(Annotations.class.getDeclaredFields())
19+
.filter(it -> it.getName().startsWith("JAXRS_"))
20+
.map(SneakyThrows.throwingFunction(it -> it.get(null).toString()))
21+
.collect(Collectors.toList());
22+
23+
assertEquals(15, annotations.size());
24+
annotations.forEach(SneakyThrows.throwingConsumer(annotation -> loader.loadClass(annotation)));
25+
}
26+
}

0 commit comments

Comments
 (0)