From 8a850c22ce0a3708c792257dd6605e5f80711f90 Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Fri, 4 Dec 2015 02:58:36 -0800 Subject: [PATCH] Fix ICompilerFlagContributor. --- .../kobalt/api/IBuildDirectoryInterceptor.kt | 2 +- .../api/ISourceDirectoriesInterceptor.kt | 2 +- .../beust/kobalt/internal/KobaltPluginXml.kt | 6 ++-- .../kobalt/plugin/android/AndroidPlugin.kt | 31 ++++++++++++++++--- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt b/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt index 4d722f12..5a317c0f 100644 --- a/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt +++ b/src/main/kotlin/com/beust/kobalt/api/IBuildDirectoryInterceptor.kt @@ -3,7 +3,7 @@ package com.beust.kobalt.api /** * Plug-ins can alter the build directory by implementing this interface. */ -interface IBuildDirectoryIncerceptor : IPluginActor { +interface IBuildDirectoryIncerceptor : IInterceptor { fun intercept(project: Project, context: KobaltContext, buildDirectory: String) : String } diff --git a/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt b/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt index 6e8af5eb..aa39712b 100644 --- a/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt +++ b/src/main/kotlin/com/beust/kobalt/api/ISourceDirectoriesInterceptor.kt @@ -5,7 +5,7 @@ import java.io.File /** * Plug-ins can alter the source directories by implementing this interface. */ -interface ISourceDirectoriesIncerceptor : IPluginActor { +interface ISourceDirectoryIncerceptor : IInterceptor { fun intercept(project: Project, context: KobaltContext, sourceDirectories: List) : List } diff --git a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt b/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt index e665407e..1c01008d 100644 --- a/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt +++ b/src/main/kotlin/com/beust/kobalt/internal/KobaltPluginXml.kt @@ -63,7 +63,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { val repoContributors = arrayListOf() val compilerFlagContributors = arrayListOf() val compilerInterceptors = arrayListOf() - val sourceDirectoriesInterceptors = arrayListOf() + val sourceDirectoriesInterceptors = arrayListOf() val buildDirectoryInterceptors = arrayListOf() val runnerContributors = arrayListOf() val testRunnerContributors = arrayListOf() @@ -128,9 +128,10 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { if (this is IProjectContributor) projectContributors.add(this) if (this is IInitContributor<*>) initContributors.add(this as IInitContributor) if (this is IRepoContributor) repoContributors.add(this) + if (this is ICompilerFlagContributor) compilerFlagContributors.add(this) if (this is ICompilerContributor) compilerContributors.add(this) if (this is ICompilerInterceptor) compilerInterceptors.add(this) - if (this is ISourceDirectoriesIncerceptor) sourceDirectoriesInterceptors.add(this) + if (this is ISourceDirectoryIncerceptor) sourceDirectoriesInterceptors.add(this) if (this is IBuildDirectoryIncerceptor) buildDirectoryInterceptors.add(this) if (this is IRunnerContributor) runnerContributors.add(this) if (this is ITestRunnerContributor) testRunnerContributors.add(this) @@ -154,6 +155,7 @@ class PluginInfo(val xml: KobaltPluginXml, val classLoader: ClassLoader?) { projectContributors.addAll(pluginInfo.projectContributors) initContributors.addAll(pluginInfo.initContributors) repoContributors.addAll(pluginInfo.repoContributors) + compilerFlagContributors.addAll(pluginInfo.compilerFlagContributors) compilerInterceptors.addAll(pluginInfo.compilerInterceptors) sourceDirectoriesInterceptors.addAll(pluginInfo.sourceDirectoriesInterceptors) buildDirectoryInterceptors.addAll(pluginInfo.buildDirectoryInterceptors) diff --git a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt index c8351487..36291a8f 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/android/AndroidPlugin.kt @@ -206,13 +206,36 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler, v override fun flagsFor(project: Project, currentFlags: List) : List { if (isAndroid(project)) { val result = arrayListOf() + var foundSource = false + var foundTarget = false var noWarn = false - if (! currentFlags.contains("-source")) with(result) { - addAll(listOf("-source", "1.6")) + var i = 0 + while (i < currentFlags.size) { + with(currentFlags[i]) { + if (this == "-source") { + result.add(this) + result.add(currentFlags[i + 1]) + i++ + foundSource = true + } else if (this == "-target") { + result.add(this) + result.add(currentFlags[i + 1]) + i++ + foundTarget = true + } else { + result.add(this) + } + } + i++ + } + if (! foundSource) { + result.add("-source") + result.add("1.6") noWarn = true } - if (!currentFlags.contains("-target")) with(result) { - addAll(listOf("-target", "1.6")) + if (! foundTarget) { + result.add("-target") + result.add("1.6") noWarn = true } if (noWarn) {