Refactoring kotlin-maven-plugin:
* cleanup KotlinCompileMojoBase moved JVM specific things to KotlinCompileMojo; * add support noInline in JS.
This commit is contained in:
+25
-62
@@ -17,16 +17,16 @@
|
|||||||
package org.jetbrains.kotlin.maven.doc;
|
package org.jetbrains.kotlin.maven.doc;
|
||||||
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
import org.jetbrains.jet.cli.common.CLICompiler;
|
||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||||
import org.jetbrains.kotlin.doc.KDocArguments;
|
import org.jetbrains.kotlin.doc.KDocArguments;
|
||||||
import org.jetbrains.kotlin.doc.KDocCompiler;
|
import org.jetbrains.kotlin.doc.KDocCompiler;
|
||||||
import org.jetbrains.kotlin.doc.KDocConfig;
|
import org.jetbrains.kotlin.doc.KDocConfig;
|
||||||
import org.jetbrains.kotlin.maven.KotlinCompileMojoBase;
|
import org.jetbrains.kotlin.maven.K2JVMCompileMojo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -39,45 +39,7 @@ import java.util.Map;
|
|||||||
* @requiresDependencyResolution test
|
* @requiresDependencyResolution test
|
||||||
* @noinspection UnusedDeclaration
|
* @noinspection UnusedDeclaration
|
||||||
*/
|
*/
|
||||||
public class KDocMojo extends KotlinCompileMojoBase {
|
public class KDocMojo extends K2JVMCompileMojo {
|
||||||
|
|
||||||
/**
|
|
||||||
* 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 apidoc classes.
|
|
||||||
*
|
|
||||||
* @parameter default-value="${project.build.outputDirectory}"
|
|
||||||
* @required
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
public String output;
|
|
||||||
|
|
||||||
// TODO not sure why this doesn't work :(
|
|
||||||
// * @parameter default-value="$(project.basedir}/src/main/resources"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The directories used to scan for annotation.xml files for Kotlin annotations
|
|
||||||
*
|
|
||||||
* @parameter
|
|
||||||
*/
|
|
||||||
public List<String> annotationPaths;
|
|
||||||
|
|
||||||
// TODO not sure why default is stopping us passing this value in via a config
|
// TODO not sure why default is stopping us passing this value in via a config
|
||||||
// default-value="${project.compileSourceRoots}"
|
// default-value="${project.compileSourceRoots}"
|
||||||
|
|
||||||
@@ -176,6 +138,11 @@ public class KDocMojo extends KotlinCompileMojoBase {
|
|||||||
*/
|
*/
|
||||||
private Map<String, String> packageSummaryText;
|
private Map<String, String> packageSummaryText;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getSources() {
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected K2JVMCompiler createCompiler() {
|
protected K2JVMCompiler createCompiler() {
|
||||||
return new KDocCompiler();
|
return new KDocCompiler();
|
||||||
@@ -187,10 +154,11 @@ public class KDocMojo extends KotlinCompileMojoBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NotNull
|
||||||
protected ExitCode executeCompiler(
|
protected ExitCode executeCompiler(
|
||||||
CLICompiler compiler,
|
@NotNull CLICompiler<K2JVMCompilerArguments> compiler,
|
||||||
CommonCompilerArguments arguments,
|
@NotNull K2JVMCompilerArguments arguments,
|
||||||
MessageCollector messageCollector
|
@NotNull MessageCollector messageCollector
|
||||||
) {
|
) {
|
||||||
ExitCode exitCode = super.executeCompiler(compiler, arguments, messageCollector);
|
ExitCode exitCode = super.executeCompiler(compiler, arguments, messageCollector);
|
||||||
if (exitCode == ExitCode.COMPILATION_ERROR) {
|
if (exitCode == ExitCode.COMPILATION_ERROR) {
|
||||||
@@ -202,11 +170,7 @@ public class KDocMojo extends KotlinCompileMojoBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
||||||
if (arguments instanceof K2JVMCompilerArguments) {
|
|
||||||
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, docModule, sources, classpath, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arguments instanceof KDocArguments) {
|
if (arguments instanceof KDocArguments) {
|
||||||
KDocArguments kdoc = (KDocArguments) arguments;
|
KDocArguments kdoc = (KDocArguments) arguments;
|
||||||
KDocConfig docConfig = kdoc.getDocConfig();
|
KDocConfig docConfig = kdoc.getDocConfig();
|
||||||
@@ -215,8 +179,6 @@ public class KDocMojo extends KotlinCompileMojoBase {
|
|||||||
kdoc.noJdkAnnotations = true;
|
kdoc.noJdkAnnotations = true;
|
||||||
kdoc.annotations = getFullAnnotationsPath(getLog(), annotationPaths);
|
kdoc.annotations = getFullAnnotationsPath(getLog(), annotationPaths);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ignorePackages != null) {
|
if (ignorePackages != null) {
|
||||||
docConfig.getIgnorePackages().addAll(ignorePackages);
|
docConfig.getIgnorePackages().addAll(ignorePackages);
|
||||||
}
|
}
|
||||||
@@ -235,19 +197,20 @@ public class KDocMojo extends KotlinCompileMojoBase {
|
|||||||
docConfig.setWarnNoComments(warnNoComments);
|
docConfig.setWarnNoComments(warnNoComments);
|
||||||
docConfig.setSourceRootHref(sourceRootHref);
|
docConfig.setSourceRootHref(sourceRootHref);
|
||||||
docConfig.setProjectRootDir(projectRootDir);
|
docConfig.setProjectRootDir(projectRootDir);
|
||||||
getLog().info("API docs output to: " + docConfig.getDocOutputDir());
|
|
||||||
getLog().info("classpath: " + classpath);
|
LOG.info("API docs output to: " + docConfig.getDocOutputDir());
|
||||||
getLog().info("title: " + title);
|
LOG.info("classpath: " + classpath);
|
||||||
getLog().info("sources: " + sources);
|
LOG.info("title: " + title);
|
||||||
getLog().info("sourceRootHref: " + sourceRootHref);
|
LOG.info("sources: " + sources);
|
||||||
getLog().info("projectRootDir: " + projectRootDir);
|
LOG.info("sourceRootHref: " + sourceRootHref);
|
||||||
getLog().info("kotlin annotations: " + kdoc.annotations);
|
LOG.info("projectRootDir: " + projectRootDir);
|
||||||
getLog().info("packageDescriptionFiles: " + packageDescriptionFiles);
|
LOG.info("kotlin annotations: " + kdoc.annotations);
|
||||||
getLog().info("packagePrefixToUrls: " + packagePrefixToUrls);
|
LOG.info("packageDescriptionFiles: " + packageDescriptionFiles);
|
||||||
getLog().info("API docs ignore packages: " + ignorePackages);
|
LOG.info("packagePrefixToUrls: " + packagePrefixToUrls);
|
||||||
|
LOG.info("API docs ignore packages: " + ignorePackages);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getLog().warn("No KDocArguments available!");
|
LOG.warn("No KDocArguments available!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,11 @@
|
|||||||
<artifactId>kotlin-runtime</artifactId>
|
<artifactId>kotlin-runtime</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-js-library</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-project</artifactId>
|
||||||
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>test-js-extraArguments</artifactId>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>kotlin-maven-plugin</artifactId>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
<artifactId>kotlin-js-library</artifactId>
|
||||||
|
<version>${project.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>compile</id>
|
||||||
|
<goals>
|
||||||
|
<goal>js</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<args>
|
||||||
|
<arg>-Xno-inline</arg>
|
||||||
|
</args>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package org.jetbrains
|
||||||
|
|
||||||
|
fun main(args : Array<String>) {
|
||||||
|
println(getGreeting())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getGreeting() : String {
|
||||||
|
return "Hello, World!"
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
+19
-29
@@ -21,8 +21,7 @@ import com.google.common.io.InputSupplier;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.jetbrains.jet.cli.common.CLICompiler;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments;
|
import org.jetbrains.jet.cli.common.arguments.K2JSCompilerArguments;
|
||||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||||
import org.jetbrains.k2js.config.MetaInfServices;
|
import org.jetbrains.k2js.config.MetaInfServices;
|
||||||
@@ -31,7 +30,6 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts Kotlin to JavaScript code
|
* Converts Kotlin to JavaScript code
|
||||||
@@ -40,11 +38,10 @@ import java.util.List;
|
|||||||
* @phase compile
|
* @phase compile
|
||||||
* @noinspection UnusedDeclaration
|
* @noinspection UnusedDeclaration
|
||||||
*/
|
*/
|
||||||
public class K2JSCompilerMojo extends KotlinCompileMojo {
|
public class K2JSCompilerMojo extends KotlinCompileMojoBase<K2JSCompilerArguments> {
|
||||||
public static final String KOTLIN_JS_MAPS = "kotlin-maps.js";
|
public static final String KOTLIN_JS_MAPS = "kotlin-maps.js";
|
||||||
public static final String KOTLIN_JS_LONG = "kotlin-long.js";
|
public static final String KOTLIN_JS_LONG = "kotlin-long.js";
|
||||||
public static final String KOTLIN_JS_LIB = "kotlin-lib.js";
|
public static final String KOTLIN_JS_LIB = "kotlin-lib.js";
|
||||||
public static final String KOTLIN_JS_LIB_ECMA3 = "kotlin-lib-ecma3.js";
|
|
||||||
public static final String KOTLIN_JS_LIB_ECMA5 = "kotlin-lib-ecma5.js";
|
public static final String KOTLIN_JS_LIB_ECMA5 = "kotlin-lib-ecma5.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,13 +80,14 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
super.execute();
|
super.execute();
|
||||||
|
|
||||||
if (appendLibraryJS != null && appendLibraryJS) {
|
if (appendLibraryJS != null && appendLibraryJS) {
|
||||||
try {
|
try {
|
||||||
Charset charset = Charset.defaultCharset();
|
Charset charset = Charset.defaultCharset();
|
||||||
File file = new File(outputFile);
|
File file = new File(outputFile);
|
||||||
String text = Files.toString(file, charset);
|
String text = Files.toString(file, charset);
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
appendFile(KOTLIN_JS_LIB_ECMA3, builder);
|
appendFile(KOTLIN_JS_LIB_ECMA5, builder);
|
||||||
appendFile(KOTLIN_JS_LIB, builder);
|
appendFile(KOTLIN_JS_LIB, builder);
|
||||||
appendFile(KOTLIN_JS_MAPS, builder);
|
appendFile(KOTLIN_JS_MAPS, builder);
|
||||||
appendFile(KOTLIN_JS_LONG, builder);
|
appendFile(KOTLIN_JS_LONG, builder);
|
||||||
@@ -101,22 +99,21 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (copyLibraryJS != null && copyLibraryJS) {
|
if (copyLibraryJS != null && copyLibraryJS) {
|
||||||
getLog().info("Copying kotlin JS library to " + outputKotlinJSDir);
|
LOG.info("Copying kotlin JS library to " + outputKotlinJSDir);
|
||||||
|
|
||||||
copyJsLibraryFile(KOTLIN_JS_MAPS);
|
copyJsLibraryFile(KOTLIN_JS_MAPS);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LONG);
|
copyJsLibraryFile(KOTLIN_JS_LONG);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB);
|
copyJsLibraryFile(KOTLIN_JS_LIB);
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA3);
|
|
||||||
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA5);
|
copyJsLibraryFile(KOTLIN_JS_LIB_ECMA5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendFile(String jsLib, StringBuilder builder) throws MojoExecutionException {
|
private void appendFile(String jsLib, StringBuilder builder) throws MojoExecutionException {
|
||||||
// lets copy the kotlin library into the output directory
|
// lets copy the kotlin library into the output directory
|
||||||
try {
|
try {
|
||||||
final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib);
|
final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
System.out.println("WARNING: Could not find " + jsLib + " on the classpath!");
|
LOG.warn("Could not find " + jsLib + " on the classpath!");
|
||||||
} else {
|
} else {
|
||||||
InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
|
InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -132,14 +129,16 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void copyJsLibraryFile(String jsLib) throws MojoExecutionException {
|
private void copyJsLibraryFile(String jsLib) throws MojoExecutionException {
|
||||||
// lets copy the kotlin library into the output directory
|
|
||||||
try {
|
try {
|
||||||
outputKotlinJSDir.mkdirs();
|
|
||||||
final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib);
|
final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib);
|
||||||
if (inputStream == null) {
|
if (inputStream == null) {
|
||||||
System.out.println("WARNING: Could not find " + jsLib + " on the classpath!");
|
LOG.warn("Could not find " + jsLib + " on the classpath!");
|
||||||
} else {
|
} else {
|
||||||
|
if (!outputKotlinJSDir.exists() && !outputKotlinJSDir.mkdirs()) {
|
||||||
|
throw new MojoExecutionException("Could not create output directory '" + outputKotlinJSDir + "'.");
|
||||||
|
}
|
||||||
|
|
||||||
InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
|
InputSupplier<InputStream> inputSupplier = new InputSupplier<InputStream>() {
|
||||||
@Override
|
@Override
|
||||||
public InputStream getInput() throws IOException {
|
public InputStream getInput() throws IOException {
|
||||||
@@ -154,28 +153,19 @@ public class K2JSCompilerMojo extends KotlinCompileMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JSCompilerArguments arguments) throws MojoExecutionException {
|
||||||
super.configureCompilerArguments(arguments);
|
arguments.outputFile = outputFile;
|
||||||
|
|
||||||
if (arguments instanceof K2JSCompilerArguments) {
|
|
||||||
K2JSCompilerArguments k2jsArgs = (K2JSCompilerArguments)arguments;
|
|
||||||
k2jsArgs.outputFile = outputFile;
|
|
||||||
if (getLog().isDebugEnabled()) {
|
|
||||||
k2jsArgs.verbose = true;
|
|
||||||
}
|
|
||||||
List<String> sources = getSources();
|
|
||||||
k2jsArgs.freeArgs.addAll(sources);
|
|
||||||
getLog().info("Compiling Kotlin src from " + sources + " to JavaScript at: " + outputFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected CommonCompilerArguments createCompilerArguments() {
|
protected K2JSCompilerArguments createCompilerArguments() {
|
||||||
return new K2JSCompilerArguments();
|
return new K2JSCompilerArguments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected CLICompiler createCompiler() {
|
protected K2JSCompiler createCompiler() {
|
||||||
return new K2JSCompiler();
|
return new K2JSCompiler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+243
@@ -0,0 +1,243 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.util.ArrayUtil;
|
||||||
|
import com.sampullara.cli.Args;
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugin.logging.Log;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
||||||
|
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
import static com.intellij.openapi.util.text.StringUtil.join;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compiles kotlin sources
|
||||||
|
*
|
||||||
|
* @goal compile
|
||||||
|
* @phase compile
|
||||||
|
* @requiresDependencyResolution compile
|
||||||
|
* @noinspection UnusedDeclaration
|
||||||
|
*/
|
||||||
|
public class K2JVMCompileMojo extends KotlinCompileMojoBase<K2JVMCompilerArguments> {
|
||||||
|
/**
|
||||||
|
* The directories used to scan for annotation.xml files for Kotlin annotations
|
||||||
|
*
|
||||||
|
* @parameter
|
||||||
|
*/
|
||||||
|
public List<String> annotationPaths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @parameter default-value="true"
|
||||||
|
*/
|
||||||
|
public boolean scanForAnnotations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected K2JVMCompiler createCompiler() {
|
||||||
|
return new K2JVMCompiler();
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
protected K2JVMCompilerArguments createCompilerArguments() {
|
||||||
|
return new K2JVMCompilerArguments();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
||||||
|
LOG.info("Classes directory is " + output);
|
||||||
|
arguments.destination = output;
|
||||||
|
|
||||||
|
// don't include runtime, it should be in maven dependencies
|
||||||
|
arguments.noStdlib = true;
|
||||||
|
|
||||||
|
ArrayList<String> classpathList = new ArrayList<String>();
|
||||||
|
|
||||||
|
if (module != null) {
|
||||||
|
LOG.info("Compiling Kotlin module " + module);
|
||||||
|
arguments.module = module;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO: Move it compiler
|
||||||
|
classpathList.addAll(getSources());
|
||||||
|
}
|
||||||
|
|
||||||
|
classpathList.addAll(classpath);
|
||||||
|
|
||||||
|
if (classpathList.remove(output)) {
|
||||||
|
LOG.debug("Removed target directory from compiler classpath (" + output + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classpathList.size() > 0) {
|
||||||
|
String classPathString = join(classpathList, File.pathSeparator);
|
||||||
|
LOG.info("Classpath: " + classPathString);
|
||||||
|
arguments.classpath = classPathString;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG.info("Classes directory is " + output);
|
||||||
|
arguments.destination = output;
|
||||||
|
|
||||||
|
arguments.noJdkAnnotations = true;
|
||||||
|
arguments.annotations = getFullAnnotationsPath(LOG, annotationPaths);
|
||||||
|
LOG.info("Using kotlin annotations from " + arguments.annotations);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Args.parse(arguments, ArrayUtil.toStringArray(args));
|
||||||
|
}
|
||||||
|
catch (IllegalArgumentException e) {
|
||||||
|
throw new MojoExecutionException(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arguments.noOptimize) {
|
||||||
|
LOG.info("Optimization is turned off");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getFullAnnotationsPath(Log log, List<String> annotations) {
|
||||||
|
String jdkAnnotation = getJdkAnnotations().getPath();
|
||||||
|
|
||||||
|
List<String> list = new ArrayList<String>();
|
||||||
|
list.add(jdkAnnotation);
|
||||||
|
|
||||||
|
if (annotations != null) {
|
||||||
|
for (String annotationPath : annotations) {
|
||||||
|
if (new File(annotationPath).exists()) {
|
||||||
|
list.add(annotationPath);
|
||||||
|
} else {
|
||||||
|
log.info("annotation path " + annotationPath + " does not exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scanForAnnotations) {
|
||||||
|
for (String path : scanAnnotations(log)) {
|
||||||
|
if (!list.contains(path)) {
|
||||||
|
list.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return join(list, File.pathSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static File getJdkAnnotations() {
|
||||||
|
ClassLoader classLoader = KotlinCompileMojoBase.class.getClassLoader();
|
||||||
|
if (!(classLoader instanceof URLClassLoader)) {
|
||||||
|
throw new RuntimeException("Kotlin plugin`s class loader is not URLClassLoader");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (URL url : ((URLClassLoader) classLoader).getURLs()) {
|
||||||
|
String path = url.getPath();
|
||||||
|
if (StringUtil.isEmpty(path)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(path);
|
||||||
|
if (file.getName().startsWith("kotlin-jdk-annotations")) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException("Could not get jdk annotations from Kotlin plugin`s classpath");
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<String> scanAnnotations(Log log) {
|
||||||
|
List<String> annotations = new ArrayList<String>();
|
||||||
|
|
||||||
|
Set<Artifact> artifacts = project.getArtifacts();
|
||||||
|
for (Artifact artifact : artifacts) {
|
||||||
|
File file = artifact.getFile();
|
||||||
|
if (containsAnnotations(file, log)) {
|
||||||
|
log.info("Discovered kotlin annotations in: " + file);
|
||||||
|
try {
|
||||||
|
annotations.add(file.getCanonicalPath());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
log.warn("Error extracting canonical path from: " + file, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return annotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsAnnotations(File file, Log log) {
|
||||||
|
log.debug("Scanning for kotlin annotations in " + file);
|
||||||
|
|
||||||
|
ZipFile zipFile = null;
|
||||||
|
try {
|
||||||
|
zipFile = new ZipFile(file);
|
||||||
|
|
||||||
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
String name = entries.nextElement().getName();
|
||||||
|
if (name.endsWith("/annotations.xml")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
log.warn("Error reading contents of jar: " + file, e);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (zipFile != null) {
|
||||||
|
try {
|
||||||
|
zipFile.close();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
log.warn("Error closing: " + zipFile, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2013 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.common.arguments.CommonCompilerArguments;
|
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compiles kotlin sources
|
|
||||||
*
|
|
||||||
* @goal compile
|
|
||||||
* @phase compile
|
|
||||||
* @requiresDependencyResolution compile
|
|
||||||
* @noinspection UnusedDeclaration
|
|
||||||
*/
|
|
||||||
public class KotlinCompileMojo extends KotlinCompileMojoBase {
|
|
||||||
@Override
|
|
||||||
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
|
|
||||||
if (arguments instanceof K2JVMCompilerArguments) {
|
|
||||||
configureBaseCompilerArguments(getLog(), (K2JVMCompilerArguments) arguments, module, getSources(), classpath, output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
+32
-201
@@ -16,10 +16,8 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.maven;
|
package org.jetbrains.kotlin.maven;
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.sampullara.cli.Args;
|
import com.sampullara.cli.Args;
|
||||||
import org.apache.maven.artifact.Artifact;
|
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
@@ -30,25 +28,17 @@ import org.jetbrains.jet.cli.common.CLICompiler;
|
|||||||
import org.jetbrains.jet.cli.common.ExitCode;
|
import org.jetbrains.jet.cli.common.ExitCode;
|
||||||
import org.jetbrains.jet.cli.common.KotlinVersion;
|
import org.jetbrains.jet.cli.common.KotlinVersion;
|
||||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
|
||||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
||||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
|
||||||
import org.jetbrains.jet.config.Services;
|
import org.jetbrains.jet.config.Services;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.util.Arrays;
|
||||||
import java.net.URLClassLoader;
|
import java.util.List;
|
||||||
import java.util.*;
|
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
|
|
||||||
import static com.intellij.openapi.util.text.StringUtil.join;
|
public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> extends AbstractMojo {
|
||||||
|
|
||||||
public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|
||||||
// TODO it would be nice to avoid using 2 injected fields for sources
|
// TODO it would be nice to avoid using 2 injected fields for sources
|
||||||
// but I've not figured out how to have a defaulted parameter value
|
// but I've not figured out how to have a defaulted parameter value
|
||||||
// which is also customisable inside an <execution> in a maven pom.xml
|
// which is also customisable inside an <execution> in a maven pom.xml
|
||||||
@@ -74,13 +64,6 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
return defaultSourceDirs;
|
return defaultSourceDirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The directories used to scan for annotation.xml files for Kotlin annotations
|
|
||||||
*
|
|
||||||
* @parameter
|
|
||||||
*/
|
|
||||||
public List<String> annotationPaths;
|
|
||||||
|
|
||||||
// TODO not sure why this doesn't work :(
|
// TODO not sure why this doesn't work :(
|
||||||
// * @parameter default-value="$(project.basedir}/src/main/resources"
|
// * @parameter default-value="$(project.basedir}/src/main/resources"
|
||||||
|
|
||||||
@@ -91,29 +74,6 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
*/
|
*/
|
||||||
public MavenProject project;
|
public MavenProject project;
|
||||||
|
|
||||||
/**
|
|
||||||
* @parameter default-value="true"
|
|
||||||
*/
|
|
||||||
public boolean scanForAnnotations;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* The directory for compiled classes.
|
||||||
*
|
*
|
||||||
@@ -153,9 +113,12 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
*/
|
*/
|
||||||
public List<String> args;
|
public List<String> args;
|
||||||
|
|
||||||
|
protected final Log LOG = getLog();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
getLog().info("Kotlin Compiler version " + KotlinVersion.VERSION);
|
|
||||||
|
LOG.info("Kotlin Compiler version " + KotlinVersion.VERSION);
|
||||||
|
|
||||||
// Check sources
|
// Check sources
|
||||||
List<String> sources = getSources();
|
List<String> sources = getSources();
|
||||||
@@ -170,18 +133,17 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!sourcesExists) {
|
if (!sourcesExists) {
|
||||||
getLog().warn( "No sources found skipping Kotlin compile" );
|
LOG.warn("No sources found skipping Kotlin compile");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonCompilerArguments arguments = createCompilerArguments();
|
A arguments = createCompilerArguments();
|
||||||
configureCompilerArguments(arguments);
|
configureCompilerArguments(arguments);
|
||||||
|
|
||||||
CLICompiler compiler = createCompiler();
|
CLICompiler<A> compiler = createCompiler();
|
||||||
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
printCompilerArgumentsIfDebugEnabled(arguments, compiler);
|
||||||
|
|
||||||
final Log log = getLog();
|
|
||||||
MessageCollector messageCollector = new MessageCollector() {
|
MessageCollector messageCollector = new MessageCollector() {
|
||||||
@Override
|
@Override
|
||||||
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
public void report(@NotNull CompilerMessageSeverity severity, @NotNull String message, @NotNull CompilerMessageLocation location) {
|
||||||
@@ -191,13 +153,13 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
String text = position + message;
|
String text = position + message;
|
||||||
|
|
||||||
if (CompilerMessageSeverity.VERBOSE.contains(severity)) {
|
if (CompilerMessageSeverity.VERBOSE.contains(severity)) {
|
||||||
log.debug(text);
|
LOG.debug(text);
|
||||||
} else if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
} else if (CompilerMessageSeverity.ERRORS.contains(severity)) {
|
||||||
log.error(text);
|
LOG.error(text);
|
||||||
} else if (severity == CompilerMessageSeverity.INFO) {
|
} else if (severity == CompilerMessageSeverity.INFO) {
|
||||||
log.info(text);
|
LOG.info(text);
|
||||||
} else {
|
} else {
|
||||||
log.warn(text);
|
LOG.warn(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -213,7 +175,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printCompilerArgumentsIfDebugEnabled(CommonCompilerArguments arguments, CLICompiler compiler) {
|
private void printCompilerArgumentsIfDebugEnabled(@NotNull A arguments, @NotNull CLICompiler<A> compiler) {
|
||||||
if (getLog().isDebugEnabled()) {
|
if (getLog().isDebugEnabled()) {
|
||||||
getLog().debug("Invoking compiler " + compiler + " with arguments:");
|
getLog().debug("Invoking compiler " + compiler + " with arguments:");
|
||||||
try {
|
try {
|
||||||
@@ -242,22 +204,20 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CLICompiler createCompiler() {
|
@NotNull
|
||||||
return new K2JVMCompiler();
|
protected abstract CLICompiler<A> createCompiler();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derived classes can create custom compiler argument implementations
|
* Derived classes can create custom compiler argument implementations
|
||||||
* such as for KDoc
|
* such as for KDoc
|
||||||
*/
|
*/
|
||||||
protected CommonCompilerArguments createCompilerArguments() {
|
@NotNull
|
||||||
return new K2JVMCompilerArguments();
|
protected abstract A createCompilerArguments();
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected ExitCode executeCompiler(
|
protected ExitCode executeCompiler(
|
||||||
@NotNull CLICompiler compiler,
|
@NotNull CLICompiler<A> compiler,
|
||||||
@NotNull CommonCompilerArguments arguments,
|
@NotNull A arguments,
|
||||||
@NotNull MessageCollector messageCollector
|
@NotNull MessageCollector messageCollector
|
||||||
) {
|
) {
|
||||||
return compiler.exec(messageCollector, Services.EMPTY, arguments);
|
return compiler.exec(messageCollector, Services.EMPTY, arguments);
|
||||||
@@ -266,48 +226,22 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
/**
|
/**
|
||||||
* Derived classes can register custom plugins or configurations
|
* Derived classes can register custom plugins or configurations
|
||||||
*/
|
*/
|
||||||
protected abstract void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException;
|
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments) throws MojoExecutionException;
|
||||||
|
|
||||||
protected void configureBaseCompilerArguments(Log log, K2JVMCompilerArguments arguments, String module,
|
private void configureCompilerArguments(@NotNull A arguments) throws MojoExecutionException {
|
||||||
List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
|
if (LOG.isDebugEnabled()) {
|
||||||
// don't include runtime, it should be in maven dependencies
|
arguments.verbose = true;
|
||||||
arguments.noStdlib = true;
|
|
||||||
|
|
||||||
ArrayList<String> classpathList = new ArrayList<String>();
|
|
||||||
|
|
||||||
if (module != null) {
|
|
||||||
log.info("Compiling Kotlin module " + module);
|
|
||||||
arguments.module = module;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (sources.isEmpty())
|
|
||||||
throw new MojoExecutionException("No source roots to compile");
|
|
||||||
|
|
||||||
arguments.freeArgs.addAll(sources);
|
|
||||||
log.info("Compiling Kotlin sources from " + sources);
|
|
||||||
|
|
||||||
// TODO: Move it compiler
|
|
||||||
classpathList.addAll(sources);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
classpathList.addAll(classpath);
|
List<String> sources = getSources();
|
||||||
|
if (sources == null || sources.isEmpty()) {
|
||||||
if (classpathList.remove(output)) {
|
throw new MojoExecutionException("No source roots to compile");
|
||||||
log.debug("Removed target directory from compiler classpath (" + output + ")");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classpathList.size() > 0) {
|
arguments.freeArgs.addAll(sources);
|
||||||
String classPathString = join(classpathList, File.pathSeparator);
|
LOG.info("Compiling Kotlin sources from " + sources );
|
||||||
log.info("Classpath: " + classPathString);
|
|
||||||
arguments.classpath = classPathString;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("Classes directory is " + output);
|
configureSpecificCompilerArguments(arguments);
|
||||||
arguments.destination = output;
|
|
||||||
|
|
||||||
arguments.noJdkAnnotations = true;
|
|
||||||
arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
|
|
||||||
log.info("Using kotlin annotations from " + arguments.annotations);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Args.parse(arguments, ArrayUtil.toStringArray(args));
|
Args.parse(arguments, ArrayUtil.toStringArray(args));
|
||||||
@@ -317,110 +251,7 @@ public abstract class KotlinCompileMojoBase extends AbstractMojo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.noInline) {
|
if (arguments.noInline) {
|
||||||
log.info("Method inlining is turned off");
|
LOG.info("Method inlining is turned off");
|
||||||
}
|
}
|
||||||
if (arguments.noOptimize) {
|
|
||||||
log.info("Optimization is turned off");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getFullAnnotationsPath(Log log, List<String> annotations) {
|
|
||||||
String jdkAnnotation = getJdkAnnotations().getPath();
|
|
||||||
|
|
||||||
List<String> list = new ArrayList<String>();
|
|
||||||
list.add(jdkAnnotation);
|
|
||||||
|
|
||||||
if (annotations != null) {
|
|
||||||
for (String annotationPath : annotations) {
|
|
||||||
if (new File(annotationPath).exists()) {
|
|
||||||
list.add(annotationPath);
|
|
||||||
} else {
|
|
||||||
log.info("annotation path " + annotationPath + " does not exist");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scanForAnnotations) {
|
|
||||||
for (String path : scanAnnotations(log)) {
|
|
||||||
if (!list.contains(path)) {
|
|
||||||
list.add(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return join(list, File.pathSeparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static File getJdkAnnotations() {
|
|
||||||
ClassLoader classLoader = KotlinCompileMojoBase.class.getClassLoader();
|
|
||||||
if (!(classLoader instanceof URLClassLoader)) {
|
|
||||||
throw new RuntimeException("Kotlin plugin`s class loader is not URLClassLoader");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (URL url : ((URLClassLoader) classLoader).getURLs()) {
|
|
||||||
String path = url.getPath();
|
|
||||||
if (StringUtil.isEmpty(path)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(path);
|
|
||||||
if (file.getName().startsWith("kotlin-jdk-annotations")) {
|
|
||||||
return file;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new RuntimeException("Could not get jdk annotations from Kotlin plugin`s classpath");
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<String> scanAnnotations(Log log) {
|
|
||||||
List<String> annotations = new ArrayList<String>();
|
|
||||||
|
|
||||||
Set<Artifact> artifacts = project.getArtifacts();
|
|
||||||
for (Artifact artifact : artifacts) {
|
|
||||||
File file = artifact.getFile();
|
|
||||||
if (containsAnnotations(file, log)) {
|
|
||||||
log.info("Discovered kotlin annotations in: " + file);
|
|
||||||
try {
|
|
||||||
annotations.add(file.getCanonicalPath());
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
log.warn("Error extracting canonical path from: " + file, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return annotations;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean containsAnnotations(File file, Log log) {
|
|
||||||
log.debug("Scanning for kotlin annotations in " + file);
|
|
||||||
|
|
||||||
ZipFile zipFile = null;
|
|
||||||
try {
|
|
||||||
zipFile = new ZipFile(file);
|
|
||||||
|
|
||||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
|
||||||
while (entries.hasMoreElements()) {
|
|
||||||
String name = entries.nextElement().getName();
|
|
||||||
if (name.endsWith("/annotations.xml")) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
log.warn("Error reading contents of jar: " + file, e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (zipFile != null) {
|
|
||||||
try {
|
|
||||||
zipFile.close();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
log.warn("Error closing: " + zipFile, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-8
@@ -18,8 +18,9 @@ package org.jetbrains.kotlin.maven;
|
|||||||
|
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.jetbrains.jet.cli.common.arguments.CommonCompilerArguments;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
import org.jetbrains.jet.cli.common.arguments.K2JVMCompilerArguments;
|
||||||
|
import org.jetbrains.jet.cli.jvm.K2JVMCompiler;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ import java.util.List;
|
|||||||
* @requiresDependencyResolution test
|
* @requiresDependencyResolution test
|
||||||
* @noinspection UnusedDeclaration
|
* @noinspection UnusedDeclaration
|
||||||
*/
|
*/
|
||||||
public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
|
public class KotlinTestCompileMojo extends K2JVMCompileMojo {
|
||||||
/**
|
/**
|
||||||
* Flag to allow test compilation to be skipped.
|
* Flag to allow test compilation to be skipped.
|
||||||
*
|
*
|
||||||
@@ -86,11 +87,11 @@ public class KotlinTestCompileMojo extends KotlinCompileMojoBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configureCompilerArguments(CommonCompilerArguments arguments) throws MojoExecutionException {
|
protected void configureSpecificCompilerArguments(@NotNull K2JVMCompilerArguments arguments) throws MojoExecutionException {
|
||||||
if (arguments instanceof K2JVMCompilerArguments) {
|
module = testModule;
|
||||||
configureBaseCompilerArguments(
|
classpath = testClasspath;
|
||||||
getLog(), (K2JVMCompilerArguments) arguments,
|
output = testOutput;
|
||||||
testModule, getSources(), testClasspath, testOutput);
|
|
||||||
}
|
super.configureSpecificCompilerArguments(arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user