diff --git a/gradle.properties b/gradle.properties index 7cac60b..6406e34 100644 --- a/gradle.properties +++ b/gradle.properties @@ -34,3 +34,6 @@ org.gradle.caching = true # Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment systemProp.org.gradle.unsafe.kotlin.assignment = true + +org.gradle.parallel = true +org.gradle.jvmargs = '-Dfile.encoding=UTF-8' \ No newline at end of file diff --git a/src/main/java/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.java b/src/main/java/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.java deleted file mode 100644 index 8d656f5..0000000 --- a/src/main/java/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.github.meimingle.tsvnpwdintellij.actions; - -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.project.DumbAware; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.Messages; -import com.tomxin.tool.tangible.ParserProgram; -import com.tomxin.tool.tangible.Result; - -import java.util.List; - -/** - * @author meiMingle - */ -public class FindSvnPasswordAction extends AnAction implements DumbAware { - - public FindSvnPasswordAction() { - super("_Find Svn Password"); - } - - @Override - public void actionPerformed(AnActionEvent e) { - Project project = e.getData(CommonDataKeys.PROJECT); - List allSvnInfo = ParserProgram.findAllSvnInfo(); - if (!allSvnInfo.isEmpty()) { - Messages.showMessageDialog(project, formatSvnInfo(allSvnInfo), "SVN Information", Messages.getInformationIcon()); - } else { - Messages.showMessageDialog(project, "Can not find any information of svn", "Information", Messages.getInformationIcon()); - } - - } - - private String formatSvnInfo(List results) { - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("---------------------------------------------------\n"); - for (Result result : results) { - stringBuilder.append("FileName = ").append(result.getFilename()).append("\n"); - stringBuilder.append("Repository = ").append(result.getRepository()).append("\n"); - stringBuilder.append("Username = ").append(result.getUsername()).append("\n"); - stringBuilder.append("Password = ").append(result.getDecryptedPassword()).append("\n"); - stringBuilder.append("---------------------------------------------------\n"); - } - - return stringBuilder.toString(); - - } -} diff --git a/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.kt b/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.kt new file mode 100644 index 0000000..3d62fe2 --- /dev/null +++ b/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/actions/FindSvnPasswordAction.kt @@ -0,0 +1,60 @@ +package com.github.meimingle.tsvnpwdintellij.actions + +import com.github.meimingle.tsvnpwdintellij.bundle.TSvnPwdBundle +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.ui.Messages +import com.tomxin.tool.tangible.ParserProgram +import com.tomxin.tool.tangible.Result + +/** + * @author meiMingle + */ +class FindSvnPasswordAction : AnAction(), DumbAware { + override fun actionPerformed(e: AnActionEvent) { + val project = e.getData(CommonDataKeys.PROJECT) + + try { + val allSvnInfo = ParserProgram.findAllSvnInfo() + if (!allSvnInfo.isNullOrEmpty()) { + Messages.showMessageDialog( + project, + formatSvnInfo(allSvnInfo), + "TSvnPwd Information", + Messages.getWarningIcon() + ) + } else { + Messages.showMessageDialog( + project, + TSvnPwdBundle.message("popupTextNoResult"), + "TSvnPwd Information", + Messages.getInformationIcon() + ) + } + } catch (e: Exception) { + Messages.showMessageDialog( + project, + TSvnPwdBundle.message("popupTextException",e.message!!) , + "TSvnPwd Information", + Messages.getErrorIcon() + ) + } + + } + + private fun formatSvnInfo(results: List): String { + val stringBuilder = StringBuilder() + stringBuilder.append("---------------------------------------------------\n") + for (result in results) { + stringBuilder.append("FileName = ").append(result.filename).append("\n") + stringBuilder.append("Repository = ").append(result.repository).append("\n") + stringBuilder.append("Username = ").append(result.username).append("\n") + stringBuilder.append("Password = ").append(result.decryptedPassword).append("\n") + stringBuilder.append("---------------------------------------------------\n") + } + return stringBuilder.toString() + } + +} diff --git a/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/bundle/TSvnPwdBundle.kt b/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/bundle/TSvnPwdBundle.kt new file mode 100644 index 0000000..cfd73f3 --- /dev/null +++ b/src/main/kotlin/com/github/meimingle/tsvnpwdintellij/bundle/TSvnPwdBundle.kt @@ -0,0 +1,50 @@ +package com.github.meimingle.tsvnpwdintellij.bundle + +import com.intellij.AbstractBundle +import com.intellij.DynamicBundle +import org.jetbrains.annotations.NonNls +import org.jetbrains.annotations.PropertyKey +import java.util.* +import java.util.function.Supplier + +@NonNls +const val BUNDLE: String = "messages.TSvnPwdBundle" + +object TSvnPwdBundle : AbstractBundle(BUNDLE) { + private val adaptedControl = ResourceBundle.Control.getNoFallbackControl(ResourceBundle.Control.FORMAT_PROPERTIES) + + private val adaptedBundle: AbstractBundle? by lazy { + val dynamicLocale = DynamicBundle.getLocale() + if (dynamicLocale.toLanguageTag() == Locale.ENGLISH.toLanguageTag()) { + object : AbstractBundle(BUNDLE) { + override fun findBundle(pathToBundle: String, loader: ClassLoader, control: ResourceBundle.Control): ResourceBundle { + val dynamicBundle = ResourceBundle.getBundle(pathToBundle, dynamicLocale, loader, adaptedControl) + return dynamicBundle ?: super.findBundle(pathToBundle, loader, control) + } + } + } else null + } + + override fun findBundle(pathToBundle: String, loader: ClassLoader, control: ResourceBundle.Control): ResourceBundle = + DynamicBundle.getLocale().let { ResourceBundle.getBundle(pathToBundle, it, loader, control) } + ?: super.findBundle(pathToBundle, loader, control) + + fun getAdaptedMessage(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): String { + return adaptedBundle?.getMessage(key, *params) ?: getMessage(key, *params) + } + + fun getAdaptedLazyMessage(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any): Supplier { + return adaptedBundle?.getLazyMessage(key, *params) ?: getLazyMessage(key, *params) + } + + @Suppress("SpreadOperator") + @JvmStatic + fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = + getAdaptedMessage(key, *params) + + @Suppress("SpreadOperator", "unused") + @JvmStatic + fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) = + getAdaptedLazyMessage(key, *params) + +} diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 3aace2c..ce39f65 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -8,21 +8,11 @@ com.intellij.modules.platform - + messages.TSvnPwdBundle - - - - - - - - - - - - - + + + diff --git a/src/main/resources/messages/TSvnPwdBundle.properties b/src/main/resources/messages/TSvnPwdBundle.properties new file mode 100644 index 0000000..616ae9d --- /dev/null +++ b/src/main/resources/messages/TSvnPwdBundle.properties @@ -0,0 +1,6 @@ + +action.com.github.meimingle.tsvnpwdintellij.actions.FindSvnPasswordAction.text=_Find SVN Password +action.com.github.meimingle.tsvnpwdintellij.actions.FindSvnPasswordAction.description=Find SVN password! + +popupTextNoResult=Can not find any information of svn! +popupTextException=Exception: {0}