Package .js library file into plugin
This commit is contained in:
@@ -141,6 +141,7 @@
|
||||
<jar jarfile="${kotlin-home}/lib/kotlin-jslib.jar">
|
||||
<fileset dir = "${basedir}/js/js.libraries/src"/>
|
||||
</jar>
|
||||
<copyfile src="${basedir}/js/js.translator/testFiles/kotlin_lib.js" dest="${kotlin-home}/lib/kotlinLib.js"/>
|
||||
</target>
|
||||
|
||||
<target name="compiler">
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.util.List;
|
||||
public class PathUtil {
|
||||
|
||||
public static String JS_LIB_JAR_NAME = "kotlin-jslib.jar";
|
||||
public static String JS_LIB_JS_NAME = "kotlinLib.js";
|
||||
|
||||
private PathUtil() {}
|
||||
|
||||
@@ -72,9 +73,13 @@ public class PathUtil {
|
||||
return getFilePackedIntoLib("kotlin-runtime.jar");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getDefaultJsLibJsPath() {
|
||||
return getFilePackedIntoLib(JS_LIB_JS_NAME);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static File getDefaultJsLibPath() {
|
||||
public static File getDefaultJsLibJarPath() {
|
||||
return getFilePackedIntoLib(JS_LIB_JAR_NAME);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ import org.jetbrains.jet.utils.PathUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.plugin.k2jsrun.K2JSRunnerUtils.copyFileToDir;
|
||||
|
||||
@@ -49,19 +51,13 @@ public final class JsModuleSetUp {
|
||||
return;
|
||||
}
|
||||
|
||||
File jsLibPath = PathUtil.getDefaultJsLibPath();
|
||||
if (jsLibPath == null) {
|
||||
notifyFailure("JavaScript library not found. Make sure plugin is installed properly.");
|
||||
return;
|
||||
}
|
||||
|
||||
File rootDir = getRootDir(project);
|
||||
if (!rootDir.isDirectory()) {
|
||||
notifyFailure("Internal error: Broken content root.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!copyJsLib(jsLibPath, rootDir)) return;
|
||||
if (!copyJsLibFiles(rootDir)) return;
|
||||
|
||||
File file = new File(rootDir, JsModuleDetector.INDICATION_FILE_NAME);
|
||||
if (file.exists()) {
|
||||
@@ -74,8 +70,19 @@ public final class JsModuleSetUp {
|
||||
refreshRootDir(project);
|
||||
}
|
||||
|
||||
private static boolean copyJsLibFiles(@NotNull File rootDir) {
|
||||
File jsLibJarPath = PathUtil.getDefaultJsLibJarPath();
|
||||
File jsLibJsPath = PathUtil.getDefaultJsLibJsPath();
|
||||
if ((jsLibJarPath == null) || (jsLibJsPath == null)) {
|
||||
notifyFailure("JavaScript library not found. Make sure plugin is installed properly.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return doCopyJsLibFiles(Arrays.asList(jsLibJarPath, jsLibJsPath), rootDir);
|
||||
}
|
||||
|
||||
private static void refreshRootDir(@NotNull Project project) {
|
||||
getContentRoot(project).refresh(false, false);
|
||||
getContentRoot(project).refresh(false, true);
|
||||
}
|
||||
|
||||
private static void createIndicationFile(@NotNull File file) {
|
||||
@@ -87,9 +94,12 @@ public final class JsModuleSetUp {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean copyJsLib(@NotNull File jsLibPath, @NotNull File rootDir) {
|
||||
private static boolean doCopyJsLibFiles(@NotNull List<File> files, @NotNull File rootDir) {
|
||||
try {
|
||||
copyFileToDir(jsLibPath, new File(rootDir, "lib"));
|
||||
File lib = new File(rootDir, "lib");
|
||||
for (File file : files) {
|
||||
copyFileToDir(file, lib);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
notifyFailure("Failed to copy file: " + e.getMessage());
|
||||
|
||||
@@ -353,8 +353,7 @@ var Kotlin;
|
||||
});
|
||||
|
||||
|
||||
Kotlin.parseInt =
|
||||
function (str) {
|
||||
Kotlin.parseInt = function (str) {
|
||||
return parseInt(str, 10);
|
||||
}
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user