diff --git a/spring-cloud-cli/pom.xml b/spring-cloud-cli/pom.xml index 5c0240c..4040b32 100644 --- a/spring-cloud-cli/pom.xml +++ b/spring-cloud-cli/pom.xml @@ -42,6 +42,11 @@ org.springframework.boot spring-boot-cli ${spring-boot.version} + provided + + + org.springframework.cloud + spring-cloud-netflix-eureka-server provided diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerAstTransformation.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerAstTransformation.java new file mode 100644 index 0000000..83a6ccc --- /dev/null +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerAstTransformation.java @@ -0,0 +1,61 @@ +/* + * Copyright 2013-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.cloud.cli.compiler; + +import groovy.lang.GrabExclude; + +import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.groovy.ast.AnnotationNode; +import org.codehaus.groovy.ast.ClassHelper; +import org.codehaus.groovy.ast.ClassNode; +import org.codehaus.groovy.ast.ModuleNode; +import org.codehaus.groovy.ast.PackageNode; +import org.codehaus.groovy.ast.expr.ConstantExpression; +import org.codehaus.groovy.control.CompilePhase; +import org.codehaus.groovy.control.SourceUnit; +import org.codehaus.groovy.transform.ASTTransformation; +import org.codehaus.groovy.transform.GroovyASTTransformation; + +/** + * @author Dave Syer + * + */ +@GroovyASTTransformation(phase = CompilePhase.CONVERSION) +public class EurekaServerAstTransformation implements ASTTransformation { + + @Override + public void visit(ASTNode[] nodes, SourceUnit source) { + for (ASTNode astNode : nodes) { + if (astNode instanceof ModuleNode) { + visitModule((ModuleNode) astNode); + } + } + } + + private void visitModule(ModuleNode module) { + AnnotationNode exclude = new AnnotationNode(ClassHelper.make(GrabExclude.class)); + exclude.addMember("value", new ConstantExpression( + "org.qos.logback:logback-classic")); + PackageNode pkg = module.getPackage(); + if (pkg != null) { + pkg.addAnnotation(exclude); + } else if (!module.getClasses().isEmpty()){ + ClassNode node = module.getClasses().get(0); + node.addAnnotation(exclude); + } + } + +} diff --git a/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerCompilerAutoConfiguration.java b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerCompilerAutoConfiguration.java new file mode 100644 index 0000000..148d56f --- /dev/null +++ b/spring-cloud-cli/src/main/java/org/springframework/cloud/cli/compiler/EurekaServerCompilerAutoConfiguration.java @@ -0,0 +1,54 @@ +/* + * Copyright 2013-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.cloud.cli.compiler; + +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; + +/** + * @author Dave Syer + * + */ +public class EurekaServerCompilerAutoConfiguration extends CompilerAutoConfiguration { + + @Override + public boolean matches(ClassNode classNode) { + return AstUtils.hasAtLeastOneAnnotation(classNode, "EnableEurekaServer"); + } + + @Override + public void applyDependencies(DependencyCustomizer dependencies) { + dependencies.ifAnyMissingClasses( + "org.springframework.cloud.netflix.eureka.server.EnableEurekaServer") + .add("spring-cloud-starter-eureka-server"); + } + + @Override + public void applyImports(ImportCustomizer imports) throws CompilationFailedException { + imports.addImports("org.springframework.cloud.netflix.eureka.server.EnableEurekaServer", + "org.springframework.cloud.netflix.eureka.EnableEurekaClient", + "org.springframework.cloud.netflix.eureka.EurekaServerConfigBean", + "org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean", + "org.springframework.cloud.netflix.eureka.EurekaClientConfigBean", + "com.netflix.discovery.DiscoveryClient", + "com.netflix.appinfo.InstanceInfo"); + } + +} diff --git a/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration index e402f2d..d3d4aae 100644 --- a/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration +++ b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration @@ -3,6 +3,7 @@ org.springframework.cloud.cli.compiler.ConfigServerCompilerAutoConfiguration org.springframework.cloud.cli.compiler.OAuth2ResourceCompilerAutoConfiguration org.springframework.cloud.cli.compiler.OAuth2SsoCompilerAutoConfiguration org.springframework.cloud.cli.compiler.EurekaClientCompilerAutoConfiguration +org.springframework.cloud.cli.compiler.EurekaServerCompilerAutoConfiguration org.springframework.cloud.cli.compiler.HystrixCompilerAutoConfiguration org.springframework.cloud.cli.compiler.HystrixDashboardCompilerAutoConfiguration org.springframework.cloud.cli.compiler.ZuulCompilerAutoConfiguration diff --git a/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.SpringBootAstTransformation b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.SpringBootAstTransformation new file mode 100644 index 0000000..0551424 --- /dev/null +++ b/spring-cloud-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.SpringBootAstTransformation @@ -0,0 +1,3 @@ +# TODO: maybe it need package change to org.springframework.boot.groovy.cloud as well? +# TODO: test this is working once Boot 1.1.6 is out +org.springframework.cloud.cli.compiler.EurekaServerAstTransformation \ No newline at end of file