Skip to content

Commit

Permalink
Merge pull request #45 from BancVue/clear_grape_cache
Browse files Browse the repository at this point in the history
make clearGroupCache also clear the Groovy Grape cache
  • Loading branch information
mlueders committed Jun 27, 2014
2 parents 19dfbaa + 5890b74 commit ca4a946
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,6 +34,7 @@ class ClearArtifactCache extends DefaultTask {
assertGroupNameSet()
clearMavenCache()
clearGradleCache()
clearGroovyGrapeCache()
}

private void assertGroupNameSet() {
Expand All @@ -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)
}
Expand Down Expand Up @@ -106,4 +108,7 @@ class ClearArtifactCache extends DefaultTask {
}
}

private void clearGroovyGrapeCache() {
project.delete new File(userHome, ".groovy/grapes/${groupName}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> dirNames) {
dirNames.each { String dirName ->
Expand Down

0 comments on commit ca4a946

Please sign in to comment.