Skip to content

Commit

Permalink
Fix default environment for Unity invocation (#102)
Browse files Browse the repository at this point in the history
Description
===========

This patch sets the default environment used to call Unity
to `System.env`. It is possible to append values to this default
env or reset it completely.

Unity needs the `HOME` variable by default and maybe some more.

Changes
=======

* ![FIX] default environment for Unity invocation
  • Loading branch information
Larusso authored Jun 24, 2021
1 parent 908ab9b commit ac20a10
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,22 @@ abstract class UnityTaskIntegrationSpec<T extends UnityTask> extends UnityIntegr

@Unroll
def "set environment variable #rawValue for task exec"() {
given:
given: "some clean environment variables"
def envNames = System.getenv().keySet().toArray()
environmentVariables.clear(*envNames)

and: "a test value in system env"
initialValue.each { key, value ->
environmentVariables.set(key, value)
}

and: "an overridden environment"
appendToSubjectTask("$method($value)")
addProviderQueryTask("custom", "${subjectUnderTestName}.environment", ".get()")

and: "some values in the user environment"
environmentVariables.set("USER_A", "foo")

when:
def result = runTasksSuccessfully(subjectUnderTestName, "custom")

Expand All @@ -246,13 +258,21 @@ abstract class UnityTaskIntegrationSpec<T extends UnityTask> extends UnityIntegr
"environment" | true | ["A": true]
"environment" | false | ["A": false]

initialValue = ["B": "5", "C" : "7"]
method = (useSetter) ? "set${property.capitalize()}" : "${property}.set"
value = wrapValueBasedOnType(rawValue, Map)
}

def "adds environment for task exec"() {
given:
appendToSubjectTask("environment.set(${wrapValueBasedOnType(initialValue, Map)})")
given: "some clean environment variables"
def envNames = System.getenv().keySet().toArray()
environmentVariables.clear(*envNames)

and: "a test value in system env"
initialValue.each { key, value ->
environmentVariables.set(key, value)
}

appendToSubjectTask("$method(${wrapValueBasedOnType(rawValue, Map)})")
addProviderQueryTask("custom", "${subjectUnderTestName}.environment", ".get().sort()")

Expand Down
1 change: 1 addition & 0 deletions src/main/groovy/wooga/gradle/unity/UnityPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class UnityPlugin implements Plugin<Project> {
t.unityLogFile.convention(extension.logsDir.file(project.provider {
t.logCategory.get().isEmpty() ? "${t.name}.log" : "${t.logCategory.get()}/${t.name}.log"
}))
t.environment.putAll(project.provider({System.getenv()}))
}
}

Expand Down

0 comments on commit ac20a10

Please sign in to comment.