refactored the maven project structure so that things are in a simpler tree structure to avoid folks getting lost
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
## 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
|
||||
@@ -0,0 +1,170 @@
|
||||
<?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>tools</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
|
||||
<dependencies>
|
||||
<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>kotlin-compiler</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>runtime</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>
|
||||
|
||||
<!-- TODO Req. only for K2JSTranslator, move it to compiler -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-build-tools</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Shall be transitive dependencies of Kotlin compiler -->
|
||||
<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>
|
||||
-->
|
||||
|
||||
|
||||
<!-- for JS generation -->
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>dartc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<testSourceDirectory>src/test/java</testSourceDirectory>
|
||||
|
||||
<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>
|
||||
</plugin>
|
||||
|
||||
<!-- Get rid of it right after compiler careful packaging -->
|
||||
<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>
|
||||
</project>
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.jetbrains.jet.cli.CompilerArguments;
|
||||
|
||||
/**
|
||||
* Converts Kotlin to JavaScript code
|
||||
*
|
||||
* @goal js
|
||||
* @phase compile
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public class K2JSCompilerMojo extends KotlinCompileMojo {
|
||||
/**
|
||||
* The output JS file name
|
||||
*
|
||||
* @required
|
||||
* @parameter default-value="${project.build.directory}/js/${project.artifactId}.js"
|
||||
*/
|
||||
private String outFile;
|
||||
|
||||
@Override
|
||||
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
|
||||
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);
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.openapi.project.Project;
|
||||
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.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Compiles Kotlin code to JavaScript
|
||||
*/
|
||||
public class K2JSCompilerPlugin implements CompilerPlugin {
|
||||
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() {
|
||||
return new ArrayList<JetFile>();
|
||||
}
|
||||
};
|
||||
|
||||
K2JSTranslator translator = new K2JSTranslator(config);
|
||||
final String code = translator.generateProgramCode(sources);
|
||||
|
||||
File file = new File(outFile);
|
||||
|
||||
try {
|
||||
Files.createParentDirs(file);
|
||||
Files.write(code, file, Charset.forName("UTF-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setOutFile(String outFile) {
|
||||
this.outFile = outFile;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.jetbrains.jet.cli.CompilerArguments;
|
||||
|
||||
/**
|
||||
* Compiles kotlin sources
|
||||
*
|
||||
* @goal compile
|
||||
* @phase compile
|
||||
* @requiresDependencyResolution compile
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public class KotlinCompileMojo extends KotlinCompileMojoBase {
|
||||
@Override
|
||||
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
|
||||
configureBaseCompilerArguments(getLog(), arguments, module, sources, classpath, output);
|
||||
}
|
||||
}
|
||||
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugin.logging.Log;
|
||||
import org.jetbrains.jet.cli.CompilerArguments;
|
||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
||||
/**
|
||||
* The source directories containing the sources to be compiled.
|
||||
*
|
||||
* @parameter default-value="${project.compileSourceRoots}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
public List<String> sources;
|
||||
|
||||
/**
|
||||
* The source directories containing the sources to be compiled for tests.
|
||||
*
|
||||
* @parameter default-value="${project.testCompileSourceRoots}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected List<String> testSources;
|
||||
|
||||
/**
|
||||
* Project classpath.
|
||||
*
|
||||
* @parameter default-value="${project.compileClasspathElements}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
public List<String> classpath;
|
||||
|
||||
/**
|
||||
* Project test classpath.
|
||||
*
|
||||
* @parameter default-value="${project.testClasspathElements}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
protected List<String> testClasspath;
|
||||
|
||||
/**
|
||||
* The directory for compiled classes.
|
||||
*
|
||||
* @parameter default-value="${project.build.outputDirectory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
public String output;
|
||||
|
||||
/**
|
||||
* The directory for compiled tests classes.
|
||||
*
|
||||
* @parameter default-value="${project.build.testOutputDirectory}"
|
||||
* @required
|
||||
* @readonly
|
||||
*/
|
||||
public String testOutput;
|
||||
|
||||
/**
|
||||
* Kotlin compilation module, as alternative to source files or folders.
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
public String module;
|
||||
|
||||
/**
|
||||
* Kotlin compilation module, as alternative to source files or folders (for tests).
|
||||
*
|
||||
* @parameter
|
||||
*/
|
||||
public String testModule;
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
final CompilerArguments arguments = createCompilerArguments();
|
||||
|
||||
configureCompilerArguments(arguments);
|
||||
|
||||
final KotlinCompiler compiler = createCompiler();
|
||||
|
||||
final KotlinCompiler.ExitCode exitCode = compiler.exec(System.err, arguments);
|
||||
|
||||
switch (exitCode) {
|
||||
case COMPILATION_ERROR:
|
||||
throw new MojoExecutionException("Compilation error. See log for more details");
|
||||
|
||||
case INTERNAL_ERROR:
|
||||
throw new MojoExecutionException("Internal compiler error. See log for more details");
|
||||
}
|
||||
}
|
||||
|
||||
protected KotlinCompiler createCompiler() {
|
||||
return new KotlinCompiler();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 abstract void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException;
|
||||
|
||||
protected static void configureBaseCompilerArguments(Log log, CompilerArguments arguments, String module,
|
||||
List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
|
||||
if (module != null) {
|
||||
log.info("Compiling Kotlin module " + module);
|
||||
arguments.setModule(module);
|
||||
} else {
|
||||
if (sources.size() <= 0)
|
||||
throw new MojoExecutionException("No source roots to compile");
|
||||
|
||||
arguments.setSourceDirs(sources);
|
||||
log.info("Compiling Kotlin sources from " + arguments.getSourceDirs());
|
||||
}
|
||||
|
||||
final ArrayList<String> classpathList = new ArrayList<String>(classpath);
|
||||
|
||||
if (classpathList.remove(output)) {
|
||||
log.debug("Removed target directory from classpath (" + output + ")");
|
||||
}
|
||||
|
||||
final String classPathString = Joiner.on(File.pathSeparator).join(classpathList);
|
||||
log.info("Classpath: " + classPathString);
|
||||
arguments.setClasspath(classPathString);
|
||||
|
||||
log.info("Classes directory is " + output);
|
||||
arguments.setOutputDir(output);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.jetbrains.jet.cli.CompilerArguments;
|
||||
|
||||
/**
|
||||
* Compiles Kotlin test sources
|
||||
*
|
||||
* @goal test-compile
|
||||
* @phase test-compile
|
||||
* @requiresDependencyResolution test
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
|
||||
/**
|
||||
* Flag to allow test compilation to be skipped.
|
||||
*
|
||||
* @parameter expression="${maven.test.skip}" default-value="false"
|
||||
* @noinspection UnusedDeclaration
|
||||
*/
|
||||
private boolean skip;
|
||||
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
if (skip) {
|
||||
getLog().info("Test compilation is skipped");
|
||||
} else {
|
||||
super.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configureCompilerArguments(CompilerArguments arguments) throws MojoExecutionException {
|
||||
configureBaseCompilerArguments(
|
||||
getLog(), arguments,
|
||||
testModule, testSources, testClasspath, testOutput);
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.kotlin.maven;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class MojoTest {
|
||||
@Test
|
||||
public void dummy() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user