diff --git a/tools/helpers/build.gradle b/tools/helpers/build.gradle index 52ddb8dded9..b177bfcf1ed 100644 --- a/tools/helpers/build.gradle +++ b/tools/helpers/build.gradle @@ -25,11 +25,17 @@ apply plugin: 'kotlin' apply plugin: NativeInteropPlugin configurations { + unTar + compile.extendsFrom unTar cli_bc.extendsFrom compile } dependencies { compile project(path: ':backend.native', configuration: 'cli_bc') + // https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-archiver + unTar group: 'org.codehaus.plexus', name: 'plexus-archiver', version: '3.4' + // https://mvnrepository.com/artifact/org.codehaus.plexus/plexus-container-default + unTar group: 'org.codehaus.plexus', name: 'plexus-container-default', version: '1.7.1' cli_bc jar.outputs.files } @@ -39,6 +45,13 @@ sourceSets { } } +// TODO: shrink jar +jar { + from { + configurations.unTar.collect { it.isDirectory() ? it : zipTree(it) } + } +} + def testDependencies = project.file("${sourceSets.testOutputLocal.output.dirs.singleFile.absolutePath}/dependencies") void prepareDependenciesDir(File testDependencies) { diff --git a/tools/helpers/src/main/kotlin/DependencyDownloader.kt b/tools/helpers/src/main/kotlin/DependencyDownloader.kt index c7637dc087a..58fa0afced5 100644 --- a/tools/helpers/src/main/kotlin/DependencyDownloader.kt +++ b/tools/helpers/src/main/kotlin/DependencyDownloader.kt @@ -1,5 +1,8 @@ package org.jetbrains.kotlin.konan +import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver +import org.codehaus.plexus.logging.Logger +import org.codehaus.plexus.logging.console.ConsoleLogger import java.io.* import java.net.URL import java.util.Properties @@ -51,14 +54,12 @@ class DependencyDownloader(dependenciesRoot: File, val properties: Properties, v } private fun extract(tarGz: File) { - val tarProcess = ProcessBuilder().apply { - command("tar", "-x", "-f", "${tarGz.canonicalPath}") - directory(tarGz.parentFile) - }.start() - tarProcess.waitFor() - if (tarProcess.exitValue() != 0) { - throw RuntimeException("Cannot extract archive with dependency: ${tarGz.canonicalPath}") - } + val ua = TarGZipUnArchiver() + ua.sourceFile = tarGz + ua.destDirectory = dependenciesRoot + // Workaround. This archive library crashes if the logger is not set. + ua.enableLogging(ConsoleLogger(Logger.LEVEL_DISABLED, "Logger")) + ua.extract() } private val Long.humanReadable: String @@ -114,7 +115,6 @@ class DependencyDownloader(dependenciesRoot: File, val properties: Properties, v Thread.sleep(1000) // We can use condition variable here. updateProgressMsg(url.toString(), currentBytes, totalBytes) } - println("Done.") if (downloadError != null) { throw RuntimeException("Cannot download dependency: $url", downloadError) }