Patch run.bat to use installed JDK path
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -386,7 +386,14 @@ async function listFilesRecursively(root: string, predicate: (entryPath: string,
|
||||
return results
|
||||
}
|
||||
|
||||
async function patchRunBatFiles(root: string, pack: PackDefinition): Promise<void> {
|
||||
async function patchRunBatFiles(root: string, pack: PackDefinition, jdkPath: string): Promise<void> {
|
||||
const javaExec = resolveJavaExecutable(jdkPath)
|
||||
const quotedJavaExec = `"${javaExec}"`
|
||||
// Match a bare `java` / `java.exe` command invocation: preceded by start-of-line,
|
||||
// whitespace, or a cmd separator (& | @), and followed by whitespace or EOL. This
|
||||
// avoids touching path-embedded occurrences like `C:\jdk\bin\java.exe`.
|
||||
const javaCommandPattern = /(^|[\s&|@])java(?:\.exe)?(?=\s|$)/gim
|
||||
|
||||
const runBatFiles = await listFilesRecursively(root, (_entryPath, entryName) => entryName.toLowerCase() === 'run.bat')
|
||||
for (const runBatPath of runBatFiles) {
|
||||
const raw = await fsp.readFile(runBatPath, 'utf8')
|
||||
@@ -394,13 +401,16 @@ async function patchRunBatFiles(root: string, pack: PackDefinition): Promise<voi
|
||||
.replace(/-Xms\S+/gi, `-Xms${pack.serverMinRam}M`)
|
||||
.replace(/-Xmx\S+/gi, `-Xmx${pack.serverMaxRam}M`)
|
||||
|
||||
if (next === raw && /java(\.exe)?/i.test(raw)) {
|
||||
next = raw.replace(/java(\.exe)?/i, (match) => `${match} -Xms${pack.serverMinRam}M -Xmx${pack.serverMaxRam}M`)
|
||||
if (!/-Xm[sx]/i.test(next) && /java(\.exe)?/i.test(next)) {
|
||||
next = next.replace(javaCommandPattern, (_match, prefix: string) =>
|
||||
`${prefix}${quotedJavaExec} -Xms${pack.serverMinRam}M -Xmx${pack.serverMaxRam}M`)
|
||||
} else {
|
||||
next = next.replace(javaCommandPattern, (_match, prefix: string) => `${prefix}${quotedJavaExec}`)
|
||||
}
|
||||
|
||||
if (next !== raw) {
|
||||
await fsp.writeFile(runBatPath, next, 'utf8')
|
||||
sendLog(`run.bat 램 설정 반영: ${path.relative(root, runBatPath)}`)
|
||||
sendLog(`run.bat JDK/램 설정 반영: ${path.relative(root, runBatPath)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,7 +491,7 @@ async function startInstall(payload: InstallPayload): Promise<{ nextStep: number
|
||||
|
||||
const extractedRoot = await downloadAndExtractPack(packMeta.baseUrl, packMeta.packDefinition, payload.installPath)
|
||||
await ensureEditableConfigFiles(extractedRoot, packMeta.packDefinition)
|
||||
await patchRunBatFiles(extractedRoot, packMeta.packDefinition)
|
||||
await patchRunBatFiles(extractedRoot, packMeta.packDefinition, payload.jdkPath)
|
||||
|
||||
const eulaPath = path.join(extractedRoot, 'eula.txt')
|
||||
if (fs.existsSync(eulaPath)) {
|
||||
|
||||
Reference in New Issue
Block a user