Add EurekaServer support

This commit is contained in:
Dave Syer
2014-09-04 10:46:37 +01:00
parent 02c5670dda
commit 89a5612f9f
5 changed files with 124 additions and 0 deletions

View File

@@ -42,6 +42,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-cli</artifactId>
<version>${spring-boot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-eureka-server</artifactId>
<scope>provided</scope>
</dependency>
<dependency>

View File

@@ -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);
}
}
}

View File

@@ -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");
}
}

View File

@@ -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

View File

@@ -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