diff --git a/base-plugin/build.gradle b/base-plugin/build.gradle index 104f254..927ac09 100644 --- a/base-plugin/build.gradle +++ b/base-plugin/build.gradle @@ -1,4 +1,10 @@ -archivesBaseName = 'jruby-gradle-plugin' +import org.gradle.plugins.ide.idea.model.IdeaModel +import org.gradle.plugins.ide.idea.model.IdeaModule + +archivesBaseName = 'jruby-gradle-plugin' // TODO: FIX !! + +apply plugin: TestConfigPlugin +apply plugin: 'java-gradle-plugin' apply from: "${rootProject.projectDir}/gradle/integration-tests.gradle" apply plugin: 'maven-publish' @@ -9,6 +15,8 @@ configurations { } ext { + flatRepoDir = file("${buildDir}/tmp/integrationTest/flatRepo") + jrubyClassPathFromConfiguration = { Configuration cfg -> def f = cfg.files.find { it.name.startsWith('jruby-complete-') } return f?.absolutePath @@ -80,6 +88,11 @@ test { } } +generateTestConfig { + testProperties mavenrepo: file('src/integTest/mavenrepo').absolutePath, + flatrepo: flatRepoDir.absolutePath +} + task copyIntegrationTestJRuby (type:Copy) { from ({configurations.testJRubyPrepare.files}) into new File(buildDir,'tmp/integrationTest/flatRepo') @@ -152,3 +165,4 @@ bintrayUpload.dependsOn assemble gradleTest.mustRunAfter integrationTest // vim: ft=groovy + diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle new file mode 100644 index 0000000..76fd4bf --- /dev/null +++ b/buildSrc/build.gradle @@ -0,0 +1,8 @@ +plugins { + id 'groovy' +} + +dependencies { + compile localGroovy() + compile gradleApi() +} \ No newline at end of file diff --git a/buildSrc/src/main/groovy/TestConfigPlugin.groovy b/buildSrc/src/main/groovy/TestConfigPlugin.groovy new file mode 100644 index 0000000..8ebc82c --- /dev/null +++ b/buildSrc/src/main/groovy/TestConfigPlugin.groovy @@ -0,0 +1,48 @@ +import groovy.transform.CompileDynamic +import groovy.transform.CompileStatic +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.GroovyPlugin +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.SourceSet +import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.tasks.TaskContainer + +@CompileStatic +class TestConfigPlugin implements Plugin { + @Override + void apply(Project project) { + + project.apply plugin: GroovyPlugin + + SourceSetContainer sourceSets = getSourceSets(project) + TestConfigTask generateTestConfig = project.tasks.create('generateTestConfig', TestConfigTask) + + generateTestConfig.with { + group = 'verification' + description = 'Create property file readable by tests.' + } + + sourceSets.all { SourceSet it -> + configureSourceSet(it, generateTestConfig) + } + + sourceSets.whenObjectAdded { SourceSet it -> + configureSourceSet(it, generateTestConfig) + } + } + + @CompileDynamic + SourceSetContainer getSourceSets(Project project) { + project.sourceSets + } + + static void configureSourceSet(SourceSet sourceSet, TestConfigTask generateTestConfig) { + if (sourceSet.name != 'main') { + Project project = generateTestConfig.project + TaskContainer tasks = project.tasks + Copy processResources = (Copy) tasks.getByName(sourceSet.getProcessResourcesTaskName()) + processResources.from generateTestConfig + } + } +} diff --git a/buildSrc/src/main/groovy/TestConfigTask.groovy b/buildSrc/src/main/groovy/TestConfigTask.groovy new file mode 100644 index 0000000..9cb9a0a --- /dev/null +++ b/buildSrc/src/main/groovy/TestConfigTask.groovy @@ -0,0 +1,34 @@ +import groovy.transform.CompileStatic +import org.gradle.api.DefaultTask +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +@CompileStatic +class TestConfigTask extends DefaultTask { + + TestConfigTask() { + outputFile = project.file( "${project.buildDir}/.testconfig/jruby-gradle-testconfig.properties") + + onlyIf { testProperties.size() } + } + + @Input + final Map testProperties = [:] + + void testProperties(Map props) { + this.testProperties.putAll(props) + } + + @OutputFile + File outputFile + + @TaskAction + void exec() { + Properties props = new Properties() + props.putAll(testProperties) + outputFile.withOutputStream { strm -> + props.store(strm,'') + } + } +}