Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
Merge pull request #80 from ysb33r/development
Browse files Browse the repository at this point in the history
FIXED #65
FIXED #68 
FIXED #74 
FIXED #78
FIXED #79
  • Loading branch information
ysb33r authored Aug 30, 2017
2 parents 11014ec + f89309f commit df654cf
Show file tree
Hide file tree
Showing 18 changed files with 142 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ sudo: required
before_script:
- ./gradlew -S clean --console=plain

install: true

script:
- ./gradlew -S -i --console=plain assemble
- ./gradlew -S -i --console=plain test
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ for a specific release, please visit the http://ysb33r.github.io/gradleTest[plug
* https://github.com/ysb33r/gradleTest/issues/54[#54] - Added base plugin `org.ysb33r.gradletest.base`.
* https://github.com/ysb33r/gradleTest/issues/62[#62] - Propagate `--rerun-tasks` down to test instances.
* https://github.com/ysb33r/gradleTest/issues/67[#67] - `org.ysb33r.gradlerunner` plugin provides `gradleRunner` task which can interleave different steps with independent Gradle executions.
* https://github.com/ysb33r/gradleTest/issues/79[#79] - Make Gradle deprecation messages fail tests.

=== Bugs

Expand All @@ -41,6 +42,7 @@ for a specific release, please visit the http://ysb33r.github.io/gradleTest[plug
* https://github.com/ysb33r/gradleTest/issues/53[#53] - Skip test generation if `src/gradleTest` does not exist.
* https://github.com/ysb33r/gradleTest/issues/57[#57] - Transitive dependencies for pluginsare not injected into classpath.
* https://github.com/ysb33r/gradleTest/issues/59[#59] - GradleTest does not detect new folders if previous task completed successfully
* https://github.com/ysb33r/gradleTest/issues/74[#74] - Plugin resolves configuration `$$gradleRunner$$classpath$$` at configuration time.

=== Other

Expand All @@ -59,6 +61,8 @@ for a specific release, please visit the http://ysb33r.github.io/gradleTest[plug
* https://github.com/ysb33r/gradleTest/issues/60[#60] - Mention alternative approaches to `GradleTest`.
* https://github.com/ysb33r/gradleTest/issues/61[#61] - Validate support for Gradle 3.3.
* https://github.com/ysb33r/gradleTest/issues/63[#63] - Documented `--offline` behaviour.
* https://github.com/ysb33r/gradleTest/issues/65[#65] - Documented CodeNarc plugin behaviour.
* https://github.com/ysb33r/gradleTest/issues/78[#78] - Fix various deprecation messages with Gradle 4.x.

// end::changelog[]

Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test_script:
- gradlew.bat test compatibilityTest --info --no-daemon -DgradleTest.versions=2.12,2.13,2.14.1 -DnonLegacyOnlyGradleTest.versions=3.1
- gradlew.bat test compatibilityTest --info --no-daemon -DgradleTest.versions=3.0,3.1,3.2.1 -DnonLegacyOnlyGradleTest.versions=3.2.1
- gradlew.bat test compatibilityTest --info --no-daemon -DgradleTest.versions=3.3,3.4.1,3.5 -DnonLegacyOnlyGradleTest.versions=3.3,3.4.1,3.5
- gradlew.bat test compatibilityTest --info --no-daemon -DgradleTest.versions=4.0,4.1 -DnonLegacyOnlyGradleTest.versions=4.0,4.1

branches:
only:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import org.asciidoctor.gradle.AsciidoctorTask

group = 'org.ysb33r.gradle'
archivesBaseName = 'gradletest'
version = '1.0-beta11'
version = '1.0-beta12'

apply from : 'gradle/integration-tests.gradle'
apply from : 'gradle/compatibility-tests.gradle'
Expand Down
2 changes: 2 additions & 0 deletions compatibility/compatibility.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ gradleTest {
dependsOn sanityCheck
systemProperties = [:]
// tag::applyplugin2[]
versions '4.0', '4.1'
versions '3.5', '3.4.1'
versions '3.3', '3.2.1', '3.1', '3.0'
versions '2.14.1'
Expand Down Expand Up @@ -120,6 +121,7 @@ if(GradleVersion.current() >= GradleVersion.version('2.13')) {
additionalGradleTestSet 'nonLegacyOnly' // <1>

nonLegacyOnlyGradleTest { // <2>
versions '4.0', '4.1'
versions '3.5', '3.4.1', '3.3'
versions '3.2', '3.1', '3.0' // <3>
versions '2.14.1'
Expand Down
4 changes: 2 additions & 2 deletions src/docs/asciidoc/parts/bootstrap.adoc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
= Bootstrap
== Bootstrap

GradleTest is available in the https://plugins.gradle.org/plugin/org.ysb33r.gradletest[Gradle Plugins] repository.
To use it, add the appropriate plugin to the `plugins` block.

[source,groovy,subs="attributes"]
[source,groovy,subs="+attributes"]
----
plugins {
id 'org.ysb33r.gradletest' version '{revnumber}' // <1>
Expand Down
12 changes: 12 additions & 0 deletions src/docs/asciidoc/parts/configuration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ NOTE: When the system property is set it will override all `distributionUri` set
* If gradle is run with `--offline`, it will be passed to the Gradle.
* `--full-stacktrace` is set and output is captured to test report.

=== Deprecation Messages

As Gradle evolves, certain functionality is marked as deprecated. When these messages are detected during testing, it will
cause the compatibility test to fail. This behaviour can be turned on (default) or off via the `deprecatedMessagesAreFailures` setting.

[source,groovy]
----
gradleTest {
deprecatedMessagesAreFailures false // <1>
}
----
<1> Turns off default behaviour of failing on deprecated Gradle functionality.
3 changes: 2 additions & 1 deletion src/docs/asciidoc/parts/gradle-runner.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

The `org.ysb33r.gradlerunner` plugin adds a default task called `gradleRunner` which is of type `GradleRunnerSteps`. This task allows people to run specific Gradle steps interlevaed via other actions such as copying files. This is specifically useful for people who need to document development steps where Gradle is involved.

== Steps

Steps are added via the `step` keyword. Each step has a name which can later be used to extract information after execution.

[source,groovy]
Expand All @@ -16,7 +18,6 @@ gradleRunner {
failingStep 'this gradle will fail', 'non-existing-task' // <4>
}
----
<1> A step can be a closure or an `Action`.
<2> Every step will have an unique directory for dropping files,
Expand Down
12 changes: 11 additions & 1 deletion src/docs/asciidoc/parts/other-plugins.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ its own internally generated license headers.
There is an https://github.com/hierynomus/license-gradle-plugin/issues/115[open issue] against this,
but for now the best workaround is to exclude the test code generated by `GradleTest`.

.Configuring licence plugin for exclusiion
.Configuring licence plugin for exclusion
[source,groovy]
----
license {
exclude '**/*CompatibilitySpec.groovy'
}
----

=== CodeNarc plugin

When adding GradleTest to a project that also has codenarc configured, the tests generated by GradleTest will be scanned by CodeNarc.

.Configuring CodeNarc to ignore GradleTest
[source,groovy]
----
codenarcGradleTest.enabled = false
----
2 changes: 1 addition & 1 deletion src/docs/landingPage/display-versions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# List versions in order that they should appear on the landing page
#
1.0-beta11
1.0-beta12
0.5.5
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class GradleRunnerSteps extends DefaultTask {
}

for (Step step : steps ) {
logger.info " -- ${step.getName()}"
step.execute( work, new File(report,FileUtils.toSafeFileName(step.getName()) ) )
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package org.ysb33r.gradle.gradlerunner.internal

import groovy.transform.CompileStatic
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.ysb33r.gradle.gradlerunner.GradleRunnerPlugin

import java.lang.reflect.Method
Expand All @@ -27,17 +28,18 @@ import java.lang.reflect.Method
class GradleRunnerFactory {

GradleRunnerFactory(Project project) {
URL[] urls = project.configurations.getByName(GradleRunnerPlugin.CLASSPATH_CONFIGURATION).files.collect { File f ->
f.absoluteFile.toURI().toURL()
} as URL[]
URLClassLoader loader = URLClassLoader.newInstance(urls,this.getClass().classLoader)
this.gradleRunner = loader.loadClass('org.gradle.testkit.runner.GradleRunner')
configuration = project.configurations.getByName(GradleRunnerPlugin.CLASSPATH_CONFIGURATION)
}

def createRunner() {
URL[] urls = configuration.files.collect { File f ->
f.absoluteFile.toURI().toURL()
} as URL[]
URLClassLoader loader = URLClassLoader.newInstance(urls,this.getClass().classLoader)
Class gradleRunner = loader.loadClass('org.gradle.testkit.runner.GradleRunner')
Method createMethod = gradleRunner.getDeclaredMethod('create')
createMethod.invoke(gradleRunner)
}

private Class gradleRunner
private Configuration configuration
}
26 changes: 22 additions & 4 deletions src/main/groovy/org/ysb33r/gradle/gradletest/GradleTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ class GradleTest extends Test {
notSupported('useTestNG()')
}

/** If Gradle issues a depcreation messages, treat this as a failure
*
* <P> {@code true} by default.
*/
@Input
boolean deprecationMessagesAreFailures = true

/** Convenience method to allow for setting deprecation message mode.
*
* @param setting Deprecation mode.
*/
void deprecationMessagesAreFailures(boolean setting) {
this.deprecationMessagesAreFailures = setting
}

/** Returns path to initscript that will be used for tests
*
* @return Path to init.gradle script
Expand Down Expand Up @@ -210,10 +225,14 @@ class GradleTest extends Test {

@CompileDynamic
void setHtmlReportFolder() {
reports.html.destination = {
"${project.reporting.baseDir}/${owner.name}"
Closure getDir = {
project.file("${project.reporting.baseDir}/${owner.name}")
}
if( GradleVersion.current() < GradleVersion.version('4.0')) {
reports.html.destination = getDir
} else {
reports.html.destination = project.provider(getDir)
}

}

private void notSupported(final String name) {
Expand All @@ -233,7 +252,6 @@ class GradleTest extends Test {
private URI baseDistributionUri
private List<Pattern> expectedFailures = []


static final String BACKSLASH = '\\'

}
Expand Down
21 changes: 18 additions & 3 deletions src/main/groovy/org/ysb33r/gradle/gradletest/TestGenerator.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ class TestGenerator extends DefaultTask {
linkedTask.defaultTask
}

/** Whether to treat Gradle's deprecation messages as failures.
*
* @return {@code true} if deprecation messages should fail the tests.
*/
@Input
boolean getDeprecationMessageAreFailures() {
linkedTask.getDeprecationMessagesAreFailures()
}

/** The root directory where to find tests for this specific GradleTest grouping
* The default root directory by convention is {@code src/gradleTest}. THe patterns for the
* directory is {@code src/} + {@code gradleTestSetName}.
Expand Down Expand Up @@ -172,6 +181,7 @@ class TestGenerator extends DefaultTask {
final File workDir = project.file("${project.buildDir}/${linkedTestTaskName}")
final File repoDir = new File(workDir,'repo')
final List<Pattern> testPatternsForFailures = getLinkedTask().getExpectedFailures()
final boolean deprecation = getDeprecationMessageAreFailures()

Set<File> externalDependencies = []
try {
Expand Down Expand Up @@ -201,7 +211,8 @@ class TestGenerator extends DefaultTask {
workDir,
testLocation,
gradleArguments,
expectFailure
expectFailure,
deprecation
)
}

Expand Down Expand Up @@ -273,6 +284,7 @@ class TestGenerator extends DefaultTask {
* @param testProjectSrcDir Directory where test project is located
* @param arguments Arguments that will be passed during a run.
* @param willFail Set to {@code true} if the Gradle script under test is expected to fail.
* @param deprecationMessageMode Set to {@code true} to force Gradle's deprecation messages to fail the test.
*/
@CompileDynamic
private void copy(
Expand All @@ -283,7 +295,8 @@ class TestGenerator extends DefaultTask {
final File workDir,
final File testProjectSrcDir,
final List<String> arguments,
final boolean willFail
final boolean willFail,
final boolean deprecationMessageMode
) {

final def fromSource = templateFile
Expand All @@ -292,6 +305,7 @@ class TestGenerator extends DefaultTask {
final String manifest = pathAsUriStr(manifestFile)
final String work = pathAsUriStr(workDir)
final String src = pathAsUriStr(testProjectSrcDir)
final String deprecation = deprecationMessageMode.toString()

testName
project.copy {
Expand All @@ -307,7 +321,8 @@ class TestGenerator extends DefaultTask {
DISTRIBUTION_URI : gradleDistributionUri ?: '',
WORKDIR : work,
SOURCEDIR : src,
FAILMODE : willFail
FAILMODE : willFail,
CHECK_WARNINGS : deprecation
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/main/groovy/org/ysb33r/gradle/gradletest/TestSet.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,21 @@ class TestSet {
}

project.tasks.getByName(testTaskName).configure {
testClassesDir = project.sourceSets.getByName(testSetBaseName).output.classesDir
classpath = project.sourceSets.getByName(testSetBaseName).runtimeClasspath

if(GradleVersion.current() < GradleVersion.version('3.0') ) {
inputs.source (project.sourceSets.getByName(testSetBaseName).output.classesDir)
if(GradleVersion.current() < GradleVersion.version('4.0') ) {
testClassesDir = project.sourceSets.getByName(testSetBaseName).output.classesDir

if(GradleVersion.current() < GradleVersion.version('3.0') ) {
inputs.source(project.sourceSets.getByName(testSetBaseName).output.classesDir)
} else {
inputs.dir (project.sourceSets.getByName(testSetBaseName).output.classesDir).skipWhenEmpty
}
} else {
inputs.dir (project.sourceSets.getByName(testSetBaseName).output.classesDir).skipWhenEmpty
testClassesDirs = project.sourceSets.getByName(testSetBaseName).output.classesDirs

inputs.files (project.sourceSets.getByName(testSetBaseName).output.classesDirs).skipWhenEmpty
}
classpath = project.sourceSets.getByName(testSetBaseName).runtimeClasspath

}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ${TESTPACKAGE}

import java.util.regex.Pattern
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import org.apache.commons.io.FileUtils
Expand All @@ -16,9 +17,15 @@ class ${TESTNAME.replaceAll(/\W/,'_')}CompatibilitySpec extends Specification {
static final File SOURCEDIR = new File('${SOURCEDIR}'.toURI())
static final File CP_MANIFEST = new File('${MANIFEST}'.toURI())
static final File WORKDIR = new File('${WORKDIR}'.toURI())
static final boolean CHECK_WARNINGS = ${CHECK_WARNINGS}

static final String DISTRIBUTION_URI = System.getProperty('org.ysb33r.gradletest.distribution.uri') ?: '${DISTRIBUTION_URI}'
static final List<String> gradleArguments = [${ARGUMENTS}]
static final List<Pattern> warnings = [
~/The .+ method has been deprecated and is scheduled to be removed in Gradle/,
~/Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set/
]

static List<File> pluginClasspath
static String buildscriptClasspath

Expand Down Expand Up @@ -98,12 +105,23 @@ class ${TESTNAME.replaceAll(/\W/,'_')}CompatibilitySpec extends Specification {
} else {
pre25_checkoutcome(${FAILMODE},result.output)
}
no_deprecation_warnings(result.output)

where:
version << [${VERSIONS}]
}

boolean pre25_checkoutcome(boolean is_failmode,def output) {
private boolean no_deprecation_warnings(final String output) {
if(!CHECK_WARNINGS) {
true
} else {
!warnings.any { pat ->
output =~ pat
}
}
}

private boolean pre25_checkoutcome(boolean is_failmode,def output) {
if(is_failmode) {
output.matches(':${DEFAULTTASK} FAILED')
} else {
Expand Down
Loading

0 comments on commit df654cf

Please sign in to comment.