diff --git a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt index e69c4a2b6bb..05a25bc3057 100644 --- a/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt +++ b/libraries/tools/kotlin-gradle-plugin-core/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/Tasks.kt @@ -600,6 +600,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile() { args.outputPostfix = kotlinOptions.outputPostfix args.metaInfo = kotlinOptions.metaInfo args.kjsm = kotlinOptions.kjsm + args.moduleKind = kotlinOptions.moduleKind val kotlinJsLibsFromDependencies = project.configurations.getByName("compile") diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt index 30140274410..39070d3c47f 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/test/kotlin/org/jetbrains/kotlin/gradle/Kotlin2JsGradlePluginIT.kt @@ -61,6 +61,15 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() { } } + @Test + fun testModuleKind() { + val project = Project("kotlin2JsModuleKind", "2.10") + + project.build("runRhino") { + assertSuccessful() + } + } + @Test fun testNoOutputFileFails() { val project = Project("kotlin2JsNoOutputFileProject", "2.10") diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/amd.js b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/amd.js new file mode 100644 index 00000000000..ebb9c1278cd --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/amd.js @@ -0,0 +1,9 @@ +var amdModules = {}; +function define(moduleName, dependencies, body) { + var resolvedDependencies = []; + for (var i = 0; i < dependencies.length; ++i) { + resolvedDependencies.push(amdModules[dependencies[i]]); + } + amdModules[moduleName] = body.apply(body, resolvedDependencies); +} +define.amd = {}; \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/build.gradle b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/build.gradle new file mode 100644 index 00000000000..54af06112a5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/build.gradle @@ -0,0 +1,61 @@ +buildscript { + repositories { + mavenCentral() + maven { + url "file://" + pathToKotlinPlugin + } + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-SNAPSHOT" + } +} + +apply plugin: "kotlin2js" +apply plugin: 'java' + +def outDir = "${buildDir}/kotlin2js/main/" +compileKotlin2Js.kotlinOptions.moduleKind = "amd" +compileKotlin2Js.kotlinOptions.outputFile = outDir + "app.js" + +repositories { + maven { + url "file://" + pathToKotlinPlugin + } + mavenCentral() +} + +dependencies { + compile "org.jetbrains.kotlin:kotlin-js-library:1.1-SNAPSHOT" + compile "org.mozilla:rhino:1.7.7.1" +} + +task runRhino(type: JavaExec) { + classpath = sourceSets.main.runtimeClasspath + workingDir = "${buildDir}/kotlin2js/main/" + main = 'org.mozilla.javascript.tools.shell.Main' + args = ["-opt", "-1", "-f", "amd.js", "-f", "kotlin.js", "-f", "app.js", "-f", "check.js"] +} + +build.doLast { + configurations.compile.each { File file -> + copy { + includeEmptyDirs = false + + from zipTree(file.absolutePath) + into "${buildDir}/kotlin2js/main/" + include { fileTreeElement -> + def path = fileTreeElement.path + path.endsWith(".js") && (path.startsWith("META-INF/resources/") || !path.startsWith("META-INF/")) + } + } + } + copy { + from "." + include "amd.js" + include "check.js" + into "${buildDir}/kotlin2js/main/" + } +} + +runRhino.dependsOn build \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/check.js b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/check.js new file mode 100644 index 00000000000..90985ec44e6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/check.js @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +define("check", ["app"], function(app) { + if (app.foo.bar() != "OK") { + throw new Error("Unexpected result"); + } +}); \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt new file mode 100644 index 00000000000..ec5efeeb1e2 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin/src/test/resources/testProject/kotlin2JsModuleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package foo + +fun bar() = "OK" diff --git a/libraries/tools/kotlin-maven-plugin-test/pom.xml b/libraries/tools/kotlin-maven-plugin-test/pom.xml index 07d1fbe88cd..a5fbbe650d4 100644 --- a/libraries/tools/kotlin-maven-plugin-test/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/pom.xml @@ -56,6 +56,13 @@ maven-invoker-plugin 1.9 + + + org.mozilla + rhino + 1.7.7.1 + + src/it ${project.build.directory}/it diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/amd.js b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/amd.js new file mode 100644 index 00000000000..ebb9c1278cd --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/amd.js @@ -0,0 +1,9 @@ +var amdModules = {}; +function define(moduleName, dependencies, body) { + var resolvedDependencies = []; + for (var i = 0; i < dependencies.length; ++i) { + resolvedDependencies.push(amdModules[dependencies[i]]); + } + amdModules[moduleName] = body.apply(body, resolvedDependencies); +} +define.amd = {}; \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/check.js b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/check.js new file mode 100644 index 00000000000..decc2977b35 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/check.js @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +define("check", ["test-js-moduleKind"], function(app) { + if (app.foo.bar() != "OK") { + throw new Error("Unexpected result"); + } +}); \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml index c40f36e96a9..14ca5df6ac6 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.jetbrains.kotlin - test-js-extraArguments + test-js-moduleKind 1.0-SNAPSHOT @@ -35,6 +35,33 @@ umd + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + unpack + package + + unpack + + + + + org.jetbrains.kotlin + kotlin-js-library + ${kotlin.version} + jar + false + ${project.build.directory}/js/ + **/*.js + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt index f7c367dedc6..ec5efeeb1e2 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -14,12 +14,6 @@ * limitations under the License. */ -package org.jetbrains +package foo -fun main(args : Array) { - println(getGreeting()) -} - -fun getGreeting() : String { - return "Hello, World!" -} +fun bar() = "OK" diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh index b5da31475d7..6fc4473c9e5 100644 --- a/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh @@ -1,6 +1,15 @@ import java.io.*; +import org.mozilla.javascript.tools.shell.Main; -File file = new File(basedir, "target/js/test-js-extraArguments.js"); +File file = new File(basedir, "target/js/test-js-moduleKind.js"); if (!file.exists() || !file.isFile()) { throw new FileNotFoundException("Could not find generated JS : " + file); } + +String basePath = basedir.getPath(); +Main.main(new String[] { + "-O", "-1", + "-f", basePath + "/amd.js", + "-f", basePath + "/target/js/kotlin.js", + "-f", basePath + "/target/js/test-js-moduleKind.js", + "-f", basePath + "/check.js"})