diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ToolProcessTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ToolProcessTask.kt index 580ae619439ca122327509a4cbbcce288f3d3a79..70855ad26b75284086bffdbbd90ee994ecc16506 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ToolProcessTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ToolProcessTask.kt @@ -55,8 +55,11 @@ abstract class ToolProcessTask<ResultType> : Task() { } catch (e: Throwable) { sendTaskFailedEvent(e) } + cleanUp() } + protected open fun cleanUp() {} + private suspend fun sendProcessTaskDoneEvent() { val event = if (groupID != null) { diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/detekt/DetektTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/detekt/DetektTask.kt index 79deafe5b2c7774a2a097aa1c65cf3d7082aab5b..07369b1e85c31ee901f9cba08ce5978b942fb4de 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/detekt/DetektTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/detekt/DetektTask.kt @@ -5,6 +5,7 @@ import de.fraunhofer.iem.dataprovider.taskManager.tasks.tools.sarif.SarifTask import de.fraunhofer.iem.dataprovider.toolRun.service.ToolRunService import org.springframework.core.io.ClassPathResource import org.springframework.core.io.Resource +import java.io.File import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -23,11 +24,18 @@ class DetektTask( private val resource: Resource = ClassPathResource("scripts/detekt.sh") override val outputDirectory = Paths.get(outputDirectoryPath, "detekt", taskID.toString()).toString() override val resultFileOutputPath: Path = Paths.get(outputDirectory, "report.sarif") + private val copiedRepositoryPath = Paths.get(outputDirectory, "copiedRepo") override val flags: Array<String> = arrayOf(resource.file.absolutePath, repositoryDirectoryPath, outputDirectory) + override fun cleanUp() { + File(copiedRepositoryPath.toUri()).deleteRecursively() + } init { + val repoFile = File(repositoryDirectoryPath) + val copiedRepo = File(copiedRepositoryPath.toUri()) + repoFile.copyRecursively(copiedRepo) Files.createDirectories(Paths.get(outputDirectory)) } } diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/occmd/OccmdTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/occmd/OccmdTask.kt index 9adbaaeade114409e9c21b6caca961b0f1fc6fc2..88fd7987848b8b46cdd0ac01707bd5e4948e0c2b 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/occmd/OccmdTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/occmd/OccmdTask.kt @@ -8,6 +8,7 @@ import de.fraunhofer.iem.dataprovider.taskManager.tasks.tools.sarif.SarifTask import de.fraunhofer.iem.dataprovider.toolRun.service.ToolRunService import org.springframework.core.io.ClassPathResource import org.springframework.core.io.Resource +import java.io.File import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths @@ -27,6 +28,7 @@ class OccmdTask( private val resource: Resource = ClassPathResource("scripts/occmd.sh") override val outputDirectory: String = Paths.get(outputDirectoryPath, "occmd", taskID.toString()).toString() + private val copiedRepositoryPath = Paths.get(outputDirectory, "copiedRepo") override val getSarif = ::getOccmdSarifFromFilePath private val repositoryID = getRepositoryId(repoId) @@ -40,7 +42,7 @@ class OccmdTask( "--username", "USERNAME", //TODO: Make sure is it required? if not delete otherwise dynamically take the username "--proj-path", - repositoryDirectoryPath, + copiedRepositoryPath.toString(), "--out-dir", Paths.get(outputDirectory, "app", "notes").toAbsolutePath().toString(), "--console-out-file", @@ -72,7 +74,15 @@ class OccmdTask( "blacklist" ) + override fun cleanUp() { + File(copiedRepositoryPath.toUri()).deleteRecursively() + } + init { + val repoFile = File(repositoryDirectoryPath) + val copiedRepo = File(copiedRepositoryPath.toUri()) + repoFile.copyRecursively(copiedRepo) + Files.createDirectories(dbRawPath) Files.createDirectories(blacklistPath) Files.createDirectories(checkSecretPath) diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ort/OrtAnalyzerTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ort/OrtAnalyzerTask.kt index 80a9ccf56bb157fca44127e752ba173ee1797a75..58022e6035436a4de305f25c06c2f1c5462820da 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ort/OrtAnalyzerTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/ort/OrtAnalyzerTask.kt @@ -6,12 +6,13 @@ import de.fraunhofer.iem.dataprovider.taskManager.events.OrtAnalyzerDoneEvent import de.fraunhofer.iem.dataprovider.taskManager.tasks.tools.ToolProcessTask import org.springframework.core.io.ClassPathResource import org.springframework.core.io.Resource +import java.io.File import java.nio.file.Path import java.nio.file.Paths import java.util.* class OrtAnalyzerTask( - private val repositoryDirectoryPath: String, + repositoryDirectoryPath: String, outputDirectoryPath: String, override val responseChannel: suspend (event: Event) -> Unit, override val repoId: UUID, @@ -21,8 +22,9 @@ class OrtAnalyzerTask( private val resource: Resource = ClassPathResource("scripts/ort/ort_analyzer.sh") override val outputDirectory = Paths.get(outputDirectoryPath, "ort-analyzer", taskID.toString()).toString() override val resultFileOutputPath: Path = Paths.get(outputDirectory, "analyzer-result.json") + private val copiedRepositoryPath = Paths.get(outputDirectory, "copiedRepo") - override val flags = arrayOf(resource.file.absolutePath, repositoryDirectoryPath, outputDirectory) + override val flags = arrayOf(resource.file.absolutePath, copiedRepositoryPath.toString(), outputDirectory) override suspend fun parseProcessResults(resultPath: Path): List<DependencyCreateDto> { return emptyList() @@ -35,4 +37,14 @@ class OrtAnalyzerTask( responseChannel(OrtAnalyzerDoneEvent(outputDirectory, repoId, taskID, groupID)) } + override fun cleanUp() { + File(copiedRepositoryPath.toUri()).deleteRecursively() + } + + init { + val repoFile = File(repositoryDirectoryPath) + val copiedRepo = File(copiedRepositoryPath.toUri()) + repoFile.copyRecursively(copiedRepo) + } + } \ No newline at end of file diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/qodana/QodanaTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/qodana/QodanaTask.kt index f9fec09e674f1a47a0fbb49332504972db353363..bc9f7bddfa9602301fb4681a842fd9b779fc324a 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/qodana/QodanaTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/tools/qodana/QodanaTask.kt @@ -6,6 +6,7 @@ import de.fraunhofer.iem.dataprovider.taskManager.tasks.tools.sarif.SarifTask import de.fraunhofer.iem.dataprovider.toolRun.service.ToolRunService import org.springframework.core.io.ClassPathResource import org.springframework.core.io.Resource +import java.io.File import java.nio.file.Path import java.nio.file.Paths import java.util.* @@ -22,11 +23,22 @@ class QodanaTask( private val resource: Resource = ClassPathResource("scripts/qodana.sh") override val outputDirectory = Paths.get(outputDirectoryPath, "qodana", taskID.toString()).toString() + private val copiedRepositoryPath = Paths.get(outputDirectory, "copiedRepo") override val flags: Array<String> = - arrayOf(resource.file.absolutePath, repositoryDirectoryPath, outputDirectory) + arrayOf(resource.file.absolutePath, copiedRepositoryPath.toString(), outputDirectory) override val resultFileOutputPath: Path = Paths.get(outputDirectory, "qodana.sarif.json") override val getSarif = ::getQodanaSarifFromFilePath + + override fun cleanUp() { + File(copiedRepositoryPath.toUri()).deleteRecursively() + } + + init { + val repoFile = File(repositoryDirectoryPath) + val copiedRepo = File(copiedRepositoryPath.toUri()) + repoFile.copyRecursively(copiedRepo) + } } \ No newline at end of file