Add a test configuration plugin to simplify testing
This commit is contained in:
parent
62c46c489d
commit
2d8d1a1ff9
|
@ -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
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
plugins {
|
||||
id 'groovy'
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile localGroovy()
|
||||
compile gradleApi()
|
||||
}
|
|
@ -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<Project> {
|
||||
@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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String,String> testProperties = [:]
|
||||
|
||||
void testProperties(Map<String,String> props) {
|
||||
this.testProperties.putAll(props)
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
File outputFile
|
||||
|
||||
@TaskAction
|
||||
void exec() {
|
||||
Properties props = new Properties()
|
||||
props.putAll(testProperties)
|
||||
outputFile.withOutputStream { strm ->
|
||||
props.store(strm,'')
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue