From 8da9f5301a64719c9919d351fde453bc12cd0e10 Mon Sep 17 00:00:00 2001 From: Thad House Date: Sun, 6 Jan 2019 13:15:22 -0800 Subject: [PATCH] Add way to disable the force no cache deletion behavior (#287) * Add way to disable the force no cache deletion behavior Fixes #286 The displays a large warning when the property is set, with no way to disable the message. We really do not want teams to have that property enabled. * Remove setting examples --- .../wpi/first/gradlerio/GradleRIOPlugin.groovy | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/edu/wpi/first/gradlerio/GradleRIOPlugin.groovy b/src/main/groovy/edu/wpi/first/gradlerio/GradleRIOPlugin.groovy index 7ec5bf15..005c4b20 100644 --- a/src/main/groovy/edu/wpi/first/gradlerio/GradleRIOPlugin.groovy +++ b/src/main/groovy/edu/wpi/first/gradlerio/GradleRIOPlugin.groovy @@ -69,7 +69,7 @@ class GradleRIOPlugin implements Plugin { } } - disableCacheCleanup() + disableCacheCleanup(project) project.gradle.taskGraph.whenReady { TaskExecutionGraph graph -> try { @@ -97,16 +97,25 @@ class GradleRIOPlugin implements Plugin { _registered_build_finished = true } + private static final String GRADLERIO_DISABLE_CACHE_CLEANUP_PROPERTY = "gradlerio.disable.cache.cleanup" private static final String CACHE_CLEANUP_PROPERTY = "org.gradle.cache.cleanup" // Write to ~/.gradle/gradle.properties, to disable cache cleanup. Cache cleanup // has the possibility to make dependencies 'go missing' if left unattended for a long time. // There's a chance this could happen during competition. - void disableCacheCleanup() { + void disableCacheCleanup(Project project) { def logger = ETLoggerFactory.INSTANCE.create("GR_CACHECLEANUP") + if (project.findProperty(GRADLERIO_DISABLE_CACHE_CLEANUP_PROPERTY) == "false") { + logger.logErrorHead("Warning! You have the property gradlerio.disable.cache.cleanup set to false") + logger.logError("This can cause issues when going to competition, since this means your dependencies can be deleted unwillingly after a month.") + logger.logError("Remove this from your gradle.properties file unless you know what you're doing.") + logger.logError("Note, this may result in you not being able to deploy code at competition") + return + } + try { // TODO: Issue #6084 on gradle/gradle, this may not work in 5.1 or all use cases - def gradleProperties = new File("${System.getProperty('user.home')}/.gradle/gradle.properties") + def gradleProperties = new File("${project.gradle.gradleUserHomeDir}/gradle.properties") if (gradleProperties.isFile()) { Properties props = GUtil.loadProperties(gradleProperties) String cleanup = props.getProperty(CACHE_CLEANUP_PROPERTY)