Skip to content
Permalink
Browse files
[JENKINS-12193] hook up injected tests, but disabled by default becau…
…se of JENKINS-21977
  • Loading branch information
daspilker committed Feb 6, 2015
1 parent 9f6de01 commit fc956747d8ea5150984e0e86b811dd9113b77582
@@ -1,5 +1,8 @@
## 0.8.2 (unreleased)

* added task to inject tests for checking the syntax of Jelly and other things
[JENKINS-12193](https://issues.jenkins-ci.org/browse/JENKINS-12193)

## 0.8.1 (2015-01-28)

* create `target` directory (for coreVersions >= 1.545 and < 1.592), clean `target` directory (for coreVersions
@@ -248,6 +248,23 @@ class JpiExtension {
*/
String gitHubUrl

/**
* If true, the automatic test injection will be skipped.
*
* Disabled by default because of <a href="https://issues.jenkins-ci.org/browse/JENKINS-21977">JENKINS-21977</a>.
*/
boolean disabledTestInjection = true

/**
* Name of the injected test.
*/
String injectedTestName = 'InjectedTest'

/**
* If true, verify that all the jelly scripts have the Jelly XSS PI in them.
*/
boolean requirePI = true

Developers developers = new Developers()

def developers(Closure closure) {
@@ -135,6 +135,9 @@ class JpiPlugin implements Plugin<Project> {

gradleProject.tasks.compileJava.dependsOn(LocalizerTask.TASK_NAME)

Task testInsertionTask = gradleProject.tasks.create(TestInsertionTask.TASK_NAME, TestInsertionTask)
gradleProject.tasks.compileTestJava.dependsOn(testInsertionTask)

def sourcesJar = gradleProject.task(SOURCES_JAR_TASK_NAME, type: Jar, dependsOn: 'classes') {
classifier = 'sources'
from gradleProject.sourceSets.main.allSource
@@ -0,0 +1,51 @@
package org.jenkinsci.gradle.plugins.jpi

import org.gradle.api.DefaultTask
import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.TaskAction

import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME
import static org.gradle.api.tasks.SourceSet.TEST_SOURCE_SET_NAME

class TestInsertionTask extends DefaultTask {
public static final String TASK_NAME = 'insertTest'

@TaskAction
void generateInjectedTest() {
JpiExtension jpiExtension = project.extensions.getByType(JpiExtension)
JavaPluginConvention javaConvention = project.convention.getPlugin(JavaPluginConvention)
SourceSet mainSourceSet = javaConvention.sourceSets.getByName(MAIN_SOURCE_SET_NAME)
SourceSet testSourceSet = javaConvention.sourceSets.getByName(TEST_SOURCE_SET_NAME)

if (jpiExtension.disabledTestInjection) {
return
}

File root = new File(project.buildDir, 'inject-tests')
root.mkdirs()
testSourceSet.java.srcDirs += root

File javaFile = new File(root, "${jpiExtension.injectedTestName}.java")
javaFile.text = """import java.util.*;
/**
* Entry point to auto-generated tests (generated by gradle-jpi-plugin).
*/
public class ${jpiExtension.injectedTestName} extends junit.framework.TestCase {
public static junit.framework.Test suite() throws Exception {
Map parameters = new HashMap();
parameters.put("basedir", ${quote(project.projectDir.absolutePath)});
parameters.put("artifactId", ${quote(jpiExtension.shortName)});
parameters.put("outputDirectory", ${quote(mainSourceSet.output.resourcesDir.absolutePath)});
parameters.put("requirePI", ${quote(String.valueOf(jpiExtension.requirePI))});
return new org.jvnet.hudson.test.PluginAutomaticTestBuilder().build(parameters);
}
}
"""
}

private static String quote(String s) {
"\"${s.replace('\\', '\\\\')}\""
}
}
@@ -26,10 +26,11 @@ class JpiPluginSpec extends Specification {
taskClass.isInstance(project.tasks[taskName])

where:
taskName | taskClass
'jpi' | Jpi
'server' | ServerTask
'localizer' | LocalizerTask
'stapler' | StaplerGroovyStubsTask
taskName | taskClass
'jpi' | Jpi
'server' | ServerTask
'localizer' | LocalizerTask
'stapler' | StaplerGroovyStubsTask
'insertTest' | TestInsertionTask
}
}

0 comments on commit fc95674

Please sign in to comment.