23 changed files with 0 additions and 1246 deletions
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
# Spring Bootstrap Groovy |
||||
|
||||
Spring Bootstrap Groovy gives you the quickest possible getting |
||||
started experience with Spring apps, whether you are writing a web |
||||
app, a batch job or a standalone java app. |
||||
|
||||
## Building and Testing |
||||
|
||||
To avoid problems with classpaths and existing JVM-based build tools, |
||||
Spring Bootstrap Groovy uses an exec plugin call to launch `groovyc`. |
||||
You need to have a `sh` on your path along with `groovyc` (2.1.x), |
||||
`find` and `xargs`. These tools are standard on a Mac or Linux |
||||
distribution, and available using Cygwin on Windows. Once it is |
||||
built, the zip file is portable. |
||||
|
||||
Here are the steps to build and test: |
||||
|
||||
$ mvn install |
||||
|
||||
The `spring` executable is then available at |
||||
`spring-bootstrap-groovy/target/spring-<VERSION>`. There is also a jar |
||||
file with the Groovy Bootstrap components. The `spring` executable |
||||
includes jars from `SPRING_HOME` in the classpath so you can run it |
||||
while you are developing like this |
||||
|
||||
$ export SPRING_HOME=<spring-bootstrap-groovy>/target |
||||
$ <spring-bootstrap-groovy>/src/main/scripts/spring App.groovy |
||||
@ -1,180 +0,0 @@
@@ -1,180 +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.bootstrap</groupId> |
||||
<artifactId>spring-bootstrap-parent</artifactId> |
||||
<version>0.0.1-SNAPSHOT</version> |
||||
</parent> |
||||
<artifactId>spring-bootstrap-groovy</artifactId> |
||||
<packaging>jar</packaging> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.springframework.bootstrap</groupId> |
||||
<artifactId>spring-bootstrap</artifactId> |
||||
<version>${project.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.springframework</groupId> |
||||
<artifactId>spring-web</artifactId> |
||||
<version>${dependency.springframework.version}</version> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.codehaus.groovy</groupId> |
||||
<artifactId>groovy</artifactId> |
||||
<version>2.1.1</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>org.apache.ivy</groupId> |
||||
<artifactId>ivy</artifactId> |
||||
<version>2.2.0</version> |
||||
<scope>provided</scope> |
||||
</dependency> |
||||
</dependencies> |
||||
<profiles> |
||||
<profile> |
||||
<id>grapes</id> |
||||
<build> |
||||
<plugins> |
||||
<plugin> |
||||
<artifactId>maven-clean-plugin</artifactId> |
||||
<version>2.5</version> |
||||
<configuration> |
||||
<filesets> |
||||
<fileset> |
||||
<directory>${user.home}/.groovy/grapes</directory> |
||||
<includes> |
||||
<include>org.springframework*/**</include> |
||||
</includes> |
||||
<followSymlinks>false</followSymlinks> |
||||
</fileset> |
||||
</filesets> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</build> |
||||
</profile> |
||||
</profiles> |
||||
<build> |
||||
<resources> |
||||
<resource> |
||||
<directory>src/main/groovy</directory> |
||||
<filtering>true</filtering> |
||||
<targetPath>../generated-sources/groovy</targetPath> |
||||
</resource> |
||||
</resources> |
||||
<plugins> |
||||
<plugin> |
||||
<!-- Using exec plugin to compile groovy because it needs to be forked |
||||
cleanly. Only works if sh, find, xargs and groovyc are on PATH --> |
||||
<groupId>org.codehaus.mojo</groupId> |
||||
<artifactId>exec-maven-plugin</artifactId> |
||||
<version>1.2.1</version> |
||||
<executions> |
||||
<execution> |
||||
<id>compile-plugin</id> |
||||
<phase>compile</phase> |
||||
<goals> |
||||
<goal>exec</goal> |
||||
</goals> |
||||
<configuration> |
||||
<executable>sh</executable> |
||||
<arguments> |
||||
<argument>-c</argument> |
||||
<argument>find target/generated-sources/groovy -name *.groovy | |
||||
xargs groovyc -d target/classes</argument> |
||||
</arguments> |
||||
</configuration> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<artifactId>maven-assembly-plugin</artifactId> |
||||
<inherited>false</inherited> |
||||
<configuration> |
||||
<descriptors> |
||||
<descriptor>src/main/assembly/descriptor.xml</descriptor> |
||||
</descriptors> |
||||
</configuration> |
||||
<executions> |
||||
<execution> |
||||
<id>make-distribution</id> |
||||
<phase>install</phase> |
||||
<goals> |
||||
<goal>single</goal> |
||||
</goals> |
||||
</execution> |
||||
</executions> |
||||
</plugin> |
||||
<plugin> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<configuration> |
||||
<compilerId>groovy-eclipse-compiler</compilerId> |
||||
</configuration> |
||||
<dependencies> |
||||
<dependency> |
||||
<groupId>org.codehaus.groovy</groupId> |
||||
<artifactId>groovy-eclipse-compiler</artifactId> |
||||
<version>2.7.0-01</version> |
||||
</dependency> |
||||
</dependencies> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-surefire-plugin</artifactId> |
||||
<configuration> |
||||
<includes> |
||||
<include>**/*Tests.java</include> |
||||
</includes> |
||||
<excludes> |
||||
<exclude>**/Abstract*.java</exclude> |
||||
</excludes> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
<pluginManagement> |
||||
<plugins> |
||||
<!--This plugin's configuration is used to store Eclipse m2e settings |
||||
only. It has no influence on the Maven build itself. --> |
||||
<plugin> |
||||
<groupId>org.eclipse.m2e</groupId> |
||||
<artifactId>lifecycle-mapping</artifactId> |
||||
<version>1.0.0</version> |
||||
<configuration> |
||||
<lifecycleMappingMetadata> |
||||
<pluginExecutions> |
||||
<pluginExecution> |
||||
<pluginExecutionFilter> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-compiler-plugin</artifactId> |
||||
<versionRange>[3.0,)</versionRange> |
||||
<goals> |
||||
<goal>testCompile</goal> |
||||
<goal>compile</goal> |
||||
</goals> |
||||
</pluginExecutionFilter> |
||||
<action> |
||||
<ignore></ignore> |
||||
</action> |
||||
</pluginExecution> |
||||
</pluginExecutions> |
||||
</lifecycleMappingMetadata> |
||||
</configuration> |
||||
</plugin> |
||||
<plugin> |
||||
<groupId>org.apache.maven.plugins</groupId> |
||||
<artifactId>maven-resources-plugin</artifactId> |
||||
<version>2.6</version> |
||||
<configuration> |
||||
<delimiters> |
||||
<delimiter>@@</delimiter> |
||||
</delimiters> |
||||
<useDefaultDelimiters>false</useDefaultDelimiters> |
||||
</configuration> |
||||
</plugin> |
||||
</plugins> |
||||
</pluginManagement> |
||||
</build> |
||||
</project> |
||||
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
<assembly> |
||||
<id>dist</id> |
||||
<formats> |
||||
<format>zip</format> |
||||
<format>dir</format> |
||||
</formats> |
||||
<baseDirectory>spring-${project.version}</baseDirectory> |
||||
<includeBaseDirectory>true</includeBaseDirectory> |
||||
<fileSets> |
||||
<fileSet> |
||||
<directory>src/main/scripts</directory> |
||||
<outputDirectory>bin</outputDirectory> |
||||
<useDefaultExcludes>true</useDefaultExcludes> |
||||
</fileSet> |
||||
<fileSet> |
||||
<directory>src/main/resources</directory> |
||||
<outputDirectory>bin</outputDirectory> |
||||
<useDefaultExcludes>true</useDefaultExcludes> |
||||
<filtered>true</filtered> |
||||
</fileSet> |
||||
</fileSets> |
||||
<dependencySets> |
||||
<dependencySet> |
||||
<includes> |
||||
<include>org.springframework.bootstrap:spring-bootstrap-groovy:jar:*</include> |
||||
</includes> |
||||
<outputDirectory>lib</outputDirectory> |
||||
</dependencySet> |
||||
</dependencySets> |
||||
</assembly> |
||||
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
@GrabResolver(name='spring-milestone', root='http://repo.springframework.org/milestone') |
||||
@GrabResolver(name='spring-snapshot', root='http://repo.springframework.org/snapshot') |
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework.bootstrap:spring-bootstrap:@@version@@") |
||||
@Grab("org.springframework.batch:spring-batch-core:2.2.0.M1") |
||||
@Grab("org.springframework:spring-context:@@dependency.springframework.version@@") |
||||
class BatchGrapes { |
||||
} |
||||
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean |
||||
import org.springframework.bootstrap.CommandLineRunner |
||||
import org.springframework.batch.core.Job |
||||
import org.springframework.batch.core.converter.DefaultJobParametersConverter |
||||
import org.springframework.batch.core.converter.JobParametersConverter |
||||
import org.springframework.batch.core.launch.JobLauncher |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.beans.factory.annotation.Autowired |
||||
import org.springframework.context.annotation.Bean |
||||
import org.springframework.util.StringUtils |
||||
import groovy.util.logging.Log |
||||
|
||||
@Configuration |
||||
@ConditionalOnMissingBean(CommandLineRunner) |
||||
@Log |
||||
class BatchCommand { |
||||
|
||||
@Autowired(required=false) |
||||
private JobParametersConverter converter = new DefaultJobParametersConverter() |
||||
|
||||
@Autowired |
||||
private JobLauncher jobLauncher |
||||
|
||||
@Autowired |
||||
private Job job |
||||
|
||||
@Bean |
||||
CommandLineRunner batchCommandLineRunner() { |
||||
return new CommandLineRunner() { |
||||
void run(String... args) { |
||||
log.info("Running default command line with: ${args}") |
||||
launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")) |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected void launchJobFromProperties(Properties properties) { |
||||
jobLauncher.run(job, converter.getJobParameters(properties)) |
||||
} |
||||
|
||||
} |
||||
@ -1,40 +0,0 @@
@@ -1,40 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
@GrabResolver(name='spring-milestone', root='http://repo.springframework.org/milestone') |
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework:spring-jdbc:4.0.0.BOOTSTRAP-SNAPSHOT") |
||||
@Grab("org.springframework.batch:spring-batch-core:2.2.0.M1") |
||||
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils |
||||
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator |
||||
import javax.annotation.PostConstruct |
||||
import javax.sql.DataSource |
||||
import org.springframework.beans.factory.annotation.Autowired |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.core.env.Environment |
||||
import org.springframework.core.io.ResourceLoader |
||||
|
||||
@Configuration // TODO: make this conditional |
||||
class BatchInitializationGrapes { |
||||
|
||||
@Autowired |
||||
private DataSource dataSource |
||||
|
||||
@Autowired |
||||
private Environment environment |
||||
|
||||
@Autowired |
||||
private ResourceLoader resourceLoader |
||||
|
||||
@PostConstruct |
||||
protected void initialize() { |
||||
String platform = org.springframework.batch.support.DatabaseType.fromMetaData(dataSource).toString().toLowerCase() |
||||
if (platform=="hsql") { |
||||
platform = "hsqldb" |
||||
} |
||||
ResourceDatabasePopulator populator = new ResourceDatabasePopulator() |
||||
populator.addScript(resourceLoader.getResource("org/springframework/batch/core/schema-${platform}.sql")) |
||||
populator.setContinueOnError(true) |
||||
DatabasePopulatorUtils.execute(populator, dataSource) |
||||
} |
||||
|
||||
} |
||||
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
// Spring stuff needs to be on the system classloader apparently (when using @Configuration) |
||||
@GrabResolver(name='spring-snapshot', root='http://repo.springframework.org/snapshot') |
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework:spring-context:@@dependency.springframework.version@@") |
||||
@Grab("org.springframework.bootstrap:spring-bootstrap:@@version@@") |
||||
@GrabExclude("commons-logging:commons-logging") |
||||
@Grab("org.slf4j:jcl-over-slf4j:1.6.1") |
||||
@Grab("org.slf4j:slf4j-jdk14:1.6.1") |
||||
class BootstrapGrapes { |
||||
} |
||||
|
||||
import org.springframework.bootstrap.context.annotation.EnableAutoConfiguration |
||||
import org.springframework.context.annotation.Configuration |
||||
|
||||
@Configuration |
||||
// @EnableAutoConfiguration |
||||
class BootstrapAutoConfiguration { |
||||
} |
||||
@ -1,92 +0,0 @@
@@ -1,92 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
import org.springframework.core.type.StandardAnnotationMetadata |
||||
import org.springframework.util.ClassUtils |
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory |
||||
import groovy.util.logging.Log |
||||
|
||||
@GrabResolver(name='spring-snapshot', root='http://repo.springframework.org/snapshot') |
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework:spring-core:4.0.0.BOOTSTRAP-SNAPSHOT") |
||||
@GrabExclude("commons-logging:commons-logging") |
||||
@Grab("org.slf4j:jcl-over-slf4j:1.6.1") |
||||
@Grab("org.slf4j:slf4j-jdk14:1.6.1") |
||||
@Log |
||||
class Dependencies { |
||||
|
||||
static List<String> defaults() { |
||||
return ["org.springframework.bootstrap.grapes.BootstrapGrapes"] |
||||
} |
||||
|
||||
static List<String> dependencies(Collection<String> configs) { |
||||
|
||||
def result = [] |
||||
if (isWeb(configs)) { |
||||
log.info("Adding web dependencies.") |
||||
result.addAll(web()) |
||||
} |
||||
|
||||
if (isBatch(configs)) { |
||||
log.info("Adding batch dependencies.") |
||||
result.addAll(batch()) |
||||
result << "org.springframework.bootstrap.grapes.BatchCommand" |
||||
result << "org.springframework.bootstrap.grapes.BatchInitializationGrapes" |
||||
} |
||||
|
||||
if (isHadoop(configs)) { |
||||
log.info("Adding info dependencies.") |
||||
result.addAll(hadoop()) |
||||
result << "org.springframework.bootstrap.grapes.HadoopContext" |
||||
} |
||||
|
||||
return result |
||||
|
||||
} |
||||
|
||||
static String[] web() { |
||||
def result = [] |
||||
result << "org.springframework.bootstrap.grapes.WebGrapes" |
||||
if (!isEmbeddedServerAvailable()) { result << "org.springframework.bootstrap.grapes.TomcatGrapes" } |
||||
return result |
||||
} |
||||
|
||||
static String[] batch() { |
||||
def result = [] |
||||
result << "org.springframework.bootstrap.grapes.BatchGrapes" |
||||
return result |
||||
} |
||||
|
||||
static String[] hadoop() { |
||||
def result = [] |
||||
result << "org.springframework.bootstrap.grapes.HadoopGrapes" |
||||
return result |
||||
} |
||||
|
||||
static boolean isWeb(Collection<String> configs) { |
||||
SimpleMetadataReaderFactory factory = new SimpleMetadataReaderFactory() |
||||
return configs.any { config -> |
||||
def meta = factory.getMetadataReader(config).getAnnotationMetadata() |
||||
meta.hasAnnotation("org.springframework.stereotype.Controller") || meta.hasAnnotation("org.springframework.web.servlet.config.annotation.EnableWebMvc") |
||||
} |
||||
} |
||||
|
||||
static boolean isHadoop(Collection<String> configs) { |
||||
SimpleMetadataReaderFactory factory = new SimpleMetadataReaderFactory() |
||||
return configs.any { config -> |
||||
config.contains("Hadoop") |
||||
} |
||||
} |
||||
|
||||
static boolean isBatch(Collection<String> configs) { |
||||
SimpleMetadataReaderFactory factory = new SimpleMetadataReaderFactory() |
||||
return configs.any { config -> |
||||
def meta = factory.getMetadataReader(config).getAnnotationMetadata() |
||||
meta.hasAnnotation("org.springframework.batch.core.configuration.annotation.EnableBatchProcessing") |
||||
} |
||||
} |
||||
|
||||
static boolean isEmbeddedServerAvailable() { |
||||
return ClassUtils.isPresent("org.apache.catalina.startup.Tomcat") || ClassUtils.isPresent("org.mortbay.jetty.Server") |
||||
} |
||||
|
||||
} |
||||
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework.data:spring-data-hadoop:1.0.0.RELEASE") |
||||
@Grab("org.springframework.bootstrap:spring-bootstrap:@@version@@") |
||||
@Grab("org.springframework:spring-context:4.0.0.BOOTSTRAP-SNAPSHOT") |
||||
@Grab("org.apache.hadoop:hadoop-examples:1.0.4") |
||||
@GrabExclude("org.mortbay.jetty:sevlet-api-2.5") |
||||
@GrabExclude("org.mortbay.jetty:jetty") |
||||
@GrabExclude("org.mortbay.jetty:jetty-util") |
||||
@GrabExclude("org.mortbay.jetty:jsp-2.1") |
||||
@GrabExclude("org.mortbay.jetty:jsp-api-2.1") |
||||
@GrabExclude("tomcat:jasper-runtime") |
||||
@GrabExclude("tomcat:jasper-compiler") |
||||
class HadoopGrapes { |
||||
} |
||||
|
||||
import org.springframework.bootstrap.context.annotation.ConditionalOnMissingBean |
||||
import org.springframework.context.annotation.Configuration |
||||
import org.springframework.context.annotation.ImportResource |
||||
|
||||
@Configuration |
||||
@ConditionalOnMissingBean(org.apache.hadoop.conf.Configuration) |
||||
@ImportResource("hadoop-context.xml") |
||||
class HadoopContext { |
||||
} |
||||
@ -1,9 +0,0 @@
@@ -1,9 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
@GrabConfig(systemClassLoader=true) |
||||
// Grab some Tomcat dependencies |
||||
@Grab("org.apache.tomcat.embed:tomcat-embed-core:7.0.32") |
||||
// JULI logging has sensible defaults in JAVA_HOME, so no need for user to create it |
||||
@Grab("org.apache.tomcat.embed:tomcat-embed-logging-juli:7.0.32") |
||||
class TomcatGrapes { |
||||
} |
||||
@ -1,5 +0,0 @@
@@ -1,5 +0,0 @@
|
||||
package org.springframework.bootstrap.grapes |
||||
|
||||
@Grab("org.springframework:spring-webmvc:4.0.0.BOOTSTRAP-SNAPSHOT") |
||||
class WebGrapes { |
||||
} |
||||
@ -1,20 +0,0 @@
@@ -1,20 +0,0 @@
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" |
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||
xmlns:c="http://www.springframework.org/schema/c" |
||||
xmlns:p="http://www.springframework.org/schema/p" |
||||
xmlns:context="http://www.springframework.org/schema/context" |
||||
xmlns:hdp="http://www.springframework.org/schema/hadoop" |
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd |
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd |
||||
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd"> |
||||
|
||||
|
||||
<hdp:resource-loader id="hadoopResourceLoader" /> |
||||
|
||||
<hdp:configuration> |
||||
fs.default.name=${hd.fs:hdfs://localhost:9000} |
||||
</hdp:configuration> |
||||
|
||||
<bean id="defaultResourceLoaders" class="org.springframework.data.hadoop.fs.CustomResourceLoaderRegistrar" p:loader-ref="hadoopResourceLoader" /> |
||||
|
||||
</beans> |
||||
@ -1,100 +0,0 @@
@@ -1,100 +0,0 @@
|
||||
import org.codehaus.groovy.control.customizers.ASTTransformationCustomizer |
||||
import org.codehaus.groovy.ast.ClassHelper |
||||
import groovy.util.logging.Log |
||||
|
||||
def bootstrap = 'org.springframework.bootstrap.grapes.BootstrapGrapes' as Class |
||||
|
||||
void addImport(module, path) { |
||||
def name = path.lastIndexOf('.').with {it != -1 ? path[it+1..<path.length()] : path} |
||||
if (name=="*") { |
||||
// Doesn't work? |
||||
name = path.lastIndexOf('.').with {path[0..<it] } |
||||
module.addStarImport(name, []) |
||||
} else { |
||||
module.addImport(name, ClassHelper.make(path), []) |
||||
} |
||||
} |
||||
|
||||
withConfig(configuration) { |
||||
|
||||
ast(Log) |
||||
|
||||
imports { |
||||
normal 'javax.sql.DataSource' |
||||
normal 'org.springframework.stereotype.Component' |
||||
normal 'org.springframework.stereotype.Controller' |
||||
normal 'org.springframework.stereotype.Repository' |
||||
normal 'org.springframework.stereotype.Service' |
||||
normal 'org.springframework.beans.factory.annotation.Autowired' |
||||
normal 'org.springframework.beans.factory.annotation.Value' |
||||
normal 'org.springframework.context.annotation.Import' |
||||
normal 'org.springframework.context.annotation.ImportResource' |
||||
normal 'org.springframework.context.annotation.Profile' |
||||
normal 'org.springframework.context.annotation.Scope' |
||||
normal 'org.springframework.context.annotation.Configuration' |
||||
normal 'org.springframework.context.annotation.Bean' |
||||
normal 'org.springframework.bootstrap.CommandLineRunner' |
||||
} |
||||
|
||||
def dependencySource = "org.springframework.bootstrap.grapes.Dependencies" as Class // TODO: maybe strategise this |
||||
|
||||
inline(phase:'CONVERSION') { source, context, classNode -> |
||||
|
||||
def module = source.getAST() |
||||
|
||||
if (classNode.name.contains("Hadoop")) { |
||||
def hadoop = dependencySource.hadoop() as Class[] |
||||
['org.springframework.data.hadoop.mapreduce.JobRunner', |
||||
'org.springframework.data.hadoop.mapreduce.JobFactoryBean' |
||||
].each { path -> addImport(module, path) } |
||||
module.addImport("HadoopConfiguration", ClassHelper.make("org.apache.hadoop.conf.Configuration"), []) |
||||
} |
||||
|
||||
classNode.annotations.each { |
||||
|
||||
def name = it.classNode.name |
||||
if (name=='Controller' || name=='EnableWebMvc') { |
||||
def web = dependencySource.web() as Class[] |
||||
['org.springframework.web.bind.annotation.RequestBody', |
||||
'org.springframework.web.bind.annotation.RequestParam', |
||||
'org.springframework.web.bind.annotation.PathVariable', |
||||
'org.springframework.web.bind.annotation.RequestHeader', |
||||
'org.springframework.web.bind.annotation.RequestMethod', |
||||
'org.springframework.web.bind.annotation.RequestBody', |
||||
'org.springframework.web.bind.annotation.ResponseBody', |
||||
'org.springframework.web.bind.annotation.ResponseStatus', |
||||
'org.springframework.web.bind.annotation.RequestMapping', |
||||
'org.springframework.web.bind.annotation.ExceptionHandler', |
||||
'org.springframework.web.bind.annotation.ModelAttribute', |
||||
'org.springframework.web.bind.annotation.CookieValue', |
||||
'org.springframework.web.servlet.config.annotation.EnableWebMvc', |
||||
'org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry', |
||||
'org.springframework.web.servlet.config.annotation.ViewControllerRegistry', |
||||
'org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter'].each { path -> addImport(module, path) } |
||||
} |
||||
|
||||
if (name=='EnableBatchProcessing') { |
||||
def batch = dependencySource.batch() as Class[] |
||||
['org.springframework.batch.repeat.RepeatStatus', |
||||
'org.springframework.batch.core.scope.context.ChunkContext', |
||||
'org.springframework.batch.core.step.tasklet.Tasklet', |
||||
'org.springframework.batch.core.configuration.annotation.StepScope', |
||||
'org.springframework.batch.core.configuration.annotation.JobBuilderFactory', |
||||
'org.springframework.batch.core.configuration.annotation.StepBuilderFactory', |
||||
'org.springframework.batch.core.configuration.annotation.EnableBatchProcessing', |
||||
'org.springframework.batch.core.Step', |
||||
'org.springframework.batch.core.StepExecution', |
||||
'org.springframework.batch.core.StepContribution', |
||||
'org.springframework.batch.core.Job', |
||||
'org.springframework.batch.core.JobExecution', |
||||
'org.springframework.batch.core.JobParameter', |
||||
'org.springframework.batch.core.JobParameters', |
||||
'org.springframework.batch.core.launch.JobLauncher', |
||||
'org.springframework.batch.core.converter.DefaultJobParametersConverter'].each { path -> addImport(module, path) } |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -1,33 +0,0 @@
@@ -1,33 +0,0 @@
|
||||
############################################################################## |
||||
## ## |
||||
## Groovy Classloading Configuration ## |
||||
## ## |
||||
############################################################################## |
||||
|
||||
## |
||||
## $Revision$ $Date$ |
||||
## |
||||
## Note: do not add classes from java.lang here. No rt.jar and on some |
||||
## platforms no tools.jar |
||||
## |
||||
## See http://groovy.codehaus.org/api/org/codehaus/groovy/tools/LoaderConfiguration.html |
||||
## for the file format |
||||
|
||||
# load required libraries |
||||
load !{groovy.home}/lib/a*.jar |
||||
load !{groovy.home}/lib/b*.jar |
||||
load !{groovy.home}/lib/c*.jar |
||||
load !{groovy.home}/lib/g*.jar |
||||
load !{groovy.home}/lib/h*.jar |
||||
load !{groovy.home}/lib/i*.jar |
||||
load !{groovy.home}/lib/j*.jar |
||||
load !{groovy.home}/lib/q*.jar |
||||
load !{groovy.home}/lib/t*.jar |
||||
load !{groovy.home}/lib/x*.jar |
||||
|
||||
# load user specific libraries |
||||
load !{user.home}/.groovy/lib/*.jar |
||||
|
||||
# tools.jar for ant tasks |
||||
load ${tools.jar} |
||||
|
||||
@ -1,163 +0,0 @@
@@ -1,163 +0,0 @@
|
||||
#!/bin/bash |
||||
|
||||
# OS specific support (must be 'true' or 'false'). |
||||
cygwin=false; |
||||
darwin=false; |
||||
case "`uname`" in |
||||
CYGWIN*) |
||||
cygwin=true |
||||
;; |
||||
|
||||
Darwin*) |
||||
darwin=true |
||||
;; |
||||
esac |
||||
|
||||
if [ "$SPRING_HOME" == "" ]; then |
||||
SPRING_HOME=`cd "$(dirname $0)"/.. && pwd` |
||||
fi |
||||
SPRING_BIN=$(dirname $0) |
||||
|
||||
export GROOVY_CONF="${SPRING_BIN}"/groovy.conf |
||||
SPRING_HANDLER=auto |
||||
|
||||
TARGETDIR=target/classes |
||||
if [ -f build.gradle ]; then |
||||
TARGETDIR=build/classes/main |
||||
fi |
||||
mkdir -p "${TARGETDIR%/}" |
||||
|
||||
function find_classfile { |
||||
classname="$( echo ${1%%.groovy} | sed -e 's,.*/,,')" |
||||
package="$( grep ^package ${1} | sed -e 's,package\s,,g' -e 's,;,,g' -e 's,\.,/,g')" |
||||
if [ "${package}" != "" ]; then package="${package}/"; fi |
||||
for f in $( find "${TARGETDIR}" -name "${classname}.class" ); do |
||||
if [ "${f}" == "${TARGETDIR}/${package}${classname}.class" ]; then |
||||
echo $f; return 0 |
||||
fi |
||||
done |
||||
} |
||||
|
||||
function is_compile_needed { |
||||
config=$1 |
||||
STATOPTS="-c %X" |
||||
if $darwin; then STATOPTS="-f %Dm"; fi |
||||
# Compile .groovy files if necessary |
||||
if [ ! -f ${config} ]; then |
||||
echo "File ${config} does not exist. Did you point at the wrong file?" |
||||
exit 3 |
||||
else |
||||
classfile=$( find_classfile ${config} ) |
||||
if [ ! -f "${classfile}" -o $(stat "${STATOPTS}" ${config}) -gt $(stat "${STATOPTS}" ${classfile} 2>/dev/null || echo 0) ]; then |
||||
return 0 |
||||
fi |
||||
fi |
||||
return 1 |
||||
} |
||||
|
||||
function is_option { |
||||
echo "$1" | grep -q "^--.*" |
||||
} |
||||
|
||||
function is_groovy { |
||||
[ "${1%%.groovy}" != "${1}" ] |
||||
} |
||||
|
||||
function convert_config_to_class { |
||||
classfile=$( find_classfile ${config} ) |
||||
if [ -z "${classfile}" ]; then |
||||
echo "No class found for ${config}. Compiler failed or class not defined?" |
||||
exit 1 |
||||
fi |
||||
config="${classfile#${TARGETDIR}/}" |
||||
while [ "${config%/*}" != "${config}" ]; do |
||||
config="${config%/*}"."${config##*/}" |
||||
done |
||||
} |
||||
|
||||
config=$1; shift |
||||
configs=() |
||||
compilables=() |
||||
while [ "$config" != "" ]; do |
||||
if is_groovy "$config"; then |
||||
if is_compile_needed "${config}"; then |
||||
compilables[${#compilables[@]}]="${config}" |
||||
fi |
||||
configs[${#configs[@]}]="${config}" |
||||
elif is_option "${config}"; then |
||||
case "${config%=*}" in |
||||
"--handler") SPRING_HANDLER="${config#*=}";; |
||||
esac |
||||
else |
||||
args[${#args[@]}]="${config}" |
||||
fi |
||||
config=$1; shift |
||||
done |
||||
|
||||
CLASSPATH="${SPRING_BIN}":"${TARGETDIR}" |
||||
|
||||
for f in "${SPRING_HOME}"/lib/*.jar; do |
||||
CLASSPATH="${CLASSPATH}":$f |
||||
done |
||||
|
||||
for f in "${SPRING_HOME}"/*.jar; do |
||||
CLASSPATH="${CLASSPATH}":$f |
||||
done |
||||
|
||||
if $cygwin; then |
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` |
||||
fi |
||||
|
||||
if [ "${#compilables[@]}" -gt 0 ]; then |
||||
groovyc -cp "${CLASSPATH}" --configscript "$SPRING_BIN"/customizer.groovy -d "${TARGETDIR}" "${compilables[@]}" |
||||
fi |
||||
|
||||
config_classes=("org.springframework.bootstrap.grapes.BootstrapAutoConfiguration.class") |
||||
for config in "${configs[@]}"; do |
||||
convert_config_to_class |
||||
config_classes[${#config_classes[@]}]="${config}" |
||||
done |
||||
|
||||
if [ "${#config_classes[@]}" == "0" ]; then |
||||
echo "No files to run." |
||||
exit 2 |
||||
fi |
||||
|
||||
exec groovy -cp "${CLASSPATH}" -Dspring.home="${SPRING_HOME}" --configscript "$SPRING_BIN"/customizer.groovy "$SPRING_BIN"/spring-"${SPRING_HANDLER}".groovy "${config_classes[@]}" "${args[@]}" |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,24 +0,0 @@
@@ -1,24 +0,0 @@
|
||||
// Get the args and turn them into classes |
||||
def configs = [] |
||||
def parameters = [] |
||||
args.each { arg -> |
||||
if (arg.endsWith(".class")) { |
||||
configs << arg.replaceAll(".class", "") |
||||
} else { |
||||
parameters << arg |
||||
} |
||||
} |
||||
|
||||
// Dynamically grab some dependencies |
||||
def dependencySource = "org.springframework.bootstrap.grapes.Dependencies" as Class // TODO: maybe strategise this |
||||
def dependencies = [*dependencySource.defaults(), *dependencySource.dependencies(configs)] |
||||
configs = dependencies + configs |
||||
|
||||
// Do this before any Spring auto stuff is used in case it enhances the classpath |
||||
configs = configs as Class[] |
||||
parameters = parameters as String[] |
||||
|
||||
// Now run the application |
||||
def applicationClass = "org.springframework.bootstrap.SpringApplication" as Class |
||||
|
||||
applicationClass.run(configs, parameters) |
||||
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
// Spring stuff needs to be on the system classloader apparently (when using @Configuration) |
||||
@GrabResolver(name='spring-milestone', root='http://maven.springframework.org/milestone') |
||||
@GrabConfig(systemClassLoader=true) |
||||
@Grab("org.springframework:spring-context:4.0.0.BOOTSTRAP-SNAPSHOT") |
||||
@GrabExclude("commons-logging:commons-logging") |
||||
@Grab("org.slf4j:jcl-over-slf4j:1.6.1") |
||||
@Grab("org.slf4j:slf4j-jdk14:1.6.1") |
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext |
||||
|
||||
// Now create a Spring context |
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext() |
||||
// Get the args and turn them into classes |
||||
def configs = [] |
||||
def parameters = [] |
||||
boolean endconfigs = false |
||||
args.each { arg -> |
||||
if (arg.endsWith(".class")) { |
||||
configs += arg.replaceAll(".class", "") |
||||
} else { |
||||
parameters += arg |
||||
} |
||||
} |
||||
configs = configs as Class[] |
||||
parameters = parameters as String[] |
||||
// Register the config classes, can be @Configuration or @Component etc. |
||||
ctx.register(configs) |
||||
ctx.refresh() |
||||
@ -1,8 +0,0 @@
@@ -1,8 +0,0 @@
|
||||
@Controller |
||||
class App { |
||||
@RequestMapping("/") |
||||
@ResponseBody |
||||
String home() { |
||||
return "Hello World!" |
||||
} |
||||
} |
||||
@ -1,4 +0,0 @@
@@ -1,4 +0,0 @@
|
||||
@Configuration |
||||
class Empty { |
||||
|
||||
} |
||||
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
@Grab("org.hsqldb:hsqldb-j5:2.0.0") |
||||
@EnableBatchProcessing |
||||
class JobConfig { |
||||
|
||||
@Autowired |
||||
private JobBuilderFactory jobs |
||||
|
||||
@Autowired |
||||
private StepBuilderFactory steps |
||||
|
||||
@Bean |
||||
protected Tasklet tasklet() { |
||||
return new Tasklet() { |
||||
RepeatStatus execute(StepContribution contribution, ChunkContext context) { |
||||
return RepeatStatus.FINISHED |
||||
} |
||||
} |
||||
} |
||||
|
||||
@Bean |
||||
Job job() throws Exception { |
||||
return jobs.get("job").start(step1()).build() |
||||
} |
||||
|
||||
@Bean |
||||
protected Step step1() throws Exception { |
||||
return steps.get("step1").tasklet(tasklet()).build() |
||||
} |
||||
|
||||
} |
||||
@ -1,18 +0,0 @@
@@ -1,18 +0,0 @@
|
||||
import java.io.File; |
||||
|
||||
import org.springframework.bootstrap.CommandLineRunner; |
||||
|
||||
@Component |
||||
class Signal implements CommandLineRunner { |
||||
|
||||
private File messages = new File("target/messages") |
||||
|
||||
boolean ready = false |
||||
|
||||
@Override |
||||
void run(String... args) { |
||||
messages.mkdirs() |
||||
new File(messages, "ready").write("Ready!") |
||||
ready = true |
||||
} |
||||
} |
||||
@ -1,174 +0,0 @@
@@ -1,174 +0,0 @@
|
||||
/* |
||||
* Cloud Foundry 2012.02.03 Beta |
||||
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. |
||||
* |
||||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). |
||||
* You may not use this product except in compliance with the License. |
||||
* |
||||
* This product includes a number of subcomponents with |
||||
* separate copyright notices and license terms. Your use of these |
||||
* subcomponents is subject to the terms and conditions of the |
||||
* subcomponent's license, as noted in the LICENSE file. |
||||
*/ |
||||
|
||||
package org.springframework.bootstrap.groovy |
||||
|
||||
/** |
||||
* <p>As part of the gvm test suite we need to launch a bash shell and execute |
||||
* multiple commands in it. This is tricky to do using Java's support for |
||||
* working with external processes as the API can't tell you when a command |
||||
* has finished executing.</p> |
||||
* <p>This class provides some hacks that allow you to serially execute commands |
||||
* in an external bash process in a fairly reliable manner and to retrieve the |
||||
* output of those commands.</p> |
||||
*/ |
||||
class BashEnv { |
||||
|
||||
static final PROMPT = "" |
||||
static final EXIT_CODE_CMD = 'echo "Exit code is: $?"' |
||||
static final EXIT_CODE_PATTERN = ~/Exit code is: (\d+)\s*${PROMPT}?$/ |
||||
|
||||
private final Object outputLock = new Object() |
||||
|
||||
def exitCode |
||||
def process |
||||
def processOutput = new StringBuilder() |
||||
def commandOutput |
||||
|
||||
// Command timeout in milliseconds |
||||
def timeout = 5000 |
||||
def workDir |
||||
def env |
||||
|
||||
BashEnv(workDir, Map env) { |
||||
this.workDir = workDir as File |
||||
|
||||
env = env + [PS1: PROMPT] |
||||
this.env = env.collect { k, v -> k + '=' + v } |
||||
} |
||||
|
||||
/** |
||||
* Starts the external bash process. |
||||
*/ |
||||
void start() { |
||||
process = ["bash", "--noprofile", "--norc", "-i"].execute(env, workDir) |
||||
|
||||
consumeProcessStream(process.inputStream) |
||||
consumeProcessStream(process.errorStream) |
||||
} |
||||
|
||||
/** |
||||
* Stops the external bash process and waits for it to finish. |
||||
*/ |
||||
void stop() { |
||||
execute("exit") |
||||
process.waitFor() |
||||
} |
||||
|
||||
/** |
||||
* Sends a command line to the external bash process and returns once the |
||||
* command has finished executing. If the command is interactive and requires |
||||
* input during it's execution (for example a y/n answer to a question) you |
||||
* can provide that input as a list of strings. |
||||
*/ |
||||
void execute(String cmdline, List inputs = []) { |
||||
resetOutput() |
||||
|
||||
if (cmdline != "exit") { |
||||
exitCode = null |
||||
} |
||||
|
||||
process.outputStream << cmdline << "\n" |
||||
process.outputStream.flush() |
||||
|
||||
if (cmdline != "exit") { |
||||
for (input in inputs) { |
||||
process.outputStream << input << "\n" |
||||
} |
||||
process.outputStream << EXIT_CODE_CMD << "\n" |
||||
process.outputStream.flush() |
||||
} |
||||
|
||||
def start = System.currentTimeMillis() |
||||
while (cmdline != "exit") { |
||||
Thread.sleep 100 |
||||
|
||||
synchronized (outputLock) { |
||||
// Remove all the extraneous text that's not related to the |
||||
// command's output. This includes the command string itself, |
||||
// the 'echo' command to display the command's exit code, and |
||||
// the exit code line. |
||||
removeFromOutput(cmdline + "\n") |
||||
removeFromOutput(PROMPT + EXIT_CODE_CMD + "\n") |
||||
|
||||
def str = processOutput.toString() |
||||
def m = EXIT_CODE_PATTERN.matcher(str) |
||||
commandOutput = str |
||||
if (m) { |
||||
exitCode = m[0][1] |
||||
|
||||
// Remove this exit code line from the output. |
||||
commandOutput = m.replaceAll('') |
||||
break |
||||
} |
||||
|
||||
// If the command times out, we should break out of the loop and |
||||
// display whatever output has already been produced. |
||||
if (System.currentTimeMillis() - start > timeout) { |
||||
commandOutput = "ALERT! Command timed out. Last output was:\n\n${processOutput}" |
||||
break |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Returns the exit code of the last command that was executed. |
||||
*/ |
||||
int getStatus() { |
||||
if (!exitCode) throw new IllegalStateException("Did you run execute() before getting the status?") |
||||
return exitCode.toInteger() |
||||
} |
||||
|
||||
/** |
||||
* Returns the text output (both stdout and stderr) of the last command |
||||
* that was executed. |
||||
*/ |
||||
String getOutput() { |
||||
return commandOutput |
||||
} |
||||
|
||||
/** |
||||
* Clears the saved command output. |
||||
*/ |
||||
void resetOutput() { |
||||
synchronized (outputLock) { |
||||
processOutput = new StringBuilder() |
||||
} |
||||
} |
||||
|
||||
private void consumeProcessStream(final InputStream stream) { |
||||
char[] buffer = new char[256] |
||||
Thread.start { |
||||
def reader = new InputStreamReader(stream) |
||||
def charsRead = 0 |
||||
while (charsRead != -1) { |
||||
charsRead = reader.read(buffer, 0, 256) |
||||
if (charsRead > 0) { |
||||
synchronized (outputLock) { |
||||
processOutput.append(buffer, 0, charsRead) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void removeFromOutput(String line) { |
||||
synchronized (outputLock) { |
||||
def pos = processOutput.indexOf(line) |
||||
if (pos != -1) { |
||||
processOutput.delete(pos, pos + line.size() - 1) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,70 +0,0 @@
@@ -1,70 +0,0 @@
|
||||
/* |
||||
* Cloud Foundry 2012.02.03 Beta |
||||
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. |
||||
* |
||||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). |
||||
* You may not use this product except in compliance with the License. |
||||
* |
||||
* This product includes a number of subcomponents with |
||||
* separate copyright notices and license terms. Your use of these |
||||
* subcomponents is subject to the terms and conditions of the |
||||
* subcomponent's license, as noted in the LICENSE file. |
||||
*/ |
||||
|
||||
package org.springframework.bootstrap.groovy; |
||||
|
||||
import static org.junit.Assert.* |
||||
|
||||
import java.util.concurrent.ExecutorService |
||||
import java.util.concurrent.Executors |
||||
|
||||
import org.junit.After |
||||
import org.junit.Before |
||||
import org.junit.Test |
||||
|
||||
/** |
||||
* @author Dave Syer |
||||
* |
||||
*/ |
||||
class ScriptTests { |
||||
|
||||
private BashEnv bash |
||||
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(2) |
||||
|
||||
@Before |
||||
void init() { |
||||
bash = new BashEnv(".", [SPRING_HOME: "target"]) |
||||
bash.start() |
||||
bash.execute("export GVM_DIR=~/.gvm") |
||||
bash.execute("source ~/.gvm/bin/gvm-init.sh") |
||||
assertEquals("You need to install gvm to run these tests", 0, bash.status) |
||||
bash.execute("gvm use groovy 2.1.0") |
||||
assertEquals("You need to do this before running the tests: > gvm install groovy 2.1.0", 0, bash.status) |
||||
} |
||||
|
||||
@After |
||||
void clean() { |
||||
bash?.stop() |
||||
} |
||||
|
||||
@Test |
||||
void testVanillaApplicationContext() { |
||||
execute(bash, "src/main/scripts/spring src/test/apps/Empty.groovy") |
||||
assertEquals(0, bash.status) |
||||
} |
||||
|
||||
@Test |
||||
void testBatchApplicationContext() { |
||||
execute(bash, "src/main/scripts/spring src/test/apps/JobConfig.groovy foo=bar") |
||||
assertEquals(0, bash.status) |
||||
assertTrue(bash.output.contains("[SimpleJob: [name=job]] completed with the following parameters: [{foo=bar}]")) |
||||
} |
||||
|
||||
private void execute(BashEnv bash, String cmdline) { |
||||
bash.execute(cmdline) |
||||
if (bash.exitCode && bash.status!=0) { |
||||
println "Unsuccessful execution (${cmdline}). Output: \n${bash.output}" |
||||
} |
||||
} |
||||
} |
||||
@ -1,94 +0,0 @@
@@ -1,94 +0,0 @@
|
||||
/* |
||||
* Cloud Foundry 2012.02.03 Beta |
||||
* Copyright (c) [2009-2012] VMware, Inc. All Rights Reserved. |
||||
* |
||||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). |
||||
* You may not use this product except in compliance with the License. |
||||
* |
||||
* This product includes a number of subcomponents with |
||||
* separate copyright notices and license terms. Your use of these |
||||
* subcomponents is subject to the terms and conditions of the |
||||
* subcomponent's license, as noted in the LICENSE file. |
||||
*/ |
||||
|
||||
package org.springframework.bootstrap.groovy; |
||||
|
||||
import static org.junit.Assert.* |
||||
|
||||
import java.util.concurrent.ExecutorService |
||||
import java.util.concurrent.Executors |
||||
|
||||
import org.junit.After |
||||
import org.junit.Before |
||||
import org.junit.Ignore |
||||
import org.junit.Test |
||||
import org.springframework.web.client.RestTemplate |
||||
|
||||
/** |
||||
* @author Dave Syer |
||||
* |
||||
*/ |
||||
class WebScriptTests { |
||||
|
||||
private BashEnv bash |
||||
|
||||
private ExecutorService executor = Executors.newFixedThreadPool(2) |
||||
|
||||
private File messages = new File("target/messages") |
||||
|
||||
@Before |
||||
void init() { |
||||
assertTrue("Couldn't delete messages directory", messages.deleteDir()) |
||||
bash = new BashEnv(".", [SPRING_HOME: "target"]) |
||||
bash.start() |
||||
bash.execute("export GVM_DIR=~/.gvm") |
||||
bash.execute("source ~/.gvm/bin/gvm-init.sh") |
||||
assertEquals("You need to install gvm to run these tests", 0, bash.status) |
||||
bash.execute("gvm use groovy 2.1.0") |
||||
assertEquals("You need to do this before running the tests: > gvm install groovy 2.1.0", 0, bash.status) |
||||
} |
||||
|
||||
@After |
||||
void clean() { |
||||
killit() |
||||
bash?.stop() |
||||
} |
||||
|
||||
@Test |
||||
@Ignore |
||||
void testWebApplicationContext() { |
||||
executor.submit { |
||||
execute(bash, "src/main/scripts/spring src/test/apps/App.groovy src/test/apps/Signal.groovy") |
||||
} |
||||
File ready = new File(messages, "ready") |
||||
long timeout = 10000 |
||||
long t0 = System.currentTimeMillis() |
||||
while (!ready.exists() && System.currentTimeMillis() - t0 < timeout) { |
||||
println "Waiting for app to start" |
||||
Thread.sleep(1000) |
||||
} |
||||
if (ready.exists()) { |
||||
println ready.text |
||||
} else { |
||||
fail("Timed out waiting for app to start") |
||||
} |
||||
|
||||
// assertEquals(0, bash.status) |
||||
def response = new RestTemplate().getForEntity("http://localhost:8080", String.class) |
||||
assertEquals("Hello World!", response.body) |
||||
} |
||||
|
||||
private void killit() { |
||||
BashEnv reaper = new BashEnv(".", [SPRING_HOME: "target"]) |
||||
reaper.start() |
||||
reaper?.execute("pkill -9 -f '\\--configscript src/main/scripts/customizer.groovy'") |
||||
reaper?.stop() |
||||
} |
||||
|
||||
private void execute(BashEnv bash, String cmdline) { |
||||
bash.execute(cmdline) |
||||
if (bash.exitCode && bash.status!=0) { |
||||
println "Unsuccessful execution (${cmdline}). Output: \n${bash.output}" |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue