Skip to content

Support subfolder XML search #2102

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 1 commit into from
Apr 5, 2023
Merged
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
Expand Up @@ -15,7 +15,6 @@ import org.jetbrains.kotlin.idea.core.getPackage
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
import org.jetbrains.kotlin.idea.util.rootManager
import org.jetbrains.kotlin.idea.util.sourceRoot
import org.jetbrains.kotlin.utils.addToStdlib.flatMapToNullable
import org.utbot.common.PathUtil.fileExtension
import org.utbot.framework.codegen.domain.ProjectType
import org.utbot.framework.plugin.api.CodegenLanguage
Expand All @@ -25,10 +24,8 @@ import org.utbot.intellij.plugin.ui.utils.getSortedTestRoots
import org.utbot.intellij.plugin.ui.utils.isBuildWithGradle
import org.utbot.intellij.plugin.ui.utils.suitableTestSourceRoots
import java.nio.file.Files
import java.nio.file.Path
import javax.xml.parsers.DocumentBuilderFactory
import kotlin.streams.asSequence
import kotlin.streams.toList

val PsiClass.packageName: String get() = this.containingFile.containingDirectory.getPackage()?.qualifiedName ?: ""
const val HISTORY_LIMIT = 10
Expand Down Expand Up @@ -123,7 +120,7 @@ open class BaseTestsModel(
val resourcesPaths =
setOf(testModule, srcModule).flatMapTo(mutableSetOf()) { it.getResourcesPaths() }
val xmlFilePaths = resourcesPaths.flatMapTo(mutableListOf()) { path ->
Files.list(path)
Files.walk(path)
.asSequence()
.filter { it.fileExtension == ".xml" }
}
Expand All @@ -132,10 +129,10 @@ open class BaseTestsModel(
return xmlFilePaths.mapNotNullTo(mutableSetOf()) { path ->
val doc = builder.parse(path.toFile())

val isBeanTagName = doc.documentElement.tagName == "beans"
val hasBeanTagName = doc.documentElement.tagName == "beans"
val hasAttribute = doc.documentElement.getAttribute("xmlns") == "http://www.springframework.org/schema/beans"
when {
isBeanTagName && hasAttribute -> path.toString()
hasBeanTagName && hasAttribute -> path.toString()
else -> null
}
}
Expand Down