diff --git a/spring-boot-cli/samples/retry.groovy b/spring-boot-cli/samples/retry.groovy new file mode 100644 index 0000000000..652cc607cf --- /dev/null +++ b/spring-boot-cli/samples/retry.groovy @@ -0,0 +1,30 @@ +package org.test + +@EnableRetry +@Component +class Example implements CommandLineRunner { + + @Autowired + private MyService myService + + void run(String... args) { + println "Hello ${this.myService.sayWorld()} From ${getClass().getClassLoader().getResource('samples/retry.groovy')}" + } +} + + +@Service +class MyService { + + static int count = 0 + + @Retryable + String sayWorld() { + if (count++==0) { + throw new IllegalStateException("Planned") + } + return "World!" + } +} + + diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringRetryCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringRetryCompilerAutoConfiguration.java new file mode 100644 index 0000000000..2ba0afdd2f --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpringRetryCompilerAutoConfiguration.java @@ -0,0 +1,49 @@ +/* + * 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.boot.cli.compiler.autoconfigure; + +import org.codehaus.groovy.ast.ClassNode; +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; + +/** + * {@link CompilerAutoConfiguration} for Spring Retry. + * + * @author Dave Syer + */ +public class SpringRetryCompilerAutoConfiguration extends CompilerAutoConfiguration { + + @Override + public boolean matches(ClassNode classNode) { + return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableRetry", "Retryable", + "Recover"); + } + + @Override + public void applyDependencies(DependencyCustomizer dependencies) { + dependencies.ifAnyMissingClasses( + "org.springframework.retry.annotation.EnableRetry").add("spring-retry", + "spring-boot-starter-aop"); + } + + @Override + public void applyImports(ImportCustomizer imports) { + imports.addStarImports("org.springframework.retry.annotation"); + } +} diff --git a/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration b/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration index 05e8637a54..abf1699498 100644 --- a/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration +++ b/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration @@ -13,8 +13,8 @@ org.springframework.boot.cli.compiler.autoconfigure.TransactionManagementCompile org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityOAuth2CompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityCompilerAutoConfiguration -org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityOAuth2CompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringMobileCompilerAutoConfiguration +org.springframework.boot.cli.compiler.autoconfigure.SpringRetryCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSocialFacebookCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSocialLinkedInCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSocialTwitterCompilerAutoConfiguration diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java index 7f823192c0..d91f23773b 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java @@ -49,6 +49,14 @@ public class SampleIntegrationTests { output.contains("Hello World! From " + scriptUri)); } + @Test + public void retrySample() throws Exception { + String output = this.cli.run("retry.groovy"); + URI scriptUri = new File("samples/retry.groovy").toURI(); + assertTrue("Wrong output: " + output, + output.contains("Hello World! From " + scriptUri)); + } + @Test public void beansSample() throws Exception { this.cli.run("beans.groovy"); diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 9a021174fa..a5abc695c0 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -130,6 +130,7 @@ 1.2.3.RELEASE 1.1.3.RELEASE 1.2.0.RELEASE + 1.1.2.RELEASE 4.0.1.RELEASE 1.0.3.RELEASE 2.0.7.RELEASE @@ -1521,6 +1522,11 @@ spring-plugin-core ${spring-plugin.version} + + org.springframework.retry + spring-retry + ${spring-retry.version} + org.springframework.security spring-security-bom