Merge pull request #670 from dsyer:feature/function

* pr/670:
  Polish "Add Spring Cloud Function"
  Add Spring Cloud Function
This commit is contained in:
Stephane Nicoll
2018-07-13 16:33:59 +02:00
3 changed files with 141 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadata;
import org.springframework.stereotype.Component;
/**
* Determine the appropriate Spring Cloud function dependency according to the messaging
* and/or platform dependencies requested.
*
* @author Dave Syer
*/
@Component
class SpringCloudFunctionRequestPostProcessor
extends AbstractProjectRequestPostProcessor {
static final Dependency SCS_ADAPTER = Dependency.withId("cloud-function-stream",
"org.springframework.cloud", "spring-cloud-function-stream");
static final Dependency WEB_ADAPTER = Dependency.withId("cloud-function-web",
"org.springframework.cloud", "spring-cloud-function-web");
@Override
public void postProcessAfterResolution(ProjectRequest request,
InitializrMetadata metadata) {
Dependency cloudFunction = getDependency(request, "cloud-function");
if (cloudFunction != null) {
List<Dependency> swap = new ArrayList<>();
if (hasDependency(request, "cloud-stream")
|| hasDependency(request, "reactive-cloud-stream")) {
swap.add(SCS_ADAPTER);
}
if (hasDependency(request, "web")) {
swap.add(WEB_ADAPTER);
}
if (!swap.isEmpty()) {
request.getResolvedDependencies().remove(cloudFunction);
request.getResolvedDependencies().addAll(swap);
}
}
}
}

View File

@@ -814,6 +814,18 @@ initializr:
groupId: org.springframework.cloud
artifactId: spring-cloud-starter
weight: 100
- name: Cloud Function
id: cloud-function
groupId: org.springframework.cloud
artifactId: spring-cloud-function-context
description: Functions as Spring Beans
versionRange: 2.0.2.RELEASE
links:
- rel: reference
href: https://cloud.spring.io/spring-cloud-function/
- rel: sample
href: https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples
description: Various sample apps using Spring Cloud Function
- name: Cloud Security
id: cloud-security
description: Secure load balancing and routing with spring-cloud-security

View File

@@ -0,0 +1,65 @@
/*
* 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 org.junit.Test;
/**
* Tests for {@link SpringCloudFunctionRequestPostProcessor}.
*
* @author Dave Syer
*/
public class SpringCloudFunctionRequestPostProcessorTests
extends AbstractRequestPostProcessorTests {
@Test
public void functionOnly() {
ProjectRequest request = createProjectRequest("cloud-function");
generateMavenPom(request).hasDependency(getDependency("cloud-function"))
.hasSpringBootStarterTest().hasDependenciesCount(2);
}
@Test
public void springCloudStreamWithRabbit() {
ProjectRequest request = createProjectRequest("cloud-stream", "amqp",
"cloud-function");
generateMavenPom(request).hasDependency(getDependency("cloud-stream"))
.hasDependency(getDependency("amqp"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.SCS_ADAPTER)
.hasDependenciesCount(6);
}
@Test
public void reactiveSpringCloudStreamWithKafka() {
ProjectRequest request = createProjectRequest("reactive-cloud-stream", "kafka",
"cloud-function");
generateMavenPom(request).hasDependency(getDependency("reactive-cloud-stream"))
.hasDependency(getDependency("kafka"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.SCS_ADAPTER)
.hasDependenciesCount(6);
}
@Test
public void web() {
ProjectRequest request = createProjectRequest("web", "cloud-function");
generateMavenPom(request).hasDependency(getDependency("web"))
.hasDependency(SpringCloudFunctionRequestPostProcessor.WEB_ADAPTER)
.hasDependenciesCount(3);
}
}