Compare commits

...

36 Commits

Author SHA1 Message Date
R. Tyler Croy 5baf5ff1ff
Update the README to contain some slightly more updated info 2015-10-08 16:01:25 -07:00
R. Tyler Croy 6c609bf5a9
Remove install -> check dependency which causes duplicate tests for bintrayUpload
It seems the bintrayUpload task depends on install so our release cycle
in travis is doing redundant test runs
2015-10-01 17:20:00 -07:00
R. Tyler Croy bf8d3a0e4e Merge pull request #34 from rtyler/fix-jrubydir
Upgrade the dependency on JRuby/Gradle base and jar plugins
2015-10-01 17:05:59 -07:00
R. Tyler Croy 036e875653
Upgrade the dependency on JRuby/Gradle base and jar plugins to generate .jrubydir properly
Fixes #24
2015-10-01 16:49:56 -07:00
R. Tyler Croy 48d3f248ba Merge pull request #33 from rtyler/five-zero-fixes
Better integration testing and a bug fix
2015-09-21 16:31:44 -07:00
R. Tyler Croy 6506a3d5d4
If no parentTask for JRubyStormLocal is set, use the default configuration for the classpath
Fixes #29
2015-09-21 15:59:39 -07:00
R. Tyler Croy 2a3f0b709a
Start adding more integration test cases including one for JRubyStormLocal tasks 2015-09-21 14:48:17 -07:00
R. Tyler Croy 2ad81ecb40
Upgrade the gradle wrapper
Bumping to Gradle 2.7
2015-09-21 14:48:01 -07:00
R. Tyler Croy 980b579549 Merge pull request #32 from rtyler/task-deps
Propogate task dependencies from JRubyStorm to its children tasks
2015-09-20 17:58:17 -07:00
R. Tyler Croy 2becff34d2
Propogate task dependencies from JRubyStorm to its children tasks
Fixes #31
2015-09-20 17:48:18 -07:00
R. Tyler Croy 7b1c81004c
Upgrade to the latest stable redstorm (0.9.2)
Fixes #27
2015-09-15 14:38:01 -07:00
R. Tyler Croy 94d7efc522
Avoid trying to normalize paths for the JRubyStormLocal configuration
This can cause problems, apparently, on Mac OS X such as:

    > Could not normalize path for file '/Users/asavchenko/.gradle/caches/modules-

NOTE: This has not yet been tested on OS X
2015-09-15 14:28:37 -07:00
R. Tyler Croy 790772a8f7
Upgrade the default redstorm version 2015-09-11 11:19:36 -07:00
R. Tyler Croy 16a7f0886b
Work-around Gradle 2.2 super() issue by not calling super at all
According to @ysb33r:

    Gradle 2.2 is indeed the culprit. There was binary change in the Jar class when
    they moved it from a Groovy implementation to a Java one. It was corrected in a
    subequent release, but 2.2 remains an issue.

Gradle 2.2 was just a bad release :(

Fixes #26
2015-09-11 08:55:30 -07:00
R. Tyler Croy ecc92d61a0
Force the jar plugin into our classpath in the example 2015-09-10 17:17:47 -07:00
R. Tyler Croy 90499d72da
A bit more build cleanup
Just cleaning up some cruft left over from tinkering a while back
2015-09-10 17:03:24 -07:00
R. Tyler Croy cc1ef8df32
Remove oraclejdk7 from travis
Similar to jruby-gradle/jruby-gradle-plugin#217
2015-09-10 17:01:27 -07:00
R. Tyler Croy 27ec0761d0
Upgrade to jruby/gradle core 1.0.4 with some more recent bugfixes
This commit also changes JRubyStormJar a bit to override properties now that
they are properly overwritable in 1.0.4

Fixes #22
2015-09-10 16:03:57 -07:00
R. Tyler Croy b8f6b9886e
Set some default groups and descriptions on our packaging/run tasks
Fixes #19
2015-09-10 11:20:44 -07:00
R. Tyler Croy ca083054b4
Ensure that setting of the jrubyVersion for the topology jar works properly
This contains some workarounds until jruby-gradle/redstorm#11 is fixed which
will allow us to work on JRuby 9k, until then we'll default to the latest
stable JRuby 1.7.x branch

Fixes #23
2015-09-09 15:33:56 -07:00
R. Tyler Croy a6d92230c9
Ensure that the jrubyStormLocal configuration extends the classpath configuration 2015-09-09 15:33:40 -07:00
R. Tyler Croy 26a8316f49
Introduce a new configuration for unzipping things directly into the topology jar
This goes hand-in-hand with jruby-gradle/redstorm#12 and allows us to
incorporate things like storm-kafka early on in the load time of a topology
while still allowing most JRuby-originating jar dependencies to be packed "as
per usual." (See fast-rsa-engine and others which pack jar files inside gem
archives)

Fixes #25
2015-09-09 13:51:42 -07:00
R. Tyler Croy 61794ed1d2
Upgrade to the latest version of JRuby 1.7.x 2015-09-09 13:06:12 -07:00
R. Tyler Croy 8b59d41c0d
Bump version for next "major" bit of dev work 2015-09-09 13:06:12 -07:00
R. Tyler Croy d60010f797
Rely on the user to provide a jcenter-compatible repository by default
Fixes #18
2015-09-09 13:06:12 -07:00
R. Tyler Croy d0de027097
Move the bintray{} invocation to the main build.gradle
I forgot that the plugin seems to act funny when you try to use it from an
applied script like I had been using it previously
2015-09-09 13:05:41 -07:00
R. Tyler Croy d28608f31f Add some build/bintray badges 2015-08-18 13:11:51 -07:00
R. Tyler Croy c70216f1c4
Support auto-releasing the plugin on git tagging from Travis CI 2015-08-18 12:55:58 -07:00
R. Tyler Croy 6f2631ce45 Merge pull request #17 from rtyler/jrubystormlocal-configuration
Prevent JRubyStormLocal task from erroneously using jrubyExec
2015-08-18 11:09:52 -07:00
R. Tyler Croy a0b287c92a
Prevent JRubyStormLocal task from erroneously using the jrubyExec configuration
Fixes #12
2015-08-18 10:52:58 -07:00
R. Tyler Croy 998e9961c2 Merge pull request #16 from rtyler/fix-npe
Fix null dereference when JRubyStormLocal is standalone
2015-08-18 10:37:54 -07:00
R. Tyler Croy 68904a8bf8 Merge pull request #15 from rtyler/depends-and-assemble
dependsOn and assembleTask delegation
2015-08-18 10:03:33 -07:00
R. Tyler Croy 90c92d045d
Fix null dereference when JRubyStormLocal is standalone, i.e. no parentTask
Fixes #11
2015-08-18 10:01:53 -07:00
R. Tyler Croy 8c7e2ddc14
Delegate to our assembleTask for methods not already defined in JRubyStorm
Fixes #13
2015-08-18 09:39:08 -07:00
R. Tyler Croy 2046c89c29
Executing the jrubyStorm task should also execute its assemble task
Fixes #14
2015-08-17 16:10:00 -07:00
R. Tyler Croy 2934164708
Upgrade to the latest release of redstorm which has some better version ranges 2015-08-17 16:09:37 -07:00
21 changed files with 434 additions and 152 deletions

View File

@ -1,24 +1,18 @@
language: groovy
sudo: false
install:
- ./gradlew clean
- "./gradlew clean"
script:
- ./gradlew -S -i
- ./gradlew -S -i gradleTest
- "./gradlew -S -i check gradleTest assemble"
jdk:
- oraclejdk7
- oraclejdk8
- openjdk7
os:
- linux
- osx
env: TERM=dumb
- oraclejdk8
- openjdk7
env:
matrix:
- TERM=dumb
global:
secure: MwCVmyShcCHpe9CAQqveN5FWA4z0H+iYv/pzae0up1pCN9OqTL1h9jHkVoMhOQGw5aQQiptObt+5Y2aNlxSXBDPlpyQHV3EtH1ABJxNbdVNvhm2DACvUgF1uGinP2Gof7hm+2S54vEqAaYSd516lMV741H2CvmpjQhaJNpKeQO0=
cache:
directories:
- $HOME/.gradle
- "$HOME/.gradle"
after_success: "./gradlew bintrayUpload -i -PbintrayUser=rtyler -PbintrayKey=${BINTRAY_KEY}"

View File

@ -1,46 +1,27 @@
= JRuby/Gradle Storm Plugin
image:https://travis-ci.org/jruby-gradle/jruby-gradle-storm-plugin.svg?branch=master["Build Status", link="https://travis-ci.org/jruby-gradle/jruby-gradle-storm-plugin"]
image::https://api.bintray.com/packages/jruby-gradle/plugins/jruby-gradle-storm-plugin/images/download.svg[link="https://bintray.com/jruby-gradle/plugins/jruby-gradle-storm-plugin/_latestVersion"]
JRuby/Gradle plugin to manage creating Storm topology jars
== Usage
**NOTE:** This plugin is stili in a very early stages.
Including the plugin:
[source, groovy]
----
buildscript {
repositories { jcenter() }
dependencies {
classpath "com.github.jruby-gradle:jruby-gradle-storm-plugin:0.2.0"
classpath "com.github.jruby-gradle:jruby-gradle-storm-plugin:[0.4.4,0.5)"
}
}
----
== Running a "local topology"
The `JRubyStormLocal` task provides the underlying machinery to run a
link:https://github.com/jruby-gradle/redstorm[Redstorm] topology in "local"
mode:
[source, groovy]
----
import com.github.jrubygradle.storm.JRubyStormLocal
task runLocalTopology(type: JRubyStormLocal) {
// path is considered relative to the working directory
// the task is executed in
topology 'topologies/example_topology.rb'
}
----
Then you can run the local topology with: `./gradlew runLocalTopology`
NOTE: The Gradle script will block until the local topology is terminated (Ctrl+C)
== Creating a topolog .jar
@ -48,7 +29,4 @@ Creating a topology `.jar` file is useflu when you plan on uploading your
topology to a running Storm cluster. *Currently* this plugin will only create
that jar for you, it will not upload it.
By default the plugin will include `bolts/` and `/topologies/` in the generated
`.jar` file.
* `./gradlew jrubyStorm` will create a `.jar` in `build/libs/`

View File

@ -15,13 +15,19 @@ buildscript {
apply plugin: 'codenarc'
apply plugin: 'groovy'
apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
apply from: 'gradle/integration-test.gradle'
apply from: 'gradle/releasing.gradle'
group = 'com.github.jruby-gradle'
version = '0.2.0'
version = '0.4.4'
defaultTasks 'check', 'assemble'
// Any time we're not expicitly saying "build me a release build" we'll change
// the version to -SNAPSHOT
if (!(System.env.TRAVIS_TAG as Boolean)) {
version = "${version}-SNAPSHOT"
}
repositories {
jcenter()
}
@ -38,6 +44,9 @@ dependencies {
testCompile ("org.spockframework:spock-core:0.7-groovy-${gradle.gradleVersion.startsWith('1.')?'1.8':'2.0'}") {
exclude module : 'groovy-all'
}
/* Used for mocking non interface types */
testCompile 'cglib:cglib-nodep:3.1'
}
plugins.withType(JavaPlugin) {
@ -67,4 +76,42 @@ test {
}
}
task sourcesJar(type: Jar) {
classifier = 'sources'
dependsOn classes
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
configurations = ['archives']
/*
* Only only publish when we're tagging a release and if we've executed on
* the JDK7 build. This is to prevent multiple attempts by the build matrix
* to publish the artifacts
*/
dryRun = !((System.env.TRAVIS_TAG as boolean) && (System.env.TRAVIS_JDK_VERSION == 'openjdk7'))
pkg {
userOrg = 'jruby-gradle'
repo = 'plugins'
name = 'jruby-gradle-storm-plugin'
labels = ['jruby','storm','java']
version {
name = project.version
vcsTag = "v${project.version}"
attributes = ['gradle-plugin' : 'com.github.jruby-gradle.storm:com.github.jruby-gradle:jruby-gradle-storm-plugin']
desc = project.description
}
}
}
bintrayUpload.dependsOn assemble
// vim: ft=groovy

View File

@ -7,12 +7,11 @@ buildscript {
}
dependencies {
classpath 'com.github.jruby-gradle:jruby-gradle-jar-plugin:1.0.2'
/* Replace "%%VERSION%%" with the version of JRuby/Gradle Storm you wish to
* use if you want to use this build.gradle outside of gradleTest
*/
classpath 'com.github.jruby-gradle:jruby-gradle-storm-plugin:%%VERSION%%'
//classpath 'com.github.jruby-gradle:jruby-gradle-storm-plugin:0.2.0'
classpath 'com.github.jruby-gradle:jruby-gradle-jar-plugin:1.1.4+'
}
}

View File

@ -4,4 +4,4 @@ bintrayKey=
sourceCompatibility=1.7
targetCompatibility=1.7
jrubyGradleMinVersion=1.0.2
jrubyGradleMinVersion=1.1.4

View File

@ -47,7 +47,7 @@ task integrationTest(type: Test) {
check.dependsOn integrationTest
gradleTest {
versions '2.0', '2.2', '2.4', '2.6'
versions '2.0', '2.2', '2.6'
dependsOn test, integrationTest, jar
}

View File

@ -1,33 +0,0 @@
apply plugin: 'com.jfrog.bintray'
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
bintray {
user = project.bintrayUser
key = project.bintrayKey
publish = true
dryRun = false
configurations = ['archives']
pkg {
userOrg = 'jruby-gradle'
repo = 'plugins'
name = 'jruby-gradle-storm-plugin'
labels = ['jruby','storm','java']
version {
name = project.version
vcsTag = "v${project.version}"
attributes = ['gradle-plugin' : 'com.github.jruby-gradle.storm:com.github.jruby-gradle:jruby-gradle-storm-plugin']
desc = 'This plugin encapsulates Storm topology building functionality for JRuby Gradle projects'
}
}
}
bintrayUpload.dependsOn assemble

Binary file not shown.

View File

@ -1,6 +1,6 @@
#Tue Sep 16 15:17:56 PDT 2014
#Mon Sep 21 11:21:40 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-bin.zip

6
gradlew vendored
View File

@ -42,11 +42,6 @@ case "`uname`" in
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched.
if $cygwin ; then
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
@ -114,6 +109,7 @@ fi
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`

View File

@ -0,0 +1,52 @@
package com.github.jrubygradle.storm
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/**
* Integration testing base class for common integration testing behaviors
*/
class JRubyStormIntegrationSpecification extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text
}
/**
* Apply the necessary plugin configuration to integration test a Gradle build
* with the given <pre>build</pre> {@code File}
*
* @param build Temporary file representing the build.gradle
*/
void applyPluginTo(File build) {
build << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
repositories {
jcenter()
}
"""
}
}

View File

@ -0,0 +1,111 @@
package com.github.jrubygradle.storm
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import spock.lang.*
/**
*/
class JRubyStormLocalIntegrationSpec extends JRubyStormIntegrationSpecification {
def "executing runJRubyStorm with no topology should error"() {
given:
applyPluginTo(buildFile)
buildFile << "jrubyStorm { topology 'foo.rb' }"
when:
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('runJRubyStorm')
.buildAndFail()
then:
result.task(":runJRubyStorm").outcome == TaskOutcome.FAILED
}
File createHelloWorldTopology() {
File topologyFile = testProjectDir.newFile('topo.rb')
topologyFile << """
require 'red_storm'
class HelloWorldSpout < RedStorm::DSL::Spout
on_init {@words = ["hello", "world"]}
on_send {@words.shift unless @words.empty?}
end
class HelloWorldBolt < RedStorm::DSL::Bolt
on_receive :emit => false do |tuple|
puts tuple
end
end
class HelloWorldTopology < RedStorm::DSL::Topology
spout HelloWorldSpout do
output_fields :word
end
bolt HelloWorldBolt do
source HelloWorldSpout, :global
end
configure do
debug false
max_task_parallelism 4
num_workers 1
max_spout_pending 1000
end
on_submit do
Thread.start {
sleep 20
cluster.shutdown
}
end
end
"""
return topologyFile
}
def "running in local mode with a basic topology"() {
given:
applyPluginTo(buildFile)
File topo = createHelloWorldTopology()
buildFile << "jrubyStorm { topology '${topo.absolutePath}' }"
when: 'runJRubyStorm is invoked'
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('runJRubyStorm')
.build()
then: 'the task should succeed'
result.task(":runJRubyStorm").outcome == TaskOutcome.SUCCESS
and: "it should have logged hello world"
result.standardOutput.contains('{"word"=>"hello"}')
result.standardOutput.contains('{"word"=>"world"}')
}
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/29')
def "JRubyStormLocal tasks should not require a parent task"() {
given:
applyPluginTo(buildFile)
File topo = createHelloWorldTopology()
buildFile << """
import com.github.jrubygradle.storm.JRubyStormLocal
task run(type: JRubyStormLocal) {
topology '${topo.absolutePath}'
}
"""
when: 'the run task is invoked'
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('run')
.build()
then: 'the task should succeed'
result.task(":run").outcome == TaskOutcome.SUCCESS
}
}

View File

@ -1,44 +1,32 @@
package com.github.jrubygradle.storm
import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.gradle.testkit.runner.BuildResult
import org.gradle.api.artifacts.Dependency
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.*
/** Integration tests which actually execute Gradle via the GradleTestKit */
class JRubyStormTestKitSpec extends Specification {
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
String pluginDependencies
class JRubyStormTestKitSpec extends JRubyStormIntegrationSpecification {
def "executing the task without a topolgoy should error"() {
given:
applyPluginTo(buildFile)
buildFile << 'jrubyStorm { }'
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.json")
when:
BuildResult result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('jrubyStorm')
.buildAndFail()
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
}
pluginDependencies = pluginClasspathResource.text
then:
result.task(":jrubyStorm").outcome == TaskOutcome.FAILED
}
def "executing the assemble task produces a jar artifact"() {
given:
applyPluginTo(buildFile)
buildFile << """
buildscript {
dependencies {
classpath files(${pluginDependencies})
}
}
apply plugin: 'com.github.jruby-gradle.storm'
jrubyStorm {
}
"""

View File

@ -1,26 +1,30 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.JRubyPlugin
import org.gradle.api.DefaultTask
import org.gradle.api.Incubating
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
import com.github.jrubygradle.storm.internal.JRubyStorm as JRubyStormInternal
import org.gradle.api.tasks.bundling.AbstractArchiveTask
/**
* Implement the custom behaviors needed to build a JRubyStorm topology
*/
@Incubating
class JRubyStorm extends DefaultTask {
static final String DEFAULT_CONFIGURATION_NAME = 'jrubyStorm'
/** Dynamically created dependent task for running the topology in local mode*/
private Task runTask
/** Dynamically created dependent task for building the topology jar */
private Task assembleTask
/**
* Dynamically created dependent task for building the topology jar
*/
@Delegate
AbstractArchiveTask assembleTask
/** Default version of redstorm to use */
protected String customRedstormVersion
@ -29,6 +33,22 @@ class JRubyStorm extends DefaultTask {
/** Configuration which has all of our dependencies */
protected Configuration configuration
Task getAssembleTask() {
return assembleTask
}
/**
* Apply a task dependency to this task and its child tasks
*
* @param dependencies
* @return this task
*/
Task dependsOn(Object... dependencies) {
assembleTask?.dependsOn(dependencies)
runTask?.dependsOn(dependencies)
return super.dependsOn(dependencies)
}
/** Path (absolute or relative) to the Ruby file containing the topology */
@Input
String topology
@ -63,24 +83,14 @@ 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)
this.assembleTask = JRubyStormInternal.createAssembleTask(this.project, this)
runTask = JRubyStormInternal.createRunTask(this.project, this)
assembleTask = JRubyStormInternal.createAssembleTask(this.project, this)
super.dependsOn(assembleTask)
group JRubyPlugin.TASK_GROUP_NAME
project.afterEvaluate { this.updateDependencies() }
}
@ -101,6 +111,7 @@ class JRubyStorm extends DefaultTask {
project.dependencies.add(localConfiguration.name, "org.apache.storm:storm-core:${stormVersion}")
localConfiguration.extendsFrom configuration
localConfiguration.extendsFrom project.configurations.findByName(JRubyStormPlugin.CLASSPATH_CONFIGURATION)
}
/**

View File

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

View File

@ -1,5 +1,6 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.internal.JRubyExecUtils
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.JavaExec
@ -10,9 +11,20 @@ import com.github.jrubygradle.internal.JRubyExecTraits
* a given codebase
*/
class JRubyStormLocal extends JavaExec implements JRubyExecTraits {
static final String DEFAULT_JRUBYSTORMLOCAL_CONFIG = 'jrubyStormLocal'
/** parent from which this task will inherit some configuration */
JRubyStorm parentTask
@Input
@Override
String getConfiguration() {
/* Prevent the usage of jrubyExec as our configuration which is never correct */
if (JRubyExecTraits.super.getConfiguration() == JRubyExecUtils.DEFAULT_JRUBYEXEC_CONFIG) {
return DEFAULT_JRUBYSTORMLOCAL_CONFIG
}
return JRubyExecTraits.super.getConfiguration()
}
/** Set a custom path (relative or absolute) to the file defining a Redstorm topology
*
* If this is not set, the parentTask's topology will be used
@ -32,16 +44,23 @@ class JRubyStormLocal extends JavaExec implements JRubyExecTraits {
JRubyStormLocal() {
super()
super.setMain 'redstorm.TopologyLauncher'
description 'Execute the topology in "local" mode'
}
@Override
void exec() {
logger.info("JRubyStormLocal parentTask: ${parentTask} (${parentTask.topology})")
logger.info("JRubyStormLocal executing with parent (${parentTask}) and topology: ${topology}")
super.setArgs(['local', topology])
super.setEnvironment getPreparedEnvironment(environment)
if (parentTask) {
super.classpath parentTask.localConfiguration.asPath
super.classpath parentTask.localConfiguration
}
else {
/* make sure we always have some form of valid classpath set, see
* also: https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/29
*/
super.classpath project.configurations.findByName(getConfiguration())
}
prepareDependencies(project)

View File

@ -8,6 +8,7 @@ import org.gradle.api.Project
/**
*/
class JRubyStormPlugin implements Plugin<Project> {
static final CLASSPATH_CONFIGURATION = 'jrubyStormClasspath'
void apply(Project project) {
project.apply plugin : 'com.github.jruby-gradle.base'
project.apply plugin : 'com.github.jruby-gradle.jar'
@ -15,14 +16,14 @@ class JRubyStormPlugin implements Plugin<Project> {
project.extensions.create('storm', JRubyStormExtension)
project.task('jrubyStorm', type: JRubyStorm)
project.configurations.maybeCreate(CLASSPATH_CONFIGURATION)
updateRepositories(project)
}
@PackageScope
void updateRepositories(Project project) {
project.repositories {
// jcenter contains the redstorm and gradle dependencies
jcenter()
// Repositories for Storm dependencies
maven { url 'http://clojars.org/repo/' }
maven { url 'http://conjars.org/repo/' }

View File

@ -1,6 +1,7 @@
package com.github.jrubygradle.storm.internal
import com.github.jrubygradle.jar.JRubyJar
import com.github.jrubygradle.storm.JRubyStormPlugin
import groovy.transform.InheritConstructors
import com.github.jrubygradle.storm.JRubyStorm
@ -15,22 +16,40 @@ class JRubyStormJar extends JRubyJar {
/** 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'
/**
* Return the version of JRuby safe for usage in redstorm
*/
@Override
String getJrubyVersion() {
if (embeddedJRubyVersion == null) {
/* Default to 1.7.22 <https://github.com/jruby-gradle/redstorm/issues/11> */
return '1.7.22'
}
return embeddedJRubyVersion
}
@Override
String getMainClass() {
return REDSTORM_MAIN
}
@Override
String getConfiguration() {
return parentTask.configuration.name
if (parentTask) {
return parentTask.configuration.name
}
return JRubyStorm.DEFAULT_CONFIGURATION_NAME
}
JRubyStormJar() {
super()
appendix = ''
description 'Package a Storm topology jar'
project.afterEvaluate {
this.includeRedstorm()
this.includeTopology()
this.includeClasspathDependencies()
}
}
@ -48,4 +67,12 @@ class JRubyStormJar extends JRubyJar {
into('') { from parentTask.topology }
}
}
void includeClasspathDependencies() {
project.configurations.findByName(JRubyStormPlugin.CLASSPATH_CONFIGURATION).files.each { File f ->
if (f.name.endsWith(".jar")) {
from { project.zipTree(f) }
}
}
}
}

View File

@ -10,26 +10,24 @@ import org.gradle.testfixtures.ProjectBuilder
*
*/
class JRubyStormLocalSpec extends Specification {
protected Project project
Project project
JRubyStormLocal task
void setup() {
project = ProjectBuilder.builder().build()
project.apply plugin: 'com.github.jruby-gradle.storm'
task = project.task('spock', type: JRubyStormLocal)
}
def "jrubyStormLocal task should be a proper instance"() {
when:
project.task('jrubyStormLocal', type: JRubyStormLocal)
then:
project.tasks.jrubyStormLocal instanceof JRubyStormLocal
expect:
task instanceof JRubyStormLocal
}
def "the task should inherit the topology configured on the parent"() {
given:
JRubyStorm parent = project.task('spock-parent', type: JRubyStorm)
parent.topology = 'foo.rb'
JRubyStormLocal task = project.task('spock', type: JRubyStormLocal)
when:
task.parentTask = parent
@ -40,7 +38,6 @@ class JRubyStormLocalSpec extends Specification {
def "I should be able to set a topology to run without a parent task"() {
given:
JRubyStormLocal task = project.task('spock', type: JRubyStormLocal)
String topologyFile = 'topology.rb'
when:
@ -49,4 +46,21 @@ class JRubyStormLocalSpec extends Specification {
then:
task.topology == topologyFile
}
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/12')
def "default configuration should not be from JRubyExec"() {
expect:
task.configuration == JRubyStormLocal.DEFAULT_JRUBYSTORMLOCAL_CONFIG
}
def "setting the configuration should work"() {
given:
final String configName = 'someConfiguration'
when:
task.configuration configName
then:
task.configuration == configName
}
}

View File

@ -1,5 +1,6 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.storm.internal.JRubyStormJar
import org.gradle.api.artifacts.Dependency
import spock.lang.*
@ -61,6 +62,39 @@ class JRubyStormSpec extends Specification {
runTask.topology == 'spock.rb'
}
def "JRubyStorm task should depend on its assembleTask"() {
given:
Task task = project.task('spock', type: JRubyStorm)
expect:
task.dependsOn.find { it == task.assembleTask }
}
def "into(destPath) should delegate to the assembleTask"() {
given:
final String path = "some-path"
JRubyStormJar assembleTask = Mock(JRubyStormJar)
JRubyStorm task = project.task('spock', type: JRubyStorm)
task.assembleTask = assembleTask
1 * assembleTask.into(path) >> assembleTask
expect:
task.into(path) == assembleTask
}
def "into(destPath, copySpec) should delegate to the assembleTask"() {
given:
final String path = "some-path"
JRubyStormJar assembleTask = Mock(JRubyStormJar)
JRubyStorm task = project.task('spock', type: JRubyStorm)
task.assembleTask = assembleTask
Closure copySpec = { 1 + 1 }
1 * assembleTask.into(path, copySpec) >> assembleTask
expect:
task.into(path, copySpec) == assembleTask
}
def "getStormVersion() should return the storm.defaultStormVersion by default"() {
given:
JRubyStorm task = project.task('spock', type: JRubyStorm)
@ -108,6 +142,29 @@ class JRubyStormSpec extends Specification {
then:
project.configurations.findByName(JRubyStorm.DEFAULT_CONFIGURATION_NAME)
}
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/19')
def "group should be set by default on the sub-tasks"() {
given:
JRubyStorm task = project.task('spock', type: JRubyStorm)
expect:
task.assembleTask.group == task.group
}
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/31')
def "assemble task should depend on whatever the parent dependsOn"() {
given:
JRubyStorm task = project.task('spock', type: JRubyStorm)
Task otherTask = project.task('dependentTask')
when:
task.dependsOn otherTask
then:
task.dependsOn.contains(otherTask)
task.assembleTask.dependsOn.contains(otherTask)
}
}
@Ignore("For some reason these are running with DEBUG log level and it won't turn off")

View File

@ -37,4 +37,25 @@ class JRubyStormJarSpec extends Specification {
expect: "that it has no special appendix in the filename"
task.appendix == ''
}
@Issue('https://github.com/jruby-gradle/redstorm/issues/11')
@Issue('https://github.com/jruby-gradle/jruby-gradle-storm-plugin/issues/23')
def 'jrubyVersion should be default to 1.7.xx'() {
given:
JRubyStormJar task = project.task('spock', type: JRubyStormJar)
expect:
task.jrubyVersion == '1.7.22'
}
def "Setting jrubyVersion should override the default"() {
given:
final String version = '1.7.21'
JRubyStormJar task = project.task('spock', type: JRubyStormJar) {
jrubyVersion version
}
expect:
task.jrubyVersion == version
}
}