Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Gradle's build in warning mode failure #120

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions gradle/dependency-locks/compile.lockfile

This file was deleted.

3 changes: 0 additions & 3 deletions gradle/dependency-locks/compileOnly.lockfile

This file was deleted.

10 changes: 0 additions & 10 deletions gradle/dependency-locks/integTestCompile.lockfile

This file was deleted.

3 changes: 0 additions & 3 deletions gradle/dependency-locks/integTestCompileOnly.lockfile

This file was deleted.

10 changes: 0 additions & 10 deletions gradle/dependency-locks/integTestRuntime.lockfile

This file was deleted.

10 changes: 0 additions & 10 deletions gradle/dependency-locks/runtime.lockfile

This file was deleted.

10 changes: 0 additions & 10 deletions gradle/dependency-locks/testCompile.lockfile

This file was deleted.

3 changes: 0 additions & 3 deletions gradle/dependency-locks/testCompileOnly.lockfile

This file was deleted.

10 changes: 0 additions & 10 deletions gradle/dependency-locks/testRuntime.lockfile

This file was deleted.

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
49 changes: 6 additions & 43 deletions src/main/groovy/nebula/test/BaseIntegrationSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nebula.test
import groovy.transform.CompileStatic
import groovy.transform.TypeCheckingMode
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.junit.Rule
import org.junit.rules.TestName
import spock.lang.Specification
Expand Down Expand Up @@ -81,39 +82,6 @@ abstract class BaseIntegrationSpec extends Specification {
file
}

protected static void checkForDeprecations(String output) {
def deprecations = output.readLines().findAll {
it.contains("has been deprecated and is scheduled to be removed in Gradle") ||
it.contains("Deprecated Gradle features were used in this build") ||
it.contains("has been deprecated. This is scheduled to be removed in Gradle") ||
it.contains("This behaviour has been deprecated and is scheduled to be removed in Gradle")
}
// temporary for known issue with overwriting task
// overridden task expected to not be needed in future version
if (deprecations.size() == 1 && deprecations.first().contains("Creating a custom task named 'dependencyInsight' has been deprecated and is scheduled to be removed in Gradle 5.0.")) {
return
}
if (!System.getProperty("ignoreDeprecations") && !deprecations.isEmpty()) {
throw new IllegalArgumentException("Deprecation warnings were found (Set the ignoreDeprecations system property during the test to ignore):\n" + deprecations.collect {
" - $it"
}.join("\n"))
}
}

protected static void checkForMutableProjectState(String output) {
def mutableProjectStateWarnings = output.readLines().findAll {
it.contains("was resolved without accessing the project in a safe manner") ||
it.contains("This may happen when a configuration is resolved from a thread not managed by Gradle or from a different project")

}

if (!System.getProperty("ignoreMutableProjectStateWarnings") && !mutableProjectStateWarnings.isEmpty()) {
throw new IllegalArgumentException("Mutable Project State warnings were found (Set the ignoreMutableProjectStateWarnings system property during the test to ignore):\n" + mutableProjectStateWarnings.collect {
" - $it"
}.join("\n"))
}
}

protected void writeHelloWorld(File baseDir = getProjectDir()) {
writeHelloWorld('nebula', baseDir)
}
Expand Down Expand Up @@ -211,15 +179,11 @@ abstract class BaseIntegrationSpec extends Specification {
getProjectDir().getName().replaceAll(/_\d+/, '')
}

protected List<String> calculateArguments(String... args) {
protected List<String> calculateArguments(WarningMode warningMode, String... args) {
// We have to avoid the command line switch for backwards compatibility and system properties in non-forked and forked modes are weird so we use gradle.properties
new File(projectDir, 'gradle.properties') << '\norg.gradle.warning.mode=' + warningMode.name().toLowerCase()

List<String> arguments = []
// Gradle will use these files name from the PWD, instead of the project directory. It's easier to just leave
// them out and let the default find them, since we're not changing their default names.
//arguments += '--build-file'
//arguments += (buildFile.canonicalPath - projectDir.canonicalPath).substring(1)
//arguments += '--settings-file'
//arguments += (settingsFile.canonicalPath - projectDir.canonicalPath).substring(1)
//arguments += '--no-daemon'
switch (getLogLevel()) {
case LogLevel.INFO:
arguments += '--info'
Expand All @@ -232,9 +196,8 @@ abstract class BaseIntegrationSpec extends Specification {
arguments += '--parallel'
}
arguments += '--stacktrace'
arguments += '-Dorg.gradle.warning.mode=all'
arguments.addAll(args)
arguments.addAll(initScripts.collect { file -> '-I' + file.absolutePath })
arguments
}
}
}
30 changes: 19 additions & 11 deletions src/main/groovy/nebula/test/IntegrationSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import nebula.test.functional.internal.GradleHandle
import nebula.test.multiproject.MultiProjectIntegrationHelper
import org.apache.commons.io.FileUtils
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode

/**
* @author Justin Ryan
Expand All @@ -34,7 +35,7 @@ import org.gradle.api.logging.LogLevel
@CompileStatic
abstract class IntegrationSpec extends BaseIntegrationSpec {
private static final String DEFAULT_REMOTE_DEBUG_JVM_ARGUMENTS = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
private static final Integer DEFAULT_DAEMON_MAX_IDLE_TIME_IN_SECONDS_IN_MEMORY_SAFE_MODE = 15;
private static final Integer DEFAULT_DAEMON_MAX_IDLE_TIME_IN_SECONDS_IN_MEMORY_SAFE_MODE = 15

// Holds State of last run
private ExecutionResult result
Expand Down Expand Up @@ -72,8 +73,8 @@ abstract class IntegrationSpec extends BaseIntegrationSpec {
helper = new MultiProjectIntegrationHelper(getProjectDir(), settingsFile)
}

protected GradleHandle launcher(String... args) {
List<String> arguments = calculateArguments(args)
protected GradleHandle launcher(WarningMode warningMode, String ... args) {
List<String> arguments = calculateArguments(warningMode, args)
List<String> jvmArguments = calculateJvmArguments()
Integer daemonMaxIdleTimeInSeconds = calculateMaxIdleDaemonTimeoutInSeconds()

Expand Down Expand Up @@ -144,7 +145,11 @@ abstract class IntegrationSpec extends BaseIntegrationSpec {

/* Execution */
protected ExecutionResult runTasksSuccessfully(String... tasks) {
ExecutionResult result = runTasks(tasks)
return runTasksSuccessfully(WarningMode.Fail, tasks)
}

protected ExecutionResult runTasksSuccessfully(WarningMode warningMode, String... tasks) {
ExecutionResult result = runTasks(warningMode, tasks)
if (result.failure) {
result.rethrowFailure()
}
Expand All @@ -153,20 +158,23 @@ abstract class IntegrationSpec extends BaseIntegrationSpec {

@CompileStatic(TypeCheckingMode.SKIP)
protected ExecutionResult runTasksWithFailure(String... tasks) {
ExecutionResult result = runTasks(tasks)
return runTasksWithFailure(WarningMode.Fail, tasks)
}

@CompileStatic(TypeCheckingMode.SKIP)
protected ExecutionResult runTasksWithFailure(WarningMode warningMode, String... tasks) {
ExecutionResult result = runTasks(warningMode, tasks)
assert result.failure
result
}

protected ExecutionResult runTasks(String... tasks) {
ExecutionResult result = launcher(tasks).run()
this.result = result
return checkForDeprecations(result)
return runTasks(WarningMode.Fail, tasks)
}

protected ExecutionResult checkForDeprecations(ExecutionResult result) {
checkForMutableProjectState(result.standardOutput)
checkForDeprecations(result.standardOutput)
protected ExecutionResult runTasks(WarningMode warningMode, String... tasks) {
ExecutionResult result = launcher(warningMode, tasks).run()
this.result = result
return result
}

Expand Down
36 changes: 21 additions & 15 deletions src/main/groovy/nebula/test/IntegrationTestKitSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package nebula.test


import nebula.test.functional.internal.classpath.ClasspathAddingInitScriptBuilder
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.GFileUtils
Expand All @@ -41,7 +43,7 @@ abstract class IntegrationTestKitSpec extends BaseIntegrationSpec {
boolean definePluginOutsideOfPluginBlock = false

def setup() {
if (! settingsFile) {
if (!settingsFile) {
settingsFile = new File(projectDir, "settings.gradle")
settingsFile.text = "rootProject.name='${moduleName}'\n"
}
Expand All @@ -68,15 +70,19 @@ abstract class IntegrationTestKitSpec extends BaseIntegrationSpec {
}

BuildResult runTasks(String... tasks) {
BuildResult result = createRunner(tasks)
.build()
return checkForDeprecations(result)
return runTasks(WarningMode.Fail, tasks)
}

BuildResult runTasks(WarningMode warningMode, String... tasks) {
return createRunner(warningMode, tasks).build()
}

BuildResult runTasksAndFail(String... tasks) {
BuildResult result = createRunner(tasks)
.buildAndFail()
return checkForDeprecations(result)
return runTasksAndFail(WarningMode.Fail, tasks)
}

BuildResult runTasksAndFail(WarningMode warningMode, String... tasks) {
return createRunner(warningMode, tasks).buildAndFail()
}

def tasksWereSuccessful(BuildResult result, String... tasks) {
Expand All @@ -90,14 +96,19 @@ abstract class IntegrationTestKitSpec extends BaseIntegrationSpec {
}

GradleRunner createRunner(String... tasks) {
def pluginArgs = definePluginOutsideOfPluginBlock ? createGradleTestKitInitArgs() : new ArrayList<>()
return createRunner(WarningMode.Fail, tasks)
}

GradleRunner createRunner(WarningMode warningMode, String... tasks) {
def arguments = calculateArguments(warningMode, tasks)
def pluginArgs = definePluginOutsideOfPluginBlock ? createGradleTestKitInitArgs() : new ArrayList<String>()
def gradleRunnerBuilder = GradleRunner.create()
.withProjectDir(projectDir)
.withArguments(calculateArguments(tasks) + pluginArgs)
.withArguments(arguments + pluginArgs)
.withDebug(debug)
.withPluginClasspath()

if(forwardOutput) {
if (forwardOutput) {
gradleRunnerBuilder.forwardOutput()
}
if (gradleVersion != null) {
Expand All @@ -122,9 +133,4 @@ abstract class IntegrationTestKitSpec extends BaseIntegrationSpec {

return Arrays.asList("--init-script", initScript.getAbsolutePath())
}

protected BuildResult checkForDeprecations(BuildResult result) {
checkForDeprecations(result.output)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nebula.test
class MutableProjectStateWarningCheckIntegrationSpec extends IntegrationSpec {

def setup() {
gradleVersion = "5.1"
gradleVersion = "5.6.4"
}

def 'mutable project state warning when configuration in another project is resolved unsafely'() {
Expand Down Expand Up @@ -38,11 +38,10 @@ class MutableProjectStateWarningCheckIntegrationSpec extends IntegrationSpec {


when:
runTasks("resolve", "--parallel", "--warning-mode", "all")
def failure = runTasksWithFailure("resolve", "--parallel").failure

then:
def e = thrown(IllegalArgumentException)
e.message.contains('Mutable Project State warnings were found (Set the ignoreMutableProjectStateWarnings system property during the test to ignore)')
failure.message.contains('Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0')
}

def 'mutable project state warning when configuration is resolved from a non-gradle thread'() {
Expand Down Expand Up @@ -81,11 +80,10 @@ class MutableProjectStateWarningCheckIntegrationSpec extends IntegrationSpec {


when:
runTasks("resolve", "--warning-mode", "all")
def failure = runTasksWithFailure("resolve").failure

then:
def e = thrown(IllegalArgumentException)
e.message.contains('Mutable Project State warnings were found (Set the ignoreMutableProjectStateWarnings system property during the test to ignore)')
failure.message.contains('Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0')
}

def 'mutable project state warning when configuration is resolved while evaluating a different project'() {
Expand Down Expand Up @@ -117,11 +115,10 @@ class MutableProjectStateWarningCheckIntegrationSpec extends IntegrationSpec {


when:
runTasks(":bar:help", "--parallel", "--warning-mode", "all")
def failure = runTasksWithFailure(":bar:help", "--parallel").failure

then:
def e = thrown(IllegalArgumentException)
e.message.contains('Mutable Project State warnings were found (Set the ignoreMutableProjectStateWarnings system property during the test to ignore)')
failure.message.contains('Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0')
}

}