From a11a78a63a182b21a69d963492f50d6beae93580 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Fri, 14 Nov 2025 19:20:56 +0900 Subject: [PATCH 1/4] Allow JSON5 in JSONDecoder I hadn't realized JSONDecoder has gained JSON5 support, so we don't need to do the manual // stripping and can just enable 5 mode when decoding JSON :-) --- Plugins/JavaCompilerPlugin/JavaCompilerPlugin.swift | 4 +++- .../SwiftJavaConfigurationShared/Configuration.swift | 12 ++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Plugins/JavaCompilerPlugin/JavaCompilerPlugin.swift b/Plugins/JavaCompilerPlugin/JavaCompilerPlugin.swift index f90150fd..93c358df 100644 --- a/Plugins/JavaCompilerPlugin/JavaCompilerPlugin.swift +++ b/Plugins/JavaCompilerPlugin/JavaCompilerPlugin.swift @@ -38,7 +38,9 @@ struct JavaCompilerBuildToolPlugin: BuildToolPlugin { let config: Configuration? if let configData = try? Data(contentsOf: configFile) { - config = try? JSONDecoder().decode(Configuration.self, from: configData) + let decoder = JSONDecoder() + decoder.allowsJSON5 = true + config = try? decoder.decode(Configuration.self, from: configData) } else { config = nil } diff --git a/Sources/SwiftJavaConfigurationShared/Configuration.swift b/Sources/SwiftJavaConfigurationShared/Configuration.swift index a840a7cf..493ee4bc 100644 --- a/Sources/SwiftJavaConfigurationShared/Configuration.swift +++ b/Sources/SwiftJavaConfigurationShared/Configuration.swift @@ -174,18 +174,14 @@ public func readConfiguration(configPath: URL, file: String = #fileID, line: UIn } public func readConfiguration(string: String, configPath: URL?, file: String = #fileID, line: UInt = #line) throws -> Configuration? { - let cleanedConfigString = string - .split(separator: "\n") - .filter { line in - !line.trimmingCharacters(in: .whitespaces).starts(with: "//") - }.joined(separator: "\n") - - guard let configData = cleanedConfigString.data(using: .utf8) else { + guard let configData = string.data(using: .utf8) else { return nil } do { - return try JSONDecoder().decode(Configuration.self, from: configData) + let decoder = JSONDecoder() + decoder.allowsJSON5 = true + return try decoder.decode(Configuration.self, from: configData) } catch { throw ConfigurationError(message: "Failed to parse SwiftJava configuration at '\(configPath.map({ $0.absoluteURL.description }) ?? "")'! \(#fileID):\(#line)", error: error, file: file, line: line) From 479b626c03662bfa7b9d6455454d202efa91dca4 Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Fri, 14 Nov 2025 19:38:56 +0900 Subject: [PATCH 2/4] add docs about swift-java.config --- .../Documentation.docc/SwiftJavaCommandLineTool.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md index 32a82eb4..e600651b 100644 --- a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md +++ b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md @@ -254,3 +254,14 @@ public final class SomeModule ... { public static void globalFunction() { ... } } ``` + +### The swift-java.config file + +Many of the tools–as well as SwiftPM plugin's–behaviors can be configured using the `swift-java.config` file. + +You can refer to the ``SwiftJavaSharedConfiguration/Configuration`` struct to learn about the supported options. + +Configuration from the config files may be overriden or augmented by explicit command line parameters, +please refer to the options documentation for details on their behavior. + +> Note: **Comments in configuration**: The configuration is a JSON 5 file, which among other things allows `//` and `/* */` comments, so feel free to add line comments explaining rationale for some of the settings in youf configuration. \ No newline at end of file From 4c9307ca484ae3bbc3f5d4ca518b408c6a01560b Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Mon, 17 Nov 2025 11:00:51 +0900 Subject: [PATCH 3/4] scripts: improve validate_docs to not add the dependency if already there --- .github/scripts/validate_docs.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/scripts/validate_docs.sh b/.github/scripts/validate_docs.sh index 8ee777b0..5e553943 100755 --- a/.github/scripts/validate_docs.sh +++ b/.github/scripts/validate_docs.sh @@ -3,11 +3,17 @@ set -e set -x -cat <> Package.swift +DEPENDENCY='.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0")' + +if grep -q "$DEPENDENCY" Package.swift; then + echo "Package.swift already contains 'swift-docc-plugin" +else + cat <> Package.swift package.dependencies.append( - .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0") + $DEPENDENCY ) EOF +fi swift package --disable-sandbox plugin generate-documentation --target "SwiftJavaDocumentation" --warnings-as-errors --analyze From 03906bf67c1648a890656848d5752842a0d5a33b Mon Sep 17 00:00:00 2001 From: Konrad Malawski Date: Mon, 17 Nov 2025 11:20:39 +0900 Subject: [PATCH 4/4] resolve docs issue --- .../Documentation.docc/SwiftJavaCommandLineTool.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md index e600651b..82371383 100644 --- a/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md +++ b/Sources/SwiftJavaDocumentation/Documentation.docc/SwiftJavaCommandLineTool.md @@ -259,7 +259,7 @@ public final class SomeModule ... { Many of the tools–as well as SwiftPM plugin's–behaviors can be configured using the `swift-java.config` file. -You can refer to the ``SwiftJavaSharedConfiguration/Configuration`` struct to learn about the supported options. +You can refer to the `SwiftJavaConfigurationShared/Configuration` struct to learn about the supported options. Configuration from the config files may be overriden or augmented by explicit command line parameters, please refer to the options documentation for details on their behavior.