Fix import of compiler arguments in IDEA if source set dependencies
could not be resolved (e.g. due to misspelling in artifact name). Fix works only in case when both new IDEA and gradle plugins are used #KT-28627 Fixed
This commit is contained in:
+11
@@ -989,6 +989,17 @@ class GradleFacetImportTest : GradleImportingTestCase() {
|
||||
TestCase.assertEquals("1.1", holder.settings.languageVersion)
|
||||
}
|
||||
|
||||
@Ignore //TODO enable this test after the Kotlin gradle plugin with required fixes is released
|
||||
@Test
|
||||
fun testImportCompilerArgumentsWithInvalidDependencies() {
|
||||
configureByFiles()
|
||||
importProject()
|
||||
with(facetSettings("project_main")) {
|
||||
Assert.assertEquals("1.8", (mergedCompilerArguments as K2JVMCompilerArguments).jvmTarget)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun checkStableModuleName(projectName: String, expectedName: String, platform: TargetPlatform, isProduction: Boolean) {
|
||||
val module = getModule(projectName)
|
||||
val moduleInfo = if (isProduction) module.productionSourceInfo() else module.testSourceInfo()
|
||||
|
||||
@@ -123,12 +123,12 @@ class KotlinGradleModelBuilder : AbstractKotlinGradleModelBuilder() {
|
||||
private fun Project.pathOrName() = if (path == ":") name else path
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun Task.getCompilerArguments(methodName: String): List<String> {
|
||||
private fun Task.getCompilerArguments(methodName: String): List<String>? {
|
||||
return try {
|
||||
javaClass.getDeclaredMethod(methodName).invoke(this) as List<String>
|
||||
} catch (e: Exception) {
|
||||
// No argument accessor method is available
|
||||
emptyList()
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,8 @@ class KotlinGradleModelBuilder : AbstractKotlinGradleModelBuilder() {
|
||||
|
||||
val sourceSetName = compileTask.getSourceSetName()
|
||||
val currentArguments = compileTask.getCompilerArguments("getSerializedCompilerArguments")
|
||||
val defaultArguments = compileTask.getCompilerArguments("getDefaultSerializedCompilerArguments")
|
||||
?: compileTask.getCompilerArguments("getSerializedCompilerArgumentsIgnoreClasspathIssues") ?: emptyList()
|
||||
val defaultArguments = compileTask.getCompilerArguments("getDefaultSerializedCompilerArguments").orEmpty()
|
||||
val dependencyClasspath = compileTask.getDependencyClasspath()
|
||||
compilerArgumentsBySourceSet[sourceSetName] = ArgsInfoImpl(currentArguments, defaultArguments, dependencyClasspath)
|
||||
}
|
||||
|
||||
+6
-3
@@ -25,6 +25,9 @@ interface CompilerArgumentAware<T : CommonToolArguments> {
|
||||
val serializedCompilerArguments: List<String>
|
||||
get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments())
|
||||
|
||||
val serializedCompilerArgumentsIgnoreClasspathIssues: List<String>
|
||||
get() = ArgumentUtils.convertArgumentsToStringList(prepareCompilerArguments(ignoreClasspathResolutionErrors = true))
|
||||
|
||||
val defaultSerializedCompilerArguments: List<String>
|
||||
get() = createCompilerArgs()
|
||||
.also { setupCompilerArgs(it, defaultsOnly = true) }
|
||||
@@ -34,11 +37,11 @@ interface CompilerArgumentAware<T : CommonToolArguments> {
|
||||
get() = CompilerArgumentsGradleInput.createInputsMap(prepareCompilerArguments())
|
||||
|
||||
fun createCompilerArgs(): T
|
||||
fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false)
|
||||
fun setupCompilerArgs(args: T, defaultsOnly: Boolean = false, ignoreClasspathResolutionErrors: Boolean = false)
|
||||
}
|
||||
|
||||
internal fun <T : CommonToolArguments> CompilerArgumentAware<T>.prepareCompilerArguments() =
|
||||
createCompilerArgs().also { setupCompilerArgs(it) }
|
||||
internal fun <T : CommonToolArguments> CompilerArgumentAware<T>.prepareCompilerArguments(ignoreClasspathResolutionErrors: Boolean = false) =
|
||||
createCompilerArgs().also { setupCompilerArgs(it, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors) }
|
||||
|
||||
interface CompilerArgumentAwareWithInput<T : CommonToolArguments> : CompilerArgumentAware<T> {
|
||||
@get:Internal
|
||||
|
||||
+2
-2
@@ -84,8 +84,8 @@ open class KaptGenerateStubsTask : KotlinCompile() {
|
||||
!stubsDir.isParentOf(source) &&
|
||||
!generatedSourcesDir.isParentOf(source)
|
||||
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) {
|
||||
kotlinCompileTask.setupCompilerArgs(args)
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
kotlinCompileTask.setupCompilerArgs(args, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
val pluginOptionsWithKapt = pluginOptions.withWrappedKaptOptions(withApClasspath = kaptClasspath)
|
||||
args.pluginOptions = (pluginOptionsWithKapt.arguments + args.pluginOptions!!).toTypedArray()
|
||||
|
||||
+2
-2
@@ -46,8 +46,8 @@ open class KaptWithKotlincTask : KaptTask(), CompilerArgumentAwareWithInput<K2JV
|
||||
|
||||
override fun createCompilerArgs(): K2JVMCompilerArguments = K2JVMCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) {
|
||||
kotlinCompileTask.setupCompilerArgs(args)
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
kotlinCompileTask.setupCompilerArgs(args, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.pluginClasspaths = pluginClasspath.toSortedPathsArray()
|
||||
|
||||
|
||||
+2
-2
@@ -46,9 +46,9 @@ open class KotlinCompileCommon : AbstractKotlinCompile<K2MetadataCompilerArgumen
|
||||
override fun findKotlinCompilerClasspath(project: Project): List<File> =
|
||||
findKotlinMetadataCompilerClasspath(project)
|
||||
|
||||
override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean) {
|
||||
override fun setupCompilerArgs(args: K2MetadataCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
args.apply { fillDefaultValues() }
|
||||
super.setupCompilerArgs(args, defaultsOnly)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.moduleName = friendTask?.moduleName ?: this@KotlinCompileCommon.moduleName
|
||||
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ import java.io.File
|
||||
|
||||
override fun createCompilerArgs(): K2JSDceArguments = K2JSDceArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2JSDceArguments, defaultsOnly: Boolean) {
|
||||
override fun setupCompilerArgs(args: K2JSDceArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
dceOptionsImpl.updateArguments(args)
|
||||
args.declarationsToKeep = keep.toTypedArray()
|
||||
}
|
||||
|
||||
+10
-6
@@ -325,7 +325,7 @@ abstract class AbstractKotlinCompile<T : CommonCompilerArguments>() : AbstractKo
|
||||
*/
|
||||
internal abstract fun callCompilerAsync(args: T, sourceRoots: SourceRoots, changedFiles: ChangedFiles)
|
||||
|
||||
override fun setupCompilerArgs(args: T, defaultsOnly: Boolean) {
|
||||
override fun setupCompilerArgs(args: T, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
args.coroutinesState = when (coroutines) {
|
||||
Coroutines.ENABLE -> CommonCompilerArguments.ENABLE
|
||||
Coroutines.WARN -> CommonCompilerArguments.WARN
|
||||
@@ -393,9 +393,9 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
override fun createCompilerArgs(): K2JVMCompilerArguments =
|
||||
K2JVMCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean) {
|
||||
override fun setupCompilerArgs(args: K2JVMCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
args.apply { fillDefaultValues() }
|
||||
super.setupCompilerArgs(args, defaultsOnly)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.moduleName = friendTask?.moduleName ?: moduleName
|
||||
logger.kotlinDebug { "args.moduleName = ${args.moduleName}" }
|
||||
@@ -406,7 +406,11 @@ open class KotlinCompile : AbstractKotlinCompile<K2JVMCompilerArguments>(), Kotl
|
||||
if (defaultsOnly) return
|
||||
|
||||
args.allowNoSourceFiles = true
|
||||
args.classpathAsList = compileClasspath.toList()
|
||||
args.classpathAsList = try {
|
||||
compileClasspath.toList()
|
||||
} catch (e: Exception) {
|
||||
if (ignoreClasspathResolutionErrors) emptyList() else throw(e)
|
||||
}
|
||||
args.destinationAsFile = destinationDir
|
||||
parentKotlinOptionsImpl?.updateArguments(args)
|
||||
kotlinOptionsImpl.updateArguments(args)
|
||||
@@ -539,9 +543,9 @@ open class Kotlin2JsCompile : AbstractKotlinCompile<K2JSCompilerArguments>(), Ko
|
||||
override fun createCompilerArgs(): K2JSCompilerArguments =
|
||||
K2JSCompilerArguments()
|
||||
|
||||
override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean) {
|
||||
override fun setupCompilerArgs(args: K2JSCompilerArguments, defaultsOnly: Boolean, ignoreClasspathResolutionErrors: Boolean) {
|
||||
args.apply { fillDefaultValues() }
|
||||
super.setupCompilerArgs(args, defaultsOnly)
|
||||
super.setupCompilerArgs(args, defaultsOnly = defaultsOnly, ignoreClasspathResolutionErrors = ignoreClasspathResolutionErrors)
|
||||
|
||||
args.outputFile = outputFile.canonicalPath
|
||||
|
||||
|
||||
Reference in New Issue
Block a user