added a spike of a pure Java set of kotlin maven plugins which use the kotlin-compiler, build tools and associated dependencies from the Ant build. The kotlin-install module installs all the Ant build stuff into the local mvn repo, so they can be shaded and included into the plugin itself so it can be easily used from any mvn like build

This commit is contained in:
James Strachan
2012-03-29 20:48:06 +01:00
parent ec367a0bf0
commit abe72e5adc
11 changed files with 423 additions and 81 deletions
+129
View File
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven-plugin-anno.version>1.4.1</maven-plugin-anno.version>
<maven.version>3.0.4</maven.version>
</properties>
<parent>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-project</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>kotlin-install</artifactId>
<packaging>pom</packaging>
<description>Installs the Kotlin runtime dependencies into the local maven repo</description>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<executions>
<execution>
<id>org.jetbrains.kotlin:kotlin-compiler</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/kotlin-compiler.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>org.jetbrains.kotlin:kotlin-build-tools</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-build-tools</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/kotlin-build-tools.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>org.jetbrains.kotlin:intellij-core</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>intellij-core</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/intellij-core.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>org.jetbrains.kotlin:intellij-annotations</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>intellij-annotations</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/annotations.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>org.jetbrains.kotlin:trove4j</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>trove4j</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/trove4j.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
<execution>
<id>org.jetbrains.kotlin:picocontainer</id>
<phase>verify</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>picocontainer</artifactId>
<version>${project.version}</version>
<packaging>jar</packaging>
<file>${kotlin-sdk}/lib/picocontainer.jar</file>
<createChecksum>true</createChecksum>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
+1 -1
View File
@@ -1,4 +1,4 @@
## NOTE - this is just an initial spike so far as Kotlin doesn't support value annotations yet
## NOTE - this is just an initial spike of some maven plugins
Until this plugin is working, please use this maven plugin:
http://evgeny-goldin.com/wiki/Kotlin-maven-plugin
+120 -39
View File
@@ -16,61 +16,142 @@
</parent>
<artifactId>kotlin-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.jfrog.maven.annomojo</groupId>
<artifactId>maven-plugin-anno</artifactId>
<version>${maven-plugin-anno.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${maven.version}</version>
</dependency>
-->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>stdlib</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-compiler</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-build-tools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>intellij-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>intellij-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-tree</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>asm</groupId>
<artifactId>asm-util</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>trove4j</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>net.sf.trove4j</groupId>
<artifactId>trove4j</artifactId>
<version>3.0.2</version>
</dependency>
-->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>picocontainer</artifactId>
<version>${project.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.picocontainer</groupId>
<artifactId>picocontainer</artifactId>
<version>2.9</version>
</dependency>
-->
</dependencies>
<build>
<plugins>
<sourceDirectory>src/main/java</sourceDirectory>
<testSourceDirectory>src/test/java</testSourceDirectory>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- AnnoMojo: http://wiki.jfrog.org/confluence/display/OSS/Maven+Anno+Mojo -->
<!-- http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin-plugin/ -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>2.9</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-tools-api</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jfrog.maven.annomojo</groupId>
<artifactId>maven-plugin-tools-anno</artifactId>
<version>${maven-plugin-anno.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!--
<createDependencyReducedPom>true</createDependencyReducedPom>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
-->
<artifactSet>
<includes>
<include>org.jetbrains.kotlin:*</include>
</includes>
<excludes>
<exclude>org.jetbrains.kotlin:stdlib</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>download</id>
<pluginRepositories>
<pluginRepository>
<id>jfrog-plugins</id>
<name>jfrog-plugins-dist</name>
<url>http://repo.jfrog.org/artifactory/plugins-releases</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</project>
@@ -0,0 +1,30 @@
package org.jetbrains.kotlin.maven;
import org.jetbrains.jet.cli.CompilerArguments;
/**
* Converts Kotlin to JavaScript code
*
* @goal js
* @phase compile
*/
public class K2JSCompilerMojo extends KotlinBaseMojo {
private String outFile;
@Override
protected void configureCompilerArguments(CompilerArguments arguments) {
super.configureCompilerArguments(arguments);
K2JSCompilerPlugin plugin = new K2JSCompilerPlugin();
plugin.setOutFile(outFile);
arguments.getCompilerPlugins().add(plugin);
getLog().info("Compiling Kotlin src from " + arguments.getSrc() + " to JavaScript at: " + outFile);
}
@Override
protected CompilerArguments createCompilerArguments() {
CompilerArguments answer = new CompilerArguments();
return answer;
}
}
@@ -0,0 +1,79 @@
package org.jetbrains.kotlin.maven;
import com.intellij.openapi.project.Project;
import jet.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.compiler.CompilerPlugin;
import org.jetbrains.jet.compiler.CompilerPluginContext;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.k2js.config.Config;
import org.jetbrains.k2js.facade.K2JSTranslator;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import static kotlin.io.namespace.use;
/**
* Compiles Kotlin code to JavaScript
*/
public class K2JSCompilerPlugin implements CompilerPlugin {
/**
* @required
* @parameter default-value="${project.build.directory}/target/js/${project.artifactId}.js"
*/
private String outFile = "target/js/program.js";
public void processFiles(CompilerPluginContext context) {
if (context != null) {
Project project = context.getProject();
BindingContext bindingContext = context.getContext();
List<JetFile> sources = context.getFiles();
if (bindingContext != null && sources != null && project != null) {
Config config = new Config(project) {
@NotNull
@Override
public List<JetFile> getLibFiles() {
// TODO
return null;
}
};
K2JSTranslator translator = new K2JSTranslator(config);
final String code = translator.generateProgramCode(sources);
File file = new File(outFile);
File outDir = file.getParentFile();
if (outDir != null && !outDir.exists()) {
outDir.mkdirs();
}
try {
use(new FileWriter(file), new Function1<FileWriter, Object>() {
@Override
public Object invoke(FileWriter writer) {
try {
writer.write(code);
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
});
} catch (IOException e) {
System.out.println("Error: " + e);
e.printStackTrace();
}
}
}
}
public String getOutFile() {
return outFile;
}
public void setOutFile(String outFile) {
this.outFile = outFile;
}
}
@@ -0,0 +1,51 @@
package org.jetbrains.kotlin.maven;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.jetbrains.jet.cli.CompilerArguments;
import org.jetbrains.jet.cli.KotlinCompiler;
/**
* Abstract base class for Kotlin maven plugins
*/
public abstract class KotlinBaseMojo extends AbstractMojo {
private KotlinCompiler compiler = new KotlinCompiler();
private CompilerArguments arguments;
/**
* The source directory to compile
*
* @required
* @parameter default-value="${basedir}/src/main/kotlin"
*/
private String src;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
arguments = createCompilerArguments();
if (src != null) {
arguments.setSrc(src);
}
configureCompilerArguments(arguments);
compiler.exec(System.err, arguments);
}
/**
* Derived classes can create custom compiler argument implementations
* such as for KDoc
*/
protected CompilerArguments createCompilerArguments() {
return new CompilerArguments();
}
/**
* Derived classes can register custom plugins or configurations
*/
protected void configureCompilerArguments(CompilerArguments arguments) {
}
}
@@ -1,17 +0,0 @@
package org.jetbrains.kotlin.maven
import org.jfrog.maven.annomojo.annotations.*
import org.apache.maven.plugin.AbstractMojo
/**
* Kotlin compiler mojo
*/
[MojoGoal("compile")]
[MojoPhase( "compile" )]
[MojoRequiresDependencyResolution( "compile" )]
class KotlinCompileMojo() : KotlinMojoSupport() {
override fun execute() {
println("===== Kotlin maven compiler!!! src = $src")
}
}
@@ -1,15 +0,0 @@
package org.jetbrains.kotlin.maven
import org.jfrog.maven.annomojo.annotations.*
/**
* Base class for Kotlin compiler plugins
*/
import org.apache.maven.plugin.AbstractMojo
import java.lang.String
abstract class KotlinMojoSupport : AbstractMojo() {
[MojoParameter(required = false)]
public var src: String? = null
}
@@ -0,0 +1,10 @@
package org.jetbrains.kotlin.maven;
import org.junit.Test;
public class MojoTest {
@Test
public void dummy() {
}
}
@@ -1,9 +0,0 @@
package test.org.jetbrains.kotlin.maven
import junit.framework.TestCase
class MojoTest: TestCase() {
fun testFoo() {
}
}
+3
View File
@@ -21,6 +21,8 @@
<pegdown.version>1.1.0</pegdown.version>
<surefire-version>2.5</surefire-version>
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
<asm.version>3.3.1</asm.version>
<guava.version>11.0.2</guava.version>
</properties>
@@ -41,6 +43,7 @@
<modules>
<module>kotlin-install</module>
<module>kunit</module>
<module>stdlib</module>
<module>kdoc</module>