Commit af0d08c9 authored by Phillip Webb's avatar Phillip Webb

Polish

parent b772f7c2
...@@ -35,12 +35,6 @@ import static org.junit.Assert.assertTrue; ...@@ -35,12 +35,6 @@ import static org.junit.Assert.assertTrue;
*/ */
public class AopAutoConfigurationTests { public class AopAutoConfigurationTests {
public interface TestInterface {
public abstract void foo();
}
private AnnotationConfigApplicationContext context; private AnnotationConfigApplicationContext context;
@Test @Test
...@@ -118,4 +112,10 @@ public class AopAutoConfigurationTests { ...@@ -118,4 +112,10 @@ public class AopAutoConfigurationTests {
} }
} }
public interface TestInterface {
public abstract void foo();
}
} }
...@@ -27,9 +27,7 @@ public interface ArtifactCoordinatesResolver { ...@@ -27,9 +27,7 @@ public interface ArtifactCoordinatesResolver {
/** /**
* Gets the group id of the artifact identified by the given {@code artifactId}. * Gets the group id of the artifact identified by the given {@code artifactId}.
* Returns {@code null} if the artifact is unknown to the resolver. * Returns {@code null} if the artifact is unknown to the resolver.
*
* @param artifactId The id of the artifact * @param artifactId The id of the artifact
*
* @return The group id of the artifact * @return The group id of the artifact
*/ */
String getGroupId(String artifactId); String getGroupId(String artifactId);
...@@ -37,9 +35,7 @@ public interface ArtifactCoordinatesResolver { ...@@ -37,9 +35,7 @@ public interface ArtifactCoordinatesResolver {
/** /**
* Gets the version of the artifact identified by the given {@code artifactId}. * Gets the version of the artifact identified by the given {@code artifactId}.
* Returns {@code null} if the artifact is unknown to the resolver. * Returns {@code null} if the artifact is unknown to the resolver.
*
* @param artifactId The id of the artifact * @param artifactId The id of the artifact
*
* @return The version of the artifact * @return The version of the artifact
*/ */
String getVersion(String artifactId); String getVersion(String artifactId);
......
...@@ -18,7 +18,6 @@ package org.springframework.boot.cli.compiler; ...@@ -18,7 +18,6 @@ package org.springframework.boot.cli.compiler;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.List;
import java.util.Set; import java.util.Set;
import org.codehaus.groovy.ast.AnnotatedNode; import org.codehaus.groovy.ast.AnnotatedNode;
...@@ -37,30 +36,28 @@ import org.codehaus.groovy.ast.MethodNode; ...@@ -37,30 +36,28 @@ import org.codehaus.groovy.ast.MethodNode;
public abstract class AstUtils { public abstract class AstUtils {
/** /**
* Determine if an {@link AnnotatedNode} has one or more of the specified annotations. * Determine if a {@link ClassNode} has one or more of the specified annotations on
* N.B. the annotation type names are not normally fully qualified. * the class or any of its methods. N.B. the type names are not normally fully
* qualified.
*/ */
public static boolean hasAtLeastOneAnnotation(AnnotatedNode node, public static boolean hasAtLeastOneAnnotation(ClassNode node, String... annotations) {
String... annotations) { if (hasAtLeastOneAnnotation((AnnotatedNode) node, annotations)) {
for (AnnotationNode annotationNode : node.getAnnotations()) {
for (String annotation : annotations) {
if (annotation.equals(annotationNode.getClassNode().getName())) {
return true; return true;
} }
for (MethodNode method : node.getMethods()) {
if (hasAtLeastOneAnnotation(method, annotations)) {
return true;
} }
} }
return false; return false;
} }
/** /**
* Determine if a {@link ClassNode} has one or more of the specified annotations on the class * Determine if an {@link AnnotatedNode} has one or more of the specified annotations.
* or any of its methods. * N.B. the annotation type names are not normally fully qualified.
* N.B. the type names are not normally fully qualified.
*/ */
public static boolean hasAtLeastOneAnnotation(ClassNode node, String... annotations) { public static boolean hasAtLeastOneAnnotation(AnnotatedNode node,
String... annotations) {
for (AnnotationNode annotationNode : node.getAnnotations()) { for (AnnotationNode annotationNode : node.getAnnotations()) {
for (String annotation : annotations) { for (String annotation : annotations) {
if (annotation.equals(annotationNode.getClassNode().getName())) { if (annotation.equals(annotationNode.getClassNode().getName())) {
...@@ -68,17 +65,6 @@ public abstract class AstUtils { ...@@ -68,17 +65,6 @@ public abstract class AstUtils {
} }
} }
} }
List<MethodNode> methods = node.getMethods();
for (MethodNode method : methods) {
for (AnnotationNode annotationNode : method.getAnnotations()) {
for (String annotation : annotations) {
if (annotation.equals(annotationNode.getClassNode().getName())) {
return true;
}
}
}
}
return false; return false;
} }
...@@ -88,28 +74,23 @@ public abstract class AstUtils { ...@@ -88,28 +74,23 @@ public abstract class AstUtils {
* normally fully qualified. * normally fully qualified.
*/ */
public static boolean hasAtLeastOneFieldOrMethod(ClassNode node, String... types) { public static boolean hasAtLeastOneFieldOrMethod(ClassNode node, String... types) {
Set<String> typesSet = new HashSet<String>(Arrays.asList(types));
Set<String> set = new HashSet<String>(Arrays.asList(types)); for (FieldNode field : node.getFields()) {
List<FieldNode> fields = node.getFields(); if (typesSet.contains(field.getType().getName())) {
for (FieldNode field : fields) {
if (set.contains(field.getType().getName())) {
return true; return true;
} }
} }
List<MethodNode> methods = node.getMethods(); for (MethodNode method : node.getMethods()) {
for (MethodNode method : methods) { if (typesSet.contains(method.getReturnType().getName())) {
if (set.contains(method.getReturnType().getName())) {
return true; return true;
} }
} }
return false; return false;
} }
/** /**
* Determine if a {@link ClassNode} subclasses any of the specified types * Determine if a {@link ClassNode} subclasses any of the specified types N.B. the
* N.B. the type names are not normally fully qualified. * type names are not normally fully qualified.
*/ */
public static boolean subclasses(ClassNode node, String... types) { public static boolean subclasses(ClassNode node, String... types) {
for (String type : types) { for (String type : types) {
...@@ -117,7 +98,6 @@ public abstract class AstUtils { ...@@ -117,7 +98,6 @@ public abstract class AstUtils {
return true; return true;
} }
} }
return false; return false;
} }
......
...@@ -64,6 +64,7 @@ import org.codehaus.groovy.transform.ASTTransformationVisitor; ...@@ -64,6 +64,7 @@ import org.codehaus.groovy.transform.ASTTransformationVisitor;
* *
* @author Phillip Webb * @author Phillip Webb
* @author Dave Syer * @author Dave Syer
* @author Andy Wilkinson
*/ */
public class GroovyCompiler { public class GroovyCompiler {
...@@ -73,6 +74,8 @@ public class GroovyCompiler { ...@@ -73,6 +74,8 @@ public class GroovyCompiler {
private ArtifactCoordinatesResolver artifactCoordinatesResolver; private ArtifactCoordinatesResolver artifactCoordinatesResolver;
private final ASTTransformation dependencyCoordinatesTransformation = new DefaultDependencyCoordinatesAstTransformation();
/** /**
* Create a new {@link GroovyCompiler} instance. * Create a new {@link GroovyCompiler} instance.
* @param configuration the compiler configuration * @param configuration the compiler configuration
...@@ -168,7 +171,6 @@ public class GroovyCompiler { ...@@ -168,7 +171,6 @@ public class GroovyCompiler {
try { try {
Field field = CompilationUnit.class.getDeclaredField("phaseOperations"); Field field = CompilationUnit.class.getDeclaredField("phaseOperations");
field.setAccessible(true); field.setAccessible(true);
LinkedList[] phaseOperations = (LinkedList[]) field.get(compilationUnit); LinkedList[] phaseOperations = (LinkedList[]) field.get(compilationUnit);
processConversionOperations(phaseOperations[Phases.CONVERSION]); processConversionOperations(phaseOperations[Phases.CONVERSION]);
} }
...@@ -186,13 +188,10 @@ public class GroovyCompiler { ...@@ -186,13 +188,10 @@ public class GroovyCompiler {
if (operation.getClass().getName() if (operation.getClass().getName()
.startsWith(ASTTransformationVisitor.class.getName())) { .startsWith(ASTTransformationVisitor.class.getName())) {
conversionOperations.add(i, new CompilationUnit.SourceUnitOperation() { conversionOperations.add(i, new CompilationUnit.SourceUnitOperation() {
private final ASTTransformation transformation = new DefaultDependencyCoordinatesAstTransformation();
@Override @Override
public void call(SourceUnit source) throws CompilationFailedException { public void call(SourceUnit source) throws CompilationFailedException {
this.transformation.visit(new ASTNode[] { source.getAST() }, GroovyCompiler.this.dependencyCoordinatesTransformation.visit(
source); new ASTNode[] { source.getAST() }, source);
} }
}); });
break; break;
...@@ -312,6 +311,7 @@ public class GroovyCompiler { ...@@ -312,6 +311,7 @@ public class GroovyCompiler {
.getGroupId(module)); .getGroupId(module));
grabAnnotation.setMember("group", groupIdExpression); grabAnnotation.setMember("group", groupIdExpression);
} }
if (grabAnnotation.getMember("version") == null) { if (grabAnnotation.getMember("version") == null) {
ConstantExpression versionExpression = new ConstantExpression( ConstantExpression versionExpression = new ConstantExpression(
GroovyCompiler.this.artifactCoordinatesResolver GroovyCompiler.this.artifactCoordinatesResolver
......
...@@ -24,6 +24,11 @@ import java.net.URL; ...@@ -24,6 +24,11 @@ import java.net.URL;
import java.util.Collections; import java.util.Collections;
import java.util.Properties; import java.util.Properties;
/**
* {@link ArtifactCoordinatesResolver} backed by a properties file.
*
* @author Andy Wilkinson
*/
final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinatesResolver { final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinatesResolver {
private final GroovyClassLoader loader; private final GroovyClassLoader loader;
...@@ -60,7 +65,7 @@ final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinates ...@@ -60,7 +65,7 @@ final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinates
try { try {
properties.load(inputStream); properties.load(inputStream);
} }
catch (IOException ioe) { catch (IOException ex) {
// Swallow and continue // Swallow and continue
} }
finally { finally {
...@@ -68,7 +73,7 @@ final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinates ...@@ -68,7 +73,7 @@ final class PropertiesArtifactCoordinatesResolver implements ArtifactCoordinates
} }
} }
} }
catch (IOException e) { catch (IOException ex) {
// Swallow and continue // Swallow and continue
} }
this.properties = properties; this.properties = properties;
......
...@@ -43,10 +43,8 @@ public class JUnitCompilerAutoConfiguration extends CompilerAutoConfiguration { ...@@ -43,10 +43,8 @@ public class JUnitCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override @Override
public void applyImports(ImportCustomizer imports) throws CompilationFailedException { public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
imports.addStarImports("org.junit") imports.addStarImports("org.junit").addStaticStars("org.junit.Assert")
.addStaticStars("org.junit.Assert").addImports()
.addStaticStars("org.hamcrest.MatcherAssert") .addStaticStars("org.hamcrest.MatcherAssert")
.addStaticStars("org.hamcrest.Matchers"); .addStaticStars("org.hamcrest.Matchers");
} }
} }
...@@ -49,7 +49,8 @@ public class SampleAmqpSimpleApplication { ...@@ -49,7 +49,8 @@ public class SampleAmqpSimpleApplication {
@Bean @Bean
public SimpleMessageListenerContainer container() { public SimpleMessageListenerContainer container() {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory); SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(
this.connectionFactory);
Object listener = new Object() { Object listener = new Object() {
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void handleMessage(String foo) { public void handleMessage(String foo) {
...@@ -62,7 +63,6 @@ public class SampleAmqpSimpleApplication { ...@@ -62,7 +63,6 @@ public class SampleAmqpSimpleApplication {
return container; return container;
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
SpringApplication.run(SampleAmqpSimpleApplication.class, args); SpringApplication.run(SampleAmqpSimpleApplication.class, args);
} }
......
/*
* 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.sample.amqp; package org.springframework.boot.sample.amqp;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
...@@ -18,12 +34,12 @@ public class Sender { ...@@ -18,12 +34,12 @@ public class Sender {
@PostConstruct @PostConstruct
public void setUpQueue() { public void setUpQueue() {
amqpAdmin.declareQueue(new Queue("foo")); this.amqpAdmin.declareQueue(new Queue("foo"));
} }
@Scheduled(fixedDelay=1000L) @Scheduled(fixedDelay = 1000L)
public void send() { public void send() {
rabbitTemplate.convertAndSend("foo","hello"); this.rabbitTemplate.convertAndSend("foo", "hello");
} }
} }
...@@ -32,6 +32,7 @@ import org.springframework.boot.gradle.task.RunJar; ...@@ -32,6 +32,7 @@ import org.springframework.boot.gradle.task.RunJar;
public class SpringBootPlugin implements Plugin<Project> { public class SpringBootPlugin implements Plugin<Project> {
private static final String REPACKAGE_TASK_NAME = "repackage"; private static final String REPACKAGE_TASK_NAME = "repackage";
private static final String RUN_JAR_TASK_NAME = "runJar"; private static final String RUN_JAR_TASK_NAME = "runJar";
@Override @Override
......
...@@ -644,6 +644,15 @@ public class SpringApplication { ...@@ -644,6 +644,15 @@ public class SpringApplication {
this.initializers = new ArrayList<ApplicationContextInitializer<?>>(initializers); this.initializers = new ArrayList<ApplicationContextInitializer<?>>(initializers);
} }
/**
* Add {@link ApplicationContextInitializer}s to be applied to the Spring
* {@link ApplicationContext} .
* @param initializers the initializers to add
*/
public void addInitializers(ApplicationContextInitializer<?>... initializers) {
this.initializers.addAll(Arrays.asList(initializers));
}
/** /**
* Returns a mutable list of the {@link ApplicationContextInitializer}s that will be * Returns a mutable list of the {@link ApplicationContextInitializer}s that will be
* applied to the Spring {@link ApplicationContext}. * applied to the Spring {@link ApplicationContext}.
......
...@@ -56,8 +56,8 @@ public class ContextIdApplicationContextInitializer implements ...@@ -56,8 +56,8 @@ public class ContextIdApplicationContextInitializer implements
private int order = Integer.MAX_VALUE - 10; private int order = Integer.MAX_VALUE - 10;
public ContextIdApplicationContextInitializer() { public ContextIdApplicationContextInitializer() {
this( this("${spring.application.name:${vcap.application.name:"
"${spring.application.name:${vcap.application.name:${spring.config.name:application}}}"); + "${spring.config.name:application}}}");
} }
/** /**
......
...@@ -50,7 +50,6 @@ import org.springframework.web.context.support.GenericWebApplicationContext; ...@@ -50,7 +50,6 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
* create the application context. * create the application context.
* *
* @author Dave Syer * @author Dave Syer
*
*/ */
public class SpringApplicationContextLoader extends AbstractContextLoader { public class SpringApplicationContextLoader extends AbstractContextLoader {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment