Skip to content

Commit

Permalink
Update kotlin code from intellij and suppress errors (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnu-liguobin authored Dec 17, 2023
1 parent 3cd9a80 commit 09b58a8
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 78 deletions.
10 changes: 5 additions & 5 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ labels: bug
assignees: ''

---

### Preparation action completed
- [ ] have added `addDependencyTreePlugin` into `plugins.sbt`
- [ ] have added `addDependencyTreePlugin` into `plugins.sbt` (sbt.1.4+)
- [ ] have set `organization := ` for root project and cross-platform

### Screenshot of the current SBT Shell
### Screenshot of the current sbt Shell

your images

### Screenshot of the current DependencyTree
### Screenshot of the current dependency tree

your images


### Scala platform(scala js, scala jvm, scala native) and version (scala 2.xx, scala 3.xx)
### Scala platform(scala js, scala jvm, scala native)and version (scala 2.x, scala 3.x)

your images or text

### IDEA version comes from `About Intellij IDEA`
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lazy val ktVersion = "1.9.10"
// https://youtrack.jetbrains.com/articles/IDEA-A-2100661679/IntelliJ-IDEA-2023.3-Latest-Builds
// NOTE: Latest-Builds 233
lazy val intellijVersion = "233.11799.241"
lazy val pluginVersion = s"0.3.0-$intellijVersion"
lazy val pluginVersion = s"0.3.1-$intellijVersion"

ThisBuild / version := pluginVersion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class DependencyAnalyzerManager(private val project: Project) {
}
}
}
if (file.getViews().isEmpty()) {
fileEditorManager.openFile(file, true)
}
fileEditorManager.openFile(file, true, true)
return requireNotNull(file.getViews().firstOrNull()) {
"DependencyAnalyzerView should be created during file open"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.awt.BorderLayout
import javax.swing.JComponent
import javax.swing.tree.DefaultMutableTreeNode
import javax.swing.tree.DefaultTreeModel
import java.util.Locale

import bitlap.sbt.analyzer.jbexternal.util.*
import bitlap.sbt.analyzer.jbexternal.util.DependencyGroup.Companion.hasWarnings
Expand Down Expand Up @@ -47,6 +48,9 @@ import com.intellij.util.concurrency.AppExecutorUtil
import com.intellij.util.ui.JBUI
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerDependency as Dependency

/**
* https://github.com/JetBrains/intellij-community/blob/idea/233.11799.300/platform/external-system-impl/src/com/intellij/openapi/externalSystem/dependency/analyzer/DependencyAnalyzerViewImpl.kt
*/
class DependencyAnalyzerViewImpl(
private val project: Project, private val systemId: ProjectSystemId, private val parentDisposable: Disposable
) : DependencyAnalyzerView {
Expand Down Expand Up @@ -158,8 +162,10 @@ class DependencyAnalyzerViewImpl(
val dependencyDataFilter = dependencyDataFilter
val dependencyScopeFilter = dependencyScopeFilter.filter { it.isSelected }.map { it.scope }
val showDependencyWarnings = showDependencyWarnings
return filter { dependency -> dependencyDataFilter in dependency.data.getDisplayText(showDependencyGroupId) }
.filter { dependency -> dependency.scope in dependencyScopeFilter }
return filter { dependency ->
dependencyDataFilter.lowercase(Locale.ENGLISH) in dependency.data.getDisplayText(showDependencyGroupId)
.lowercase(Locale.ENGLISH)
}.filter { dependency -> dependency.scope in dependencyScopeFilter }
.filter { dependency -> if (showDependencyWarnings) dependency.hasWarnings else true }
}

Expand Down Expand Up @@ -206,9 +212,11 @@ class DependencyAnalyzerViewImpl(
}

private fun updateDependencyEmptyState() {
dependencyEmptyState = when {
dependencyLoadingOperation.isOperationInProgress() -> ""
else -> ExternalSystemBundle.message("external.system.dependency.analyzer.resolved.empty")
runInEdt {
dependencyEmptyState = when {
dependencyLoadingOperation.isOperationInProgress() -> ""
else -> ExternalSystemBundle.message("external.system.dependency.analyzer.resolved.empty")
}
}
}

Expand Down Expand Up @@ -311,16 +319,13 @@ class DependencyAnalyzerViewImpl(

private fun Iterable<Dependency>.createDependencyGroups(): List<DependencyGroup> = sortedWith(
Comparator.comparing(
{ it.data },
DependencyDataComparator(showDependencyGroupId)
{ it.data }, DependencyDataComparator(showDependencyGroupId)
)
).groupBy { it.data.getGroup() }.map { DependencyGroup(it.value) }

fun createComponent(): JComponent {
val externalProjectSelector = ExternalProjectSelector(
externalProjectProperty,
externalProjects,
iconsProvider
externalProjectProperty, externalProjects, iconsProvider
).bindEnabled(!dependencyLoadingProperty)
val dataFilterField = SearchTextField(SEARCH_HISTORY_PROPERTY).apply { setPreferredWidth(JBUI.scale(240)) }
.apply { textEditor.bind(dependencyDataFilterProperty) }.bindEnabled(!dependencyLoadingProperty)
Expand All @@ -332,17 +337,14 @@ class DependencyAnalyzerViewImpl(
}.apply { templatePresentation.icon = AllIcons.General.ShowWarning }.asActionButton(ACTION_PLACE)
.bindEnabled(!dependencyLoadingProperty)
val showDependencyGroupIdAction = toggleAction(showDependencyGroupIdProperty).apply {
templatePresentation.text =
ExternalSystemBundle.message("external.system.dependency.analyzer.groupId.show")
templatePresentation.text = ExternalSystemBundle.message("external.system.dependency.analyzer.groupId.show")
}
val showDependencySizeAction = toggleAction(showDependencySizeProperty).apply {
templatePresentation.text = SbtDependencyExternalBundle.message("analyzer.external.showSize.name")
}
val viewOptionsButton =
popupActionGroup(showDependencyGroupIdAction, showDependencySizeAction).apply {
templatePresentation.icon = AllIcons.Actions.Show
}
.asActionButton(ACTION_PLACE).bindEnabled(!dependencyLoadingProperty)
val viewOptionsButton = popupActionGroup(showDependencyGroupIdAction, showDependencySizeAction).apply {
templatePresentation.icon = AllIcons.Actions.Show
}.asActionButton(ACTION_PLACE).bindEnabled(!dependencyLoadingProperty)
val reloadNotificationProperty = isNotificationVisibleProperty(project, systemId)
val projectReloadSeparator = separator().bindVisible(reloadNotificationProperty)
val projectReloadAction = action { ProjectRefreshAction.refreshProject(project) }.apply {
Expand All @@ -351,26 +353,15 @@ class DependencyAnalyzerViewImpl(

val dependencyTitle = label(ExternalSystemBundle.message("external.system.dependency.analyzer.resolved.title"))
val dependencyList = DependencyList(
dependencyListModel,
showDependencyGroupIdProperty,
showDependencySizeProperty,
this
).bindEmptyText(
dependencyEmptyTextProperty
).bindDependency(dependencyProperty).bindEnabled(!dependencyLoadingProperty)
dependencyListModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
).bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
.bindEnabled(!dependencyLoadingProperty)
val dependencyTree = DependencyTree(
dependencyTreeModel,
showDependencyGroupIdProperty,
showDependencySizeProperty,
this
).bindEmptyText(
dependencyEmptyTextProperty
).bindDependency(dependencyProperty).bindEnabled(!dependencyLoadingProperty)
dependencyTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
).bindEmptyText(dependencyEmptyTextProperty).bindDependency(dependencyProperty)
.bindEnabled(!dependencyLoadingProperty)
val dependencyPanel = cardPanel<Boolean> {
ScrollPaneFactory.createScrollPane(
if (it) dependencyTree else dependencyList,
true
)
ScrollPaneFactory.createScrollPane(if (it) dependencyTree else dependencyList, true)
}.bind(showDependencyTreeProperty)
val dependencyLoadingPanel =
JBLoadingPanel(BorderLayout(), parentDisposable).apply { add(dependencyPanel, BorderLayout.CENTER) }
Expand All @@ -388,12 +379,8 @@ class DependencyAnalyzerViewImpl(

val usagesTitle = label(usagesTitleProperty)
val usagesTree = UsagesTree(
usagesTreeModel,
showDependencyGroupIdProperty,
showDependencySizeProperty,
this
).apply { emptyText.text = "" }
.bindEnabled(!dependencyLoadingProperty)
usagesTreeModel, showDependencyGroupIdProperty, showDependencySizeProperty, this
).apply { emptyText.text = "" }.bindEnabled(!dependencyLoadingProperty)
val expandUsagesTreeButton =
expandTreeAction(usagesTree).asActionButton(ACTION_PLACE).bindEnabled(!dependencyLoadingProperty)
val collapseUsagesTreeButton =
Expand Down Expand Up @@ -432,11 +419,7 @@ class DependencyAnalyzerViewImpl(
secondComponent = toolWindowPanel {
toolbar = toolbarPanel {
addToLeft(usagesTitle)
addToRight(
horizontalPanel(
expandUsagesTreeButton, collapseUsagesTreeButton
)
)
addToRight(horizontalPanel(expandUsagesTreeButton, collapseUsagesTreeButton))
}
setContent(ScrollPaneFactory.createScrollPane(usagesTree, true))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import com.intellij.openapi.externalSystem.util.ExternalSystemBundle
import com.intellij.openapi.project.Project
import com.intellij.util.containers.DisposableWrapperList

internal class DependencyAnalyzerVirtualFile(
private val project: Project,
private val systemId: ProjectSystemId
) : UIComponentVirtualFile(
ExternalSystemBundle.message("external.system.dependency.analyzer.editor.tab.name"),
AllIcons.Actions.DependencyAnalyzer
) {
/**
* https://github.com/JetBrains/intellij-community/blob/idea/233.11799.300/platform/external-system-impl/src/com/intellij/openapi/externalSystem/dependency/analyzer/DependencyAnalyzerVirtualFile.kt
*/
internal class DependencyAnalyzerVirtualFile(private val project: Project, private val systemId: ProjectSystemId) :
UIComponentVirtualFile(
ExternalSystemBundle.message("external.system.dependency.analyzer.editor.tab.name"),
AllIcons.Actions.DependencyAnalyzer
) {
private val views = DisposableWrapperList<DependencyAnalyzerView>()

fun getViews(): List<DependencyAnalyzerView> = views.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class SbtDAArtifact(
override val artifactId: String,
override val version: String,
val size: Long,
val totalSize:Long
val totalSize: Long
) : UserDataHolderBase(), Dependency.Data.Artifact {
override fun toString() = "$groupId:$artifactId:$version"
}
11 changes: 9 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<idea-plugin>
<id>org.bitlap.sbtDependencyAnalyzer</id>
<name>Sbt Dependency Analyzer</name>
<version>0.3.0-233.11799.241</version>
<version>0.3.1-233.11799.241</version>
<vendor url="https://github.com/bitlap/intellij-sbt-dependency-analyzer" email="[email protected]">Bitlap
</vendor>
<!-- please see https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for description -->
Expand Down Expand Up @@ -128,7 +128,14 @@
<change-notes>

<![CDATA[
<h1>0.3.1-233.11799.241</h1>
<ul>
<li>Suppress errors and delete some errors</li>
<li>Filter ignores case</li>
</ul>
<!-- @@ -->
<h1>0.3.0-233.11799.241</h1>
<ul>
<li>Support idea 2023.3.</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ final class SbtDependencyAnalyzerConfigurable(project: Project) extends Searchab
// create a ui form
private val panel: SbtDependencyAnalyzerPanel = new SbtDependencyAnalyzerPanel(project)

override def getId(): String = SbtDependencyAnalyzerPlugin.PLUGIN_ID
override def getId: String = SbtDependencyAnalyzerPlugin.PLUGIN_ID

override def getDisplayName(): String = SbtDependencyAnalyzerBundle.message("analyzer.settings.page.name")
override def getDisplayName: String = SbtDependencyAnalyzerBundle.message("analyzer.settings.page.name")

override def getHelpTopic(): String = "default"
override def getHelpTopic: String = "default"

override def createComponent(): JComponent = panel.$$$getRootComponent$$$()

override def isModified(): Boolean = panel.isModified
override def isModified: Boolean = panel.isModified

override def apply(): Unit = panel.apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import scala.collection.mutable.ListBuffer
import scala.concurrent.*
import scala.concurrent.duration.*
import scala.jdk.CollectionConverters.*
import scala.util.Try

import bitlap.sbt.analyzer.activity.*
import bitlap.sbt.analyzer.jbexternal.SbtDAArtifact
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ final class ProjectViewDependencyAnalyzerAction extends AbstractSbtDependencyAna
selectedData: Module
): DependencyAnalyzerDependency.Data = DAModule(selectedData.getName)

override def isEnabledAndVisible(e: AnActionEvent): Boolean = {
super.isEnabledAndVisible(e)
&& (e.getData(LangDataKeys.MODULE_CONTEXT_ARRAY) != null || !ActionPlaces.isPopupPlace(e.getPlace))
}

end ProjectViewDependencyAnalyzerAction

final class ToolbarDependencyAnalyzerAction extends BaseDependencyAnalyzerAction():
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/bitlap/sbt/analyzer/parser/DotUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ import model.ModuleContext

object DotUtil {

private val LOG = Logger.getInstance(classOf[DotUtil.type])
private val LOG: Logger = Logger.getInstance(classOf[DotUtil.type])

private lazy val parser = (new Parser).forEngine(ValidatorEngine.DOT).notValidating()

private def parseAsGraphTestOnly(file: String): MutableGraph = {
Try(parser.read(new File(file))).getOrElse(null)

}

def parseAsGraph(context: ModuleContext): MutableGraph = {
Expand All @@ -45,7 +44,7 @@ object DotUtil {
VfsUtil.markDirtyAndRefresh(false, false, false, vfsFile)
} else {
if (System.currentTimeMillis() - start > Constants.TIMEOUT.toMillis) {
LOG.error(s"Cannot get dot file: $file")
LOG.warn(s"The dot file: $file has expired, try to click refresh")
Notifications.notifyParseFileError(file)
return null
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/bitlap/sbt/analyzer/util/DependencyUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object DependencyUtils {
scalaVersion: String
)

private val LOG = Logger.getInstance(classOf[DependencyUtils.type])
private val LOG: Logger = Logger.getInstance(classOf[DependencyUtils.type])

def getDeclaredDependency(module: Module): List[DeclaredDependency] = {
declaredDependencies(module).asScala.toList
Expand Down Expand Up @@ -298,7 +298,7 @@ object DependencyUtils {
} catch {
case c: ControlFlowException => throw c
case e: Exception =>
LOG.error(
LOG.warn(
s"Error occurs when obtaining the list of dependencies for module ${module.getName} using package search plugin",
e
)
Expand Down
9 changes: 5 additions & 4 deletions src/main/scala/bitlap/sbt/analyzer/util/SbtUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ object SbtUtils {

def refreshProject(project: Project): Unit = {
ExternalSystemUtil.refreshProjects(
new ImportSpecBuilder(project, SbtProjectSystem.Id).dontReportRefreshErrors().build()
new ImportSpecBuilder(project, SbtProjectSystem.Id)
.dontNavigateToError()
.dontReportRefreshErrors()
.build()
)
}

def untilProjectReady(project: Project): Boolean = {
while (!SbtUtils.isProjectReady(project)) {
waitInterval(1.second)
waitInterval(100.millis)
}
true
}
Expand All @@ -78,8 +81,6 @@ object SbtUtils {
if (
processingManager
.findTask(ExternalSystemTaskType.RESOLVE_PROJECT, SbtProjectSystem.Id, externalProjectPath) != null
|| processingManager
.findTask(ExternalSystemTaskType.EXECUTE_TASK, SbtProjectSystem.Id, externalProjectPath) != null
|| processingManager
.findTask(ExternalSystemTaskType.REFRESH_TASKS_LIST, SbtProjectSystem.Id, externalProjectPath) != null
) {
Expand Down

0 comments on commit 09b58a8

Please sign in to comment.