From 496539d101239056d41ab169dff91111910b7721 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 22 Apr 2016 12:23:56 +0300 Subject: [PATCH] KT-3008 Add module kind attribute to Maven plugin. Fix tests from libraries subproject --- .../browser-example-with-library/sample.html | 2 +- .../examples/browser-example/sample.html | 2 +- .../kotlin/gradle/Kotlin2JsGradlePluginIT.kt | 2 +- .../src/it/test-js-moduleKind/pom.xml | 46 +++++++++++++++++++ .../main/kotlin/org/jetbrains/HelloWorld.kt | 25 ++++++++++ .../src/it/test-js-moduleKind/verify.bsh | 6 +++ .../kotlin/maven/K2JSCompilerMojo.java | 16 +++++++ 7 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh diff --git a/libraries/examples/browser-example-with-library/sample.html b/libraries/examples/browser-example-with-library/sample.html index 0c3cf97a246..573600fe9d0 100644 --- a/libraries/examples/browser-example-with-library/sample.html +++ b/libraries/examples/browser-example-with-library/sample.html @@ -18,7 +18,7 @@ any annotated methods with documentReady --> diff --git a/libraries/examples/browser-example/sample.html b/libraries/examples/browser-example/sample.html index f8c59c90eaf..4916584e96b 100644 --- a/libraries/examples/browser-example/sample.html +++ b/libraries/examples/browser-example/sample.html @@ -17,7 +17,7 @@ any annotated methods with documentReady --> 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 0334de032f7..30140274410 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 @@ -29,7 +29,7 @@ class Kotlin2JsGradlePluginIT : BaseGradleIT() { // into Rhino and running assertions on that. See https://github.com/abesto/kotlin/commit/120ec1bda3d95630189d4d33d0b2afb4253b5186 // for the (original) discussion on this. assertFileContains("libraryProject/build/kotlin2js/main/test-library.js", "Counter: Kotlin.createClass") - assertFileContains("mainProject/web/js/app.js", "var counter = new Kotlin.modules['test-library'].example.library.Counter(counterText);") + assertFileContains("mainProject/web/js/app.js", "var counter = new \$module\$test_library.example.library.Counter(counterText);") } project.build("build") { 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 new file mode 100644 index 00000000000..8b9ba81dfb9 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/pom.xml @@ -0,0 +1,46 @@ + + + 4.0.0 + + + org.jetbrains.kotlin + kotlin-project + 0.1-SNAPSHOT + ../../pom.xml + + + test-js-extraArguments + + + + org.jetbrains.kotlin + kotlin-js-library + ${project.version} + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${project.version} + + + compile + + js + + + + + umd + + + + + + 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 new file mode 100644 index 00000000000..f7c367dedc6 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,25 @@ +/* + * 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 org.jetbrains + +fun main(args : Array) { + println(getGreeting()) +} + +fun getGreeting() : String { + return "Hello, World!" +} 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 new file mode 100644 index 00000000000..b5da31475d7 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-js-moduleKind/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/js/test-js-extraArguments.js"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JS : " + file); +} diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java index 8559aa000b7..55b9cffc944 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java @@ -74,12 +74,28 @@ public class K2JSCompilerMojo extends KotlinCompileMojoBaseSpecifies which JS module system to generate compatible sources for. Options are:

+ *
    + *
  • amd — + * Asynchronous Module System;
  • + *
  • commonjs — npm/CommonJS conventions based on synchronous require + * function;
  • + *
  • plain (default) — no module system, keep all modules in global scope;
  • + *
  • umd — Universal Module Definition, stub wrapper that detects current + * module system in runtime and behaves as plain if none detected.
  • + *
+ */ + @Parameter(defaultValue = "plain") + private String moduleKind; + @Override protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException { arguments.outputFile = outputFile; arguments.noStdlib = true; arguments.metaInfo = metaInfo; arguments.kjsm = kjsm; + arguments.moduleKind = moduleKind; List libraries = getKotlinJavascriptLibraryFiles(); getLog().debug("libraryFiles: " + libraries);