From c525689b0f1eee2c8443019307385878563897e9 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 7 Oct 2015 19:05:28 -0700 Subject: [PATCH] Polish --- .../compiler/GenericBomAstTransformation.java | 41 ++++++++----------- .../GenericBomAstTransformationTests.java | 13 +++--- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GenericBomAstTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GenericBomAstTransformation.java index 70d337dea5..f90d306500 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GenericBomAstTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GenericBomAstTransformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2012-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. @@ -39,15 +39,15 @@ import org.springframework.core.Ordered; /** * A base class that lets plugin authors easily add additional BOMs to all apps. All the - * dependencies in the bom (and it's transitives) will be added to the dependency + * dependencies in the BOM (and it's transitives) will be added to the dependency * management lookup, so an app can use just the artifact id (e.g. "spring-jdbc") in a - * @Grab. To install, implement the missing methods and list the class in - * META-INF/services/org.springframework.boot.cli.compiler.SpringBootAstTransformation + * {@code @Grab}. To install, implement the missing methods and list the class in + * {@code META-INF/services/org.springframework.boot.cli.compiler.SpringBootAstTransformation} * . The {@link #getOrder()} value needs to be before * {@link DependencyManagementBomTransformation#ORDER}. * * @author Dave Syer - * + * @since 1.3.0 */ @GroovyASTTransformation(phase = CompilePhase.CONVERSION) public abstract class GenericBomAstTransformation @@ -67,11 +67,10 @@ public abstract class GenericBomAstTransformation /** * The bom to be added to dependency management in compact form: * "<groupId>:<artifactId>:<version>" (like in a - * @Grab). - * - * @return the maven co-ordinates of the bom to add + * {@code @Grab}). + * @return the maven co-ordinates of the BOM to add */ - abstract protected String getBomModule(); + protected abstract String getBomModule(); private void visitModule(ModuleNode node, String module) { addDependencyManagementBom(node, module); @@ -89,30 +88,24 @@ public abstract class GenericBomAstTransformation } private AnnotationNode getAnnotation(AnnotatedNode annotated) { - AnnotationNode annotation; List annotations = annotated.getAnnotations(BOM); - if (annotations.isEmpty()) { - annotation = new AnnotationNode(BOM); - annotated.addAnnotation(annotation); - } - else { - annotation = annotations.get(0); + if (!annotations.isEmpty()) { + return annotations.get(0); } + AnnotationNode annotation = new AnnotationNode(BOM); + annotated.addAnnotation(annotation); return annotation; } private AnnotatedNode getAnnotatedNode(ModuleNode node) { - PackageNode pkg = node.getPackage(); - if (pkg != null) { - if (!pkg.getAnnotations(BOM).isEmpty()) { - return pkg; - } + PackageNode packageNode = node.getPackage(); + if (packageNode != null && !packageNode.getAnnotations(BOM).isEmpty()) { + return packageNode; } if (!node.getClasses().isEmpty()) { - ClassNode cls = node.getClasses().get(0); - return cls; + return node.getClasses().get(0); } - return pkg; + return packageNode; } private List getConstantExpressions(Expression valueExpression) { diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/GenericBomAstTransformationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/GenericBomAstTransformationTests.java index a51d3562ca..48024bdf26 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/GenericBomAstTransformationTests.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/GenericBomAstTransformationTests.java @@ -40,6 +40,7 @@ import static org.junit.Assert.assertEquals; * Tests for {@link ResolveDependencyCoordinatesTransformation} * * @author Andy Wilkinson + * @author Dave Syer */ public final class GenericBomAstTransformationTests { @@ -59,6 +60,7 @@ public final class GenericBomAstTransformationTests { protected String getBomModule() { return "test:child:1.0.0"; } + }; @Test @@ -106,16 +108,15 @@ public final class GenericBomAstTransformationTests { } private AnnotationNode findAnnotation() { - PackageNode pkg = this.moduleNode.getPackage(); + PackageNode packageNode = this.moduleNode.getPackage(); ClassNode bom = ClassHelper.make(DependencyManagementBom.class); - if (pkg != null) { - if (!pkg.getAnnotations(bom).isEmpty()) { - return pkg.getAnnotations(bom).get(0); + if (packageNode != null) { + if (!packageNode.getAnnotations(bom).isEmpty()) { + return packageNode.getAnnotations(bom).get(0); } } if (!this.moduleNode.getClasses().isEmpty()) { - ClassNode cls = this.moduleNode.getClasses().get(0); - return cls.getAnnotations(bom).get(0); + return this.moduleNode.getClasses().get(0).getAnnotations(bom).get(0); } throw new IllegalStateException("No package or class node found"); }