Skip to content

Commit

Permalink
refactoring: combining Module and Provider for non-deprecated modules
Browse files Browse the repository at this point in the history
  • Loading branch information
andrus committed Nov 25, 2023
1 parent 181f347 commit 7fb52b6
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@

package io.bootique.mvc.freemarker;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.mvc.MvcModule;

import javax.inject.Singleton;

public class MvcFreemarkerModule extends ConfigModule {
public class MvcFreemarkerModule implements BQModule, BQModuleProvider {

@Override
public BuiltModule buildModule() {
return BuiltModule.of(this)
.description("Integrates Freemarker-based renderer for bootique-mvc.")
.build();
}

@Override
public void configure(Binder binder) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
#
# Licensed to ObjectStyle LLC under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ObjectStyle LLC licenses
# this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

io.bootique.mvc.freemarker.MvcFreemarkerModuleProvider
io.bootique.mvc.freemarker.MvcFreemarkerModule
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@
import io.bootique.junit5.BQModuleProviderChecker;
import org.junit.jupiter.api.Test;


/**
* @author Lukasz Bachman
*/
public class MvcFreemarkerModuleProviderTest {
public class MvcFreemarkerModuleTest {

@Test
public void presentInJar() {
BQModuleProviderChecker.testAutoLoadable(MvcFreemarkerModuleProvider.class);
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(MvcFreemarkerModule.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,35 @@

package io.bootique.mvc.mustache;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.jersey.JerseyModule;
import io.bootique.mvc.MvcModule;
import io.bootique.mvc.renderer.RenderableTemplateCache;

import javax.inject.Singleton;
import java.util.Collection;

public class MvcMustacheModule extends ConfigModule {
import static java.util.Arrays.asList;

public class MvcMustacheModule implements BQModule, BQModuleProvider {

@Override
public BuiltModule buildModule() {
return BuiltModule.of(new MvcMustacheModule())
.provider(this)
.description("Integrates Mustache-based renderer for bootique-mvc.")
.build();
}

@Override
@Deprecated(since = "3.0", forRemoval = true)
public Collection<BQModuleProvider> dependencies() {
return asList(new MvcModule(), new JerseyModule());
}

@Override
public void configure(Binder binder) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.mvc.mustache.MvcMustacheModuleProvider
io.bootique.mvc.mustache.MvcMustacheModule
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
import org.junit.jupiter.api.Test;

@BQTest
public class MvcMustacheModuleProviderTest {
public class MvcMustacheModuleTest {

@BQTestTool
final BQTestFactory testFactory = new BQTestFactory();

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(MvcMustacheModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(MvcMustacheModule.class);
}

@Test
public void moduleDeclaresDependencies() {
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new MvcMustacheModuleProvider()).createRuntime();
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new MvcMustacheModule()).createRuntime();
BQRuntimeChecker.testModulesLoaded(bqRuntime,
JerseyModule.class,
MvcModule.class,
Expand Down
29 changes: 25 additions & 4 deletions bootique-mvc-jakarta/src/main/java/io/bootique/mvc/MvcModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package io.bootique.mvc;

import io.bootique.ConfigModule;
import io.bootique.BQModuleProvider;
import io.bootique.bootstrap.BuiltModule;
import io.bootique.config.ConfigurationFactory;
import io.bootique.di.BQModule;
import io.bootique.di.Binder;
import io.bootique.di.Provides;
import io.bootique.jersey.JerseyModule;
Expand All @@ -31,9 +33,13 @@
import io.bootique.mvc.resolver.TemplateResolver;

import javax.inject.Singleton;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

public class MvcModule extends ConfigModule {
public class MvcModule implements BQModule, BQModuleProvider {

private static final String CONFIG_PREFIX = "mvc";

/**
* Returns an instance of {@link MvcModuleExtender} used by downstream modules to load custom extensions to the
Expand All @@ -46,6 +52,21 @@ public static MvcModuleExtender extend(Binder binder) {
return new MvcModuleExtender(binder);
}

@Override
public BuiltModule buildModule() {
return BuiltModule.of(new MvcModule())
.provider(this)
.description("Provides Bootique's own REST-based web MVC engine with pluggable view renderers.")
.config(CONFIG_PREFIX, MvcFactory.class)
.build();
}

@Override
@Deprecated(since = "3.0", forRemoval = true)
public Collection<BQModuleProvider> dependencies() {
return Collections.singletonList(new JerseyModule());
}

@Override
public void configure(Binder binder) {
JerseyModule.extend(binder).addFeature(MvcFeature.class);
Expand All @@ -67,12 +88,12 @@ TemplateRenderers createTemplateRendererFactory(Map<String, TemplateRenderer> re
@Singleton
@Provides
TemplateResolver createTemplateResolver(ConfigurationFactory configFactory) {
return config(MvcFactory.class, configFactory).createResolver();
return configFactory.config(MvcFactory.class, CONFIG_PREFIX).createResolver();
}

@Singleton
@Provides
RenderableTemplateCache createRenderableTemplateCache(ConfigurationFactory configFactory) {
return config(MvcFactory.class, configFactory).createRenderableTemplateCache();
return configFactory.config(MvcFactory.class, CONFIG_PREFIX).createRenderableTemplateCache();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
io.bootique.mvc.MvcModuleProvider
io.bootique.mvc.MvcModule
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@
import org.junit.jupiter.api.Test;

@BQTest
public class MvcModuleProviderTest {
public class MvcModuleTest {

@BQTestTool
public BQTestFactory testFactory = new BQTestFactory();

@Test
public void autoLoadable() {
BQModuleProviderChecker.testAutoLoadable(MvcModuleProvider.class);
BQModuleProviderChecker.testAutoLoadable(MvcModule.class);
}

@Deprecated
@Test
public void moduleDeclaresDependencies() {
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new MvcModuleProvider()).createRuntime();
final BQRuntime bqRuntime = testFactory.app().moduleProvider(new MvcModule()).createRuntime();
BQRuntimeChecker.testModulesLoaded(bqRuntime,
JerseyModule.class,
MvcModule.class
Expand Down

0 comments on commit 7fb52b6

Please sign in to comment.