JS: add support of JS module kind to Gradle task. Add tests of support of module kind to Maven tests
This commit is contained in:
+1
@@ -600,6 +600,7 @@ open class Kotlin2JsCompile() : AbstractKotlinCompile<K2JSCompilerArguments>() {
|
|||||||
args.outputPostfix = kotlinOptions.outputPostfix
|
args.outputPostfix = kotlinOptions.outputPostfix
|
||||||
args.metaInfo = kotlinOptions.metaInfo
|
args.metaInfo = kotlinOptions.metaInfo
|
||||||
args.kjsm = kotlinOptions.kjsm
|
args.kjsm = kotlinOptions.kjsm
|
||||||
|
args.moduleKind = kotlinOptions.moduleKind
|
||||||
|
|
||||||
val kotlinJsLibsFromDependencies =
|
val kotlinJsLibsFromDependencies =
|
||||||
project.configurations.getByName("compile")
|
project.configurations.getByName("compile")
|
||||||
|
|||||||
+9
@@ -61,6 +61,15 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testModuleKind() {
|
||||||
|
val project = Project("kotlin2JsModuleKind", "2.10")
|
||||||
|
|
||||||
|
project.build("runRhino") {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testNoOutputFileFails() {
|
fun testNoOutputFileFails() {
|
||||||
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
|
val project = Project("kotlin2JsNoOutputFileProject", "2.10")
|
||||||
|
|||||||
+9
@@ -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 = {};
|
||||||
+61
@@ -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
|
||||||
+21
@@ -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");
|
||||||
|
}
|
||||||
|
});
|
||||||
+19
@@ -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"
|
||||||
@@ -56,6 +56,13 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-invoker-plugin</artifactId>
|
<artifactId>maven-invoker-plugin</artifactId>
|
||||||
<version>1.9</version>
|
<version>1.9</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mozilla</groupId>
|
||||||
|
<artifactId>rhino</artifactId>
|
||||||
|
<version>1.7.7.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
<configuration>
|
<configuration>
|
||||||
<projectsDirectory>src/it</projectsDirectory>
|
<projectsDirectory>src/it</projectsDirectory>
|
||||||
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
<cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
|
||||||
|
|||||||
@@ -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 = {};
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>test-js-extraArguments</artifactId>
|
<artifactId>test-js-moduleKind</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -35,6 +35,33 @@
|
|||||||
<moduleKind>umd</moduleKind>
|
<moduleKind>umd</moduleKind>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>2.10</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>unpack</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>unpack</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-js-library</artifactId>
|
||||||
|
<version>${kotlin.version}</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<overWrite>false</overWrite>
|
||||||
|
<outputDirectory>${project.build.directory}/js/</outputDirectory>
|
||||||
|
<includes>**/*.js</includes>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
+2
-8
@@ -14,12 +14,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains
|
package foo
|
||||||
|
|
||||||
fun main(args : Array<String>) {
|
fun bar() = "OK"
|
||||||
println(getGreeting())
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getGreeting() : String {
|
|
||||||
return "Hello, World!"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
import java.io.*;
|
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()) {
|
if (!file.exists() || !file.isFile()) {
|
||||||
throw new FileNotFoundException("Could not find generated JS : " + file);
|
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"})
|
||||||
|
|||||||
Reference in New Issue
Block a user