added a basic working JS compiler maven plugin (though it doesn't currently let you specify any library files to compile)
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package sample
|
package sample
|
||||||
|
|
||||||
class Hello {
|
class Hello {
|
||||||
|
var x = 0
|
||||||
|
|
||||||
fun doSomething(): Unit {
|
fun doSomething(): Unit {
|
||||||
println("Hello world!")
|
x++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,6 +122,22 @@
|
|||||||
<generatePom>true</generatePom>
|
<generatePom>true</generatePom>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>org.jetbrains.kotlin:dartc</id>
|
||||||
|
<phase>verify</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>install-file</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>dartc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<file>${kotlin-sdk}/lib/js/dartc.jar</file>
|
||||||
|
<createChecksum>true</createChecksum>
|
||||||
|
<generatePom>true</generatePom>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@@ -107,6 +107,14 @@
|
|||||||
<version>2.9</version>
|
<version>2.9</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- for JS generation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>dartc</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src/main/java</sourceDirectory>
|
<sourceDirectory>src/main/java</sourceDirectory>
|
||||||
|
|||||||
+6
@@ -10,6 +10,12 @@ import org.jetbrains.jet.cli.CompilerArguments;
|
|||||||
*/
|
*/
|
||||||
public class K2JSCompilerMojo extends KotlinBaseMojo {
|
public class K2JSCompilerMojo extends KotlinBaseMojo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output JS file name
|
||||||
|
*
|
||||||
|
* @required
|
||||||
|
* @parameter default-value="${project.build.directory}/js/${project.artifactId}.js"
|
||||||
|
*/
|
||||||
private String outFile;
|
private String outFile;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+2
-6
@@ -13,6 +13,7 @@ import org.jetbrains.k2js.facade.K2JSTranslator;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static kotlin.io.namespace.use;
|
import static kotlin.io.namespace.use;
|
||||||
@@ -22,10 +23,6 @@ import static kotlin.io.namespace.use;
|
|||||||
*/
|
*/
|
||||||
public class K2JSCompilerPlugin implements CompilerPlugin {
|
public class K2JSCompilerPlugin implements CompilerPlugin {
|
||||||
|
|
||||||
/**
|
|
||||||
* @required
|
|
||||||
* @parameter default-value="${project.build.directory}/target/js/${project.artifactId}.js"
|
|
||||||
*/
|
|
||||||
private String outFile = "target/js/program.js";
|
private String outFile = "target/js/program.js";
|
||||||
|
|
||||||
public void processFiles(CompilerPluginContext context) {
|
public void processFiles(CompilerPluginContext context) {
|
||||||
@@ -38,8 +35,7 @@ public class K2JSCompilerPlugin implements CompilerPlugin {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public List<JetFile> getLibFiles() {
|
public List<JetFile> getLibFiles() {
|
||||||
// TODO
|
return new ArrayList<JetFile>();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
K2JSTranslator translator = new K2JSTranslator(config);
|
K2JSTranslator translator = new K2JSTranslator(config);
|
||||||
|
|||||||
+11
@@ -21,6 +21,14 @@ public abstract class KotlinBaseMojo extends AbstractMojo {
|
|||||||
*/
|
*/
|
||||||
private String src;
|
private String src;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The output directory for bytecode classes
|
||||||
|
*
|
||||||
|
* @required
|
||||||
|
* @parameter default-value="${project.build.directory}/classes"
|
||||||
|
*/
|
||||||
|
private String outputDir;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
arguments = createCompilerArguments();
|
arguments = createCompilerArguments();
|
||||||
@@ -28,6 +36,9 @@ public abstract class KotlinBaseMojo extends AbstractMojo {
|
|||||||
if (src != null) {
|
if (src != null) {
|
||||||
arguments.setSrc(src);
|
arguments.setSrc(src);
|
||||||
}
|
}
|
||||||
|
if (outputDir != null) {
|
||||||
|
arguments.setOutputDir(outputDir);
|
||||||
|
}
|
||||||
configureCompilerArguments(arguments);
|
configureCompilerArguments(arguments);
|
||||||
|
|
||||||
compiler.exec(System.err, arguments);
|
compiler.exec(System.err, arguments);
|
||||||
|
|||||||
Reference in New Issue
Block a user