Add AST transformations and version metadata

This commit is contained in:
Dave Syer
2014-07-31 12:43:30 -07:00
commit c61a72fedd
16 changed files with 3412 additions and 0 deletions

1
spring-platform-cli/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target/

View File

@@ -0,0 +1,97 @@
Integration between [Cloudfoundry](https://github.com/cloudfoundry)
and the [Spring Platform](https://github.com/spring-platform).
Add this project to a Spring Boot REST service and deploy to
Cloudfoundry (and use the Actuator for maximum flexibility). It will
expose service-broker endpoints automatically (look in /mappings for
/v2/*) and you can register it with the Cloud Controller as described
here:
[http://docs.cloudfoundry.org/services/managing-service-brokers.html](http://docs.cloudfoundry.org/services/managing-service-brokers.html).
Example script to deploy and register a broker:
```
DOMAIN=mydomain.net
cf push app -p target/*.jar --no-start
cf env app | grep SPRING_PROFILES_ACTIVE || cf set-env app SPRING_PROFILES_ACTIVE cloud
cf env app | grep APPLICATION_DOMAIN || cf set-env app APPLICATION_DOMAIN ${DOMAIN}
cf services | grep configserver && cf bind app configserver
cf restart app
cf create-service-broker app user secure http://app.${DOMAIN}
for f in `cf curl /v2/service_plans | grep '\"guid' | sed -e 's/.*: "//' -e 's/".*//'`; do
cf curl v2/service_plans/$f -X PUT -d '{"public":true}'
done
cf create-service app free appi
```
At which point you have a service called "app" and a service instance called "appi":
```
$ cf marketplace
OK
service plans description
app free Singleton service app
$ cf services
Getting services in org default / space development as admin...
OK
name service plan bound apps
appi app free
```
Your application can define a configuration property
`application.domain` (defaults to "cfapps.io") which will be used to
construct the credentials for any app that binds to your service. Or
it can define the URI directly using
`cloudfoundry.service.definition.metadata.uri`.
You can change some other basic metadata by setting config properties:
* `cloudfoundry.service.definition.*` is bound to a
`ServiceDefinition` (defined in spring-boot-cf-service-broker) which
has optional setters for plans and metadata.
* `cloudfoundry.service.broker.*` is bound to an internal bean. It has
optional setters for "name" (the service name), "description" (user
friendly description) and "prefix" (used to create a unique id from
the name).
An app which binds to your service will get credentials that contain a
"uri" property linking to your service. A Spring Boot app can bind to
that through the `vcap.services.[service].credentials.uri` environment
property.
If your service also has a
[Eureka core](https://github.com/Netflix/eureka) dependency, and you
can expose it as a Eureka service, then any service which registers
with Eureka will also become a Cloudfoundry service. Example app with
Eureka server (include jersey 1.13 to get the JAX-RS dependencies):
```
@Configuration
@EnableAutoConfiguration
public class Application extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public FilterRegistrationBean jersey() {
FilterRegistrationBean bean = new FilterRegistrationBean();
bean.setFilter(new ServletContainer());
bean.addInitParameter("com.sun.jersey.config.property.WebPageContentRegex",
"(/|/(flex/|images/|js/|css/|jsp/|admin/|v2/catalog|v2/service_instances).*)");
bean.addInitParameter("com.sun.jersey.config.property.packages",
"com.sun.jersey;com.netflix");
return bean;
}
}
```

167
spring-platform-cli/pom.xml Normal file
View File

@@ -0,0 +1,167 @@
<?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>
<groupId>org.springframework.platform</groupId>
<artifactId>spring-platform-cli</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-platform-cli</name>
<description>Spring Patform Cli integration project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.5.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.platform</groupId>
<artifactId>spring-platform-netflix</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.platform</groupId>
<artifactId>spring-platform-config</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-cli</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<profiles>
<profile>
<id>milestone</id>
<distributionManagement>
<repository>
<id>repo.spring.io</id>
<name>Spring Milestone Repository</name>
<url>https://repo.spring.io/libs-milestone-local</url>
</repository>
</distributionManagement>
</profile>
<profile>
<id>central</id>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<name>Nexus Release Repository</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<distributionManagement>
<!-- see 'staging' profile for dry-run deployment settings -->
<downloadUrl>http://www.springsource.com/download/community
</downloadUrl>
<site>
<id>spring-docs</id>
<url>scp://static.springframework.org/var/www/domains/springframework.org/static/htdocs/spring-platform-cli/docs/${project.version}
</url>
</site>
<repository>
<id>repo.spring.io</id>
<name>Spring Release Repository</name>
<url>https://repo.spring.io/libs-release-local</url>
</repository>
<snapshotRepository>
<id>repo.spring.io</id>
<name>Spring Snapshot Repository</name>
<url>https://repo.spring.io/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>spring-releases</id>
<name>Spring Releases</name>
<url>http://repo.spring.io/release</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>http://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -0,0 +1,35 @@
/*
* 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.platform.cli.command;
import java.util.Collection;
import java.util.Collections;
import org.springframework.boot.cli.command.Command;
import org.springframework.boot.cli.command.CommandFactory;
/**
* @author Dave Syer
*
*/
public class EncryptCommand implements CommandFactory {
@Override
public Collection<Command> getCommands() {
return Collections.emptySet();
}
}

View File

@@ -0,0 +1,131 @@
/*
* 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.platform.cli.compiler;
import groovy.grape.Grape;
import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.aether.graph.Dependency;
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
import org.springframework.boot.cli.compiler.DependencyCustomizer;
import org.springframework.boot.dependency.tools.Dependencies;
import org.springframework.boot.dependency.tools.ManagedDependencies;
import org.springframework.boot.dependency.tools.PropertiesFileDependencies;
/**
* @author Dave Syer
*
*/
public class SpringPlatformCompilerAutoConfiguration extends CompilerAutoConfiguration {
@Override
public void applyDependencies(DependencyCustomizer dependencies) {
addManagedDependencies(dependencies);
dependencies.ifAnyMissingClasses(
"org.springframework.boot.actuate.endpoint.EnvironmentEndpoint").add(
"spring-boot-starter-actuator");
dependencies
.ifAnyMissingClasses("org.springframework.platform.config.Environment")
.add("spring-platform-config-client");
}
private void addManagedDependencies(DependencyCustomizer dependencies) {
List<Dependencies> managedDependencies = new ArrayList<Dependencies>();
managedDependencies.add(new AetherManagedDependencies(dependencies
.getDependencyResolutionContext().getManagedDependencies()));
managedDependencies.addAll(getAdditionalDependencies());
dependencies.getDependencyResolutionContext().setManagedDependencies(
ManagedDependencies.get(managedDependencies));
}
private List<Dependencies> getAdditionalDependencies() {
String[] components = "org.springframework.platform:spring-platform-components-versions:1.0.0.BUILD-SNAPSHOT"
.split(":");
Map<String, String> dependency;
dependency = new HashMap<String, String>();
dependency.put("group", components[0]);
dependency.put("module", components[1]);
dependency.put("version", components[2]);
dependency.put("type", "properties");
URI[] uris = Grape.getInstance().resolve(null, dependency);
List<Dependencies> managedDependencies = new ArrayList<Dependencies>(uris.length);
for (URI uri : uris) {
try {
managedDependencies.add(new PropertiesFileDependencies(uri.toURL()
.openStream()));
}
catch (Exception ex) {
throw new IllegalStateException("Failed to parse '" + uris[0]
+ "'. Is it a valid properties file?", ex);
}
}
return managedDependencies;
}
static class AetherManagedDependencies implements Dependencies {
private Map<String, org.springframework.boot.dependency.tools.Dependency> groupAndArtifactToDependency = new HashMap<String, org.springframework.boot.dependency.tools.Dependency>();
private Map<String, String> artifactToGroupAndArtifact = new HashMap<String, String>();
public AetherManagedDependencies(List<Dependency> dependencies) {
for (Dependency dependency : dependencies) {
String groupId = dependency.getArtifact().getGroupId();
String artifactId = dependency.getArtifact().getArtifactId();
String version = dependency.getArtifact().getVersion();
List<org.springframework.boot.dependency.tools.Dependency.Exclusion> exclusions = new ArrayList<org.springframework.boot.dependency.tools.Dependency.Exclusion>();
org.springframework.boot.dependency.tools.Dependency value = new org.springframework.boot.dependency.tools.Dependency(groupId, artifactId, version, exclusions);
groupAndArtifactToDependency.put(groupId + ":" + artifactId, value);
artifactToGroupAndArtifact.put(artifactId, groupId + ":" + artifactId);
}
}
@Override
public org.springframework.boot.dependency.tools.Dependency find(String groupId,
String artifactId) {
return groupAndArtifactToDependency.get(groupId + ":" + artifactId);
}
@Override
public org.springframework.boot.dependency.tools.Dependency find(String artifactId) {
String groupAndArtifact = artifactToGroupAndArtifact.get(artifactId);
if (groupAndArtifact==null) {
return null;
}
return groupAndArtifactToDependency.get(groupAndArtifact);
}
@Override
public Iterator<org.springframework.boot.dependency.tools.Dependency> iterator() {
return groupAndArtifactToDependency.values().iterator();
}
}
}

View File

@@ -0,0 +1 @@
org.springframework.platform.cli.command.EncryptCommand

View File

@@ -0,0 +1 @@
org.springframework.platform.cli.compiler.SpringPlatformCompilerAutoConfiguration

View File

@@ -0,0 +1,15 @@
debug: true
spring:
application:
name: eureka
management:
context-path: /admin
eureka:
server:
waitTimeInMsWhenSyncEmpty: 1000
client:
serviceUrl:
defaultZone: http://localhost:8080/v2/
default.defaultZone: http://localhost:8080/v2/
registerWithEureka: false
fetchRegistry: false