diff --git a/starter-core/src/main/java/io/micronaut/starter/feature/server/HttpPoja.java b/starter-core/src/main/java/io/micronaut/starter/feature/server/HttpPoja.java new file mode 100644 index 00000000000..0076a01ed58 --- /dev/null +++ b/starter-core/src/main/java/io/micronaut/starter/feature/server/HttpPoja.java @@ -0,0 +1,66 @@ +/* + * Copyright 2017-2022 original authors + * + * Licensed 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 + * + * https://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. + */ +package io.micronaut.starter.feature.server; + +import io.micronaut.core.annotation.NonNull; +import io.micronaut.starter.application.generator.GeneratorContext; +import io.micronaut.starter.build.dependencies.Dependency; +import io.micronaut.starter.options.BuildTool; +import jakarta.inject.Singleton; + +@Singleton +public class HttpPoja extends AbstractMicronautServerFeature { + + @Override + public String getName() { + return "http-poja"; + } + + @Override + public String getTitle() { + return "Plain Old Java HTTP Application"; + } + + @Override + public String getDescription() { + return "Add support for HTTP POJA based on Apache libraries"; + } + + @Override + public String getMicronautDocumentation() { + return "https://micronaut-projects.github.io/micronaut-servlet/latest/guide/index.html#httpPoja"; + } + + @Override + public void doApply(GeneratorContext generatorContext) { + if (generatorContext.getBuildTool() == BuildTool.MAVEN) { + generatorContext.addDependency(Dependency.builder() + .groupId("io.micronaut.servlet") + .artifactId("micronaut-http-poja-apache") + .compile()); + generatorContext.addDependency(Dependency.builder() + .groupId("io.micronaut.servlet") + .artifactId("micronaut-http-poja-test") + .test()); + } + } + + @Override + @NonNull + public String resolveMicronautRuntime(@NonNull GeneratorContext generatorContext) { + return "http_poja"; + } +} diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/build/maven/MavenSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/build/maven/MavenSpec.groovy index 097d6c9ec55..62d57491e23 100644 --- a/starter-core/src/test/groovy/io/micronaut/starter/feature/build/maven/MavenSpec.groovy +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/build/maven/MavenSpec.groovy @@ -191,6 +191,7 @@ class MavenSpec extends ApplicationContextSpec implements CommandOutputFixture { ApplicationType.DEFAULT | ["aws-lambda", 'graalvm'] | "lambda" ApplicationType.DEFAULT | ["tomcat-server"] | "tomcat" ApplicationType.DEFAULT | ["jetty-server"] | "jetty" + ApplicationType.DEFAULT | ["http-poja"] | "http_poja" ApplicationType.DEFAULT | ["netty-server"] | "netty" ApplicationType.DEFAULT | ["undertow-server"] | "undertow" } diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/server/HttpPojaTestSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/server/HttpPojaTestSpec.groovy new file mode 100644 index 00000000000..75c989f738d --- /dev/null +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/server/HttpPojaTestSpec.groovy @@ -0,0 +1,41 @@ +package io.micronaut.starter.feature.server + +import io.micronaut.starter.BeanContextSpec +import io.micronaut.starter.BuildBuilder +import io.micronaut.starter.build.BuildTestUtil +import io.micronaut.starter.build.BuildTestVerifier +import io.micronaut.starter.fixture.CommandOutputFixture +import io.micronaut.starter.options.BuildTool +import io.micronaut.starter.options.Language + +class HttpPojaTestSpec extends BeanContextSpec implements CommandOutputFixture { + + void 'test readme.md with feature http-poja contains links to micronaut docs'() { + when: + Map output = generate(['http-poja']) + String readme = output["README.md"] + + then: + readme + readme.contains("https://micronaut-projects.github.io/micronaut-servlet/latest/guide/index.html#httpPoja") + } + + void 'test #buildTool http-poja feature for language=#language'(Language language, BuildTool buildTool) { + when: + String template = new BuildBuilder(beanContext, buildTool) + .language(language) + .features(["http-poja"]) + .render() + BuildTestVerifier verifier = BuildTestUtil.verifier(buildTool, language, template) + + then: + template.contains("runtime(\"http_poja\")") || template.contains("http_poja") + + and: "Contains required dependencies" + buildTool != BuildTool.MAVEN + || template.contains("micronaut-http-poja-apache") && template.contains("micronaut-http-poja-test") + + where: + [language, buildTool] << [Language.values().toList(), BuildTool.values()].combinations() + } +} diff --git a/starter-core/src/test/groovy/io/micronaut/starter/feature/server/ServerSpec.groovy b/starter-core/src/test/groovy/io/micronaut/starter/feature/server/ServerSpec.groovy index c5bfcd19d32..845cdef4220 100644 --- a/starter-core/src/test/groovy/io/micronaut/starter/feature/server/ServerSpec.groovy +++ b/starter-core/src/test/groovy/io/micronaut/starter/feature/server/ServerSpec.groovy @@ -25,6 +25,7 @@ class ServerSpec extends ApplicationContextSpec { "jetty-server" | 'runtime("jetty")' "tomcat-server" | 'runtime("tomcat")' "undertow-server" | 'runtime("undertow")' + "http-poja" | 'runtime("http_poja")' } @Unroll @@ -79,11 +80,12 @@ class ServerSpec extends ApplicationContextSpec { "jetty-server" | 'io.micronaut.servlet' | 'micronaut-http-server-jetty' "tomcat-server" | 'io.micronaut.servlet' | 'micronaut-http-server-tomcat' "undertow-server" | 'io.micronaut.servlet' | 'micronaut-http-server-undertow' + "http-poja" | 'io.micronaut.servlet' | 'micronaut-http-poja-apache' } void 'test there can only be one server feature'() { when: - getFeatures(["netty-server", "jetty-server", "tomcat-server", "undertow-server"]) + getFeatures(["netty-server", "jetty-server", "tomcat-server", "undertow-server", "http-poja"]) then: def ex = thrown(IllegalArgumentException)