Skip to content

Commit

Permalink
Update listener and notification translation (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnu-liguobin authored Sep 2, 2023
1 parent 316abf6 commit 70f4f86
Show file tree
Hide file tree
Showing 26 changed files with 469 additions and 80 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lazy val scala3Version = "3.3.0"

lazy val intellijVersion =
"231.9392.1" // https://youtrack.jetbrains.com/articles/IDEA-A-2100661425/IntelliJ-IDEA-2023.1-Latest-Builds
lazy val pluginVersion = s"0.1.4-$intellijVersion"
lazy val pluginVersion = s"0.2.0-RC1-$intellijVersion"

ThisBuild / version := pluginVersion

Expand Down
35 changes: 28 additions & 7 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.1.4-231.9392.1</version>
<version>0.2.0-RC1-231.9392.1</version>
<vendor url="https://github.com/bitlap/intellij-sbt-dependency-analyzer" email="[email protected]">Bitlap
</vendor>
<idea-version since-build="231.0"/>
Expand All @@ -17,32 +17,46 @@
<extensions defaultExtensionNs="com.intellij">
<externalSystemDependencyAnalyzer implementation="bitlap.sbt.analyzer.SbtDependencyAnalyzerExtension"/>
<notificationGroup id="Sbt.DependencyAnalyzer.Notification" displayType="BALLOON"/>
<notificationGroup id="Sbt.DependencyAnalyzer.UpdateNotification" displayType="BALLOON"/>

<registryKey key="bitlap.sbt.analyzer.SbtDependencyAnalyzerBundle"
defaultValue="true" restartRequired="false"
description="Force translation for notification"/>

<postStartupActivity implementation="bitlap.sbt.analyzer.activity.PluginUpdateActivity"/>

</extensions>

<actions>
<action id="Sbt.ViewDependencyAnalyzer" class="bitlap.sbt.analyzer.ViewDependencyAnalyzerAction"/>
<action id="Sbt.ToolbarDependencyAnalyzer" class="bitlap.sbt.analyzer.ToolbarDependencyAnalyzerAction"/>
<action id="Sbt.ViewDependencyAnalyzer" class="bitlap.sbt.analyzer.action.ViewDependencyAnalyzerAction"/>
<action id="Sbt.ToolbarDependencyAnalyzer" class="bitlap.sbt.analyzer.action.ToolbarDependencyAnalyzerAction"/>
<action id="Sbt.ProjectViewDependencyAnalyzer"
class="bitlap.sbt.analyzer.ProjectViewDependencyAnalyzerAction">
class="bitlap.sbt.analyzer.action.ProjectViewDependencyAnalyzerAction">
<add-to-group group-id="ProjectViewPopupMenu" anchor="before" relative-to-action="UML.Group"/>
</action>
<action id="Sbt.DependencyAnalyzer.OpenConfig"
class="bitlap.sbt.analyzer.SbtDependencyAnalyzerOpenConfigAction">
class="bitlap.sbt.analyzer.action.SbtDependencyAnalyzerOpenConfigAction">
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyListGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyTreeGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.UsagesTreeGroup"/>
</action>
<action id="Sbt.DependencyAnalyzer.GoTo" class="bitlap.sbt.analyzer.SbtDependencyAnalyzerGoToAction">
<action id="Sbt.DependencyAnalyzer.GoTo" class="bitlap.sbt.analyzer.action.SbtDependencyAnalyzerGoToAction">
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyListGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyTreeGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.UsagesTreeGroup"/>
</action>
<action id="Sbt.DependencyAnalyzer.RefreshDependencies" class="bitlap.sbt.analyzer.SbtRefreshDependenciesAction">
<action id="Sbt.DependencyAnalyzer.RefreshDependencies"
class="bitlap.sbt.analyzer.action.SbtRefreshDependenciesAction">
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyListGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.DependencyTreeGroup"/>
<add-to-group group-id="ExternalSystem.DependencyAnalyzer.UsagesTreeGroup"/>
</action>

<action id="Sbt.WhatsNewInSbtDependencyAnalyzer"
class="bitlap.sbt.analyzer.activity.WhatsNewAction">
<add-to-group group-id="HelpMenu" anchor="after" relative-to-action="WhatsNewAction"/>
</action>

<group id="Sbt.View.ProjectMenu">
<separator/>
<reference id="Sbt.ViewDependencyAnalyzer"/>
Expand Down Expand Up @@ -93,6 +107,13 @@
</description>
<change-notes>
<![CDATA[
<h1>0.2.0-RC1-231.9392.1</h1>
<ul>
<li>🎉Add locale zn_CN translation for notification.</li>
<li>🎉Add plugin update notification.</li>
<li>🎉Add What's New action in Help menu.</li>
</ul>
<h1>0.1.3-231.9392.1</h1>
<ul>
<li>Fix module recognition failure when analyzing cross-build projects for Scala2 and Scala3.</li>
Expand Down
24 changes: 16 additions & 8 deletions src/main/resources/messages/SbtDependencyAnalyzerBundle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
sbt.dependency.analyzer.error=Please ensure to include the 'addDependencyTreePlugin' statement in 'plugins.sbt'.
sbt.dependency.analyzer.error.unknown=Unknown problem occurs: {0} / {1} / {2}, please report the problem to the developer.
sbt.dependency.analyzer.error.parse=Failed to parse the file: {0}, please report the problem to the developer.
sbt.dependency.analyzer.error.title=Failed to use Sbt Dependency Analyzer plugin.
sbt.dependency.analyzer.action.name=Analyze SBT Dependencies...
sbt.dependency.analyzer.notification.goto.plugins.sbt=Add and Goto plugins.sbt
sbt.dependency.analyzer.refresh.dependencies.text=Refresh SBT Dependencies
sbt.dependency.analyzer.refresh.dependencies.description=Refresh SBT dependencies
analyzer.task.error.unknown.title=Please ensure to include the "addDependencyTreePlugin" statement in "plugins.sbt"
analyzer.task.error.unknown.text=Unknown problem occurs: {0} / {1} / {2}, please report the problem to the developer
analyzer.task.error.text=Failed to parse the file: {0}, please report the problem to the developer
analyzer.task.error.title=Failed to use Sbt Dependency Analyzer plugin
analyzer.action.name=Analyze SBT Dependencies...
analyzer.notification.gotoPluginsFile=Add and Goto "plugins.sbt"
analyzer.refresh.dependencies.text=Refresh SBT Dependencies
analyzer.refresh.dependencies.description=Refresh SBT dependencies
analyzer.updated.notification.title={0} plugin updated to v{1}
analyzer.updated.notification.text=Thank you for downloading \
<b><a href="https://github.com/bitlap/intellij-sbt-dependency-analyzer">Sbt Dependency Analyzer</a></b>! \
<div style="{0}">Change notes (<a href="https://github.com/bitlap/intellij-sbt-dependency-analyzer/releases/tag/v{2}">releases notes</a>)\:</div>\
<div style="margin: 2px 0">{1}</div>
analyzer.updated.notification.gotoBrowser=Go to see
analyzer.action.WhatsNew.text=What''s New in {0}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
analyzer.task.error.unknown.title=请确保在 “plugins.sbt” 中包含 “addDependencyTreePlugin” 语句
analyzer.task.error.unknown.text=出现未知问题: {0} / {1} / {2}, 请向开发人员报告问题
analyzer.task.error.title=无法使用 Sbt Dependency Analyzer 插件
analyzer.task.error.text=无法分析文件: {0}, 请向开发人员报告问题
analyzer.action.name=分析 SBT 依赖...
analyzer.notification.gotoPluginsFile=添加并打开 ”plugins.sbt“
analyzer.refresh.dependencies.text=刷新 SBT 依赖
analyzer.refresh.dependencies.description=刷新 SBT 依赖
analyzer.updated.notification.title={0} 插件已更新为 v{1}
analyzer.updated.notification.text=感谢下载 \
<b><a href="https://github.com/bitlap/intellij-sbt-dependency-analyzer">Sbt Dependency Analyzer</a></b>! \
<div style="{0}">更新说明 (<a href="https://github.com/bitlap/intellij-sbt-dependency-analyzer/releases/tag/v{2}">releases notes</a>)\:</div>\
<div style="margin: 2px 0">{1}</div>
analyzer.updated.notification.gotoBrowser=去看看
analyzer.action.WhatsNew.text={0} 最新功能
6 changes: 3 additions & 3 deletions src/main/scala/bitlap/sbt/analyzer/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ object Constants:

final val Protobuf = "protobuf"

final val timeout = 10.minutes
final val Timeout = 10.minutes

final val intervalTimeout = 1010.milliseconds
final val IntervalTimeout = 1010.milliseconds

final val fileLifespan = 1000 * 60 * 60L
final val FileLifespan = 1000 * 60 * 60L

end Constants
Original file line number Diff line number Diff line change
@@ -1,21 +1,79 @@
package bitlap.sbt.analyzer

import java.util.*

import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NotNull
import org.jetbrains.annotations.PropertyKey

import com.intellij.DynamicBundle
import com.intellij.*
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.util.registry.Registry

import SbtDependencyAnalyzerBundle.*

final class SbtDependencyAnalyzerBundle extends DynamicBundle(BUNDLE)
final class SbtDependencyAnalyzerBundle(private val pathToBundle: String) extends AbstractBundle(pathToBundle):
private val adaptedControl = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES)

private lazy val adaptedBundle: AbstractBundle = {
val dynamicLocale = getDynamicLocale
if dynamicLocale != null then
if (dynamicLocale.toLanguageTag == Locale.ENGLISH.toLanguageTag) {
new AbstractBundle(pathToBundle) {
override def findBundle(
pathToBundle: String,
loader: ClassLoader,
control: ResourceBundle.Control
): ResourceBundle = {
val dynamicBundle = ResourceBundle.getBundle(pathToBundle, dynamicLocale, loader, adaptedControl)
if dynamicBundle == null then super.findBundle(pathToBundle, loader, control) else dynamicBundle
}
}
} else null
else null
}

def getAdaptedMessage(@PropertyKey(resourceBundle = BUNDLE) key: String, params: Any*): String = {
if (adaptedBundle != null) adaptedBundle.getMessage(key, params: _*) else getMessage(key, params: _*)
}

override def findBundle(
pathToBundle: String,
loader: ClassLoader,
control: ResourceBundle.Control
): ResourceBundle =
val dynamicLocale = getDynamicLocale
if dynamicLocale != null then
if forceFollowLanguagePack then ResourceBundle.getBundle(pathToBundle, dynamicLocale, loader, adaptedControl)
else ResourceBundle.getBundle(pathToBundle, dynamicLocale, loader, control)
else super.findBundle(pathToBundle, loader, control)

end findBundle

end SbtDependencyAnalyzerBundle

object SbtDependencyAnalyzerBundle:
private val LOG = Logger.getInstance(classOf[SbtDependencyAnalyzerBundle])

private lazy val forceFollowLanguagePack: Boolean = {
Registry.get("bitlap.sbt.analyzer.SbtDependencyAnalyzerBundle").asBoolean()
}

private lazy val getDynamicLocale: Locale = {
try {
DynamicBundle.getLocale
} catch {
case e: NoSuchMethodError =>
LOG.debug("NoSuchMethodError: DynamicBundle.getLocale()")
null
}
}

final val BUNDLE = "messages.SbtDependencyAnalyzerBundle"

final val BUNDLE = "messages.SbtDependencyAnalyzerBundle"
final val INSTANCE = new SbtDependencyAnalyzerBundle
final val INSTANCE = new SbtDependencyAnalyzerBundle(BUNDLE)

@Nls def message(@NotNull @PropertyKey(resourceBundle = BUNDLE) key: String, @NotNull params: AnyRef*): String =
INSTANCE.getMessage(key, params: _*)
INSTANCE.getAdaptedMessage(key, params: _*)

end SbtDependencyAnalyzerBundle
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import scala.collection.mutable.ListBuffer
import scala.concurrent.*
import scala.jdk.CollectionConverters.*

import bitlap.sbt.analyzer.DependencyUtils.*
import bitlap.sbt.analyzer.component.*
import bitlap.sbt.analyzer.activity.*
import bitlap.sbt.analyzer.model.*
import bitlap.sbt.analyzer.parser.*
import bitlap.sbt.analyzer.task.*
import bitlap.sbt.analyzer.util.{ DependencyUtils, Notifications }
import bitlap.sbt.analyzer.util.DependencyUtils.*

import org.jetbrains.plugins.scala.project.ModuleExt
import org.jetbrains.sbt.project.SbtProjectSystem
Expand Down Expand Up @@ -247,7 +248,7 @@ object SbtDependencyAnalyzerContributor:
private def isValidFile(file: String): Boolean = {
if (isValid.get()) {
val lastModified = Path.of(file).toFile.lastModified()
System.currentTimeMillis() <= lastModified + Constants.fileLifespan
System.currentTimeMillis() <= lastModified + Constants.FileLifespan
} else {
isValid.getAndSet(true)
}
Expand Down Expand Up @@ -382,11 +383,11 @@ object SbtDependencyAnalyzerContributor:
} catch {
case _: AnalyzerCommandNotFoundException =>
if (isNotifying.compareAndSet(false, true)) {
SbtDependencyAnalyzerNotifier.notifyAndAddDependencyTreePlugin(project)
Notifications.notifyAndAddDependencyTreePlugin(project)
}
break()
case ue: AnalyzerCommandUnknownException =>
SbtDependencyAnalyzerNotifier.notifyUnknownError(project, ue.command, ue.moduleId, ue.scope)
Notifications.notifyUnknownError(project, ue.command, ue.moduleId, ue.scope)
break()
case e =>
throw e
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bitlap.sbt.analyzer

import com.intellij.ide.plugins.IdeaPluginDescriptor
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.extensions.PluginId

/** @author
* 梦境迷离
* @version 1.0,2023/9/1
*/
object SbtDependencyAnalyzerPlugin {

val PLUGIN_ID = "org.bitlap.sbtDependencyAnalyzer"

val descriptor: IdeaPluginDescriptor = PluginManagerCore.getPlugin(PluginId.getId(PLUGIN_ID))

lazy val version: String = descriptor.getVersion
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package bitlap.sbt.analyzer
package bitlap
package sbt
package analyzer
package action

import scala.jdk.CollectionConverters.*

import bitlap.sbt.analyzer.*

import org.jetbrains.sbt.project.SbtProjectSystem

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.actionSystem.*
import com.intellij.openapi.externalSystem.dependency.analyzer.*
import com.intellij.openapi.externalSystem.model.*
import com.intellij.openapi.externalSystem.model.project.*
Expand All @@ -20,7 +24,7 @@ import com.intellij.openapi.module.Module
*/
final class ViewDependencyAnalyzerAction extends AbstractDependencyAnalyzerAction[ExternalSystemNode[?]]:

getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("sbt.dependency.analyzer.action.name"))
getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("analyzer.action.name"))
getTemplatePresentation.setIcon(SbtDependencyAnalyzerIcons.ICON)

override def getDependencyScope(anActionEvent: AnActionEvent, selectedData: ExternalSystemNode[_]): String =
Expand Down Expand Up @@ -67,7 +71,7 @@ end ViewDependencyAnalyzerAction

final class ProjectViewDependencyAnalyzerAction extends AbstractDependencyAnalyzerAction[Module]:

getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("sbt.dependency.analyzer.action.name"))
getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("analyzer.action.name"))
getTemplatePresentation.setIcon(SbtDependencyAnalyzerIcons.ICON)

override def getDependencyScope(anActionEvent: AnActionEvent, data: Module): String = null
Expand All @@ -93,7 +97,7 @@ end ProjectViewDependencyAnalyzerAction

final class ToolbarDependencyAnalyzerAction extends DependencyAnalyzerAction():

getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("sbt.dependency.analyzer.action.name"))
getTemplatePresentation.setText(SbtDependencyAnalyzerBundle.message("analyzer.action.name"))
getTemplatePresentation.setIcon(SbtDependencyAnalyzerIcons.ICON)

private val viewAction = ViewDependencyAnalyzerAction()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package bitlap.sbt.analyzer
package bitlap
package sbt
package analyzer
package action

import scala.jdk.CollectionConverters.*
import scala.util.Try

import bitlap.sbt.analyzer.*
import bitlap.sbt.analyzer.util.DependencyUtils

import org.jetbrains.sbt.project.SbtProjectSystem

import com.intellij.buildsystem.model.DeclaredDependency
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package bitlap.sbt.analyzer
package bitlap
package sbt
package analyzer
package action

import org.jetbrains.sbt.project.SbtProjectSystem

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerDependency as Dependency
import com.intellij.openapi.externalSystem.dependency.analyzer.DependencyAnalyzerView
import com.intellij.openapi.externalSystem.dependency.analyzer.ExternalSystemDependencyAnalyzerOpenConfigAction
import com.intellij.openapi.externalSystem.dependency.analyzer.{
DependencyAnalyzerDependency as Dependency,
DependencyAnalyzerView,
ExternalSystemDependencyAnalyzerOpenConfigAction
}

final class SbtDependencyAnalyzerOpenConfigAction
extends ExternalSystemDependencyAnalyzerOpenConfigAction(SbtProjectSystem.Id):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package bitlap.sbt.analyzer
package bitlap
package sbt
package analyzer
package action

import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.externalSystem.action.RefreshAllExternalProjectsAction
Expand All @@ -10,11 +13,11 @@ import com.intellij.openapi.externalSystem.action.RefreshAllExternalProjectsActi
final class SbtRefreshDependenciesAction extends RefreshAllExternalProjectsAction:

getTemplatePresentation.setText(
SbtDependencyAnalyzerBundle.message("sbt.dependency.analyzer.refresh.dependencies.text")
SbtDependencyAnalyzerBundle.message("analyzer.refresh.dependencies.text")
)

getTemplatePresentation.setDescription(
SbtDependencyAnalyzerBundle.message("sbt.dependency.analyzer.refresh.dependencies.description")
SbtDependencyAnalyzerBundle.message("analyzer.refresh.dependencies.description")
)

override def beforeActionPerformedUpdate(e: AnActionEvent): Unit =
Expand Down
Loading

0 comments on commit 70f4f86

Please sign in to comment.