Skip to content

Instantly share code, notes, and snippets.

@featzima
Created October 14, 2018 14:47
Show Gist options
  • Save featzima/9cebe6d785a69bc7b24e1735de8309c2 to your computer and use it in GitHub Desktop.
Save featzima/9cebe6d785a69bc7b24e1735de8309c2 to your computer and use it in GitHub Desktop.
The cleaner for all gradle projects on a disc.
import java.io.File
interface IProjectDetector {
fun isProjectRootFolder(folder: File): Boolean
}
interface IProjectCleaner {
fun clean(folder: File)
}
interface IProjectManager : IProjectDetector, IProjectCleaner
class GradleProjectManager : IProjectManager {
override fun isProjectRootFolder(folder: File): Boolean {
return File(folder, "build.gradle").exists()
&& File(folder, "gradlew").exists()
&& File(folder, "gradlew.bat").exists()
}
override fun clean(folder: File) {
println("cleaning $folder")
File(folder, ".gradle").deleteRecursively()
File(folder, "build").deleteRecursively()
folder
.listFiles()
.filter { it.isDirectory }
.forEach { File(it, "build").deleteRecursively() }
}
}
fun main(args: Array<String>) {
val projectManagers: List<IProjectManager> = listOf(GradleProjectManager())
File("C:\\")
.walkTopDown()
.filter { it.isDirectory }
.forEach { folder ->
projectManagers
.filter { it.isProjectRootFolder(folder) }
.forEach { it.clean(folder) }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment