Merge pull request #10 from rtyler/zero-two-zero

Last round of 0.2.0 changes
This commit is contained in:
R. Tyler Croy 2015-08-14 19:08:54 -07:00
commit 343260827a
7 changed files with 93 additions and 42 deletions

View File

@ -1,3 +1,4 @@
import java.util.zip.ZipEntry
import java.util.zip.ZipFile
buildscript {
@ -18,7 +19,7 @@ buildscript {
apply plugin: 'com.github.jruby-gradle.storm'
jrubyStorm {
topology 'hello-topology.rb'
topology "${rootDir}/hello-topology.rb"
}
/*
@ -35,9 +36,8 @@ task runGradleTest {
}
/* ensure our outputs contain a valid jar file (aka Zip) */
assemble.outputs.files.files.each { File jar ->
logger.info("Looking at ${jar}")
ZipFile f = new ZipFile(jar)
if ((new ZipFile(jar)).size() <= 0) {
if (!f.entries().find { ZipEntry ze -> ze.name.matches(/hello-topology.rb/) }) {
throw new GradleException("The file ${jar} does not appear to be valid")
}
}

View File

@ -5,6 +5,7 @@ import com.github.jrubygradle.JRubyPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration
import org.gradle.api.file.CopySpec
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
@ -21,12 +22,6 @@ class JRubyStorm extends DefaultTask {
/** Dynamically created dependent task for building the topology jar */
private Task assembleTask
private static final String REDSTORM_MAIN = 'redstorm.TopologyLauncher'
private static final List<String> DEFAULT_EXCLUDES = ['*.sw*',
'*.gitkeep',
'*.md',
'META-INF/BCKEY*', ]
/** Default version of redstorm to use */
protected String customRedstormVersion
/** Default version of Storm supported included */
@ -34,7 +29,6 @@ class JRubyStorm extends DefaultTask {
/** Configuration which has all of our dependencies */
protected Configuration configuration
/** Path (absolute or relative) to the Ruby file containing the topology */
@Input
String topology
@ -69,12 +63,24 @@ class JRubyStorm extends DefaultTask {
return configuration ?: project.configurations.findByName(DEFAULT_CONFIGURATION_NAME)
}
@Input
@Optional
void into(CopySpec spec) {
assembleTask.into(spec)
}
@Input
@Optional
void from(CopySpec spec) {
assembleTask.from(spec)
}
JRubyStorm() {
super()
configuration = project.configurations.maybeCreate(DEFAULT_CONFIGURATION_NAME)
this.group JRubyPlugin.TASK_GROUP_NAME
this.runTask = JRubyStormInternal.createRunTask(this.project, this.name, this)
this.assembleTask = JRubyStormInternal.createAssembleTask(this.project, this.name)
this.runTask = JRubyStormInternal.createRunTask(this.project, this)
this.assembleTask = JRubyStormInternal.createAssembleTask(this.project, this)
project.afterEvaluate { this.updateDependencies() }
}

View File

@ -9,7 +9,7 @@ class JRubyStormExtension {
String defaultVersion = '0.9.2-incubating'
/** Default version of redstorm to use */
String defaultRedstormVersion = '0.7.1'
String defaultRedstormVersion = '0.7.2'
/** Set the Storm dependency version */
void defaultVersion(Object stormVersion) {

View File

@ -6,8 +6,11 @@ import org.gradle.api.Task
class JRubyStorm {
static Task createAssembleTask(Project project, String baseName) {
return project.task("assemble${prepareNameForSuffix(baseName)}", type: JRubyStormJar)
static Task createAssembleTask(Project project, Task parent) {
JRubyStormJar task = project.task("assemble${prepareNameForSuffix(parent.name)}",
type: JRubyStormJar)
task.parentTask = parent
return task
}
/**
@ -22,8 +25,8 @@ class JRubyStorm {
return baseName.replaceAll("(?i)jruby", 'JRuby').capitalize()
}
static Task createRunTask(Project project, String baseName, Task parent) {
JRubyStormLocal runTask = project.task("run${prepareNameForSuffix(baseName)}",
static Task createRunTask(Project project, Task parent) {
JRubyStormLocal runTask = project.task("run${prepareNameForSuffix(parent.name)}",
type: JRubyStormLocal)
runTask.parentTask = parent
return runTask

View File

@ -3,6 +3,49 @@ package com.github.jrubygradle.storm.internal
import com.github.jrubygradle.jar.JRubyJar
import groovy.transform.InheritConstructors
import com.github.jrubygradle.storm.JRubyStorm
@InheritConstructors
class JRubyStormJar extends JRubyJar {
static final String REDSTORM_MAIN = 'redstorm.TopologyLauncher'
private static final List<String> DEFAULT_EXCLUDES = ['*.sw*',
'*.gitkeep',
'*.md',
'META-INF/BCKEY*', ]
/** parent from which this task will inherit some configuration */
JRubyStorm parentTask
String mainClass = REDSTORM_MAIN
/* Default to 1.7.21 <https://github.com/jruby-gradle/redstorm/issues/11> */
String jrubyVersion = '1.7.21'
@Override
String getConfiguration() {
return parentTask.configuration.name
}
JRubyStormJar() {
super()
appendix = ''
project.afterEvaluate {
this.includeRedstorm()
this.includeTopology()
}
}
void includeRedstorm() {
from {
File redstorm = this.parentTask.configuration.find {
it.name.matches(/redstorm-(.*).jar/)
}
project.zipTree(redstorm)
}
}
void includeTopology() {
if (parentTask.topology) {
into('') { from parentTask.topology }
}
}
}

View File

@ -1,18 +1,40 @@
package com.github.jrubygradle.storm.internal
import com.github.jrubygradle.jar.JRubyJar
import org.gradle.api.InvalidUserDataException
import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.tasks.bundling.Jar
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.*
class JRubyStormJarSpec extends Specification {
Project project
def setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
}
def "when constructing the task"() {
given:
Project project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
expect: "the task to be a JRubyJar"
project.task('spock', type: JRubyStormJar) instanceof JRubyJar
}
def "mainClass should be the TopologyLauncher"() {
given:
Jar task = project.task('spock', type: JRubyStormJar)
expect:
task.mainClass == JRubyStormJar.REDSTORM_MAIN
}
def "appendix should be empty" () {
given:
Jar task = project.task('spock', type: JRubyStormJar)
expect: "that it has no special appendix in the filename"
task.appendix == ''
}
}

View File

@ -1,29 +1,6 @@
package com.github.jrubygradle.storm.internal
import com.github.jrubygradle.storm.JRubyStormLocal
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.bundling.Jar
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.*
class JRubyStormSpec extends Specification {
Project project
def setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
}
def "createAssembleTask() should return a Jar type task"() {
expect:
JRubyStorm.createAssembleTask(project, 'spock') instanceof Jar
}
def "createRunTask() should return a JRubyStormLocal type task"() {
given:
Task task = project.task('spockParent', type: com.github.jrubygradle.storm.JRubyStorm)
expect:
JRubyStorm.createRunTask(project, 'spock', task) instanceof JRubyStormLocal
}
}