Improve logging in gradle import tests
This commit is contained in:
+6
@@ -47,6 +47,9 @@ import org.jetbrains.plugins.gradle.service.project.GradleProjectResolver
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
import kotlin.collections.HashMap
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.diagnostic.debugOrInfoIfTestMode
|
||||
import org.jetbrains.kotlin.idea.util.PsiPrecedences
|
||||
|
||||
var DataNode<ModuleData>.isResolved
|
||||
by NotNullableCopyableDataNodeUserDataProperty(Key.create<Boolean>("IS_RESOLVED"), false)
|
||||
@@ -69,6 +72,7 @@ var DataNode<out ModuleData>.dependenciesCache
|
||||
|
||||
class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension() {
|
||||
val isAndroidProjectKey = Key.findKeyByName("IS_ANDROID_PROJECT_KEY")
|
||||
private val LOG = Logger.getInstance(PsiPrecedences::class.java)
|
||||
|
||||
override fun getToolingExtensionsClasses(): Set<Class<out Any>> {
|
||||
return setOf(KotlinGradleModelBuilder::class.java, Unit::class.java)
|
||||
@@ -190,6 +194,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
||||
ideModule: DataNode<ModuleData>,
|
||||
ideProject: DataNode<ProjectData>
|
||||
) {
|
||||
LOG.debugOrInfoIfTestMode { "Start populate module dependencies. Gradle module: [$gradleModule], Ide module: [$ideModule], Ide project: [$ideProject]" }
|
||||
val mppModel = resolverCtx.getExtraProject(gradleModule, KotlinMPPGradleModel::class.java)
|
||||
if (mppModel != null) {
|
||||
mppModel.targets.filterNot { it.name == "metadata" }.forEach { target ->
|
||||
@@ -227,6 +232,7 @@ class KotlinGradleProjectResolverExtension : AbstractProjectResolverExtension()
|
||||
if (useModulePerSourceSet()) {
|
||||
super.populateModuleDependencies(gradleModule, ideModule, ideProject)
|
||||
}
|
||||
LOG.debugOrInfoIfTestMode { "Finish populating module dependencies. Gradle module: [$gradleModule], Ide module: [$ideModule], Ide project: [$ideProject]" }
|
||||
}
|
||||
|
||||
private fun addImplementedModuleNames(
|
||||
|
||||
+25
@@ -36,6 +36,7 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import junit.framework.TestCase
|
||||
@@ -52,6 +53,7 @@ import org.jetbrains.plugins.gradle.settings.GradleSettings
|
||||
import org.jetbrains.plugins.gradle.util.GradleConstants
|
||||
import org.jetbrains.plugins.groovy.GroovyFileType
|
||||
import org.junit.Assume.assumeThat
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Rule
|
||||
import org.junit.rules.TestName
|
||||
import org.junit.runner.RunWith
|
||||
@@ -61,6 +63,8 @@ import java.io.IOException
|
||||
import java.io.StringWriter
|
||||
import java.net.URISyntaxException
|
||||
import java.util.*
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.junit.AfterClass
|
||||
|
||||
// part of org.jetbrains.plugins.gradle.importing.GradleImportingTestCase
|
||||
@RunWith(value = Parameterized::class)
|
||||
@@ -72,6 +76,10 @@ abstract class GradleImportingTestCase : ExternalSystemImportingTestCase() {
|
||||
@Rule
|
||||
var name = TestName()
|
||||
|
||||
@JvmField
|
||||
@Rule
|
||||
var testWatcher = ImportingTestWatcher()
|
||||
|
||||
@JvmField
|
||||
@Rule
|
||||
var versionMatcherRule = VersionMatcherRule()
|
||||
@@ -276,5 +284,22 @@ abstract class GradleImportingTestCase : ExternalSystemImportingTestCase() {
|
||||
fun wrapperJar(): File {
|
||||
return File(PathUtil.getJarPathForClass(GradleWrapperMain::class.java))
|
||||
}
|
||||
|
||||
private var persistedLoggerFactory : Logger.Factory? = null
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setLoggerFactory() {
|
||||
persistedLoggerFactory = Logger.getFactory()
|
||||
Logger.setFactory(TestLoggerFactory::class.java)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@AfterClass
|
||||
fun restoreLoggerFactory() {
|
||||
if (persistedLoggerFactory != null) {
|
||||
Logger.setFactory(persistedLoggerFactory)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.codeInsight.gradle
|
||||
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import org.junit.rules.TestWatcher
|
||||
import org.junit.runner.Description
|
||||
|
||||
class ImportingTestWatcher : TestWatcher() {
|
||||
|
||||
override fun succeeded(description: Description) {
|
||||
TestLoggerFactory.onTestFinished(true)
|
||||
}
|
||||
|
||||
override fun failed(e: Throwable, description: Description) {
|
||||
TestLoggerFactory.onTestFinished(false)
|
||||
}
|
||||
|
||||
override fun starting(description: Description) {
|
||||
TestLoggerFactory.onTestStarted()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user