-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #600 from sdeleuze:jackson-kotlin
* pr/600: Polish "Add jackson-module-kotlin dependency when appropriate" Add jackson-module-kotlin dependency when appropriate
- Loading branch information
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...c/main/java/io/spring/initializr/service/extension/JacksonKotlinRequestPostProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2012-2018 the original author or 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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
package io.spring.initializr.service.extension; | ||
|
||
import io.spring.initializr.generator.ProjectRequest; | ||
import io.spring.initializr.generator.ProjectRequestPostProcessor; | ||
import io.spring.initializr.metadata.Dependency; | ||
import io.spring.initializr.metadata.InitializrMetadata; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* A {@link ProjectRequestPostProcessor} that automatically adds "jackson-module-kotlin" | ||
* when Kotlin is used and a dependency has the "json" facet. | ||
* | ||
* @author Sebastien Deleuze | ||
*/ | ||
@Component | ||
class JacksonKotlinRequestPostProcessor implements ProjectRequestPostProcessor { | ||
|
||
private final Dependency jacksonModuleKotlin; | ||
|
||
public JacksonKotlinRequestPostProcessor() { | ||
this.jacksonModuleKotlin = Dependency.withId("jackson-module-kotlin", | ||
"com.fasterxml.jackson.module", "jackson-module-kotlin"); | ||
} | ||
|
||
@Override | ||
public void postProcessAfterResolution(ProjectRequest request, | ||
InitializrMetadata metadata) { | ||
if (request.getFacets().contains("json") | ||
&& "kotlin".equals(request.getLanguage())) { | ||
request.getResolvedDependencies().add(this.jacksonModuleKotlin); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...t/java/io/spring/initializr/service/extension/JacksonKotlinRequestPostProcessorTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2012-2017 the original author or 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 | ||
* | ||
* 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. | ||
*/ | ||
|
||
package io.spring.initializr.service.extension; | ||
|
||
import io.spring.initializr.generator.ProjectRequest; | ||
import io.spring.initializr.metadata.Dependency; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Tests for {@link JacksonKotlinRequestPostProcessor}. | ||
* | ||
* @author Sebastien Deleuze | ||
* @author Stephane Nicoll | ||
*/ | ||
public class JacksonKotlinRequestPostProcessorTests | ||
extends AbstractRequestPostProcessorTests { | ||
|
||
static final Dependency JACKSON_KOTLIN = Dependency.withId("jackson-module-kotlin", | ||
"com.fasterxml.jackson.module", "jackson-module-kotlin"); | ||
|
||
static final Dependency REACTOR_TEST = Dependency.create( | ||
"io.projectreactor", "reactor-test", null, Dependency.SCOPE_TEST); | ||
|
||
@Test | ||
public void jacksonModuleKotlinIsAdded() { | ||
ProjectRequest request = createProjectRequest("webflux"); | ||
request.setBootVersion("2.0.0.M2"); | ||
request.setLanguage("kotlin"); | ||
generateMavenPom(request) | ||
.hasSpringBootStarterDependency("webflux") | ||
.hasDependency(JACKSON_KOTLIN) | ||
.hasSpringBootStarterTest() | ||
.hasDependency(REACTOR_TEST) | ||
.hasDependency("org.jetbrains.kotlin", "kotlin-reflect") | ||
.hasDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8") | ||
.hasDependenciesCount(6); | ||
} | ||
|
||
@Test | ||
public void jacksonModuleKotlinIsNotAddedWithoutKotlin() { | ||
ProjectRequest request = createProjectRequest("webflux"); | ||
request.setBootVersion("2.0.0.M2"); | ||
generateMavenPom(request) | ||
.hasSpringBootStarterDependency("webflux") | ||
.hasSpringBootStarterTest() | ||
.hasDependency(REACTOR_TEST) | ||
.hasDependenciesCount(3); | ||
} | ||
|
||
@Test | ||
public void jacksonModuleKotlinIsNotAddedWithoutJsonFacet() { | ||
ProjectRequest request = createProjectRequest("actuator"); | ||
request.setBootVersion("2.0.0.M2"); | ||
request.setLanguage("kotlin"); | ||
generateMavenPom(request) | ||
.hasSpringBootStarterDependency("actuator") | ||
.hasSpringBootStarterTest() | ||
.hasDependency("org.jetbrains.kotlin", "kotlin-reflect") | ||
.hasDependency("org.jetbrains.kotlin", "kotlin-stdlib-jdk8") | ||
.hasDependenciesCount(4); | ||
} | ||
|
||
} |