mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Remove legacy codec, user ResourceUtil to get streams and store resource list in a descriptor file
(cherry picked from commit 8d63b22335a2cf664d3a88eec61c7947b399b1ae) (cherry picked from commit bfb4b09386f39d112a1b8321e6c05eeec253394d) IJ-MR-166587 GitOrigin-RevId: 3c8c03ec1f0d90e15b08a3bc9bc6b5a633bfc660
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6f6913b5e3
commit
ca02f8284c
@@ -31,11 +31,6 @@ internal fun buildHelpPlugin(pluginVersion: String, context: BuildContext): Plug
|
||||
spec.directoryName = "${productName.replace(" ", "")}Help"
|
||||
spec.excludeFromModule(BUILT_IN_HELP_MODULE_NAME, "com/jetbrains/builtInHelp/indexer/**")
|
||||
spec.withPatch { patcher, buildContext ->
|
||||
/* patcher.patchModuleOutput(
|
||||
moduleName = BUILT_IN_HELP_MODULE_NAME,
|
||||
path = "META-INF/services/org.apache.lucene.codecs.Codec",
|
||||
content = "org.apache.lucene.codecs.lucene50.Lucene50Codec"
|
||||
)*/
|
||||
patcher.patchModuleOutput(
|
||||
moduleName = BUILT_IN_HELP_MODULE_NAME,
|
||||
path = "META-INF/plugin.xml",
|
||||
@@ -43,6 +38,7 @@ internal fun buildHelpPlugin(pluginVersion: String, context: BuildContext): Plug
|
||||
overwrite = PatchOverwriteMode.TRUE
|
||||
)
|
||||
}
|
||||
spec.withProjectLibrary("lucene-core")
|
||||
spec.withGeneratedResources { targetDir, buildContext ->
|
||||
val assetJar = targetDir.resolve("lib/help-$productLowerCase-assets.jar")
|
||||
buildResourcesForHelpPlugin(
|
||||
|
||||
@@ -15,9 +15,7 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import kotlin.io.path.extension
|
||||
import kotlin.io.path.isRegularFile
|
||||
import kotlin.io.path.name
|
||||
import kotlin.io.path.*
|
||||
import kotlin.streams.asSequence
|
||||
|
||||
class HelpIndexer
|
||||
@@ -27,7 +25,12 @@ internal constructor(indexDir: String) {
|
||||
private val writer: IndexWriter
|
||||
|
||||
init {
|
||||
val dir = FSDirectory.open(Paths.get(indexDir))
|
||||
val targetPath = Paths.get(indexDir)
|
||||
//Make sure it's empty
|
||||
targetPath.toFile().deleteRecursively()
|
||||
targetPath.createDirectories()
|
||||
|
||||
val dir = FSDirectory.open(targetPath)
|
||||
val config = IndexWriterConfig(analyzer)
|
||||
writer = IndexWriter(dir, config)
|
||||
}
|
||||
@@ -99,6 +102,9 @@ internal constructor(indexDir: String) {
|
||||
val indexer = HelpIndexer(dirToStore)
|
||||
indexer.indexDirectory(dirToIndex)
|
||||
indexer.closeIndex()
|
||||
//Store the list of generated files for the search to work
|
||||
Path.of(dirToStore, "rlist")
|
||||
.writeLines(Path.of(dirToStore).walk().map { it.name })
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.apache.lucene.search.highlight.Scorer
|
||||
import org.apache.lucene.store.NIOFSDirectory
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
@@ -24,7 +26,6 @@ import java.util.*
|
||||
class HelpSearch {
|
||||
|
||||
companion object {
|
||||
private val resources = setOf("_0.cfe", "_0.cfs", "_0.si", "segments_1")
|
||||
|
||||
@NonNls
|
||||
private const val NOT_FOUND = "[]"
|
||||
@@ -41,21 +42,26 @@ class HelpSearch {
|
||||
if (indexDir != null)
|
||||
try {
|
||||
val indexDirPath = indexDir.toAbsolutePath().toString()
|
||||
Files.createDirectories(indexDir)
|
||||
|
||||
resources.forEach { resource ->
|
||||
ResourceUtil.getResourceAsStream(HelpSearch::class.java.classLoader,
|
||||
"search",
|
||||
resource).use { resourceStream ->
|
||||
if (resourceStream == null) return@forEach
|
||||
|
||||
Paths.get(indexDirPath, resource)
|
||||
.safeOutputStream().use { resourceOutput ->
|
||||
resourceOutput.write(resourceStream.readAllBytes())
|
||||
//Read required names from rlist and then load resources based off of them
|
||||
ResourceUtil.getResourceAsStream(HelpSearch::class.java.classLoader, "search", "rlist")
|
||||
.use { resourceList ->
|
||||
BufferedReader(InputStreamReader(resourceList)).useLines { lines ->
|
||||
lines.forEach { line ->
|
||||
val path = Paths.get(indexDirPath, line)
|
||||
ResourceUtil.getResourceAsStream(HelpSearch::class.java.classLoader,
|
||||
"search", line)
|
||||
?.use { resourceStream ->
|
||||
path.safeOutputStream().use { resourceOutput ->
|
||||
resourceOutput.write(resourceStream.readAllBytes())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
indexDirectory = NIOFSDirectory.open(indexDir) as NIOFSDirectory
|
||||
indexDirectory = NIOFSDirectory(indexDir)
|
||||
reader = DirectoryReader.open(indexDirectory)
|
||||
|
||||
val searcher = IndexSearcher(reader)
|
||||
|
||||
Reference in New Issue
Block a user