mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
[maven] IDEA-283167 Implement Maven dependency analyzer
MavenDependencyAnalyzerGoToAction - navigation to maven module GitOrigin-RevId: 9359179f1b9b3dd2931151bace01faffc355fe0b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
3c7d5bdeb2
commit
cf1a201c6e
@@ -3,17 +3,17 @@ package org.jetbrains.idea.maven.project
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.*
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerContributor
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerDependency as Dependency
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerProject
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle.message
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.util.NlsSafe
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import org.jetbrains.idea.maven.model.MavenArtifactNode
|
||||
import org.jetbrains.idea.maven.model.MavenArtifactState
|
||||
import org.jetbrains.idea.maven.model.MavenConstants
|
||||
import org.jetbrains.idea.maven.model.MavenId
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerDependency as Dependency
|
||||
|
||||
|
||||
class MavenDependencyAnalyzerContributor(private val project: Project) : DependencyAnalyzerContributor {
|
||||
@@ -51,6 +51,8 @@ class MavenDependencyAnalyzerContributor(private val project: Project) : Depende
|
||||
|
||||
private fun createDependencyList(mavenProject: MavenProject): List<Dependency> {
|
||||
val root = DAModule(mavenProject.displayName)
|
||||
val mavenId = mavenProject.mavenId
|
||||
root.putUserData(MAVEN_ARTIFACT_ID, MavenId(mavenId.groupId, mavenId.artifactId, mavenId.version))
|
||||
val rootDependency = DADependency(root, scope(MavenConstants.SCOPE_COMPILE), null, emptyList())
|
||||
val result = mutableListOf<Dependency>()
|
||||
collectDependency(mavenProject.dependencyTree, rootDependency, result)
|
||||
@@ -73,9 +75,16 @@ class MavenDependencyAnalyzerContributor(private val project: Project) : Depende
|
||||
}
|
||||
|
||||
private fun getDependencyData(mavenArtifactNode: MavenArtifactNode): Dependency.Data {
|
||||
return DAArtifact(
|
||||
val mavenProject = MavenProjectsManager.getInstance(project).findProject(mavenArtifactNode.artifact)
|
||||
val daArtifact = DAArtifact(
|
||||
mavenArtifactNode.artifact.groupId, mavenArtifactNode.artifact.artifactId, mavenArtifactNode.artifact.version
|
||||
)
|
||||
if (mavenProject != null) {
|
||||
val daModule = DAModule(mavenProject.displayName)
|
||||
daModule.putUserData(MAVEN_ARTIFACT_ID, MavenId(daArtifact.groupId, daArtifact.artifactId, daArtifact.version))
|
||||
return daModule
|
||||
}
|
||||
return daArtifact
|
||||
}
|
||||
|
||||
private fun getStatus(mavenArtifactNode: MavenArtifactNode): List<Dependency.Status> {
|
||||
@@ -98,5 +107,6 @@ class MavenDependencyAnalyzerContributor(private val project: Project) : Depende
|
||||
|
||||
companion object {
|
||||
fun scope(name: @NlsSafe String) = DAScope(name, StringUtil.toTitleCase(name))
|
||||
val MAVEN_ARTIFACT_ID = Key.create<MavenId>("MavenDependencyAnalyzerContributor.MavenId")
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,15 @@ package org.jetbrains.idea.maven.project.actions
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DAArtifact
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DAModule
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerView
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.idea.maven.model.MavenId
|
||||
import org.jetbrains.idea.maven.navigator.MavenNavigationUtil
|
||||
import org.jetbrains.idea.maven.project.MavenDependencyAnalyzerContributor
|
||||
import org.jetbrains.idea.maven.project.MavenProjectsManager
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil
|
||||
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerDependency as Dependency
|
||||
@@ -18,11 +21,11 @@ class MavenDependencyAnalyzerGoToAction : AnAction() {
|
||||
val dependency = e.getData(DependencyAnalyzerView.DEPENDENCY) ?: return
|
||||
val project = e.project ?: return
|
||||
val parent = dependency.parent ?: return
|
||||
val artifactParent = parent.data as Dependency.Data.Artifact
|
||||
val artifact = dependency.data as Dependency.Data.Artifact
|
||||
val mavenId = getMavenId(dependency.data) ?: return
|
||||
if (mavenId.groupId == null || mavenId.artifactId == null) return;
|
||||
|
||||
val artifactFile = getArtifactFile(project, artifactParent) ?: return
|
||||
val navigatable = MavenNavigationUtil.createNavigatableForDependency(project, artifactFile, artifact.groupId, artifact.artifactId)
|
||||
val artifactFile = getArtifactFile(project, parent.data) ?: return
|
||||
val navigatable = MavenNavigationUtil.createNavigatableForDependency(project, artifactFile, mavenId.groupId!!, mavenId.artifactId!!)
|
||||
if (navigatable.canNavigate()) {
|
||||
navigatable.navigate(true)
|
||||
}
|
||||
@@ -34,17 +37,24 @@ class MavenDependencyAnalyzerGoToAction : AnAction() {
|
||||
e.presentation.isEnabledAndVisible =
|
||||
systemId == MavenUtil.SYSTEM_ID &&
|
||||
e.project != null &&
|
||||
dependency?.data is Dependency.Data.Artifact &&
|
||||
dependency.parent?.data is Dependency.Data.Artifact &&
|
||||
getArtifactFile(e.project!!, dependency.parent?.data as Dependency.Data.Artifact) != null
|
||||
getMavenId(dependency?.data) != null &&
|
||||
getArtifactFile(e.project!!, dependency?.parent?.data) != null
|
||||
}
|
||||
|
||||
private fun getArtifactFile(project: Project, artifactParent: Dependency.Data.Artifact): VirtualFile? {
|
||||
val mavenId = MavenId(artifactParent.groupId, artifactParent.artifactId, artifactParent.version)
|
||||
private fun getArtifactFile(project: Project, artifactParent: Dependency.Data?): VirtualFile? {
|
||||
val mavenId = getMavenId(artifactParent) ?: return null
|
||||
val mavenProject = MavenProjectsManager.getInstance(project).findProject(mavenId)
|
||||
return mavenProject?.file ?: MavenNavigationUtil.getArtifactFile(project, mavenId)
|
||||
}
|
||||
|
||||
private fun getMavenId(dependencyData: Dependency.Data?): MavenId? {
|
||||
return when (dependencyData) {
|
||||
is DAArtifact -> MavenId(dependencyData.groupId, dependencyData.artifactId, dependencyData.version)
|
||||
is DAModule -> dependencyData.getUserData(MavenDependencyAnalyzerContributor.MAVEN_ARTIFACT_ID)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
templatePresentation.icon = null
|
||||
templatePresentation.text = ExternalSystemBundle.message("external.system.dependency.analyzer.go.to", "pom.xml")
|
||||
|
||||
Reference in New Issue
Block a user