@@ -14,6 +14,7 @@ import org.jetbrains.intellij.build.telemetry.TraceManager.spanBuilder
1414import org.jetbrains.intellij.build.telemetry.use
1515import java.nio.file.Files
1616import java.nio.file.Path
17+ import kotlin.io.path.exists
1718
1819internal const val BUILT_IN_HELP_MODULE_NAME = " intellij.builtInHelp"
1920
@@ -88,25 +89,60 @@ private fun pluginXml(buildContext: BuildContext, version: String): String {
8889 */
8990private val helpIndexerMutex = Mutex ()
9091
92+
93+ /* Offline help plugins include a separate set of help topics for each of the supported languages.
94+ This is a map of language code to descriptors that define resources associated with that language.
95+ */
96+
97+ private data class LanguageResourcesDescriptor (
98+ val isRequired : Boolean = false ,
99+ val resPath : String ,
100+ val resList : List <String > = listOf("topics", "images", "search"),
101+ )
102+
103+ private val supportedLanguages = mapOf (
104+ // Localized resources don't include images
105+ Pair (" zh-cn" , LanguageResourcesDescriptor (resPath = " zh-cn/" , resList = listOf (" topics" , " search" ))),
106+ Pair (" en-us" , LanguageResourcesDescriptor (isRequired = true , resPath = " " ))
107+ )
108+
91109private suspend fun buildResourcesForHelpPlugin (resourceRoot : Path , classPath : List <String >, assetJar : Path , context : CompilationContext ) {
92110 spanBuilder(" index help topics" ).use {
93111 helpIndexerMutex.withLock {
94- runJavaForIntellijModule(
95- context = context, mainClass = " com.jetbrains.builtInHelp.indexer.HelpIndexer" ,
96- args = listOf (
97- resourceRoot.resolve(" search" ).toString(),
98- resourceRoot.resolve(" topics" ).toString(),
99- ),
100- jvmArgs = emptyList(),
101- classPath = classPath,
102- )
112+ supportedLanguages.forEach { (lang, descriptor) ->
113+ val topicPath = resourceRoot.resolve(" ${descriptor.resPath} topics" )
114+
115+ if (topicPath.exists())
116+ runJavaForIntellijModule(
117+ context = context, mainClass = " com.jetbrains.builtInHelp.indexer.HelpIndexer" ,
118+ args = listOf (
119+ resourceRoot.resolve(" ${descriptor.resPath} search" ).toString(),
120+ topicPath.toString(),
121+ ),
122+ jvmArgs = emptyList(),
123+ classPath = classPath,
124+ )
125+ else
126+ Span .current().addEvent(" skip \" ${lang} \" for offline help plugin because it was not supplied. " )
127+ }
103128 }
104- writeNewZipWithoutIndex(file = assetJar, compress = true ) { zipCreator ->
105- val archiver = ZipArchiver ()
106- archiver.setRootDir(resourceRoot)
107- archiveDir(startDir = resourceRoot.resolve(" topics" ), addFile = { archiver.addFile(it, zipCreator) })
108- archiveDir(startDir = resourceRoot.resolve(" images" ), addFile = { archiver.addFile(it, zipCreator) })
109- archiveDir(startDir = resourceRoot.resolve(" search" ), addFile = { archiver.addFile(it, zipCreator) })
129+
130+ supportedLanguages.forEach { (lang, descriptor) ->
131+ writeNewZipWithoutIndex(file = assetJar, compress = true ) { zipCreator ->
132+ val rootDir = resourceRoot.resolve(descriptor.resPath)
133+ if (rootDir.exists()) {
134+ val archiver = ZipArchiver ()
135+ archiver.setRootDir(rootDir)
136+
137+ descriptor.resList.forEach { resDir ->
138+ archiveDir(
139+ startDir = resourceRoot.resolve(resDir),
140+ addFile = { archiver.addFile(it, zipCreator) })
141+ }
142+ }
143+ }
110144 }
111145 }
112146}
147+
148+
0 commit comments