[bs-19] Add samples and CLI support for Spring Integration
$ cd spring-bootstrap-cli
$ export SPRING_HOME=target
$ src/main/scripts/spring run samples/integration.groovy
The big disadvantage at the moment is that there is no goo way to
detect Spring Integration in the AST (at least not as good as @Enable*).
So for now we are looking for @MessageEndpoint or a class name with
SpringIntegration in it.
[#48151147]
This commit is contained in:
@@ -33,6 +33,7 @@ import org.codehaus.groovy.control.customizers.CompilationCustomizer;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBatchCompilerAutoConfiguration;
|
||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringBootstrapCompilerAutoConfiguration;
|
||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration;
|
||||
import org.springframework.bootstrap.cli.compiler.autoconfigure.SpringMvcCompilerAutoConfiguration;
|
||||
|
||||
/**
|
||||
@@ -56,6 +57,7 @@ public class GroovyCompiler {
|
||||
new SpringBootstrapCompilerAutoConfiguration(),
|
||||
new SpringMvcCompilerAutoConfiguration(),
|
||||
new SpringBatchCompilerAutoConfiguration(),
|
||||
new SpringIntegrationCompilerAutoConfiguration(),
|
||||
new SpringBootstrapCompilerAutoConfiguration() };
|
||||
|
||||
private GroovyCompilerConfiguration configuration;
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package org.springframework.bootstrap.cli.compiler.autoconfigure;
|
||||
|
||||
import groovy.grape.Grape;
|
||||
import groovy.lang.GroovyClassLoader;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.codehaus.groovy.ast.AnnotationNode;
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.classgen.GeneratorContext;
|
||||
@@ -78,9 +82,21 @@ public class SpringBootstrapCompilerAutoConfiguration extends CompilerAutoConfig
|
||||
public void applyToMainClass(GroovyClassLoader loader,
|
||||
GroovyCompilerConfiguration configuration, GeneratorContext generatorContext,
|
||||
SourceUnit source, ClassNode classNode) throws CompilationFailedException {
|
||||
if (true) {
|
||||
if (true) { // FIXME: add switch for auto config
|
||||
addEnableAutoConfigurationAnnotation(source, classNode);
|
||||
}
|
||||
// FIXME: allow the extra resolvers to be switched on (off by default)
|
||||
addExtraResolvers();
|
||||
}
|
||||
|
||||
private void addExtraResolvers() {
|
||||
Map<String, Object> resolver = new HashMap<String, Object>();
|
||||
resolver.put("name", "spring-milestone");
|
||||
resolver.put("root", "http://repo.springframework.org/milestone");
|
||||
Grape.addResolver(resolver);
|
||||
resolver.put("name", "spring-snapshot");
|
||||
resolver.put("root", "http://repo.springframework.org/snapshot");
|
||||
Grape.addResolver(resolver);
|
||||
}
|
||||
|
||||
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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 org.springframework.bootstrap.cli.compiler.autoconfigure;
|
||||
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.bootstrap.cli.compiler.AstUtils;
|
||||
import org.springframework.bootstrap.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.bootstrap.cli.compiler.DependencyCustomizer;
|
||||
|
||||
/**
|
||||
* {@link CompilerAutoConfiguration} for Spring Batch.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SpringIntegrationCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
// Slightly weird detection algorithm because there is no @Enable annotation for
|
||||
// Integration
|
||||
return AstUtils.hasLeastOneAnnotation(classNode, "MessageEndpoint")
|
||||
|| classNode.getName().contains("SpringIntegration");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyDependencies(DependencyCustomizer dependencies) {
|
||||
dependencies
|
||||
.ifAnyMissingClasses("org.springframework.integration.Message")
|
||||
.add("org.springframework.integration", "spring-integration-core",
|
||||
"2.2.3.RELEASE")
|
||||
.add("org.springframework.integration",
|
||||
"spring-integration-dsl-groovy-core", "1.0.0.M1");
|
||||
dependencies.ifAnyMissingClasses("groovy.util.XmlParser").add(
|
||||
"org.codehaus.groovy", "groovy-xml", "2.1.3");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) {
|
||||
imports.addImports("org.springframework.integration.Message",
|
||||
"org.springframework.integration.MessageChannel",
|
||||
"org.springframework.integration.MessageHeaders",
|
||||
"org.springframework.integration.annotation.MessageEndpoint",
|
||||
"org.springframework.integration.annotation.Header",
|
||||
"org.springframework.integration.annotation.Headers",
|
||||
"org.springframework.integration.annotation.Payload",
|
||||
"org.springframework.integration.annotation.Payloads",
|
||||
"org.springframework.integration.dsl.groovy.builder.IntegrationBuilder");
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class SampleIntegrationTests {
|
||||
@BeforeClass
|
||||
public static void clean() {
|
||||
// SpringBootstrapCli.main("clean");
|
||||
// System.setProperty("ivy.message.logger.level", "4");
|
||||
// System.setProperty("ivy.message.logger.level", "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,6 +63,11 @@ public class SampleIntegrationTests {
|
||||
start("samples/app.groovy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jobSample() throws Exception {
|
||||
start("samples/job.groovy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webSample() throws Exception {
|
||||
start("samples/web.groovy");
|
||||
@@ -73,4 +78,9 @@ public class SampleIntegrationTests {
|
||||
start("samples/service.groovy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void integrationSample() throws Exception {
|
||||
start("samples/integration.groovy");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user