@@ -61,81 +61,6 @@ project.afterEvaluate {
6161 tasks.findByName(" :prepareSandbox" )?.inputs?.properties?.put(" build_mode" , ext.get(" debugMode" ))
6262}
6363
64- fun Sync.prepareSandbox () {
65- // Set duplicate strategy to include files, with later sources taking precedence
66- duplicatesStrategy = DuplicatesStrategy .INCLUDE
67-
68- if (ext.get(" debugMode" ) == " idea" ) {
69- from(" ${project.projectDir.absolutePath} /src/main/resources/themes/" ) {
70- into(" ${ext.get(" debugResource" )} /${ext.get(" vscodePlugin" )} /integrations/theme/default-themes/" )
71- }
72- doLast {
73- val vscodePluginDir = File (" ${ext.get(" debugResource" )} /${ext.get(" vscodePlugin" )} " )
74- vscodePluginDir.mkdirs()
75- File (vscodePluginDir, " .env" ).createNewFile()
76- }
77- } else {
78- val vscodePluginDir = File (" ./plugins/${ext.get(" vscodePlugin" )} " )
79- if (! vscodePluginDir.exists()) {
80- throw IllegalStateException (" missing plugin dir" )
81- }
82- val list = mutableListOf<String >()
83- val depfile = File (" prodDep.txt" )
84- if (! depfile.exists()) {
85- throw IllegalStateException (" missing prodDep.txt" )
86- }
87- depfile.readLines().let {
88- it.forEach { line ->
89- list.add(line.substringAfterLast(" node_modules/" ) + " /**" )
90- }
91- }
92-
93- val pluginName = properties(" pluginGroup" ).get().split(" ." ).last()
94-
95- from(" ../host/dist" ) { into(" $pluginName /runtime/" ) }
96- from(" ../host/package.json" ) { into(" $pluginName /runtime/" ) }
97-
98- // First copy host node_modules
99- from(" ../resources/node_modules" ) {
100- into(" $pluginName /node_modules/" )
101- list.forEach {
102- include(it)
103- }
104- }
105-
106- from(" ${vscodePluginDir.path} /extension" ) { into(" $pluginName /${ext.get(" vscodePlugin" )} " ) }
107- from(" src/main/resources/themes/" ) { into(" $pluginName /${ext.get(" vscodePlugin" )} /integrations/theme/default-themes/" ) }
108-
109- // The platform.zip file required for release mode is associated with the code in ../base/vscode, currently using version 1.100.0. If upgrading this code later
110- // Need to modify the vscodeVersion value in gradle.properties, then execute the task named genPlatform, which will generate a new platform.zip file for submission
111- // To support new architectures, modify according to the logic in genPlatform.gradle script
112- if (ext.get(" debugMode" ) == " release" ) {
113- // Check if platform.zip file exists and is larger than 1MB, otherwise throw exception
114- val platformZip = File (" platform.zip" )
115- if (platformZip.exists() && platformZip.length() >= 1024 * 1024 ) {
116- // Extract platform.zip to the platform subdirectory under the project build directory
117- val platformDir = File (" ${layout.buildDirectory.get().asFile} /platform" )
118- platformDir.mkdirs()
119- copy {
120- from(zipTree(platformZip))
121- into(platformDir)
122- }
123- } else {
124- throw IllegalStateException (" platform.zip file does not exist or is smaller than 1MB. This file is supported through git lfs and needs to be obtained through git lfs" )
125- }
126-
127- val pluginName = properties(" pluginGroup" ).get().split(" ." ).last()
128- from(File (layout.buildDirectory.get().asFile, " platform/platform.txt" )) { into(" $pluginName /" ) }
129- // Copy platform node_modules last to ensure it takes precedence over host node_modules
130- from(File (layout.buildDirectory.get().asFile, " platform/node_modules" )) { into(" $pluginName /node_modules" ) }
131- }
132-
133- doLast {
134- val pluginName = properties(" pluginGroup" ).get().split(" ." ).last()
135- File (" $destinationDir /$pluginName /${ext.get(" vscodePlugin" )} /.env" ).createNewFile()
136- }
137- }
138- }
13964
14065group = properties(" pluginGroup" ).get()
14166version = properties(" pluginVersion" ).get()
@@ -227,9 +152,146 @@ tasks {
227152 println (" Configuration file generated: ${configFile.absolutePath} " )
228153 }
229154 }
155+
230156
157+ buildPlugin {
158+ dependsOn(prepareSandbox)
159+
160+ // Include the jetbrains directory contents from sandbox in the distribution root
161+ doLast {
162+ if (ext.get(" debugMode" ) != " idea" && ext.get(" debugMode" ) != " none" ) {
163+ val distributionFile = archiveFile.get().asFile
164+ val sandboxPluginsDir = layout.buildDirectory.get().asFile.resolve(" idea-sandbox/IC-2024.3/plugins" )
165+ val jetbrainsDir = sandboxPluginsDir.resolve(" jetbrains" )
166+
167+ if (jetbrainsDir.exists() && distributionFile.exists()) {
168+ logger.lifecycle(" Adding sandbox resources to distribution ZIP..." )
169+ logger.lifecycle(" Sandbox jetbrains dir: ${jetbrainsDir.absolutePath} " )
170+ logger.lifecycle(" Distribution file: ${distributionFile.absolutePath} " )
171+
172+ // Extract the existing ZIP
173+ val tempDir = layout.buildDirectory.get().asFile.resolve(" temp-dist" )
174+ tempDir.deleteRecursively()
175+ tempDir.mkdirs()
176+
177+ copy {
178+ from(zipTree(distributionFile))
179+ into(tempDir)
180+ }
181+
182+ // Copy jetbrains directory CONTENTS directly to plugin root (not the jetbrains folder itself)
183+ val pluginDir = tempDir.resolve(rootProject.name)
184+ copy {
185+ from(jetbrainsDir) // Copy contents of jetbrains dir
186+ into(pluginDir) // Directly into plugin root
187+ }
188+
189+ // Re-create the ZIP with resources included
190+ distributionFile.delete()
191+ ant.invokeMethod(" zip" , mapOf (
192+ " destfile" to distributionFile.absolutePath,
193+ " basedir" to tempDir.absolutePath
194+ ))
195+
196+ // Clean up temp directory
197+ tempDir.deleteRecursively()
198+
199+ logger.lifecycle(" Distribution ZIP updated with sandbox resources at root level" )
200+ }
201+ }
202+ }
203+ }
204+
231205 prepareSandbox {
232- prepareSandbox()
206+ dependsOn(" generateConfigProperties" )
207+ duplicatesStrategy = DuplicatesStrategy .INCLUDE
208+
209+ if (ext.get(" debugMode" ) == " idea" ) {
210+ from(" ${project.projectDir.absolutePath} /src/main/resources/themes/" ) {
211+ into(" ${ext.get(" debugResource" )} /${ext.get(" vscodePlugin" )} /integrations/theme/default-themes/" )
212+ }
213+ doLast {
214+ val vscodePluginDir = File (" ${ext.get(" debugResource" )} /${ext.get(" vscodePlugin" )} " )
215+ vscodePluginDir.mkdirs()
216+ File (vscodePluginDir, " .env" ).createNewFile()
217+ }
218+ } else if (ext.get(" debugMode" ) != " none" ) {
219+ doFirst {
220+ // Validate required files exist
221+ val vscodePluginDir = File (" ./plugins/${ext.get(" vscodePlugin" )} " )
222+ if (! vscodePluginDir.exists()) {
223+ throw IllegalStateException (" missing plugin dir: ${vscodePluginDir.absolutePath} " )
224+ }
225+ val depfile = File (" prodDep.txt" )
226+ if (! depfile.exists()) {
227+ throw IllegalStateException (" missing prodDep.txt" )
228+ }
229+
230+ // Handle platform.zip for release mode
231+ if (ext.get(" debugMode" ) == " release" ) {
232+ val platformZip = File (" platform.zip" )
233+ if (! platformZip.exists() || platformZip.length() < 1024 * 1024 ) {
234+ throw IllegalStateException (" platform.zip file does not exist or is smaller than 1MB. This file is supported through git lfs and needs to be obtained through git lfs" )
235+ }
236+
237+ // Extract platform.zip to the platform subdirectory under the project build directory
238+ val platformDir = File (" ${layout.buildDirectory.get().asFile} /platform" )
239+ platformDir.mkdirs()
240+ copy {
241+ from(zipTree(platformZip))
242+ into(platformDir)
243+ }
244+ }
245+ }
246+
247+ val vscodePluginDir = File (" ./plugins/${ext.get(" vscodePlugin" )} " )
248+ val depfile = File (" prodDep.txt" )
249+ val list = mutableListOf<String >()
250+
251+ // Read dependencies during execution
252+ doFirst {
253+ depfile.readLines().forEach { line ->
254+ list.add(line.substringAfterLast(" node_modules/" ) + " /**" )
255+ }
256+ }
257+
258+ val pluginName = properties(" pluginGroup" ).get().split(" ." ).last()
259+
260+ // Copy host runtime files
261+ from(" ../host/dist" ) { into(" $pluginName /runtime/" ) }
262+ from(" ../host/package.json" ) { into(" $pluginName /runtime/" ) }
263+
264+ // Copy host node_modules based on prodDep.txt
265+ from(" ../resources/node_modules" ) {
266+ into(" $pluginName /node_modules/" )
267+ doFirst {
268+ list.forEach {
269+ include(it)
270+ }
271+ }
272+ }
273+
274+ // Copy VSCode plugin extension
275+ from(" ${vscodePluginDir.path} /extension" ) { into(" $pluginName /${ext.get(" vscodePlugin" )} " ) }
276+
277+ // Copy themes
278+ from(" src/main/resources/themes/" ) { into(" $pluginName /${ext.get(" vscodePlugin" )} /integrations/theme/default-themes/" ) }
279+
280+ // Copy platform files for release mode
281+ if (ext.get(" debugMode" ) == " release" ) {
282+ val platformDir = File (" ${layout.buildDirectory.get().asFile} /platform" )
283+ from(File (platformDir, " platform.txt" )) { into(" $pluginName /" ) }
284+ // Copy platform node_modules last to ensure it takes precedence over host node_modules
285+ from(File (platformDir, " node_modules" )) { into(" $pluginName /node_modules" ) }
286+ }
287+
288+ doLast {
289+ File (" $destinationDir /$pluginName /${ext.get(" vscodePlugin" )} /.env" ).apply {
290+ parentFile.mkdirs()
291+ createNewFile()
292+ }
293+ }
294+ }
233295 }
234296
235297 // Generate configuration file before compilation
0 commit comments