Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m

// Configure notification urls callbacks
TestsReportNotifier.urlOpeningListener.callbacks[TestReportUrlOpeningListener.mockitoSuffix]?.plusAssign {
if (createMockFrameworkNotificationDialog() == Messages.YES) {
configureMockFramework()
}
configureMockFramework()
}

TestsReportNotifier.urlOpeningListener.callbacks[TestReportUrlOpeningListener.mockitoInlineSuffix]?.plusAssign {
if (createStaticsMockingNotificationDialog() == Messages.YES) {
configureStaticMocking()
}
configureStaticMocking()
}

init()
Expand Down Expand Up @@ -610,29 +606,21 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
//region configure frameworks

private fun configureTestFrameworkIfRequired() {
val frameworkNotInstalled = !testFrameworks.item.isInstalled

if (frameworkNotInstalled && createTestFrameworkNotificationDialog() == Messages.YES) {
if (!testFrameworks.item.isInstalled) {
configureTestFramework()
}

model.hasTestFrameworkConflict = TestFramework.allItems.count { it.isInstalled } > 1
model.hasTestFrameworkConflict = TestFramework.allItems.count { it.isInstalled } > 1
}

private fun configureMockFrameworkIfRequired() {
val frameworkNotInstalled =
mockStrategies.item != MockStrategyApi.NO_MOCKS && !MOCKITO.isInstalled

if (frameworkNotInstalled && createMockFrameworkNotificationDialog() == Messages.YES) {
if (mockStrategies.item != MockStrategyApi.NO_MOCKS && !MOCKITO.isInstalled) {
configureMockFramework()
}
}

private fun configureStaticMockingIfRequired() {
val frameworkNotConfigured =
staticsMocking.item != NoStaticMocking && !staticsMocking.item.isConfigured

if (frameworkNotConfigured && createStaticsMockingNotificationDialog() == Messages.YES) {
if (staticsMocking.item != NoStaticMocking && !staticsMocking.item.isConfigured) {
configureStaticMocking()
}
}
Expand All @@ -655,15 +643,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
.onError { selectedTestFramework.isInstalled = false }
}

private fun createTestFrameworkNotificationDialog() = Messages.showYesNoDialog(
"""Selected test framework ${testFrameworks.item.displayName} is not installed into current module.
|Would you like to install it now?""".trimMargin(),
title,
"Yes",
"No",
Messages.getQuestionIcon(),
)

private fun configureMockFramework() {
val selectedMockFramework = MOCKITO

Expand Down Expand Up @@ -740,24 +719,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
}
}

private fun createMockFrameworkNotificationDialog() = Messages.showYesNoDialog(
"""Mock framework ${MOCKITO.displayName} is not installed into current module.
|Would you like to install it now?""".trimMargin(),
title,
"Yes",
"No",
Messages.getQuestionIcon(),
)

private fun createStaticsMockingNotificationDialog() = Messages.showYesNoDialog(
"""A framework ${MOCKITO.displayName} is not configured to mock static methods.
|Would you like to configure it now?""".trimMargin(),
title,
"Yes",
"No",
Messages.getQuestionIcon(),
)

//endregion

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.utbot.intellij.plugin.util

import com.intellij.codeInsight.daemon.impl.quickfix.LocateLibraryDialog
import com.intellij.codeInsight.daemon.impl.quickfix.OrderEntryFix
import com.intellij.ide.JavaUiBundle
import com.intellij.jarRepository.JarRepositoryManager
import com.intellij.openapi.application.WriteAction
import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.DependencyScope
import com.intellij.openapi.roots.ExternalLibraryDescriptor
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.IdeaProjectModelModifier
import com.intellij.openapi.roots.libraries.LibraryTablesRegistrar
import com.intellij.openapi.roots.libraries.LibraryUtil
import com.intellij.openapi.roots.libraries.ui.OrderRoot
import com.intellij.openapi.ui.Messages
import com.intellij.util.PathUtil
import com.intellij.util.containers.ContainerUtil
import java.util.stream.Collectors
import org.jetbrains.concurrency.Promise
import org.jetbrains.concurrency.rejectedPromise
import org.jetbrains.concurrency.resolvedPromise
import org.jetbrains.idea.maven.utils.library.RepositoryLibraryDescription
import org.jetbrains.idea.maven.utils.library.RepositoryLibraryProperties
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor

class UtProjectModelModifier(val project: Project) : IdeaProjectModelModifier(project) {
override fun addExternalLibraryDependency(
modules: Collection<Module?>,
descriptor: ExternalLibraryDescriptor,
scope: DependencyScope
): Promise<Void> {
val defaultRoots = descriptor.libraryClassesRoots
val classesRoots: List<String?>
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
val firstModule = ContainerUtil.getFirstItem(modules)
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
classesRoots = if (defaultRoots.isNotEmpty()) {
LocateLibraryDialog(firstModule!!, defaultRoots, descriptor.presentableName).showAndGetResult()
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
} else {
val version = descriptor.preferredVersion
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
val mavenCoordinates = descriptor.libraryGroupId + ":" +
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
descriptor.libraryArtifactId + ":" +
(version ?: RepositoryLibraryDescription.ReleaseVersionId)

val libraryProperties = RepositoryLibraryProperties(JpsMavenRepositoryLibraryDescriptor(mavenCoordinates))
val roots = JarRepositoryManager.loadDependenciesModal(
project,
libraryProperties,
false,
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
false,
null,
null
)
if (roots.isEmpty()) {
@Suppress("SpellCheckingInspection")
Messages.showErrorDialog(
project, JavaUiBundle.message("dialog.mesage.0.was.not.loaded", descriptor.presentableName),
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
JavaUiBundle.message("dialog.title.failed.to.download.library")
)
return rejectedPromise()
}
roots.stream()
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
.filter { root: OrderRoot -> root.type === OrderRootType.CLASSES }
.map { root: OrderRoot ->
PathUtil.getLocalPath(
root.file
)
}
.collect(Collectors.toList())
}
if (classesRoots.isNotEmpty()) {
val libraryName = if (classesRoots.size > 1) descriptor.presentableName else null
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
val urls = OrderEntryFix.refreshAndConvertToUrls(classesRoots)
if (modules.size == 1) {
ModuleRootModificationUtil.addModuleLibrary(firstModule!!, libraryName, urls, emptyList(), scope)
} else {
WriteAction.run<RuntimeException> {
val library =
LibraryUtil.createLibrary(
LibraryTablesRegistrar.getInstance().getLibraryTable(project), descriptor.presentableName
)
val model = library.modifiableModel
for (url in urls) {
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
Outdated
model.addRoot(url!!, OrderRootType.CLASSES)
}
model.commit()
for (module in modules) {
ModuleRootModificationUtil.addDependency(module!!, library, scope, false)
}
}
}
}
return resolvedPromise()
}
}
Comment thread
Vassiliy-Kudryashov marked this conversation as resolved.
1 change: 1 addition & 0 deletions utbot-intellij/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<projectService serviceImplementation="org.utbot.intellij.plugin.settings.Settings" preload="true"/>
<registryKey defaultValue="false" description="Enable editing Kotlin test files" key="kotlin.ultra.light.classes.empty.text.range"/>
<postStartupActivity implementation="org.utbot.intellij.plugin.ui.GotItTooltipActivity"/>
<projectModelModifier implementation="org.utbot.intellij.plugin.util.UtProjectModelModifier"/>
</extensions>

<!-- Minimum and maximum build of IDE compatible with the plugin -->
Expand Down