Take advantage of new features in Boot

This commit is contained in:
Dave Syer
2015-10-06 09:43:22 +01:00
parent ed9ece70a3
commit b8c159b8a4
9 changed files with 44 additions and 369 deletions

View File

@@ -31,7 +31,6 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream</artifactId>
<version>${spring-cloud-stream.version}</version>
<optional>true</optional>
</dependency>
<dependency>
@@ -45,49 +44,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
<spring-cloud.version>${project.version}</spring-cloud.version>
<spring-cloud-stream.version>1.0.0.BUILD-SNAPSHOT</spring-cloud-stream.version>
<generated.pom.dir>${project.build.directory}/generated-resources/org/springframework/cloud/cli/compiler</generated.pom.dir>
</properties>
<build>
<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
</resource>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-effective-pom</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-versions</artifactId>
<version>${spring-cloud.version}</version>
<type>effective-pom</type>
<overWrite>true</overWrite>
<outputDirectory>${generated.pom.dir}</outputDirectory>
<destFileName>effective-pom.xml</destFileName>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>milestone</id>

View File

@@ -1,61 +0,0 @@
/*
* 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,43 @@
/*
* Copyright 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.
* 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.control.CompilePhase;
import org.codehaus.groovy.transform.GroovyASTTransformation;
import org.springframework.boot.cli.compiler.DependencyManagementBomTransformation;
import org.springframework.boot.cli.compiler.GenericBomAstTransformation;
/**
* @author Dave Syer
*
*/
@GroovyASTTransformation(phase = CompilePhase.CONVERSION)
public class SpringCloudBomAstTransformation extends GenericBomAstTransformation {
private static final String SPRING_CLOUD_VERSION = "Brixton.BUILD-SNAPSHOT";
@Override
protected String getBomModule() {
return "org.springframework.cloud:spring-cloud-starter-parent:" + SPRING_CLOUD_VERSION;
}
@Override
public int getOrder() {
return DependencyManagementBomTransformation.ORDER - 50;
}
}

View File

@@ -15,23 +15,10 @@
*/
package org.springframework.cloud.cli.compiler;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.DefaultModelProcessor;
import org.apache.maven.model.io.DefaultModelReader;
import org.apache.maven.model.locator.DefaultModelLocator;
import org.codehaus.groovy.control.CompilationFailedException;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;
import org.springframework.boot.cli.compiler.dependencies.Dependency;
import org.springframework.boot.cli.compiler.dependencies.MavenModelDependencyManagement;
/**
* @author Dave Syer
@@ -42,7 +29,6 @@ public class SpringCloudCompilerAutoConfiguration extends
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
addManagedDependencies(dependencies);
dependencies
.ifAnyMissingClasses(
"org.springframework.boot.actuate.endpoint.EnvironmentEndpoint")
@@ -58,82 +44,4 @@ public class SpringCloudCompilerAutoConfiguration extends
imports.addImports("org.springframework.cloud.context.config.annotation.RefreshScope");
}
private void addManagedDependencies(DependencyCustomizer dependencies) {
dependencies.getDependencyResolutionContext().addDependencyManagement(new SpringCloudDependenciesDependencyManagement());
}
public static class SpringCloudDependenciesDependencyManagement extends
MavenModelDependencyManagement {
public SpringCloudDependenciesDependencyManagement() {
super(readModel());
}
private static Model readModel() {
DefaultModelProcessor modelProcessor = new DefaultModelProcessor();
modelProcessor.setModelLocator(new DefaultModelLocator());
modelProcessor.setModelReader(new DefaultModelReader());
try {
return modelProcessor
.read(SpringCloudDependenciesDependencyManagement.class
.getResourceAsStream("effective-pom.xml"), null);
} catch (IOException ex) {
throw new IllegalStateException(
"Failed to build model from effective pom", ex);
}
}
}
static class AetherManagedDependencies implements Iterable<Dependency> {
private Map<String, Dependency> groupAndArtifactToDependency = new HashMap<String, Dependency>();
private Map<String, String> artifactToGroupAndArtifact = new HashMap<String, String>();
public AetherManagedDependencies(List<Dependency> dependencies) {
for (Dependency dependency : dependencies) {
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
String version = dependency.getVersion();
List<Dependency.Exclusion> exclusions = new ArrayList<Dependency.Exclusion>();
Dependency value = new Dependency(groupId, artifactId, version,
exclusions);
groupAndArtifactToDependency.put(groupId + ":" + artifactId,
value);
artifactToGroupAndArtifact.put(artifactId, groupId + ":"
+ artifactId);
}
}
// @Override
public Dependency find(String groupId, String artifactId) {
return groupAndArtifactToDependency.get(groupId + ":" + artifactId);
}
// @Override
public Dependency find(String artifactId) {
String groupAndArtifact = artifactToGroupAndArtifact
.get(artifactId);
if (groupAndArtifact == null) {
return null;
}
return groupAndArtifactToDependency.get(groupAndArtifact);
}
@Override
public Iterator<Dependency> iterator() {
return groupAndArtifactToDependency.values().iterator();
}
}
}

View File

@@ -1,3 +1 @@
# 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
org.springframework.cloud.cli.compiler.SpringCloudBomAstTransformation