mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-26 22:25:51 +08:00
Add Spring Cloud Function
See gh-670
This commit is contained in:
committed by
Stephane Nicoll
parent
4f43e554d6
commit
411b096fec
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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.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 STREAM_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) {
|
||||
boolean hasSpringCloudStream = hasDependency(request, "cloud-stream") || hasDependency(request, "reactive-cloud-stream");
|
||||
// TODO: add webflux when s-c-f is ready
|
||||
boolean hasWeb = hasDependency(request, "web");
|
||||
if (hasSpringCloudStream) {
|
||||
request.getResolvedDependencies().add(STREAM_ADAPTER);
|
||||
}
|
||||
if (hasWeb) {
|
||||
request.getResolvedDependencies().add(WEB_ADAPTER);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -814,6 +814,19 @@ 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: home
|
||||
href: https://cloud.spring.io/spring-cloud-function/
|
||||
description: Spring Cloud Function home page
|
||||
- rel: sample
|
||||
href: https://github.com/spring-cloud/spring-cloud-function/tree/master/spring-cloud-function-samples/function-sample
|
||||
description: A sample app using Spring Cloud Function
|
||||
- name: Cloud Security
|
||||
id: cloud-security
|
||||
description: Secure load balancing and routing with spring-cloud-security
|
||||
|
||||
@@ -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 org.junit.Test;
|
||||
|
||||
import static io.spring.initializr.service.extension.SpringCloudFunctionRequestPostProcessor.STREAM_ADAPTER;
|
||||
import static io.spring.initializr.service.extension.SpringCloudFunctionRequestPostProcessor.WEB_ADAPTER;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringCloudFunctionRequestPostProcessor}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SpringCloudFunctionRequestPostProcessorTests
|
||||
extends AbstractRequestPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void springCloudStreamWithRabbit() {
|
||||
ProjectRequest request = createProjectRequest("cloud-stream", "amqp",
|
||||
"cloud-function");
|
||||
generateMavenPom(request).hasDependency(getDependency("cloud-stream"))
|
||||
.hasDependency(getDependency("amqp")).hasDependency(STREAM_ADAPTER)
|
||||
.hasDependenciesCount(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void web() {
|
||||
ProjectRequest request = createProjectRequest("web", "cloud-function");
|
||||
generateMavenPom(request).hasDependency(getDependency("cloud-function"))
|
||||
.hasDependency(getDependency("web")).hasDependency(WEB_ADAPTER)
|
||||
.hasDependenciesCount(4);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user