Skip to content

Sort dependencies in user build file #868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,6 +1,13 @@
package org.utbot.intellij.plugin.models

import com.intellij.openapi.roots.ExternalLibraryDescriptor
import org.jetbrains.idea.maven.utils.library.RepositoryLibraryDescription

val ExternalLibraryDescriptor.mavenCoordinates: String
get() = "$libraryGroupId:$libraryArtifactId:${preferredVersion ?: RepositoryLibraryDescription.ReleaseVersionId}"

val ExternalLibraryDescriptor.id: String
get() = "$libraryGroupId:$libraryArtifactId"

//TODO: think about using JUnitExternalLibraryDescriptor from intellij-community sources (difficult to install)
fun jUnit4LibraryDescriptor(versionInProject: String?) =
Expand All @@ -10,7 +17,7 @@ fun jUnit5LibraryDescriptor(versionInProject: String?) =
ExternalLibraryDescriptor("org.junit.jupiter", "junit-jupiter", "5.8.1", null, versionInProject ?: "5.8.1")

fun testNgLibraryDescriptor(versionInProject: String?) =
ExternalLibraryDescriptor("org.testng", "testng", "6.8.8", null, versionInProject ?: "6.9.6")
ExternalLibraryDescriptor("org.testng", "testng", "7.6.0", null, versionInProject ?: "7.6.0")

fun jUnit5ParametrizedTestsLibraryDescriptor(versionInProject: String?) =
ExternalLibraryDescriptor("org.junit.jupiter", "junit-jupiter-params", "5.8.1", null, versionInProject ?: "5.8.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.TreatOverflowAsError
import org.utbot.framework.util.Conflict
import org.utbot.intellij.plugin.models.GenerateTestsModel
import org.utbot.intellij.plugin.models.id
import org.utbot.intellij.plugin.models.jUnit4LibraryDescriptor
import org.utbot.intellij.plugin.models.jUnit5LibraryDescriptor
import org.utbot.intellij.plugin.models.jUnit5ParametrizedTestsLibraryDescriptor
Expand Down Expand Up @@ -792,7 +793,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
.addDependency(model.testModule, libraryDescriptor, DependencyScope.TEST)
promise.thenRun {
module.allLibraries()
.lastOrNull { library -> library.libraryName == libraryDescriptor.presentableName }?.let {
.lastOrNull { library -> library.presentableName.contains(libraryDescriptor.id) }?.let {
ModuleRootModificationUtil.updateModel(module) { model -> placeEntryToCorrectPlace(model, it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import com.intellij.util.PathUtil
import com.intellij.util.containers.ContainerUtil
import org.jetbrains.concurrency.Promise
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
import org.utbot.intellij.plugin.models.mavenCoordinates

class UtProjectModelModifier(val project: Project) : IdeaProjectModelModifier(project) {
override fun addExternalLibraryDependency(
Expand All @@ -38,7 +38,7 @@ class UtProjectModelModifier(val project: Project) : IdeaProjectModelModifier(pr
} else {
val roots = JarRepositoryManager.loadDependenciesModal(
project,
RepositoryLibraryProperties(JpsMavenRepositoryLibraryDescriptor(descriptor.mavenCoordinates())),
RepositoryLibraryProperties(JpsMavenRepositoryLibraryDescriptor(descriptor.mavenCoordinates)),
/* loadSources = */ false,
/* loadJavadoc = */ false,
/* copyTo = */ null,
Expand Down Expand Up @@ -78,8 +78,4 @@ class UtProjectModelModifier(val project: Project) : IdeaProjectModelModifier(pr
}
return resolvedPromise()
}

private fun ExternalLibraryDescriptor.mavenCoordinates(): String {
return "$libraryGroupId:$libraryArtifactId:${preferredVersion ?: RepositoryLibraryDescription.ReleaseVersionId}"
}
}