Add Spring Mobile Device Resolver autoconfiguration

This commit is contained in:
Roy Clarkson
2013-09-26 10:26:45 -04:00
committed by Dave Syer
parent f306eda703
commit 5cdaa43912
9 changed files with 299 additions and 3 deletions

View File

@@ -0,0 +1,64 @@
/*
* Copyright 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 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.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;
/**
* {@link CompilerAutoConfiguration} for Spring Mobile.
*
* @author Roy Clarkson
*/
public class SpringMobileCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public boolean matches(ClassNode classNode) {
return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableDeviceResolver");
}
@Override
public void applyDependencies(DependencyCustomizer dependencies)
throws CompilationFailedException {
dependencies.add("org.springframework.mobile", "spring-mobile-device",
dependencies.getProperty("spring-mobile.version"));
}
@Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
imports.addStarImports("org.springframework.mobile.device");
imports.addImports(EnableDeviceResolver.class.getCanonicalName());
}
@Target(ElementType.TYPE)
@Documented
@Retention(RetentionPolicy.RUNTIME)
public static @interface EnableDeviceResolver {
}
}

View File

@@ -10,3 +10,4 @@ org.springframework.boot.cli.compiler.autoconfigure.SpockCompilerAutoConfigurati
org.springframework.boot.cli.compiler.autoconfigure.TransactionManagementCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityCompilerAutoConfiguration
org.springframework.boot.cli.compiler.autoconfigure.SpringMobileCompilerAutoConfiguration

View File

@@ -16,6 +16,9 @@
package org.springframework.boot.cli;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.net.URL;
import java.util.concurrent.Callable;
@@ -34,14 +37,12 @@ import org.springframework.boot.OutputCapture;
import org.springframework.boot.cli.command.CleanCommand;
import org.springframework.boot.cli.command.RunCommand;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Integration tests to exercise the samples.
*
* @author Dave Syer
* @author Greg Turnquist
* @author Roy Clarkson
*/
public class SampleIntegrationTests {
@@ -214,4 +215,12 @@ public class SampleIntegrationTests {
output.contains("Received Greetings from Spring Boot via RabbitMQ"));
}
@Test
public void deviceSample() throws Exception {
start("samples/device.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("Hello Normal Device!", result);
}
}