Skip to content

Commit 0793992

Browse files
committed
remove: MvcFactory fix #3705
1 parent d8c9c3e commit 0793992

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+207
-225
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import static java.util.Collections.singletonList;
99
import static java.util.Objects.requireNonNull;
10-
import static java.util.stream.StreamSupport.stream;
1110

1211
import java.io.IOException;
1312
import java.lang.reflect.Constructor;
@@ -26,8 +25,6 @@
2625
import java.util.Objects;
2726
import java.util.Optional;
2827
import java.util.Properties;
29-
import java.util.ServiceConfigurationError;
30-
import java.util.ServiceLoader;
3128
import java.util.Set;
3229
import java.util.concurrent.Executor;
3330
import java.util.concurrent.ExecutorService;
@@ -54,7 +51,6 @@
5451
import io.jooby.output.BufferedOutputFactory;
5552
import io.jooby.problem.ProblemDetailsHandler;
5653
import io.jooby.value.ValueFactory;
57-
import jakarta.inject.Provider;
5854

5955
/**
6056
* Welcome to Jooby!
@@ -520,49 +516,6 @@ public Jooby mvc(@NonNull MvcExtension router) {
520516
}
521517
}
522518

523-
@NonNull @Override
524-
@Deprecated(since = "3.8.0", forRemoval = true)
525-
public Jooby mvc(@NonNull Object router) {
526-
Provider provider = () -> router;
527-
return mvc(router.getClass(), provider);
528-
}
529-
530-
@NonNull @Override
531-
@Deprecated(since = "3.8.0", forRemoval = true)
532-
public Jooby mvc(@NonNull Class router) {
533-
return mvc(router, () -> require(router));
534-
}
535-
536-
@NonNull @Override
537-
@Deprecated(since = "3.8.0", forRemoval = true)
538-
public <T> Jooby mvc(@NonNull Class<T> router, @NonNull Provider<T> provider) {
539-
try {
540-
MvcFactory module = loadModule(router);
541-
Extension extension = module.create(provider::get);
542-
extension.install(this);
543-
return this;
544-
} catch (Exception x) {
545-
throw SneakyThrows.propagate(x);
546-
}
547-
}
548-
549-
@Deprecated(since = "3.8.0", forRemoval = true)
550-
private <T> MvcFactory<T> loadModule(Class<T> router) {
551-
try {
552-
ServiceLoader<MvcFactory> modules = ServiceLoader.load(MvcFactory.class);
553-
return stream(modules.spliterator(), false)
554-
.filter(it -> it.supports(router))
555-
.findFirst()
556-
.orElseGet(
557-
() ->
558-
/* Make happy IDE incremental build: */
559-
mvcReflectionFallback(router, getClassLoader()));
560-
} catch (ServiceConfigurationError notfound) {
561-
/* Make happy IDE incremental build: */
562-
return mvcReflectionFallback(router, getClassLoader());
563-
}
564-
}
565-
566519
@NonNull @Override
567520
public Route ws(@NonNull String pattern, @NonNull WebSocket.Initializer handler) {
568521
return router.ws(pattern, handler);
@@ -1452,29 +1405,6 @@ private void joobyRunHook(ClassLoader loader, Server server) {
14521405
}
14531406
}
14541407

1455-
/**
1456-
* This method exists to integrate IDE incremental build with MVC annotation processor. It
1457-
* fallback to reflection to lookup for a generated mvc factory.
1458-
*
1459-
* @param source Controller class.
1460-
* @param classLoader Class loader.
1461-
* @return Mvc factory.
1462-
*/
1463-
private MvcFactory mvcReflectionFallback(Class source, ClassLoader classLoader) {
1464-
try {
1465-
var moduleName =
1466-
System.getProperty("jooby.routerPrefix", "")
1467-
+ source.getName()
1468-
+ System.getProperty("jooby.routerSuffix", "_");
1469-
Class<?> moduleType = classLoader.loadClass(moduleName);
1470-
Constructor<?> constructor = moduleType.getDeclaredConstructor();
1471-
getLog().debug("Loading mvc using reflection: " + source);
1472-
return (MvcFactory) constructor.newInstance();
1473-
} catch (Exception x) {
1474-
throw Usage.mvcRouterNotFound(source);
1475-
}
1476-
}
1477-
14781408
/**
14791409
* Copy internal state from one application into other.
14801410
*

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

Lines changed: 0 additions & 32 deletions
This file was deleted.

jooby/src/main/java/io/jooby/Router.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import io.jooby.handler.AssetSource;
3939
import io.jooby.output.BufferedOutputFactory;
4040
import io.jooby.value.ValueFactory;
41-
import jakarta.inject.Provider;
4241

4342
/**
4443
* Routing DSL functions.
@@ -425,39 +424,6 @@ default Object execute(@NonNull Context context) {
425424
*/
426425
@NonNull Router mvc(@NonNull MvcExtension router);
427426

428-
/**
429-
* Import all route method from the given controller class. At runtime the controller instance is
430-
* resolved by calling {@link Jooby#require(Class)}.
431-
*
432-
* @param router Controller class.
433-
* @return This router.
434-
* @deprecated See {{@link #mvc(MvcExtension)}}
435-
*/
436-
@Deprecated
437-
@NonNull Router mvc(@NonNull Class router);
438-
439-
/**
440-
* Import all route method from the given controller class.
441-
*
442-
* @param router Controller class.
443-
* @param provider Controller provider.
444-
* @param <T> Controller type.
445-
* @return This router.
446-
* @deprecated See {{@link #mvc(MvcExtension)}}
447-
*/
448-
@Deprecated
449-
@NonNull <T> Router mvc(@NonNull Class<T> router, @NonNull Provider<T> provider);
450-
451-
/**
452-
* Import all route methods from given controller instance.
453-
*
454-
* @param router Controller instance.
455-
* @return This routes.
456-
* @deprecated See {{@link #mvc(MvcExtension)}}
457-
*/
458-
@Deprecated
459-
@NonNull Router mvc(@NonNull Object router);
460-
461427
/**
462428
* Add a websocket handler.
463429
*

jooby/src/main/java/io/jooby/internal/RouterImpl.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,6 @@ public Router mvc(@NonNull MvcExtension router) {
333333
throw new UnsupportedOperationException();
334334
}
335335

336-
@NonNull @Override
337-
public Router mvc(@NonNull Object router) {
338-
throw new UnsupportedOperationException();
339-
}
340-
341-
@NonNull @Override
342-
public Router mvc(@NonNull Class router) {
343-
throw new UnsupportedOperationException();
344-
}
345-
346-
@NonNull @Override
347-
public <T> Router mvc(@NonNull Class<T> router, @NonNull Provider<T> provider) {
348-
throw new UnsupportedOperationException();
349-
}
350-
351336
@NonNull @Override
352337
public Router encoder(@NonNull MessageEncoder encoder) {
353338
this.encoder.add(MediaType.all, encoder);

jooby/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
exports io.jooby.output;
1717
exports io.jooby.internal.output;
1818

19-
uses io.jooby.MvcFactory;
2019
uses io.jooby.Server;
2120
uses io.jooby.SslProvider;
2221
uses io.jooby.LoggingService;

modules/jooby-kotlin/src/main/kotlin/io/jooby/kt/Kooby.kt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,6 @@ open class Kooby() : Jooby() {
143143
this.init()
144144
}
145145

146-
@RouterDsl
147-
@Deprecated(message = "Use mvc(io.jooby.MvcExtension)")
148-
fun <T : Any> mvc(router: KClass<T>): Kooby {
149-
super.mvc(router.java)
150-
return this
151-
}
152-
153-
@RouterDsl
154-
@Deprecated(message = "Use mvc(io.jooby.MvcExtension)")
155-
fun <T : Any> mvc(router: KClass<T>, provider: () -> T): Kooby {
156-
super.mvc(router.java, provider)
157-
return this
158-
}
159-
160146
@RouterDsl
161147
fun use(handler: FilterContext.() -> Any): Kooby {
162148
super.use { next -> Route.Handler { ctx -> FilterContext(ctx, next).handler() } }

modules/jooby-openapi/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
<artifactId>kotlinx-coroutines-core</artifactId>
128128
<scope>test</scope>
129129
</dependency>
130+
<dependency>
131+
<groupId>net.bytebuddy</groupId>
132+
<artifactId>byte-buddy</artifactId>
133+
<version>1.17.5</version>
134+
<scope>test</scope>
135+
</dependency>
130136
</dependencies>
131137

132138
<build>

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/AnnotationParser.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public static List<OperationExt> parse(
185185
new IllegalStateException(
186186
"Mvc class not found: " + InsnSupport.toString(node)));
187187
return parse(ctx, prefix, type);
188-
} else if (signature.matches(MVC_EXTENSION) || signature.matches(Object.class)) {
188+
} else if (signature.matches(MVC_EXTENSION)) {
189189
AbstractInsnNode previous = node.getPrevious();
190190
if (previous instanceof MethodInsnNode) {
191191
MethodInsnNode methodInsnNode = (MethodInsnNode) previous;
@@ -220,8 +220,36 @@ public static List<OperationExt> parse(
220220
Type type = (Type) (ldcInsnNode).cst;
221221
return parse(ctx, prefix, type);
222222
} else {
223-
// mvc(some.myController());
224223
Type type = Type.getReturnType(methodInsnNode.desc);
224+
if (type.equals(MVC_EXTENSION)) {
225+
// support test code: toMvcExtension() but also any other thing that generate an
226+
// extension from controller class
227+
type =
228+
InsnSupport.prev(methodInsnNode.getPrevious())
229+
.filter(
230+
e ->
231+
(e instanceof LdcInsnNode ldcInsnNode
232+
&& (ldcInsnNode.cst instanceof Type))
233+
|| (e instanceof MethodInsnNode method)
234+
&& (!Type.getReturnType(method.desc)
235+
.getClassName()
236+
.equals(Object.class.getName())))
237+
.findFirst()
238+
.map(
239+
e -> {
240+
if (e instanceof LdcInsnNode ldcInsnNode) {
241+
return ldcInsnNode.cst;
242+
} else if (e instanceof MethodInsnNode method) {
243+
return Type.getReturnType(method.desc);
244+
} else {
245+
return e;
246+
}
247+
})
248+
.filter(it -> it instanceof Type)
249+
.map(it -> (Type) it)
250+
.orElse(type);
251+
}
252+
// mvc(some.myController());
225253
return parse(ctx, prefix, type);
226254
}
227255
}

modules/jooby-openapi/src/test/java/examples/ControllerExample.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
import java.util.List;
99
import java.util.Optional;
1010

11+
import org.jetbrains.annotations.NotNull;
12+
1113
import io.jooby.Context;
14+
import io.jooby.Jooby;
15+
import io.jooby.MvcExtension;
1216
import io.jooby.Session;
13-
import io.jooby.annotation.GET;
14-
import io.jooby.annotation.POST;
15-
import io.jooby.annotation.Path;
16-
import io.jooby.annotation.QueryParam;
17+
import io.jooby.annotation.*;
1718

1819
@Path("/api")
1920
public class ControllerExample {
@@ -63,3 +64,9 @@ public ABean save(ABean bean) {
6364
return bean;
6465
}
6566
}
67+
68+
@Generated(ControllerExample.class)
69+
class COntrollerExample_ implements MvcExtension {
70+
@Override
71+
public void install(@NotNull Jooby application) throws Exception {}
72+
}

modules/jooby-openapi/src/test/java/examples/FormMvcApp.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
*/
66
package examples;
77

8+
import static io.jooby.openapi.MvcExtensionGenerator.toMvcExtension;
9+
810
import io.jooby.Jooby;
911

1012
public class FormMvcApp extends Jooby {
1113

1214
{
13-
mvc(new FormController());
15+
mvc(toMvcExtension(FormController.class));
1416
}
1517
}

0 commit comments

Comments
 (0)