diff options
Diffstat (limited to 'stubs')
| -rw-r--r-- | stubs/src/kotlin/proxy/KotlinProxyOverrides.java | 82 |
1 files changed, 4 insertions, 78 deletions
diff --git a/stubs/src/kotlin/proxy/KotlinProxyOverrides.java b/stubs/src/kotlin/proxy/KotlinProxyOverrides.java index 15e875e..8d01f8d 100644 --- a/stubs/src/kotlin/proxy/KotlinProxyOverrides.java +++ b/stubs/src/kotlin/proxy/KotlinProxyOverrides.java @@ -18,12 +18,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.FileOutputStream; -import java.net.URL; -import java.nio.channels.FileChannel; -import java.nio.channels.FileLock; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; import java.util.Arrays; import java.util.ArrayList; import java.util.Collections; @@ -31,7 +25,6 @@ import java.util.Comparator; import java.util.IdentityHashMap; import java.util.Map; import java.util.UUID; -import java.util.stream.Stream; /** * Per-method custom return values for the generated stubs. @@ -104,18 +97,16 @@ public final class KotlinProxyOverrides { File nativeImage; // A distribution root such as prepare/compiler-native-image/build/dist in the Kotlin repository. String customNativeImage = System.getProperty("kotlin.proxy.nativeImage"); - if (customNativeImage != null && !customNativeImage.isEmpty()) { + if (customNativeImage == null) { + messageCollector.report(CompilerMessageSeverity.ERROR, "System property kotlin.proxy.nativeImage is not set", null); + return ExitCode.INTERNAL_ERROR; + } else { nativeImage = new File(customNativeImage, "bin/kotlinc-native-image.sh"); if (!nativeImage.exists()) { messageCollector.report(CompilerMessageSeverity.ERROR, "kotlin.proxy.nativeImage: " + nativeImage + " does not exist", null); return ExitCode.INTERNAL_ERROR; } - } else { - nativeImage = downloadNativeImage(userDir, messageCollector); - if (nativeImage == null) { - return ExitCode.INTERNAL_ERROR; - } } ArrayList<String> cmd = new ArrayList<String>(); cmd.add(nativeImage.toString()); @@ -235,69 +226,4 @@ public final class KotlinProxyOverrides { } return null; } - - /** Downloads and extracts the JetBrains native image into user.dir. Returns null after it reports an error. */ - private static File downloadNativeImage(String userDir, MessageCollector messageCollector) { - File nativeImageDir = new File(userDir, "native-image"); - File nativeImage = new File(nativeImageDir, KOTLIN_NATIVE_IMAGE + "/bin/kotlinc-native-image.sh"); - if (!nativeImage.exists()) { - nativeImageDir.mkdirs(); - - synchronized (NATIVE_IMAGE_LOCK) { - // Check again, now that we have the lock - if (!nativeImage.exists()) { - File nativeImageTar = new File(nativeImageDir, KOTLIN_NATIVE_IMAGE + ".tar.gz"); - if (!nativeImageTar.exists()) { - try (InputStream in = new URL("https://github.com/JetBrains/kotlin/releases/download/v" - + KOTLIN_VERSION + "/" + KOTLIN_NATIVE_IMAGE + ".tar.gz").openStream()) { - Files.copy(in, nativeImageTar.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e) { - MessageCollectorUtil.reportException(messageCollector, e); - return null; - } - } - File nativeImageDirTmp = new File(nativeImageDir, "tmp"); - nativeImageDirTmp.mkdir(); - ArrayList<String> cmd = new ArrayList<String>(); - cmd.add("tar"); - cmd.add("-x"); - cmd.add("-f"); - cmd.add(nativeImageTar.toString()); - cmd.add("-z"); - cmd.add("-C"); - cmd.add(nativeImageDirTmp.toString()); - ProcessBuilder builder = new ProcessBuilder(cmd); - try { - Process process = builder.start(); - int exitvalue = process.waitFor(); - if (exitvalue != 0) { - // TODO: Include error stream - messageCollector.report(CompilerMessageSeverity.ERROR, "Unable to extract native image " + nativeImageTar, null); - deleteRecursive(nativeImageDirTmp); - return null; - } - File target = new File(nativeImageDir, KOTLIN_NATIVE_IMAGE); - deleteRecursive(target); - Files.move(new File(nativeImageDirTmp, KOTLIN_NATIVE_IMAGE).toPath(), - target.toPath()); - nativeImageDirTmp.delete(); - } catch (Throwable t) { - MessageCollectorUtil.reportException(messageCollector, t); - deleteRecursive(nativeImageDirTmp); - return null; - } - } - } - } - return nativeImage; - } - - private static void deleteRecursive(File dir) { - try { - try (Stream<Path> paths = Files.walk(dir.toPath())) { - paths.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); - } - } catch (IOException e) { - } - } } |
