diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/invoker.properties b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/invoker.properties new file mode 100644 index 00000000000..c21e972fc6b --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/invoker.properties @@ -0,0 +1 @@ +invoker.buildResult = failure diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/pom.xml new file mode 100644 index 00000000000..fb9a6c583f9 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-empty-argument + 1.0-SNAPSHOT + + + + junit + junit + 4.13.1 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-source-plugin + 2.1.2 + + + + + ${project.basedir}/src/main/kotlin + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + process-sources + + compile + + + + test-compile + process-test-sources + + test-compile + + + + + + + + + + + + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/main/kotlin/org/jetbrains/HelloWorld.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/main/kotlin/org/jetbrains/HelloWorld.kt new file mode 100644 index 00000000000..bc4fbf7504e --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/main/kotlin/org/jetbrains/HelloWorld.kt @@ -0,0 +1,9 @@ +package org.jetbrains + +fun main(args : Array) { + System.out?.println(getGreeting()) +} + +fun getGreeting() : String { + return "Hello, World!" +} \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/test/java/org/jetbrains/HelloWorldJavaTest.java b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/test/java/org/jetbrains/HelloWorldJavaTest.java new file mode 100644 index 00000000000..312e9ae713d --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/src/test/java/org/jetbrains/HelloWorldJavaTest.java @@ -0,0 +1,13 @@ +package org.jetbrains; + +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class HelloWorldJavaTest { + + @Test + public void greeting() { + assertEquals("Hello, World!", org.jetbrains.HelloWorldKt.getGreeting()); + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/verify.bsh new file mode 100644 index 00000000000..f479a656464 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-empty-argument/verify.bsh @@ -0,0 +1,4 @@ +source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath()); + +assertBuildLogHasLine("[INFO] BUILD FAILURE"); +assertBuildLogHasLineThatContains("Empty compiler argument passed in the section"); diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java index 45b2ae3d875..cef833cb168 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java @@ -251,19 +251,16 @@ public abstract class KotlinCompileMojoBase e String valueString; if (value instanceof Object[]) { valueString = Arrays.deepToString((Object[]) value); - } - else if (value != null) { + } else if (value != null) { valueString = String.valueOf(value); - } - else { + } else { valueString = "(null)"; } getLog().debug(f.getName() + "=" + valueString); } getLog().debug("End of arguments"); - } - catch (Exception e) { + } catch (Exception e) { getLog().warn("Failed to print compiler arguments: " + e, e); } } @@ -277,6 +274,7 @@ public abstract class KotlinCompileMojoBase e protected abstract void configureSpecificCompilerArguments(@NotNull A arguments, @NotNull List sourceRoots) throws MojoExecutionException; + @NotNull private List getCompilerPluginClassPaths() { ArrayList result = new ArrayList<>(); @@ -443,10 +441,13 @@ public abstract class KotlinCompileMojoBase e configureSpecificCompilerArguments(arguments, sourceRoots); + if (args != null && args.contains(null)) { + throw new MojoExecutionException("Empty compiler argument passed in the section"); + } + try { compiler.parseArguments(ArrayUtil.toStringArray(args), arguments); - } - catch (IllegalArgumentException e) { + } catch (IllegalArgumentException e) { throw new MojoExecutionException(e.getMessage()); } @@ -455,7 +456,7 @@ public abstract class KotlinCompileMojoBase e } List pluginClassPaths = getCompilerPluginClassPaths(); - if (pluginClassPaths != null && !pluginClassPaths.isEmpty()) { + if (!pluginClassPaths.isEmpty()) { if (arguments.getPluginClasspaths() == null || arguments.getPluginClasspaths().length == 0) { arguments.setPluginClasspaths(pluginClassPaths.toArray(new String[pluginClassPaths.size()])); } else {