diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java index 06976db20fc..44d8df4bb25 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/DependencyAutoConfigurationTransformation.java @@ -24,6 +24,7 @@ import org.codehaus.groovy.ast.ModuleNode; import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.transform.ASTTransformation; import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; +import org.springframework.core.annotation.Order; /** * {@link ASTTransformation} to apply @@ -34,8 +35,11 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; * @author Dave Syer * @author Andy Wilkinson */ +@Order(DependencyAutoConfigurationTransformation.ORDER) public class DependencyAutoConfigurationTransformation implements ASTTransformation { + public static final int ORDER = GrabMetadataTransformation.ORDER + 100; + private final GroovyClassLoader loader; private final DependencyResolutionContext dependencyResolutionContext; diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java index a0b9014ac87..a2680ca569d 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GrabMetadataTransformation.java @@ -43,6 +43,8 @@ import org.springframework.boot.dependency.tools.Dependencies; import org.springframework.boot.dependency.tools.ManagedDependencies; import org.springframework.boot.dependency.tools.PropertiesFileDependencies; import org.springframework.boot.groovy.GrabMetadata; +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; /** * {@link ASTTransformation} for processing {@link GrabMetadata @GrabMetadata} @@ -50,8 +52,11 @@ import org.springframework.boot.groovy.GrabMetadata; * @author Andy Wilkinson * @since 1.1.0 */ +@Order(GrabMetadataTransformation.ORDER) public class GrabMetadataTransformation extends AnnotatedNodeASTTransformation { + public static final int ORDER = Ordered.HIGHEST_PRECEDENCE; + private static final Set GRAB_METADATA_ANNOTATION_NAMES = Collections .unmodifiableSet(new HashSet(Arrays.asList( GrabMetadata.class.getName(), GrabMetadata.class.getSimpleName()))); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java index 290d847c546..abe81475dba 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyBeansTransformation.java @@ -29,6 +29,7 @@ import org.codehaus.groovy.ast.expr.ClosureExpression; import org.codehaus.groovy.ast.stmt.BlockStatement; import org.codehaus.groovy.control.SourceUnit; import org.codehaus.groovy.transform.ASTTransformation; +import org.springframework.core.annotation.Order; /** * {@link ASTTransformation} to resolve beans declarations inside application source @@ -38,8 +39,11 @@ import org.codehaus.groovy.transform.ASTTransformation; * * @author Dave Syer */ +@Order(GroovyBeansTransformation.ORDER) public class GroovyBeansTransformation implements ASTTransformation { + public static final int ORDER = GrabMetadataTransformation.ORDER + 200; + @Override public void visit(ASTNode[] nodes, SourceUnit source) { for (ASTNode node : nodes) { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java index 06bdfdbc6b0..7bb8944050e 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/GroovyCompiler.java @@ -47,6 +47,7 @@ import org.springframework.boot.cli.compiler.grape.AetherGrapeEngineFactory; import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; import org.springframework.boot.cli.compiler.grape.GrapeEngineInstaller; import org.springframework.boot.cli.util.ResourceUtils; +import org.springframework.core.annotation.AnnotationAwareOrderComparator; /** * Compiler for Groovy sources. Primarily a simple Facade for @@ -112,6 +113,11 @@ public class GroovyCompiler { this.transformations.add(new ResolveDependencyCoordinatesTransformation( resolutionContext)); } + for (ASTTransformation transformation : ServiceLoader + .load(SpringBootAstTransformation.class)) { + this.transformations.add(transformation); + } + Collections.sort(this.transformations, AnnotationAwareOrderComparator.INSTANCE); } /** diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java index 85c02ba9dd3..5d2265c4f78 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/ResolveDependencyCoordinatesTransformation.java @@ -29,6 +29,7 @@ import org.codehaus.groovy.ast.expr.ConstantExpression; import org.codehaus.groovy.ast.expr.Expression; import org.codehaus.groovy.transform.ASTTransformation; import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; +import org.springframework.core.annotation.Order; /** * {@link ASTTransformation} to resolve {@link Grab} artifact coordinates. @@ -36,9 +37,12 @@ import org.springframework.boot.cli.compiler.grape.DependencyResolutionContext; * @author Andy Wilkinson * @author Phillip Webb */ +@Order(ResolveDependencyCoordinatesTransformation.ORDER) public class ResolveDependencyCoordinatesTransformation extends AnnotatedNodeASTTransformation { + public static final int ORDER = GrabMetadataTransformation.ORDER + 300; + private static final Set GRAB_ANNOTATION_NAMES = Collections .unmodifiableSet(new HashSet(Arrays.asList(Grab.class.getName(), Grab.class.getSimpleName()))); diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/SpringBootAstTransformation.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/SpringBootAstTransformation.java new file mode 100644 index 00000000000..af76633623f --- /dev/null +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/SpringBootAstTransformation.java @@ -0,0 +1,29 @@ +/* + * Copyright 2012-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.boot.cli.compiler; + +import org.codehaus.groovy.transform.ASTTransformation; + +/** + * Marker interface for AST transformations that should be installed automatically from + * META-INF/services + * + * @author Dave Syer + */ +public interface SpringBootAstTransformation extends ASTTransformation { + +}