gradle-plugin: Delete user output dirs in the clean task

This commit is contained in:
Ilya Matveev
2017-09-19 18:31:52 +03:00
committed by ilmat192
parent 0b2425026e
commit beb2ed07dc
2 changed files with 24 additions and 0 deletions
@@ -225,6 +225,10 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
findByPath(name) ?: create(name, DefaultTask::class.java)
}
private fun Project.cleanKonan() = project.konanArtifactsContainer.forEach {
project.delete(it.compilationTask.outputDir)
}
override fun apply(project: Project?) {
if (project == null) { return }
registry.register(KonanToolingModelBuilder)
@@ -254,6 +258,9 @@ class KonanPlugin @Inject constructor(private val registry: ToolingModelBuilderR
project.getTask("build").apply {
dependsOn(compileKonanTask)
}
project.getTask("clean").apply {
doLast { project.cleanKonan() }
}
// Create task to run supported executables.
project.getOrCreateTask("run").apply {
@@ -38,4 +38,21 @@ class PathSpecification extends BaseKonanSpecification {
result.task(project.defaultInteropProcessingTask()).outcome == TaskOutcome.FAILED
}
def 'Plugin should remove custom output directories'() {
when:
def customOutputDir = projectDirectory.toPath().resolve("foo").toFile()
def project = KonanInteropProject.create(projectDirectory) { KonanProject it ->
it.addCompilationSetting("outputDir", customOutputDir)
}
def res1 = project.createRunner().withArguments("build").build()
def customDirExistsAfterBuild = customOutputDir.exists()
def res2 = project.createRunner().withArguments("clean").build()
def customDirDoesntNotExistAfterClean = !customOutputDir.exists()
then:
res1.taskPaths(TaskOutcome.SUCCESS).containsAll(project.buildingTasks)
res2.taskPaths(TaskOutcome.SUCCESS).contains(":clean")
customDirExistsAfterBuild
customDirDoesntNotExistAfterClean
}
}