Skip to content

Commit da0aa6d

Browse files
committed
apt: fix build
1 parent 9d36d3c commit da0aa6d

10 files changed

Lines changed: 96 additions & 13 deletions

File tree

etc/maven.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ DIR=$(cd "$(dirname "$0")"; pwd)
44

55
echo "$@"
66

7-
mvn -pl '!docs,!tests,!examples,!modules/jooby-apt' "$@"
7+
mvn -pl '!docs,!tests,!examples' "$@"

etc/travis.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
DIR=$(cd "$(dirname "$0")"; pwd)
4+
5+
sh $DIR/maven.sh clean install -DskipTests=true
6+
sh $DIR/maven.sh checkstyle:checkstyle -P checkstyle package

jooby/src/main/java/io/jooby/MvcFactory.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,30 @@
55
*/
66
package io.jooby;
77

8+
import javax.annotation.Nonnull;
89
import javax.inject.Provider;
910

11+
/**
12+
* Created by a Jooby annotation processor tool and added discovered using the
13+
* {@link java.util.ServiceLoader} API.
14+
*
15+
* @since 2.1.0
16+
*/
1017
public interface MvcFactory {
11-
boolean supports(Class type);
18+
/**
19+
* Check if the factory applies for the given MVC route.
20+
*
21+
* @param type MVC route.
22+
* @return True for matching factory.
23+
*/
24+
boolean supports(@Nonnull Class type);
1225

13-
Extension create(Provider provider);
26+
/**
27+
* Creates an extension module. The extension module are created at compilation time by Jooby
28+
* APT.
29+
*
30+
* @param provider MVC route instance provider.
31+
* @return All mvc route as extension module.
32+
*/
33+
@Nonnull Extension create(@Nonnull Provider provider);
1434
}

jooby/src/main/java/io/jooby/Route.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,10 @@ public Route(@Nonnull String method, @Nonnull String pattern, @Nonnull Handler h
638638
* Retrieve value of this specific Attribute set to this route.
639639
*
640640
* @param name of the attribute to retrieve.
641+
* @param <T> Generic type.
641642
* @return value of the specific attribute.
642643
*/
643-
public <T> T attribute(String name) {
644+
public @Nullable <T> T attribute(@Nonnull String name) {
644645
return (T) attributes.get(name);
645646
}
646647

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import io.jooby.annotations.QueryParam;
2525
import io.jooby.annotations.TRACE;
2626

27+
import javax.annotation.Nonnull;
2728
import javax.lang.model.element.AnnotationMirror;
2829
import javax.lang.model.element.AnnotationValue;
2930
import javax.lang.model.element.ExecutableElement;
@@ -40,7 +41,15 @@
4041
import static java.util.Arrays.asList;
4142
import static java.util.Collections.unmodifiableSet;
4243

44+
/**
45+
* Annotation constants used by the APT.
46+
*
47+
* @since 2.1.0
48+
*/
4349
public interface Annotations {
50+
/**
51+
* HTTP method supported.
52+
*/
4453
Set<String> HTTP_METHODS = unmodifiableSet(new LinkedHashSet<>(Arrays.asList(
4554
GET.class.getName(),
4655
javax.ws.rs.GET.class.getName(),
@@ -68,46 +77,80 @@ public interface Annotations {
6877
TRACE.class.getName()
6978
)));
7079

80+
/**
81+
* Path parameters.
82+
*/
7183
Set<String> PATH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(PathParam.class.getName())));
7284

85+
/**
86+
* Query parameters.
87+
*/
7388
Set<String> QUERY_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
7489
QueryParam.class.getName(),
7590
javax.ws.rs.QueryParam.class.getName()
7691
)));
7792

93+
/**
94+
* Cookie parameters.
95+
*/
7896
Set<String> COOKIE_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
7997
CookieParam.class.getName(),
8098
javax.ws.rs.CookieParam.class.getName()
8199
)));
82100

101+
/**
102+
* Header parameters.
103+
*/
83104
Set<String> HEADER_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
84105
HeaderParam.class.getName(),
85106
javax.ws.rs.HeaderParam.class.getName()
86107
)));
87108

109+
/**
110+
* Flash parameters.
111+
*/
88112
Set<String> FLASH_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(FlashParam.class.getName())));
89113

114+
/**
115+
* Form parameters.
116+
*/
90117
Set<String> FORM_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
91118
FormParam.class.getName(),
92119
javax.ws.rs.FormParam.class.getName()
93120
)));
94121

122+
/**
123+
* Produces parameters.
124+
*/
95125
Set<String> PRODUCES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
96126
Produces.class.getName(),
97127
javax.ws.rs.Produces.class.getName()
98128
)));
99129

130+
/**
131+
* Consumes parameters.
132+
*/
100133
Set<String> CONSUMES_PARAMS = unmodifiableSet(new LinkedHashSet<>(asList(
101134
Consumes.class.getName(),
102135
javax.ws.rs.Consumes.class.getName()
103136
)));
104137

138+
/**
139+
* Path parameters.
140+
*/
105141
Set<String> PATH = unmodifiableSet(new LinkedHashSet<>(asList(
106142
Path.class.getName(),
107143
javax.ws.rs.Path.class.getName()
108144
)));
109145

110-
static List<String> attribute(AnnotationMirror mirror, String name) {
146+
/**
147+
* Get an annotation value.
148+
*
149+
* @param mirror Annotation.
150+
* @param name Attribute name.
151+
* @return List of values.
152+
*/
153+
static @Nonnull List<String> attribute(@Nonnull AnnotationMirror mirror, @Nonnull String name) {
111154
Function<Object, String> cleanValue = arg -> {
112155
if (arg instanceof AnnotationValue) {
113156
return ((AnnotationValue) arg).getValue().toString();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
import java.util.stream.Collectors;
3535
import java.util.stream.Stream;
3636

37+
/**
38+
* Jooby Annotation Processing Tool. It generates byte code for MVC routes.
39+
*
40+
* @since 2.1.0
41+
*/
3742
public class JoobyProcessor extends AbstractProcessor {
3843

3944
private ProcessingEnvironment processingEnvironment;

modules/jooby-apt/src/test/java/io/jooby/apt/MvcHandlerCompilerRunner.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,25 @@ public MvcHandlerCompilerRunner(Object instance) throws Exception {
3636

3737
public MvcHandlerCompilerRunner compile(String path,
3838
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
39-
return compile(path, false, consumer);
39+
return compile("GET", path, consumer);
4040
}
4141

42-
public MvcHandlerCompilerRunner compile(String path, boolean debug,
42+
public MvcHandlerCompilerRunner debug(String path,
4343
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
44-
return compile("GET", path, debug, consumer);
44+
return compile("GET", path, true, consumer);
4545
}
4646

4747
public MvcHandlerCompilerRunner compile(String method, String path,
4848
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
4949
return compile(method, path, false, consumer);
5050
}
5151

52-
public MvcHandlerCompilerRunner compile(String method, String path, boolean debug,
52+
public MvcHandlerCompilerRunner debug(String method, String path,
53+
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
54+
return compile(method, path, true, consumer);
55+
}
56+
57+
private MvcHandlerCompilerRunner compile(String method, String path, boolean debug,
5358
SneakyThrows.Consumer<Route.Handler> consumer) throws Exception {
5459
String key = method.toUpperCase() + path;
5560
HandlerCompiler compiler = processor.compilerFor(key);

modules/jooby-apt/src/test/java/io/jooby/apt/MvcModuleCompilerRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ public MvcModuleCompilerRunner module(SneakyThrows.Consumer<Jooby> consumer) thr
4141
return module(false, consumer);
4242
}
4343

44-
public MvcModuleCompilerRunner module(boolean debug, SneakyThrows.Consumer<Jooby> consumer) throws Exception {
44+
public MvcModuleCompilerRunner debugModule(SneakyThrows.Consumer<Jooby> consumer) throws Exception {
45+
return module(true, consumer);
46+
}
47+
48+
private MvcModuleCompilerRunner module(boolean debug, SneakyThrows.Consumer<Jooby> consumer) throws Exception {
4549
Class clazz = instance.getClass();
4650
ClassLoader classLoader = processor.getModuleClassLoader(debug);
4751
String factoryName = clazz.getName() + "$Factory";

modules/jooby-apt/src/test/java/tests/HandlerCompilerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void queryParam() throws Exception {
8383
@Test
8484
public void cookieParam() throws Exception {
8585
new MvcHandlerCompilerRunner(new Provisioning())
86-
.compile("/p/cookieParam", true, handler -> {
86+
.debug("/p/cookieParam", handler -> {
8787
assertEquals("cookie",
8888
handler.apply(new MockContext().setCookieMap(mapOf("c", "cookie"))));
8989
})
@@ -406,7 +406,7 @@ public void noTopLevel() throws Exception {
406406
@Test
407407
public void nullRoutes() throws Exception {
408408
new MvcHandlerCompilerRunner(new NullRoutes())
409-
.compile("/nullok", true, handler -> {
409+
.compile("/nullok", handler -> {
410410
assertEquals("null", handler.apply(new MockContext()));
411411
})
412412
.compile("/nonnull", handler -> {

modules/jooby-jackson/src/main/java/io/jooby/json/JacksonModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package io.jooby.json;
77

88
import com.fasterxml.jackson.core.JsonParseException;
9-
import com.fasterxml.jackson.core.JsonProcessingException;
109
import com.fasterxml.jackson.databind.JavaType;
1110
import com.fasterxml.jackson.databind.Module;
1211
import com.fasterxml.jackson.databind.ObjectMapper;

0 commit comments

Comments
 (0)