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

@@ -26,7 +26,6 @@
<main.basedir>${basedir}/..</main.basedir>
</properties>
<modules>
<module>spring-cloud-versions</module>
<module>spring-cloud-cli</module>
<module>docs</module>
</modules>

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

View File

@@ -1,114 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-cli-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-cloud-versions</artifactId>
<packaging>pom</packaging>
<name>Spring Cloud Versions</name>
<description>Spring Cloud Versions Property File</description>
<url>http://projects.spring.io/spring-cloud/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<spring-cloud.version>Brixton.BUILD-SNAPSHOT</spring-cloud.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
<directory>${project.build.directory}/generated-resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-help-plugin</artifactId>
<executions>
<execution>
<id>generate-effective-dependencies-pom</id>
<phase>generate-resources</phase>
<goals>
<goal>effective-pom</goal>
</goals>
<configuration>
<output>${project.build.directory}/effective-pom/spring-cloud-versions.xml</output>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<goals>
<goal>transform</goal>
</goals>
</execution>
</executions>
<configuration>
<transformationSets>
<transformationSet>
<dir>${project.build.directory}/effective-pom</dir>
<stylesheet>src/main/xslt/dependency-management-to-versions.xsl</stylesheet>
<fileMappers>
<fileMapper
implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
<targetExtension>.properties</targetExtension>
</fileMapper>
</fileMappers>
<outputDir>${project.build.directory}/generated-resources</outputDir>
</transformationSet>
</transformationSets>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/generated-resources/spring-cloud-versions.properties</file>
<type>properties</type>
</artifact>
<artifact>
<file>${project.build.directory}/effective-pom/spring-cloud-versions.xml</file>
<type>effective-pom</type>
</artifact>
</artifacts>
</configuration>
</execution>
<execution>
<id>attach-zip</id>
<phase />
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<profiles>
<profile>
<id>it-repo</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local.central</id>
<url>@localRepositoryUrl@</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>

View File

@@ -1,21 +0,0 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:mvn="http://maven.apache.org/POM/4.0.0"
version="1.0">
<xsl:output method="text" encoding="UTF-8" indent="no"/>
<xsl:template match="/">
<xsl:for-each select="//mvn:dependency">
<xsl:sort select="mvn:groupId"/>
<xsl:sort select="mvn:artifactId"/>
<xsl:copy-of select="mvn:groupId"/>
<xsl:text>\:</xsl:text>
<xsl:copy-of select="mvn:artifactId"/>
<xsl:text>=</xsl:text>
<xsl:copy-of select="mvn:version"/>
<xsl:text>&#xa;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>