Avoid failure of maven compilation if empty args are passed
#KT-54822 Fixed Merge-request: KT-MR-8103 Merged-by: Aleksei Cherepanov <aleksei.cherepanov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
8c5739739c
commit
d26b96afe1
@@ -0,0 +1 @@
|
||||
invoker.buildResult = failure
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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>
|
||||
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>test-empty-argument</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>${kotlin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>${kotlin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<phase>process-sources</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<phase>process-test-sources</phase>
|
||||
<goals>
|
||||
<goal>test-compile</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<args>
|
||||
<arg></arg>
|
||||
</args>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package org.jetbrains
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
System.out?.println(getGreeting())
|
||||
}
|
||||
|
||||
fun getGreeting() : String {
|
||||
return "Hello, World!"
|
||||
}
|
||||
+13
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
source(new File(basedir, "../../../verify-common.bsh").getAbsolutePath());
|
||||
|
||||
assertBuildLogHasLine("[INFO] BUILD FAILURE");
|
||||
assertBuildLogHasLineThatContains("Empty compiler argument passed in the <configuration> section");
|
||||
+10
-9
@@ -251,19 +251,16 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> 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<A extends CommonCompilerArguments> e
|
||||
|
||||
protected abstract void configureSpecificCompilerArguments(@NotNull A arguments, @NotNull List<File> sourceRoots) throws MojoExecutionException;
|
||||
|
||||
@NotNull
|
||||
private List<String> getCompilerPluginClassPaths() {
|
||||
ArrayList<String> result = new ArrayList<>();
|
||||
|
||||
@@ -443,10 +441,13 @@ public abstract class KotlinCompileMojoBase<A extends CommonCompilerArguments> e
|
||||
|
||||
configureSpecificCompilerArguments(arguments, sourceRoots);
|
||||
|
||||
if (args != null && args.contains(null)) {
|
||||
throw new MojoExecutionException("Empty compiler argument passed in the <configuration> 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<A extends CommonCompilerArguments> e
|
||||
}
|
||||
|
||||
List<String> 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 {
|
||||
|
||||
Reference in New Issue
Block a user