diff --git a/src/main/groovy/com/bancvue/gradle/support/ClearArtifactCache.groovy b/src/main/groovy/com/bancvue/gradle/support/ClearArtifactCache.groovy index 69b4f73..81a7a3b 100644 --- a/src/main/groovy/com/bancvue/gradle/support/ClearArtifactCache.groovy +++ b/src/main/groovy/com/bancvue/gradle/support/ClearArtifactCache.groovy @@ -22,6 +22,7 @@ import org.gradle.api.tasks.TaskAction class ClearArtifactCache extends DefaultTask { String groupName + File userHome = getDefaultUserHome() void setGroupName(String groupName) { this.groupName = groupName @@ -33,6 +34,7 @@ class ClearArtifactCache extends DefaultTask { assertGroupNameSet() clearMavenCache() clearGradleCache() + clearGroovyGrapeCache() } private void assertGroupNameSet() { @@ -43,10 +45,10 @@ class ClearArtifactCache extends DefaultTask { private void clearMavenCache() { String cachePath = groupName.replaceAll(/\./, '/') - project.delete new File(getUserHome(), ".m2/repository/${cachePath}") + project.delete new File(userHome, ".m2/repository/${cachePath}") } - private static File getUserHome() { + private static File getDefaultUserHome() { String userHome = System.getProperty("user.home") new File(userHome) } @@ -106,4 +108,7 @@ class ClearArtifactCache extends DefaultTask { } } + private void clearGroovyGrapeCache() { + project.delete new File(userHome, ".groovy/grapes/${groupName}") + } } diff --git a/src/mainTest/groovy/com/bancvue/gradle/test/AbstractProjectSpecification.groovy b/src/mainTest/groovy/com/bancvue/gradle/test/AbstractProjectSpecification.groovy index e05233d..202a8db 100644 --- a/src/mainTest/groovy/com/bancvue/gradle/test/AbstractProjectSpecification.groovy +++ b/src/mainTest/groovy/com/bancvue/gradle/test/AbstractProjectSpecification.groovy @@ -19,12 +19,14 @@ import org.gradle.api.Project import org.gradle.testfixtures.ProjectBuilder import org.junit.Rule import org.junit.rules.TemporaryFolder +import spock.lang.Shared import spock.lang.Specification abstract class AbstractProjectSpecification extends Specification { @Rule public TemporaryFolder projectDir = new TemporaryFolder() + @Shared protected Project project protected ProjectFileSystem projectFS diff --git a/src/test/groovy/com/bancvue/gradle/support/ClearArtifactCacheSpecification.groovy b/src/test/groovy/com/bancvue/gradle/support/ClearArtifactCacheSpecification.groovy index 73e2cb0..a5e3c70 100644 --- a/src/test/groovy/com/bancvue/gradle/support/ClearArtifactCacheSpecification.groovy +++ b/src/test/groovy/com/bancvue/gradle/support/ClearArtifactCacheSpecification.groovy @@ -20,6 +20,7 @@ import com.bancvue.gradle.test.AbstractProjectSpecification import com.google.common.io.Files import org.gradle.api.GradleException import org.gradle.api.tasks.TaskExecutionException +import spock.lang.Unroll @Mixin(ExceptionSupport) class ClearArtifactCacheSpecification extends AbstractProjectSpecification { @@ -85,6 +86,27 @@ class ClearArtifactCacheSpecification extends AbstractProjectSpecification { expect: ClearArtifactCache.collectGradleCacheDirsWithName(tempDir, "com.bancvue") == [new File(cacheDir, "com.bancvue")] } + + @Unroll("clearArtifactCache should clear #cacheDirParentPath") + def "clearArtifactCache should clear all caches"() { + given: + clearArtifactCacheTask.userHome = tempDir + clearArtifactCacheTask.groupName = 'com.bancvue' + File cacheDir = new File(tempDir, cacheDirParentPath) + createDirs(cacheDir, caches) + + when: + clearArtifactCacheTask.clearArtifactCache() + + then: + !new File(tempDir, cachePath).exists() + + where: + cacheDirParentPath | caches | cachePath + ".groovy/grapes" | ["com.bancvue"] | ".groovy/grapes/com.bancvue" + ".m2/repository" | ["com/bancvue"] | ".m2/repository/com/bancvue" + project.gradle.gradleUserHomeDir.absolutePath | ["caches/modules-2/files-2.1/com.bancvue"] | ".gradle/caches/modules-2/files-2.1/com.bancvue" + } private void createDirs(File parent, List dirNames) { dirNames.each { String dirName ->