feat(dameng): support JVM system properties

This commit is contained in:
Charlie Dettorre authored and GitHub committed 2026-07-28 23:18:12 +08:00
1 parent 31f0b7d6ef
commit 7f5cb3b0cc
12 files changed
+176 -4

No files matched your search

@@ -0,0 +1,39 @@
const JAVA_SYSTEM_PROPERTY_PREFIX = "-D";
const SHELL_QUOTE_PATTERN = /["']/;
export class DamengJvmSystemPropertyError extends Error {
constructor(readonly lineNumber: number) {
super(`Invalid Dameng JVM system property on line ${lineNumber}`);
this.name = "DamengJvmSystemPropertyError";
}
}
export function damengJvmSystemPropertiesText(options?: string[]): string {
return (options ?? [])
.map((option) => option.trim())
.filter(Boolean)
.join("\n");
}
export function parseDamengJvmSystemProperties(value: string): string[] {
const options: string[] = [];
for (const [index, line] of value.split(/\r?\n/).entries()) {
const option = line.trim();
if (!option) continue;
if (!isJavaSystemProperty(option)) {
throw new DamengJvmSystemPropertyError(index + 1);
}
options.push(option);
}
return options;
}
function isJavaSystemProperty(option: string): boolean {
if (!option.startsWith(JAVA_SYSTEM_PROPERTY_PREFIX) || SHELL_QUOTE_PATTERN.test(option)) return false;
const property = option.slice(JAVA_SYSTEM_PROPERTY_PREFIX.length);
const separator = property.indexOf("=");
const key = separator >= 0 ? property.slice(0, separator) : property;
return key.length > 0 && !/\s/.test(key);
}