1+ import java.io.FileInputStream
2+ import java.io.FileOutputStream
3+ import java.io.InputStream
4+ import java.io.OutputStream
5+
6+ plugins {
7+ id(" java" )
8+ id(" org.jetbrains.kotlin.jvm" ) version " 1.6.20"
9+ id(" org.jetbrains.intellij" ) version " 1.6.0"
10+ }
11+
12+ group = " com.bytedance.tools"
13+ version = " 2.0.5"
14+
15+ repositories {
16+ mavenCentral()
17+ google()
18+ }
19+
20+ dependencies {
21+ implementation(" com.google.code.gson:gson:2.9.0" )
22+ implementation(" org.jetbrains.kotlin:kotlin-stdlib" )
23+ implementation(" com.squareup.okhttp3:okhttp:3.14.9" )
24+ implementation(" com.hankcs:hanlp:portable-1.8.6" )
25+ implementation(" javazoom:jlayer:1.0.1" )
26+ implementation(project(" :CodeLocatorModel" ))
27+ implementation(" io.reactivex.rxjava3:rxjava:3.1.7" )
28+ implementation(" com.google.zxing:core:3.5.2" )
29+ implementation(fileTree(mapOf (" dir" to " libs" , " include" to listOf (" *.jar" ))))
30+ }
31+
32+ // Configure Gradle IntelliJ Plugin
33+ // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
34+ intellij {
35+ version.set(" 2022.1" )
36+ type.set(" IC" ) // Target IDE Platform
37+
38+ plugins.set(listOf (" com.intellij.java" , " org.jetbrains.kotlin" , " android" , " git4idea" ))
39+ }
40+
41+ tasks {
42+ // Set the JVM compatibility versions
43+ withType<JavaCompile > {
44+ sourceCompatibility = " 11"
45+ targetCompatibility = " 11"
46+ }
47+ withType< org.jetbrains.kotlin.gradle.tasks.KotlinCompile > {
48+ kotlinOptions.jvmTarget = " 11"
49+ }
50+
51+ patchPluginXml {
52+ sinceBuild.set(" 213" )
53+ untilBuild.set(" 999.*" )
54+ }
55+ }
56+
57+ gradle.addListener(object : TaskExecutionListener {
58+ override fun beforeExecute (task : Task ) {
59+ if (task is Zip && ! task.name.contains(" CodeLocatorModel" )) {
60+ copyFile(
61+ File (" imgcopy.m" ),
62+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} imgcopy.m" )
63+ )
64+ copyFile(
65+ File (" JarModuleTemplate.zip" ),
66+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} JarModuleTemplate.zip" )
67+ )
68+ copyFile(
69+ File (" AndroidModuleTemplate.zip" ),
70+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} AndroidModuleTemplate.zip" )
71+ )
72+ copyFile(
73+ File (" codelocatorhelper.apk" ),
74+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} codelocatorhelper.apk" )
75+ )
76+ copyFile(
77+ File (" restartAndroidStudio" ),
78+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} restartAndroidStudio" )
79+ )
80+ }
81+ }
82+
83+ override fun afterExecute (task : Task , state : TaskState ) {
84+ // 任务执行后逻辑(可选)
85+ }
86+ })
87+
88+ tasks.named(" prepareSandbox" ) {
89+ doLast {
90+ copyFile(
91+ File (" imgcopy.m" ),
92+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} imgcopy.m" )
93+ )
94+ copyFile(
95+ File (" JarModuleTemplate.zip" ),
96+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} JarModuleTemplate.zip" )
97+ )
98+ copyFile(
99+ File (" AndroidModuleTemplate.zip" ),
100+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} AndroidModuleTemplate.zip" )
101+ )
102+ copyFile(
103+ File (" codelocatorhelper.apk" ),
104+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} codelocatorhelper.apk" )
105+ )
106+ copyFile(
107+ File (" restartAndroidStudio" ),
108+ File (" build${File .separator} idea-sandbox${File .separator} plugins${File .separator} CodeLocatorPlugin${File .separator} restartAndroidStudio" )
109+ )
110+ }
111+ }
112+
113+ fun copyFile (sourceFile : File , targetFile : File ) {
114+ var inputStream: InputStream ? = null
115+ var outputStream: OutputStream ? = null
116+ try {
117+ inputStream = FileInputStream (sourceFile)
118+ outputStream = FileOutputStream (targetFile)
119+ var buffer = ByteArray (8192 )
120+ var len = 0
121+ len = inputStream.read(buffer)
122+ while (len > 0 ) {
123+ outputStream.write(buffer, 0 , len)
124+ len = inputStream.read(buffer)
125+ }
126+ inputStream.close()
127+ outputStream.close()
128+ } catch (e: Exception ) {
129+ System .out .println (" Copy Error " + e)
130+ }
131+ }
0 commit comments