From eb8138334acb4164623cfae84120d1875d75c824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Schalk=20W=2E=20Cronj=C3=A9?= Date: Wed, 27 Aug 2014 18:19:37 +0100 Subject: [PATCH] Moved code from jruby-gradle-plugin to here --- .gitignore | 1 + build.gradle | 2 +- .../github/jrubygradle/JRubyWarPlugin.groovy | 52 +++++++++++++++++++ .../jrubygradle/JRubyWarPluginSpec.groovy | 36 +++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/main/groovy/com/github/jrubygradle/JRubyWarPlugin.groovy create mode 100644 src/test/groovy/com/github/jrubygradle/JRubyWarPluginSpec.groovy diff --git a/.gitignore b/.gitignore index a99b6d7..6765401 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .gradle build/ *.sw* +*.iml diff --git a/build.gradle b/build.gradle index c38af14..f69dc8a 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { } group = 'com.github.jruby-gradle' -version = '0.1.0' +version = '0.1.1' if (System.env.RELEASE != '1') { version = "${version}-SNAPSHOT" diff --git a/src/main/groovy/com/github/jrubygradle/JRubyWarPlugin.groovy b/src/main/groovy/com/github/jrubygradle/JRubyWarPlugin.groovy new file mode 100644 index 0000000..82a288f --- /dev/null +++ b/src/main/groovy/com/github/jrubygradle/JRubyWarPlugin.groovy @@ -0,0 +1,52 @@ +package com.github.jrubygradle + +/** + * Created by schalkc on 27/08/2014. + */ +class JRubyWarPlugin { + void apply(Project project) { + // MIGHT NEED: project.apply plugin: 'java', 'java-base' or 'war' + + project.configurations.create(JRubyWar.JRUBYWAR_CONFIG) + + // TODO: Should probably check whether it exists before creating it + project.configurations { + jrubyEmbeds + } + + project.dependencies { + jrubyEmbeds group: 'com.lookout', name: 'warbler-bootstrap', version: '1.+' + } + + project.afterEvaluate { + JRubyWar.updateJRubyDependencies(project) + } + + // TODO: jarcache should rather be inside buildDir + project.task('jrubyCacheJars', type: Copy) { + group TASK_GROUP_NAME + description 'Cache .jar-based dependencies into .jarcache/' + + from project.configurations.jrubyWar + into ".jarcache" + include '**/*.jar' + } + + project.task('jrubyPrepare') { + group TASK_GROUP_NAME + description 'Pre-cache and prepare all dependencies (jars and gems)' + dependsOn project.tasks.jrubyCacheJars, project.tasks.jrubyPrepareGems + } + + // Only jRubyWar will depend on jrubyPrepare. Other JRubyWar tasks created by + // build script authors will be under their own control + // jrubyWar task will use jrubyWar as configuration + project.task('jrubyWar', type: JRubyWar) { + group JRubyPlugin.TASK_GROUP_NAME + description 'Create a JRuby-based web archive' + dependsOn project.tasks.jrubyPrepare + classpath project.configurations.jrubyWar + } + + } +} diff --git a/src/test/groovy/com/github/jrubygradle/JRubyWarPluginSpec.groovy b/src/test/groovy/com/github/jrubygradle/JRubyWarPluginSpec.groovy new file mode 100644 index 0000000..04a1b30 --- /dev/null +++ b/src/test/groovy/com/github/jrubygradle/JRubyWarPluginSpec.groovy @@ -0,0 +1,36 @@ +package com.github.jrubygradle + +import org.gradle.api.tasks.Delete +import org.gradle.testfixtures.ProjectBuilder +import org.junit.Test +import spock.lang.* + +import static org.gradle.api.logging.LogLevel.LIFECYCLE +import static org.junit.Assert.assertTrue + +/** + * @author R. Tyler Croy + * + */ +class JRubyWarPluginSpec extends Specification { + + def project + def warTask + + void setup() { + project = ProjectBuilder.builder().build() + project.buildDir = TESTROOT + project.logging.level = LIFECYCLE + project.apply plugin: 'com.github.jruby-gradle.war' + + } + + def "basic sanity check"() { + expect: + project.tasks.jrubyWar.group == 'JRuby' + project.tasks.jrubyCacheJars instanceof AbstractCopyTask + project.tasks.jrubyPrepare instanceof Task + project.tasks.jrubyWar instanceof War + project.tasks.jrubyJar instanceof Jar + } +}