diff --git a/spring-cloud-cli/pom.xml b/spring-cloud-cli/pom.xml index 88ff0c7..1a5ce56 100644 --- a/spring-cloud-cli/pom.xml +++ b/spring-cloud-cli/pom.xml @@ -28,6 +28,12 @@ ${spring-boot.version} provided + + org.springframework.cloud + spring-cloud-stream + ${spring-cloud-stream.version} + true + org.springframework.boot spring-boot-starter-test @@ -39,6 +45,7 @@ UTF-8 1.7 ${project.version} + 1.0.0.BUILD-SNAPSHOT ${project.build.directory}/generated-resources/org/springframework/cloud/cli/compiler diff --git a/spring-cloud-cli/src/main/java/org/springframework/boot/groovy/cloud/EnableBinding.java b/spring-cloud-cli/src/main/java/org/springframework/boot/groovy/cloud/EnableBinding.java new file mode 100644 index 0000000..d830ff4 --- /dev/null +++ b/spring-cloud-cli/src/main/java/org/springframework/boot/groovy/cloud/EnableBinding.java @@ -0,0 +1,40 @@ +/* + * Copyright 2015 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.boot.groovy.cloud; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.cloud.cli.compiler.StreamRabbitCompilerAutoConfiguration; + +/** + * Pseudo annotation used to trigger {@link StreamRabbitCompilerAutoConfiguration} and + * Redis. + */ +@Target(ElementType.TYPE) +@Documented +@Retention(RetentionPolicy.RUNTIME) +@org.springframework.cloud.stream.annotation.EnableBinding +public @interface EnableBinding { + + Class[]value() default {}; + + String transport() default "redis"; +} diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2SsoCompilerAutoConfiguration.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2SsoCompilerAutoConfiguration.java index 675b3e9..665a693 100644 --- a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2SsoCompilerAutoConfiguration.java +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2SsoCompilerAutoConfiguration.java @@ -16,8 +16,6 @@ package org.springframework.cloud.cli.compiler; import org.codehaus.groovy.ast.ClassNode; -import org.codehaus.groovy.control.CompilationFailedException; -import org.codehaus.groovy.control.customizers.ImportCustomizer; import org.springframework.boot.cli.compiler.AstUtils; import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; import org.springframework.boot.cli.compiler.DependencyCustomizer; @@ -37,16 +35,8 @@ public class OAuth2SsoCompilerAutoConfiguration extends CompilerAutoConfiguratio public void applyDependencies(DependencyCustomizer dependencies) { dependencies .ifAnyMissingClasses( - "org.springframework.cloud.security.oauth2.sso.EnableOAuth2Sso") - .add("spring-cloud-starter-security") - .add("spring-security-oauth2"); - } - - @Override - public void applyImports(ImportCustomizer imports) throws CompilationFailedException { - imports.addImports( - "org.springframework.cloud.security.oauth2.sso.EnableOAuth2Sso", - "org.springframework.cloud.security.oauth2.sso.OAuth2SsoConfigurerAdapter"); + "org.springframework.cloud.security.oauth2.client.OAuth2LoadBalancerClientAutoConfiguration") + .add("spring-cloud-starter-oauth2"); } } diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2ResourceCompilerAutoConfiguration.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamKafkaCompilerAutoConfiguration.java similarity index 69% rename from spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2ResourceCompilerAutoConfiguration.java rename to spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamKafkaCompilerAutoConfiguration.java index 1aa5dc7..d509d44 100644 --- a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/OAuth2ResourceCompilerAutoConfiguration.java +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamKafkaCompilerAutoConfiguration.java @@ -26,27 +26,27 @@ import org.springframework.boot.cli.compiler.DependencyCustomizer; * @author Dave Syer * */ -public class OAuth2ResourceCompilerAutoConfiguration extends CompilerAutoConfiguration { +public class StreamKafkaCompilerAutoConfiguration extends CompilerAutoConfiguration { @Override public boolean matches(ClassNode classNode) { - return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableOAuth2Resource"); + boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding"); + return annotated && StreamRedisCompilerAutoConfiguration.isTransport(classNode, "kafka"); } @Override public void applyDependencies(DependencyCustomizer dependencies) { dependencies .ifAnyMissingClasses( - "org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource") - .add("spring-cloud-starter-security") - .add("spring-security-oauth2"); + "org.springframework.cloud.stream.binder.kafka.config.KafkaServiceAutoConfiguration") + .add("spring-cloud-starter-stream-kafka"); } @Override public void applyImports(ImportCustomizer imports) throws CompilationFailedException { - imports.addImports( - "org.springframework.cloud.security.oauth2.resource.EnableOAuth2Resource", - "org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter"); + imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding"); + imports.addStarImports("org.springframework.cloud.stream.annotation", + "org.springframework.cloud.stream.messaging"); } } diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRabbitCompilerAutoConfiguration.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRabbitCompilerAutoConfiguration.java new file mode 100644 index 0000000..1b861a7 --- /dev/null +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRabbitCompilerAutoConfiguration.java @@ -0,0 +1,52 @@ +/* + * Copyright 2013-2014 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.cloud.cli.compiler; + +import org.codehaus.groovy.ast.ClassNode; +import org.codehaus.groovy.control.CompilationFailedException; +import org.codehaus.groovy.control.customizers.ImportCustomizer; +import org.springframework.boot.cli.compiler.AstUtils; +import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; +import org.springframework.boot.cli.compiler.DependencyCustomizer; + +/** + * @author Dave Syer + * + */ +public class StreamRabbitCompilerAutoConfiguration extends CompilerAutoConfiguration { + + @Override + public boolean matches(ClassNode classNode) { + boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding"); + return annotated && StreamRedisCompilerAutoConfiguration.isTransport(classNode, "rabbit"); + } + + @Override + public void applyDependencies(DependencyCustomizer dependencies) { + dependencies + .ifAnyMissingClasses( + "org.springframework.cloud.stream.binder.rabbit.config.RabbitServiceAutoConfiguration") + .add("spring-cloud-starter-stream-rabbit"); + } + + @Override + public void applyImports(ImportCustomizer imports) throws CompilationFailedException { + imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding"); + imports.addStarImports("org.springframework.cloud.stream.annotation", + "org.springframework.cloud.stream.messaging"); + } + +} diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRedisCompilerAutoConfiguration.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRedisCompilerAutoConfiguration.java new file mode 100644 index 0000000..4119429 --- /dev/null +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/StreamRedisCompilerAutoConfiguration.java @@ -0,0 +1,72 @@ +/* + * Copyright 2013-2014 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.cloud.cli.compiler; + +import org.codehaus.groovy.ast.AnnotationNode; +import org.codehaus.groovy.ast.ClassNode; +import org.codehaus.groovy.ast.expr.Expression; +import org.codehaus.groovy.control.CompilationFailedException; +import org.codehaus.groovy.control.customizers.ImportCustomizer; +import org.springframework.boot.cli.compiler.AstUtils; +import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; +import org.springframework.boot.cli.compiler.DependencyCustomizer; +import org.springframework.util.PatternMatchUtils; +import org.springframework.util.SystemPropertyUtils; + +/** + * @author Dave Syer + * + */ +public class StreamRedisCompilerAutoConfiguration extends CompilerAutoConfiguration { + + @Override + public boolean matches(ClassNode classNode) { + boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding"); + return annotated && isTransport(classNode, "redis"); + } + + static boolean isTransport(ClassNode node, String type) { + for (AnnotationNode annotationNode : node.getAnnotations()) { + String annotation = "EnableBinding"; + if (PatternMatchUtils.simpleMatch(annotation, + annotationNode.getClassNode().getName())) { + Expression expression = annotationNode.getMembers().get("transport"); + String transport = expression == null ? "redis" : expression.getText(); + if (transport != null) { + transport = SystemPropertyUtils.resolvePlaceholders(transport); + } + return transport.equals(type); + } + } + return false; + } + + @Override + public void applyDependencies(DependencyCustomizer dependencies) { + dependencies + .ifAnyMissingClasses( + "org.springframework.cloud.stream.binder.redis.config.RedisServiceAutoConfiguration") + .add("spring-cloud-starter-stream-redis"); + } + + @Override + public void applyImports(ImportCustomizer imports) throws CompilationFailedException { + imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding"); + imports.addStarImports("org.springframework.cloud.stream.annotation", + "org.springframework.cloud.stream.messaging"); + } + +} diff --git a/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration index 5703b42..4df4140 100644 --- a/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration +++ b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration @@ -1,10 +1,11 @@ org.springframework.cloud.cli.compiler.SpringCloudCompilerAutoConfiguration org.springframework.cloud.cli.compiler.ConfigServerCompilerAutoConfiguration -org.springframework.cloud.cli.compiler.OAuth2ResourceCompilerAutoConfiguration -org.springframework.cloud.cli.compiler.OAuth2SsoCompilerAutoConfiguration org.springframework.cloud.cli.compiler.EurekaClientCompilerAutoConfiguration org.springframework.cloud.cli.compiler.EurekaServerCompilerAutoConfiguration org.springframework.cloud.cli.compiler.HystrixCompilerAutoConfiguration org.springframework.cloud.cli.compiler.HystrixDashboardCompilerAutoConfiguration org.springframework.cloud.cli.compiler.RibbonClientCompilerAutoConfiguration +org.springframework.cloud.cli.compiler.StreamKafkaCompilerAutoConfiguration +org.springframework.cloud.cli.compiler.StreamRabbitCompilerAutoConfiguration +org.springframework.cloud.cli.compiler.StreamRedisCompilerAutoConfiguration org.springframework.cloud.cli.compiler.ZuulCompilerAutoConfiguration