Refactor the work into a shadowJar backed JRubyStorm task, and JavaExec-based JRubyStormLocal

This commit is contained in:
R. Tyler Croy 2014-10-22 12:00:42 -07:00
parent 0bad940e5e
commit 24af77c088
6 changed files with 168 additions and 53 deletions

View File

@ -14,7 +14,6 @@ apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.jfrog.bintray'
group = 'com.github.jruby-gradle'
version = '0.1.0'
@ -26,35 +25,21 @@ sourceCompatibility = 1.7
repositories {
jcenter()
mavenLocal()
// Repositories for Storm dependencies
mavenCentral()
maven { url 'http://clojars.org/repo/' }
maven { url 'http://conjars.org/repo/' }
}
configurations {
jrubyStorm
jrubyStormLocal.extendsFrom jrubyStorm
}
dependencies {
compile gradleApi()
compile localGroovy()
compile group: 'com.github.jruby-gradle', name: 'jruby-gradle-plugin', version: '0.1.3+'
compile group: 'com.github.jruby-gradle', name: 'jruby-gradle-jar-plugin', version: '0.1.2+'
jrubyStorm (group: 'com.github.jruby-gradle',
name: 'redstorm',
version: '0.7.0-SNAPSHOT') {
exclude module: 'storm-core'
}
jrubyStormLocal group: 'org.apache.storm',
name: 'storm-core',
version: '0.9.1-incubating',
force: true
compile group: 'com.github.jruby-gradle',
name: 'jruby-gradle-plugin',
version: '0.1.3+'
compile group: 'com.github.jruby-gradle',
name: 'jruby-gradle-jar-plugin',
version: '0.1.2+'
compile group: 'com.github.jengelman.gradle.plugins',
name: 'shadow',
version: '1.1.2+'
testCompile ("org.spockframework:spock-core:0.7-groovy-${gradle.gradleVersion.startsWith('1.')?'1.8':'2.0'}") {
exclude module : 'groovy-all'
@ -77,32 +62,6 @@ artifacts {
archives sourcesJar
}
task localTest(type: JavaExec) {
classpath configurations.jrubyStormLocal.asPath
main 'redstorm.TopologyLauncher'
args 'local', './topologies/hello_world_topology'
}
shadowJar {
exclude '*.sw*', '*.gitkeep', '*.md'
from 'topologies'
// note that zipTree call is wrapped in closure so that configuration
// is only resolved at execution time. This will take the embeds
// from within the `jrubyStorm` configuration and dump them into the war
from {
project.configurations.jrubyStorm.collect {
project.zipTree(it)
}
}
jruby {
// Use the default GEM installation directory
defaultGems()
mainClass 'redstorm.TopologyLauncher'
}
}
// Ensure we don't fail in CI or on a system without these values set in
// ~/.gradle/gradle.properties

View File

@ -1,9 +1,9 @@
package com.github.jrubygradle.storm
import org.gradle.api.tasks.bundling.Jar
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
/**
* @author R. Tyler Croy
*/
class JRubyStorm extends Jar {
class JRubyStorm extends ShadowJar {
}

View File

@ -0,0 +1,29 @@
package com.github.jrubygradle.storm
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.Input
import org.gradle.api.Project
/**
* @author R. Tyler Croy
*/
class JRubyStormLocal extends JavaExec {
static void updateDependencies(Project project) {
project.tasks.withType(JRubyStormLocal) { JRubyStormLocal t ->
t.classpath project.configurations.jrubyStormLocal.asPath
}
}
JRubyStormLocal() {
super()
super.setMain 'redstorm.TopologyLauncher'
}
@Override
void exec() {
super.setArgs(['local'] + getArgs())
super.exec()
}
}

View File

@ -1,16 +1,98 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.JRubyPlugin
import groovy.transform.PackageScope
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.testing.Test
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
/**
* @author R. Tyler Croy
*/
class JRubyStormPlugin implements Plugin<Project> {
void apply(Project project) {
project.apply plugin : 'com.github.jruby-gradle.base'
project.apply plugin : 'com.github.jruby-gradle.jar'
project.apply plugin : 'com.github.johnrengelman.shadow'
project.configurations.maybeCreate('jrubyStorm')
project.configurations.maybeCreate('jrubyStormLocal')
project.configurations {
jrubyStormLocal.extendsFrom jrubyStorm
}
project.task('jrubyStorm', type: ShadowJar) {
group JRubyPlugin.TASK_GROUP_NAME
description 'Create a JRuby-based Storm topology'
dependsOn project.tasks.jrubyPrepare
exclude '*.sw*', '*.gitkeep', '*.md'
into('topologies') {
from 'topologies'
}
into('bolts') {
from 'bolts'
}
// note that zipTree call is wrapped in closure so that configuration
// is only resolved at execution time. This will take the embeds
// from within the `jrubyStorm` configuration and dump them into the war
from {
project.configurations.jrubyStorm.collect {
project.zipTree(it)
}
}
jruby {
// Use the default GEM installation directory
defaultGems()
mainClass 'redstorm.TopologyLauncher'
}
}
updateRepositories(project)
updateDependencies(project)
project.afterEvaluate {
JRubyStormLocal.updateDependencies(project)
}
}
@PackageScope
void updateRepositories(Project project) {
project.repositories {
// jcenter contains the redstorm and gradle dependencies
jcenter()
// Repositories for Storm dependencies
mavenCentral()
maven { url 'http://clojars.org/repo/' }
maven { url 'http://conjars.org/repo/' }
}
}
@PackageScope
void updateDependencies(Project project) {
project.dependencies {
jrubyStorm (group: 'com.github.jruby-gradle',
name: 'redstorm',
version: '0.7.+') {
exclude module: 'storm-core'
}
// Forcing 0.9.1 because of API incompatibilities with redstorm and
// Storm 0.9.2 which have yet to be resolved
jrubyStormLocal group: 'org.apache.storm',
name: 'storm-core',
version: '0.9.1-incubating',
force: true
}
}
}

View File

@ -0,0 +1,19 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.JRubyPlugin
import org.gradle.api.tasks.JavaExec
import org.junit.Test
import spock.lang.*
import static org.gradle.api.logging.LogLevel.LIFECYCLE
/**
* @author R. Tyler Croy
*
*/
class JRubyStormLocalSpec extends Specification {
void setup() {
}
}

View File

@ -1,8 +1,11 @@
package com.github.jrubygradle.storm
import com.github.jrubygradle.JRubyPlugin
import org.gradle.api.Task
import org.gradle.api.tasks.*
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.artifacts.Dependency
import org.gradle.testfixtures.ProjectBuilder
import org.junit.Test
import spock.lang.*
@ -26,7 +29,30 @@ class JRubyStormPluginSpec extends Specification {
def "Basic sanity check"() {
expect:
assert true
project.tasks.jrubyStorm instanceof Task
project.tasks.jrubyStorm.group == JRubyPlugin.TASK_GROUP_NAME
}
def "Check configurations exist"() {
given:
def configs = project.configurations
expect:
configs.getByName('jrubyStorm')
configs.getByName('jrubyStormLocal')
}
def "Check jrubyStorm dependencies are correct"() {
given:
def deps = project.configurations.getByName('jrubyStorm').dependencies
expect:
deps.matching { Dependency d -> d.name == 'redstorm' }
}
def "Check jrubyStormLocal dependencies are correct"() {
given:
def deps = project.configurations.getByName('jrubyStormLocal').dependencies
expect:
deps.matching { Dependency d -> d.name == 'storm-core' }
}
}