Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,17 @@ class BeamModulePlugin implements Plugin<Project> {
}
}

// Serializes pipeline options to JSON for the beamTestPipelineOptions system property.
// On Windows each option is wrapped in literal quotes so the JSON survives the quote
// stripping applied to the forked test JVM's command line.
// See https://github.com/apache/beam/issues/39332.
static def toBeamTestPipelineOptionsJson(def options) {
if (System.properties['os.name'].toLowerCase().contains('windows')) {
return JsonOutput.toJson(options.collect { "\"$it\"" })
}
return JsonOutput.toJson(options)
}
Comment on lines +103 to +108

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If options is null, calling options.collect will throw a NullPointerException. Adding a null check ensures the method is robust against null inputs.

  static def toBeamTestPipelineOptionsJson(def options) {
    if (options && System.properties['os.name'].toLowerCase().contains('windows')) {
      return JsonOutput.toJson(options.collect { "\"$it\"" })
    }
    return JsonOutput.toJson(options)
  }


/** A class defining the set of configurable properties accepted by applyJavaNature. */
static class JavaNatureConfiguration {
/** Controls whether the spotbugs plugin is enabled and configured. */
Expand Down Expand Up @@ -2249,12 +2260,8 @@ class BeamModulePlugin implements Plugin<Project> {
}
}

// Windows handles quotation marks differently
if (pipelineOptionsString && System.properties['os.name'].toLowerCase().contains('windows')) {
def allOptionsListFormatted = allOptionsList.collect { "\"$it\"" }
pipelineOptionsStringFormatted = JsonOutput.toJson(allOptionsListFormatted)
} else if (pipelineOptionsString) {
pipelineOptionsStringFormatted = JsonOutput.toJson(allOptionsList)
if (pipelineOptionsString) {
pipelineOptionsStringFormatted = toBeamTestPipelineOptionsJson(allOptionsList)
}

systemProperties.beamTestPipelineOptions = pipelineOptionsStringFormatted ?: pipelineOptionsString
Expand Down Expand Up @@ -2691,7 +2698,7 @@ class BeamModulePlugin implements Plugin<Project> {
if (config.jobServerConfig) {
beamTestPipelineOptions.add("--jobServerConfig=${config.jobServerConfig}")
}
config.systemProperties.put("beamTestPipelineOptions", JsonOutput.toJson(beamTestPipelineOptions))
config.systemProperties.put("beamTestPipelineOptions", toBeamTestPipelineOptionsJson(beamTestPipelineOptions))
project.tasks.register(name, Test) {
group = "Verification"
description = "Validates the PortableRunner with JobServer ${config.jobServerDriver}"
Expand Down Expand Up @@ -2857,7 +2864,7 @@ class BeamModulePlugin implements Plugin<Project> {
def javaTask = project.tasks.register(config.name+"JavaUsing"+sdk, Test) {
group = "Verification"
description = "Validates runner for cross-language capability of using ${sdk} transforms from Java SDK"
systemProperty "beamTestPipelineOptions", JsonOutput.toJson(config.javaPipelineOptions)
systemProperty "beamTestPipelineOptions", toBeamTestPipelineOptionsJson(config.javaPipelineOptions)
systemProperty "expansionJar", expansionJar
systemProperty "expansionPort", port
systemProperty "semiPersistDir", config.semiPersistDir
Expand Down
Loading