Skip to content

Commit 349095c

Browse files
committed
Maven: Make compiler plugin option reporting more user-friendly
1 parent 277490b commit 349095c

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
[INFO] Kotlin Compiler version @snapshot@
22
[INFO] Compiling Kotlin sources from [/test-extension/src/main/kotlin]
33
[INFO] Module name is test-extension
4+
[WARNING] Some JAR files in the classpath have the Kotlin Runtime library bundled into them. This may cause difficult to debug problems if there's a different version @snapshot@ the Kotlin Runtime library in the classpath. Consider removing these libraries from the classpath or use '-Xskip-runtime-version-check' to suppress this warning
5+
[WARNING] /local-repo/org/jetbrains/kotlin/kotlin-compiler/1.1-SNAPSHOT/kotlin-compiler-1.1-SNAPSHOT.jar: (-1, -1) Library has Kotlin runtime bundled into it
46
[INFO] Kotlin Compiler version @snapshot@
57
[WARNING] No sources found skipping Kotlin compile
68
[INFO] Kotlin Compiler version @snapshot@
79
[INFO] Compiling Kotlin sources from [/use-test-extension/src/main/kotlin]
810
[INFO] Module name is use-test-extension
911
[INFO] Applicability test for project use-test-extension
12+
[INFO] Applied plugin: 'test-me'
1013
[INFO] Configuring test plugin with arguments
11-
[INFO] Options for plugin test-me: [plugin:org.jetbrains.kotlin.test.test-plugin:test-option=my-special-value]
1214
[INFO] Plugin applied
1315
[INFO] Option value: my-special-value
1416
[INFO] Kotlin Compiler version @snapshot@
15-
[WARNING] No sources found skipping Kotlin compile
17+
[WARNING] No sources found skipping Kotlin compile

libraries/tools/kotlin-maven-plugin-test/src/it/test-plugins/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.jetbrains.kotlin</groupId>
88
<artifactId>kotlin-compiler-extensions-test</artifactId>
9-
<version>1.1-SNAPSHOT</version>
9+
<version>1.0-SNAPSHOT</version>
1010
<modules>
1111
<module>test-extension</module>
1212
<module>use-test-extension</module>

libraries/tools/kotlin-maven-plugin-test/src/it/test-plugins/test-extension/pom.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@
55
<parent>
66
<artifactId>kotlin-compiler-extensions-test</artifactId>
77
<groupId>org.jetbrains.kotlin</groupId>
8-
<version>1.1-SNAPSHOT</version>
8+
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>test-extension</artifactId>
1313

14-
<properties>
15-
<kotlin.version>1.1-SNAPSHOT</kotlin.version>
16-
</properties>
17-
1814
<dependencies>
1915
<dependency>
2016
<groupId>org.jetbrains.kotlin</groupId>

libraries/tools/kotlin-maven-plugin-test/src/it/test-plugins/test-extension/src/main/kotlin/org/jetbrains/kotlin/test/MavenPluginComponent.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class MavenPluginComponent : KotlinMavenPluginExtension {
2323
logger.info("Configuring test plugin with arguments")
2424

2525
return listOf(PluginOption(
26+
"test-me",
2627
TestCommandLineProcessor.TestPluginId,
2728
TestCommandLineProcessor.MyTestOption.name,
2829
"my-special-value"))

libraries/tools/kotlin-maven-plugin-test/src/it/test-plugins/use-test-extension/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55
<parent>
66
<artifactId>kotlin-compiler-extensions-test</artifactId>
77
<groupId>org.jetbrains.kotlin</groupId>
8-
<version>1.1-SNAPSHOT</version>
8+
<version>1.0-SNAPSHOT</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>use-test-extension</artifactId>
1313

14-
15-
<properties>
16-
<kotlin.version>1.1-SNAPSHOT</kotlin.version>
17-
</properties>
18-
1914
<dependencies>
2015
<dependency>
2116
<groupId>org.jetbrains.kotlin</groupId>

libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/KotlinCompileMojoBase.java

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,48 @@ private List<PluginOption> getCompilerPluginOptions() throws PluginNotFoundExcep
328328
String pluginName = pluginEntry.getKey();
329329
KotlinMavenPluginExtension plugin = pluginEntry.getValue();
330330

331+
// applied plugin (...) to info()
331332
if (plugin.isApplicable(project, mojoExecution)) {
333+
getLog().info("Applied plugin: '" + pluginName + "'");
332334
List<PluginOption> optionsForPlugin = plugin.getPluginOptions(project, mojoExecution);
333-
getLog().info("Options for plugin " + pluginName + ": " + optionsForPlugin);
334-
pluginOptions.addAll(optionsForPlugin);
335+
if (!optionsForPlugin.isEmpty()) {
336+
pluginOptions.addAll(optionsForPlugin);
337+
}
335338
}
336339
}
337340

338341
if (this.pluginOptions != null) {
339342
pluginOptions.addAll(parseUserProvidedPluginOptions(this.pluginOptions, plugins));
340343
}
341344

345+
Map<String, List<PluginOption>> optionsByPluginName = new LinkedHashMap<String, List<PluginOption>>();
346+
for (PluginOption option : pluginOptions) {
347+
List<PluginOption> optionsForPlugin = optionsByPluginName.get(option.pluginName);
348+
if (optionsForPlugin == null) {
349+
optionsForPlugin = new ArrayList<PluginOption>();
350+
optionsByPluginName.put(option.pluginName, optionsForPlugin);
351+
}
352+
353+
optionsForPlugin.add(option);
354+
}
355+
356+
for (Map.Entry<String, List<PluginOption>> entry : optionsByPluginName.entrySet()) {
357+
assert !entry.getValue().isEmpty();
358+
359+
String pluginName = entry.getValue().get(0).pluginName;
360+
361+
StringBuilder renderedOptions = new StringBuilder("[");
362+
for (PluginOption option : entry.getValue()) {
363+
if (renderedOptions.length() > 1) {
364+
renderedOptions.append(", ");
365+
}
366+
renderedOptions.append(option.key).append(": ").append(option.value);
367+
}
368+
renderedOptions.append("]");
369+
370+
getLog().debug("Options for plugin " + pluginName + ": " + renderedOptions);
371+
}
372+
342373
return pluginOptions;
343374
}
344375

@@ -363,7 +394,7 @@ private static List<PluginOption> parseUserProvidedPluginOptions(
363394
throw new PluginNotFoundException(pluginName);
364395
}
365396

366-
pluginOptions.add(new PluginOption(plugin.getCompilerPluginId(), key, value));
397+
pluginOptions.add(new PluginOption(pluginName, plugin.getCompilerPluginId(), key, value));
367398
}
368399

369400
return pluginOptions;

libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/PluginOption.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package org.jetbrains.kotlin.maven;
22

33
public class PluginOption {
4+
/** The plugin name in Maven, e.g. "all-open" */
5+
public final String pluginName;
6+
7+
/** The compiler plugin identifier, e.g. "org.jetbrains.kotlin.allopen" */
48
public final String pluginId;
9+
510
public final String key;
611
public final String value;
712

8-
public PluginOption(String pluginId, String key, String value) {
13+
public PluginOption(String pluginName, String pluginId, String key, String value) {
14+
this.pluginName = pluginName;
915
this.pluginId = pluginId;
1016
this.key = key;
1117
this.value = value;

0 commit comments

Comments
 (0)