Skip to content

Commit c09e6d8

Browse files
committed
release 1.4.0
1 parent 9abae79 commit c09e6d8

File tree

7 files changed

+94
-55
lines changed

7 files changed

+94
-55
lines changed

build.gradle.kts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
2+
import org.jetbrains.intellij.platform.gradle.models.ProductRelease
13
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
24
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5+
import java.io.FileInputStream
6+
import java.util.Properties
37

48
plugins {
5-
application
69
id("java")
710
id("org.jetbrains.kotlin.jvm") version "2.1.0"
8-
id("org.jetbrains.intellij.platform") version "2.5.0"
11+
id("org.jetbrains.intellij.platform") version "2.6.0"
912
}
1013

1114
apply(plugin = "kotlin")
@@ -30,12 +33,9 @@ repositories {
3033
}
3134
}
3235

33-
application {
34-
mainClass = "me.bytebeats.polyglot.ui.PolyglotWindow"
35-
}
36-
3736
dependencies {
3837
api(libs.bundles.jacksonCore)
38+
api(libs.bundles.graalJs)
3939
intellijPlatform {
4040
create("IC", "2024.2")
4141
testFramework(org.jetbrains.intellij.platform.gradle.TestFrameworkType.Platform)
@@ -59,6 +59,20 @@ intellijPlatform {
5959
v1.4.0 regular upgrade with Java 21 and Idea 2025.<br>
6060
""".trimIndent()
6161
}
62+
63+
pluginVerification {
64+
ides {
65+
ide(IntelliJPlatformType.IntellijIdeaCommunity, "2024.3.6")
66+
local(file(project.localProperty("plugin.verifier.ide.location")))
67+
recommended()
68+
select {
69+
types = listOf(IntelliJPlatformType.IntellijIdeaCommunity, IntelliJPlatformType.AndroidStudio)
70+
channels = listOf(ProductRelease.Channel.RELEASE)
71+
sinceBuild = "242"
72+
untilBuild = "251.*"
73+
}
74+
}
75+
}
6276
}
6377

6478
tasks {
@@ -71,6 +85,10 @@ tasks {
7185
compilerOptions.jvmTarget.set(JvmTarget.JVM_21)
7286
}
7387

88+
buildSearchableOptions {
89+
enabled = false
90+
}
91+
7492
signPlugin {
7593
certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))
7694
privateKey.set(System.getenv("PRIVATE_KEY"))
@@ -86,7 +104,6 @@ tasks {
86104
}
87105

88106
register<Copy>("MoveBuildArtifacts") {
89-
dependsOn(named("distZip"))
90107
mustRunAfter("DeletePluginFiles")
91108
println("Moving Build Artifacts!")
92109
from(layout.buildDirectory.dir("distributions"))
@@ -97,7 +114,13 @@ tasks {
97114
register<Delete>("DeletePluginFiles") {
98115
delete(files("plugins"))
99116
}
100-
named("build") {
117+
named("signPlugin") {
101118
finalizedBy("MoveBuildArtifacts")
102119
}
103120
}
121+
122+
fun Project.localProperty(key: String, from: String = "local.properties"): String {
123+
val properties = Properties()
124+
properties.load(FileInputStream(rootProject.file(from)))
125+
return properties.getProperty(key)
126+
}

gradle/libs.versions.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[versions]
22
jackson-core = "2.19.0"
3+
graal-js = "24.2.1"
34

45
[libraries]
5-
jackson-annotations = { module = "com.fasterxml.jackson.core:jackson-annotations", version.ref = "jackson-core" }
6-
jackson-core = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson-core" }
7-
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson-core" }
6+
jackson-annotations = { group = "com.fasterxml.jackson.core", name = "jackson-annotations", version.ref = "jackson-core" }
7+
jackson-core = { group = "com.fasterxml.jackson.core", name = "jackson-core", version.ref = "jackson-core" }
8+
jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jackson-core" }
9+
graalvm-js-scriptengine = { group = "org.graalvm.js", name = "js-scriptengine", version.ref = "graal-js" }
10+
graalvm-polyglot-js = { group = "org.graalvm.polyglot", name = "js", version.ref = "graal-js" }
811

912
[bundles]
10-
jacksonCore = ["jackson-annotations", "jackson-core", "jackson-databind"]
13+
jacksonCore = ["jackson-annotations", "jackson-core", "jackson-databind"]
14+
graalJs = ["graalvm-js-scriptengine", "graalvm-polyglot-js"]

src/main/java/me/bytebeats/polyglot/tlr/impl/BaiduPolyglot.kt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import me.bytebeats.polyglot.tlr.AbstractPolyglot
77
import me.bytebeats.polyglot.util.GlotJsUtils
88
import me.bytebeats.polyglot.util.LogUtils
99
import me.bytebeats.polyglot.util.ParamUtils
10+
import me.bytebeats.polyglot.util.findGraalScriptEngine
1011
import org.apache.http.client.entity.UrlEncodedFormEntity
1112
import org.apache.http.client.methods.HttpPost
1213
import org.apache.http.util.EntityUtils
1314
import javax.script.Invocable
14-
import javax.script.ScriptEngineManager
1515
import javax.script.ScriptException
1616

1717
/**
@@ -20,7 +20,8 @@ import javax.script.ScriptException
2020
* @github https://github.com/bytebeats
2121
* @created on 2020/8/27 15:56
2222
* @version 1.0
23-
* @description BaiduPolyglot depends on baidu to offer translation service.
23+
* @description BaiduPolyglot depends on baidu to offer translation
24+
* service.
2425
*/
2526

2627
class BaiduPolyglot() : AbstractPolyglot(URL) {
@@ -71,9 +72,12 @@ class BaiduPolyglot() : AbstractPolyglot(URL) {
7172
}
7273

7374
/**
74-
* {"trans_result":{"data":[{"dst":"\u4e0a\u5e1d\uff0c\u4f60\u5728\u8003\u9a8c\u6211\u5417\uff1f","prefixWrap":0,"result":[[0,"\u4e0a\u5e1d\uff0c\u4f60\u5728\u8003\u9a8c\u6211\u5417\uff1f",["0|24"],[],["0|24"],["0|30"]]],"src":"God, are you testing me?"}],"from":"en","status":0,"to":"zh","type":2,"phonetic":[{"src_str":"\u4e0a","trg_str":"sh\u00e0ng"},{"src_str":"\u5e1d","trg_str":"d\u00ec"},{"src_str":"\uff0c","trg_str":" "},{"src_str":"\u4f60","trg_str":"n\u01d0"},{"src_str":"\u5728","trg_str":"z\u00e0i"},{"src_str":"\u8003","trg_str":"k\u01ceo"},{"src_str":"\u9a8c","trg_str":"y\u00e0n"},{"src_str":"\u6211","trg_str":"w\u01d2"},{"src_str":"\u5417","trg_str":"ma"},{"src_str":"\uff1f","trg_str":" "}],"keywords":[{"means":["\u795e","\u4e0a\u5e1d","\u5929\u4e3b"],"word":"God"},{"means":["\u8bd5\u9a8c","\u6d4b\u8bd5","\u68c0\u67e5","\u68d8\u624b\u7684","\u4f24\u8111\u7b4b\u7684","\u96be\u5e94\u4ed8\u7684","\u6d4b\u9a8c","\u8003\u67e5","\u5316\u9a8c","\u68c0\u9a8c","test\u7684\u73b0\u5728\u5206\u8bcd"],"word":"testing"}]},
75-
* "liju_result":{"double":"","single":""},
76-
* "logid":2220363170}
75+
* {"trans_result":{"data":[{"dst":"\u4e0a\u5e1d\uff0c\u4f60\u5728\u8003\u9a8c\u6211\u5417\uff1f","prefixWrap":0,"result":[[0,"\u4e0a\u5e1d\uff0c\u4f60\u5728\u8003\u9a8c\u6211\u5417\uff1f",["0|24"],[],["0|24"],["0|30"]]],"src":"God,
76+
* are you testing
77+
* me?"}],"from":"en","status":0,"to":"zh","type":2,"phonetic":[{"src_str":"\u4e0a","trg_str":"sh\u00e0ng"},{"src_str":"\u5e1d","trg_str":"d\u00ec"},{"src_str":"\uff0c","trg_str":"
78+
* "},{"src_str":"\u4f60","trg_str":"n\u01d0"},{"src_str":"\u5728","trg_str":"z\u00e0i"},{"src_str":"\u8003","trg_str":"k\u01ceo"},{"src_str":"\u9a8c","trg_str":"y\u00e0n"},{"src_str":"\u6211","trg_str":"w\u01d2"},{"src_str":"\u5417","trg_str":"ma"},{"src_str":"\uff1f","trg_str":"
79+
* "}],"keywords":[{"means":["\u795e","\u4e0a\u5e1d","\u5929\u4e3b"],"word":"God"},{"means":["\u8bd5\u9a8c","\u6d4b\u8bd5","\u68c0\u67e5","\u68d8\u624b\u7684","\u4f24\u8111\u7b4b\u7684","\u96be\u5e94\u4ed8\u7684","\u6d4b\u9a8c","\u8003\u67e5","\u5316\u9a8c","\u68c0\u9a8c","test\u7684\u73b0\u5728\u5206\u8bcd"],"word":"testing"}]},
80+
* "liju_result":{"double":"","single":""}, "logid":2220363170}
7781
*/
7882
override fun parse(text: String): String {
7983
val mapper = ObjectMapper()
@@ -136,11 +140,13 @@ class BaiduPolyglot() : AbstractPolyglot(URL) {
136140

137141
private fun token(text: String, gtk: String): String {
138142
try {
139-
val engine = ScriptEngineManager().getEngineByName("js")
143+
val engine = findGraalScriptEngine()
140144
val reader = GlotJsUtils.getReader(GlotJsUtils.JS_BAIDU)
141145
engine.eval(reader)
142146
if (engine is Invocable) {
143147
return engine.invokeFunction("token", text, gtk).toString()
148+
} else {
149+
throw IllegalStateException("$engine is not invocable")
144150
}
145151
} catch (e: ScriptException) {
146152
LogUtils.info(e.message)

src/main/java/me/bytebeats/polyglot/tlr/impl/GooglePolyglot.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ import me.bytebeats.polyglot.tlr.AbstractPolyglot
66
import me.bytebeats.polyglot.ui.PolyglotSettingState
77
import me.bytebeats.polyglot.util.GlotJsUtils
88
import me.bytebeats.polyglot.util.LogUtils
9+
import me.bytebeats.polyglot.util.findGraalScriptEngine
910
import org.apache.http.client.methods.HttpGet
1011
import org.apache.http.client.utils.URIBuilder
1112
import org.apache.http.util.EntityUtils
1213
import javax.script.Invocable
13-
import javax.script.ScriptEngineManager
14+
import javax.script.ScriptException
1415

1516
/**
1617
* @author bytebeats
1718
* @email <[email protected]>
1819
* @github https://github.com/bytebeats
1920
* @created on 2020/8/30 00:18
2021
* @version 1.0
21-
* @description GooglePolyglot depends on Google-translate-cn to offer translation service
22+
* @description GooglePolyglot depends on Google-translate-cn to offer
23+
* translation service
2224
*/
2325

2426
class GooglePolyglot() : AbstractPolyglot(URL_CN) {
@@ -104,13 +106,17 @@ class GooglePolyglot() : AbstractPolyglot(URL_CN) {
104106

105107
private fun token(text: String): String {
106108
try {
107-
val engine = ScriptEngineManager().getEngineByName("js")
109+
val engine = findGraalScriptEngine()
108110
val reader = GlotJsUtils.getReader(GlotJsUtils.JS_GOOGLE)
109111
engine.eval(reader)
110112
if (engine is Invocable) {
111113
return engine.invokeFunction("token", text).toString()
114+
} else {
115+
throw IllegalStateException("$engine is not invocable")
112116
}
113-
} catch (e: Exception) {
117+
} catch (e: ScriptException) {
118+
LogUtils.info(e.message)
119+
} catch (e: NoSuchMethodException) {
114120
LogUtils.info(e.message)
115121
}
116122
return ""

src/main/java/me/bytebeats/polyglot/tlr/impl/SogouPolyglot.kt

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import me.bytebeats.polyglot.tlr.AbstractPolyglot
77
import me.bytebeats.polyglot.util.GlotJsUtils
88
import me.bytebeats.polyglot.util.LogUtils
99
import me.bytebeats.polyglot.util.ParamUtils
10+
import me.bytebeats.polyglot.util.findGraalScriptEngine
1011
import org.apache.http.client.entity.UrlEncodedFormEntity
1112
import org.apache.http.client.methods.HttpPost
1213
import org.apache.http.util.EntityUtils
1314
import javax.script.Invocable
14-
import javax.script.ScriptEngineManager
15+
import javax.script.ScriptException
1516

1617
/**
1718
* @author bytebeats
@@ -51,35 +52,13 @@ class SogouPolyglot() : AbstractPolyglot(URL) {
5152
}
5253

5354
/**
54-
* {
55-
"data": {
56-
"detect": {
57-
"zly": "zly",
58-
"detect": "zh-CHS",
59-
"errorCode": "0",
60-
"language": "中文",
61-
"id": "a0761c8f8d35a43b130976bb5718504c",
62-
"text": "忧郁的小乌龟"
63-
},
64-
"translate": {
65-
"qc_type": "1",
66-
"zly": "zly",
67-
"errorCode": "10",
68-
"index": "content0",
69-
"from": "zh-CHS",
70-
"source": "sogou",
71-
"text": "忧郁的小乌龟",
72-
"to": "en",
73-
"id": "a0761c8f8d35a43b130976bb5718504c",
74-
"dit": "憂鬱的小烏龜",
75-
"orig_text": "忧郁的小乌龟",
76-
"md5": ""
77-
}
78-
},
79-
"status": "0",
80-
"info": "success",
81-
"zly": "zly"
82-
}
55+
* { "data": { "detect": { "zly": "zly", "detect": "zh-CHS", "errorCode":
56+
* "0", "language": "中文", "id": "a0761c8f8d35a43b130976bb5718504c", "text":
57+
* "忧郁的小乌龟" }, "translate": { "qc_type": "1", "zly": "zly", "errorCode":
58+
* "10", "index": "content0", "from": "zh-CHS", "source": "sogou", "text":
59+
* "忧郁的小乌龟", "to": "en", "id": "a0761c8f8d35a43b130976bb5718504c",
60+
* "dit": "憂鬱的小烏龜", "orig_text": "忧郁的小乌龟", "md5": "" }
61+
* }, "status": "0", "info": "success", "zly": "zly" }
8362
*/
8463
override fun query(): String {
8564
val request = HttpPost(url)
@@ -128,13 +107,17 @@ class SogouPolyglot() : AbstractPolyglot(URL) {
128107

129108
private fun token(): String {
130109
try {
131-
val engine = ScriptEngineManager().getEngineByName("js")
110+
val engine = findGraalScriptEngine()
132111
val reader = GlotJsUtils.getReader(GlotJsUtils.JS_SOGOU)
133112
engine.eval(reader)
134113
if (engine is Invocable) {
135114
return engine.invokeFunction("token").toString()
115+
} else {
116+
throw IllegalStateException("$engine is not invocable")
136117
}
137-
} catch (e: Exception) {
118+
} catch (e: ScriptException) {
119+
LogUtils.info(e.message)
120+
} catch (e: NoSuchMethodException) {
138121
LogUtils.info(e.message)
139122
}
140123
return ""
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.bytebeats.polyglot.util
2+
3+
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine
4+
import org.graalvm.polyglot.Context
5+
import org.graalvm.polyglot.HostAccess
6+
import javax.script.ScriptEngine
7+
8+
fun findGraalScriptEngine(): ScriptEngine {
9+
val engine = GraalJSScriptEngine.create(
10+
null,
11+
Context.newBuilder("js")
12+
.allowHostAccess(HostAccess.ALL)
13+
.allowHostClassLookup { true }
14+
.option("js.ecmascript-version", "2022"))
15+
engine.put("javaObj", Any())
16+
return engine
17+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<idea-plugin>
22
<id>me.bytebeats.polyglot</id>
33
<name>Polyglot Translator</name>
4-
<version>1.4.o</version>
4+
<version>1.4.0</version>
55
<vendor email="[email protected]" url="https://github.com/bytebeats">bytebeats</vendor>
66
<idea-version since-build="242" until-build="251.*"/>
77

0 commit comments

Comments
 (0)