Skip to content

Commit 6fee83c

Browse files
committed
use shared config parser
1 parent 27953ce commit 6fee83c

5 files changed

Lines changed: 45 additions & 34 deletions

File tree

build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ repositories {
4141
dependencies {
4242
implementation platform('com.fasterxml.jackson:jackson-bom:2.21.2')
4343
implementation group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '7.6.0.202603022253-r'
44+
// jackson-databind: .vscode/settings.json (JSON) editing; jackson-dataformat-yaml: the pruned wurst.build writer.
45+
// Reading wurst.build now goes through the shared parser (WurstProjectConfigReader, snakeyaml), so the Kotlin
46+
// binding module is no longer needed.
4447
implementation 'com.fasterxml.jackson.core:jackson-databind'
45-
implementation 'com.fasterxml.jackson.module:jackson-module-kotlin'
4648
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
47-
implementation 'com.github.wurstscript:wurst-project-config:2c7ccd1a5f'
49+
implementation 'com.github.wurstscript:wurst-project-config:348fcd4ef5'
4850
implementation 'com.github.Frotty:SimpleRegistry:f96dda96bd'
4951
implementation 'org.jline:jline:3.30.13'
5052
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.17'

src/main/kotlin/file/CoreJassProvider.kt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,13 @@ object CoreJassProvider {
185185
buildFolder.resolve("core-jass.provenance"),
186186
"wc3Patch: $patch\njassHistoryFolder: ${jassHistoryFolderForPatch(patch).orEmpty()}\n"
187187
)
188+
// Single happy-path line; stay quiet when a fallback already warned about an issue.
189+
val sources = materializedFiles.map { it.source }
190+
when {
191+
sources.all { it == CoreJassSource.CACHED } -> log.info("✔ Core JASS ready ($patch, cached)")
192+
sources.all { it == CoreJassSource.CACHED || it == CoreJassSource.FRESH } ->
193+
log.info("✔ Core JASS ready ($patch, updated)")
194+
}
188195
} else {
189196
log.warn(
190197
"Existing _build core JASS files have no Grill provenance; leaving them project-owned. " +
@@ -228,7 +235,11 @@ object CoreJassProvider {
228235
return (base + listOfNotNull(latestExactVersion)).distinct()
229236
}
230237

231-
private data class MaterializedFile(val path: Path, val managedByGrill: Boolean)
238+
private enum class CoreJassSource { CACHED, FRESH, FALLBACK, PROJECT_OWNED }
239+
240+
private data class MaterializedFile(val path: Path, val source: CoreJassSource) {
241+
val managedByGrill: Boolean get() = source != CoreJassSource.PROJECT_OWNED
242+
}
232243

233244
private fun resolveSupportedPatch(wc3Patch: String?): String {
234245
val patch = normalizePatchInput(wc3Patch)
@@ -247,28 +258,27 @@ object CoreJassProvider {
247258
}
248259

249260
if (previousPatch == null && Files.exists(target)) {
250-
log.info("Keeping existing _build/$fileName because it has no Grill provenance.")
251-
return MaterializedFile(target, managedByGrill = false)
261+
// Project-owned file: reported once as a warning in ensureFiles, not per file here.
262+
return MaterializedFile(target, CoreJassSource.PROJECT_OWNED)
252263
}
253264

254265
val canKeepExisting = previousPatch == patch
255266
if (canKeepExisting && isValidCoreJassFile(target)) {
256-
log.info("Using cached _build/$fileName for $patch.")
257-
return MaterializedFile(target, managedByGrill = true)
267+
return MaterializedFile(target, CoreJassSource.CACHED)
258268
}
259269

260270
try {
261271
downloadJassHistoryFile(fileName, patch, jassHistoryFolder, target)
262-
return MaterializedFile(target, managedByGrill = true)
272+
return MaterializedFile(target, CoreJassSource.FRESH)
263273
} catch (e: Exception) {
264274
if (canKeepExisting && isValidCoreJassFile(target)) {
265275
log.warn("Could not refresh $fileName for $patch; keeping existing _build copy. Reason: ${e.message}")
266-
return MaterializedFile(target, managedByGrill = true)
276+
return MaterializedFile(target, CoreJassSource.FALLBACK)
267277
}
268278
if (hasBundledCoreJass(patch)) {
269279
log.warn("Could not download $fileName for $patch; falling back to bundled core JASS. Reason: ${e.message}")
270280
copyBundledCoreJass(fileName, patch, target)
271-
return MaterializedFile(target, managedByGrill = true)
281+
return MaterializedFile(target, CoreJassSource.FALLBACK)
272282
}
273283
throw RuntimeException("Could not download $fileName for WC3 patch <$patch> from wurstscript/jass-history.", e)
274284
}

src/main/kotlin/file/SetupApp.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import global.InstallationManager
1313
import global.Log
1414
import logging.KotlinLogging
1515
import net.ConnectionManager
16-
import net.NetStatus
1716
import org.slf4j.LoggerFactory
1817
import org.eclipse.jgit.api.Git
1918
import java.awt.GraphicsEnvironment
@@ -97,14 +96,19 @@ object SetupApp {
9796
}
9897

9998
private fun handleCMD() {
100-
ConnectionManager.checkConnectivity("http://google.com")
101-
ConnectionManager.checkWurstBuild()
102-
InstallationManager.verifyInstallation()
103-
if (ConnectionManager.netStatus == NetStatus.ONLINE) {
104-
val latestSetupBuild = ConnectionManager.getLatestSetupBuild()
105-
val jenkinsBuildVer = InstallationManager.getJenkinsBuildVer(CompileTimeInfo.version)
106-
if (latestSetupBuild > 0) {
107-
log.debug("current setup ver: $jenkinsBuildVer latest Setup: $latestSetupBuild")
99+
// Cold-start lever: only spend network round-trips and a compiler subprocess on commands
100+
// that actually consult the installation. help/generate stay fully offline and fast.
101+
when {
102+
setup.command == CLICommand.INSTALL && setup.commandArg.equals("wurstscript", ignoreCase = true) -> {
103+
// Needs to know whether a newer compiler is available online.
104+
ConnectionManager.checkWurstBuild()
105+
InstallationManager.verifyInstallation()
106+
}
107+
setup.command == CLICommand.TEST ||
108+
setup.command == CLICommand.TYPECHECK ||
109+
setup.command == CLICommand.BUILD -> {
110+
// Only needs to know a compiler is present; skip the version subprocess and update check.
111+
InstallationManager.verifyInstallation(probeVersion = false)
108112
}
109113
}
110114
handleRunArgs()
@@ -339,7 +343,8 @@ object SetupApp {
339343
}
340344
return null
341345
}
342-
log.info("Warcraft III path: ${Wc3ClientDetector.describe(clientInfo)}")
346+
// The success path is reported once in the final generate summary, so only surface
347+
// a client/patch mismatch here (an actionable issue) rather than re-logging the path.
343348
Wc3ClientDetector.mismatchMessage(wc3Patch, clientInfo)?.let { log.warn(it) }
344349
return clientInfo.root
345350
}

src/main/kotlin/file/YamlHelper.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package file
22

3-
import com.fasterxml.jackson.core.JsonParser
4-
import com.fasterxml.jackson.databind.DeserializationFeature
5-
import com.fasterxml.jackson.databind.MapperFeature
63
import com.fasterxml.jackson.databind.ObjectMapper
74
import com.fasterxml.jackson.databind.SerializationFeature
85
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
96
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator
107
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper
11-
import com.fasterxml.jackson.module.kotlin.KotlinModule
8+
import org.wurstscript.projectconfig.WurstProjectConfigReader
129
import config.WurstProjectConfigData
1310
import config.WurstProjectBuildForce
1411
import config.WurstProjectBuildForceFlags
@@ -31,16 +28,12 @@ object YamlHelper {
3128
private val log = KotlinLogging.logger {}
3229

3330
init {
31+
// Write-only mapper: reading wurst.build is delegated to the shared parser (WurstProjectConfigReader).
32+
// dumpProjectConfig still serializes a pruned YAML map here to preserve the user-facing wurst.build shape.
3433
val yamlFactory = YAMLFactory()
3534
yamlFactory.enable(YAMLGenerator.Feature.MINIMIZE_QUOTES)
36-
yamlFactory.enable(JsonParser.Feature.ALLOW_MISSING_VALUES)
3735

3836
mapper = YAMLMapper.builder(yamlFactory)
39-
.addModule(KotlinModule.Builder().build())
40-
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
41-
.enable(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)
42-
.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY)
43-
.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS)
4437
.enable(SerializationFeature.INDENT_OUTPUT)
4538
.build()
4639
}
@@ -55,7 +48,8 @@ object YamlHelper {
5548
}
5649

5750
return try {
58-
val config = mapper.readValue(content, WurstProjectConfigData::class.java)
51+
val config = WurstProjectConfigReader.load(path)
52+
?: throw IOException("wurst.build could not be parsed")
5953
normalizeConfig(config, path)
6054
} catch (e: Exception) {
6155
log.warn("The project's wurst.build file could not be read. Recovering with defaults.", e)

src/main/kotlin/global/InstallationManager.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ object InstallationManager {
4040
var currentCompilerVersion = -1
4141
var latestCompilerVersion = 0
4242

43-
fun verifyInstallation(): InstallationStatus {
43+
fun verifyInstallation(probeVersion: Boolean = true): InstallationStatus {
4444
log.debug("verify Install")
4545
status = InstallationStatus.NOT_INSTALLED
4646
currentCompilerVersion = -1
@@ -53,7 +53,7 @@ object InstallationManager {
5353
try {
5454
if (!Files.isWritable(detectedCompilerJar)) {
5555
CLIParser.showWurstInUse()
56-
} else {
56+
} else if (probeVersion) {
5757
CLIParser.getVersionFomJar()
5858
}
5959
} catch (_: Error) {
@@ -62,7 +62,7 @@ object InstallationManager {
6262
} else {
6363
log.info("WurstScript is not currently installed (no compiler jar found at $compilerJar or $legacyCompilerJar).")
6464
}
65-
if (ConnectionManager.netStatus == NetStatus.ONLINE) {
65+
if (probeVersion && ConnectionManager.netStatus == NetStatus.ONLINE) {
6666
log.debug("Client online, check for update")
6767
latestCompilerVersion = ConnectionManager.getLatestCompilerBuild()
6868
log.debug("latest compiler: $latestCompilerVersion")

0 commit comments

Comments
 (0)