mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IJPL-162853 introduce a script for converting a message bundle to a kotlin class
GitOrigin-RevId: d00ed622cc312ca6f37ebc3ab043b4eed170a191
This commit is contained in:
committed by
intellij-monorepo-bot
parent
04c59fb9f9
commit
ead98a3249
Generated
+1
@@ -894,6 +894,7 @@
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/syntax/syntax-i18n/intellij.platform.syntax.i18n.iml" filepath="$PROJECT_DIR$/platform/syntax/syntax-i18n/intellij.platform.syntax.i18n.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/syntax/syntax-multiplatformSupport/intellij.platform.syntax.multiplatformSupport.iml" filepath="$PROJECT_DIR$/platform/syntax/syntax-multiplatformSupport/intellij.platform.syntax.multiplatformSupport.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/syntax/syntax-psi/intellij.platform.syntax.psi.iml" filepath="$PROJECT_DIR$/platform/syntax/syntax-psi/intellij.platform.syntax.psi.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/syntax/syntax-scripts/intellij.platform.syntax.scripts.iml" filepath="$PROJECT_DIR$/platform/syntax/syntax-scripts/intellij.platform.syntax.scripts.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/syntax/syntax-util/intellij.platform.syntax.util.iml" filepath="$PROJECT_DIR$/platform/syntax/syntax-util/intellij.platform.syntax.util.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/tasks-platform-api/intellij.platform.tasks.iml" filepath="$PROJECT_DIR$/platform/tasks-platform-api/intellij.platform.tasks.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/platform/tasks-platform-impl/intellij.platform.tasks.impl.iml" filepath="$PROJECT_DIR$/platform/tasks-platform-impl/intellij.platform.tasks.impl.iml" />
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
*f:com.intellij.platform.syntax.scripts.GenerateBundleMappingKt
|
||||
- sf:generateMapping(java.lang.String,java.lang.String,java.lang.String):V
|
||||
- sf:main(java.lang.String[]):V
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-stdlib" level="project" />
|
||||
<orderEntry type="library" name="jetbrains-annotations" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file: ApiStatus.Experimental
|
||||
|
||||
package com.intellij.platform.syntax.scripts
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.io.OutputStreamWriter
|
||||
import java.nio.file.Path
|
||||
import java.util.*
|
||||
import kotlin.io.path.*
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
/**
|
||||
* Generates a Kotlin class from your .properties file. This file is necessary for non-JVM targets where Java PropertyResourceBundles are not available.
|
||||
*/
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size != 3) {
|
||||
println("""
|
||||
|Please pass 3 arguments:
|
||||
| 1. the path to .properties file
|
||||
| 2. the path to the output file as arguments
|
||||
| 3. the package name to use
|
||||
|""".trimMargin())
|
||||
exitProcess(-1)
|
||||
}
|
||||
|
||||
generateMapping(args[0], args[1], args[2])
|
||||
}
|
||||
|
||||
fun generateMapping(
|
||||
properties: String,
|
||||
output: String,
|
||||
packageName: String,
|
||||
) {
|
||||
val propertiesPath = Path(properties)
|
||||
if (!propertiesPath.exists()) {
|
||||
println(".properties file does not exist! Path: $propertiesPath")
|
||||
exitProcess(-1)
|
||||
}
|
||||
|
||||
val outputPath = Path(output)
|
||||
if (!outputPath.exists()) {
|
||||
outputPath.createFile()
|
||||
}
|
||||
|
||||
val mappings = loadMappings(propertiesPath)
|
||||
|
||||
val fileName = outputPath.nameWithoutExtension
|
||||
outputPath.writer().use { writer ->
|
||||
writer.printClass(fileName, packageName, mappings, "$properties $output $packageName")
|
||||
}
|
||||
}
|
||||
|
||||
private fun OutputStreamWriter.printClass(
|
||||
className: String,
|
||||
packageName: String,
|
||||
mappings: Map<String, String>,
|
||||
parametersString: String,
|
||||
) {
|
||||
appendLine("package $packageName")
|
||||
appendLine()
|
||||
appendLine("// Generated by generateBundleMapping.kt")
|
||||
appendLine("// To regenerate the file, please run `GenerateBundleMapping` run configuration with the following parameters: ")
|
||||
appendLine("// $parametersString ")
|
||||
appendLine("internal object $className {")
|
||||
appendLine(" val mappings: Map<String, String> = mapOf(")
|
||||
for ((key, value) in mappings.entries) {
|
||||
val escapedValue = value
|
||||
.replace("\\", "\\\\")
|
||||
.replace("\n", "\\n")
|
||||
.replace("\r", "\\r")
|
||||
.replace("\t", "\\t")
|
||||
appendLine(" \"$key\" to \"$escapedValue\",")
|
||||
}
|
||||
appendLine(" )")
|
||||
appendLine('}')
|
||||
}
|
||||
|
||||
private fun loadMappings(propertiesPath: Path): Map<String, String> {
|
||||
val properties = Properties()
|
||||
propertiesPath.inputStream().use { stream ->
|
||||
properties.load(stream)
|
||||
}
|
||||
|
||||
return properties.entries.associate { (key, value) ->
|
||||
(key as String) to (value as String)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user