-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add task to set the project package resolution strategy (#171)
## Description Adds task to modify the project package resolution strategy, `setResolutionStrategy`, according to this: (https://docs.unity3d.com/Manual/upm-manifestPrj.html#resolutionStrategy) The task class derives from a base `ProjectManifestTask`, which is now shared with the existing `AddUpmPackages` task that was previously implemented. ## Changes * ![ADD] `setResolutionStrategy` plugin task * ![IMPROVE] `AddUPMPackages` task base layout into a base task, `ProjectManifestTask`
- Loading branch information
Showing
21 changed files
with
663 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/integrationTest/groovy/wooga/gradle/unity/tasks/ProjectManifestTaskSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package wooga.gradle.unity.tasks | ||
|
||
import com.wooga.gradle.test.TaskIntegrationSpec | ||
import com.wooga.gradle.test.queries.TestValue | ||
import com.wooga.gradle.test.writers.PropertyGetterTaskWriter | ||
import com.wooga.gradle.test.writers.PropertySetterWriter | ||
import spock.lang.Unroll | ||
import wooga.gradle.unity.UnityIntegrationSpec | ||
|
||
abstract class ProjectManifestTaskSpec<T extends ProjectManifestTask> | ||
extends UnityIntegrationSpec | ||
implements TaskIntegrationSpec<T> { | ||
|
||
@Override | ||
String getSubjectUnderTestName() { | ||
return "${super.getSubjectUnderTestName()}Test" | ||
} | ||
|
||
@Unroll | ||
def "can set property #propertyName with #type"() { | ||
expect: | ||
runPropertyQuery(getter, setter).matches(value) | ||
|
||
where: | ||
propertyName | type | value | ||
"projectManifestFile" | File | TestValue.projectFile("foobar") | ||
"projectLockFile" | File | TestValue.projectFile("foobar") | ||
|
||
setter = new PropertySetterWriter(subjectUnderTestName, propertyName) | ||
.set(value, type) | ||
getter = new PropertyGetterTaskWriter(setter) | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...ationTest/groovy/wooga/gradle/unity/tasks/SetResolutionStrategyTaskIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package wooga.gradle.unity.tasks | ||
|
||
|
||
import com.wooga.gradle.test.writers.PropertyGetterTaskWriter | ||
import com.wooga.gradle.test.writers.PropertySetterWriter | ||
import com.wooga.spock.extensions.unity.UnityPluginTestOptions | ||
import groovy.json.JsonOutput | ||
import groovy.json.JsonSlurper | ||
import spock.lang.Unroll | ||
import wooga.gradle.unity.models.ResolutionStrategy | ||
|
||
class SetResolutionStrategyTaskIntegrationSpec extends ProjectManifestTaskSpec<SetResolutionStrategy> { | ||
|
||
@Unroll | ||
def "can set property #propertyName with #type"() { | ||
expect: | ||
runPropertyQuery(getter, setter).matches(value) | ||
|
||
where: | ||
propertyName | type | value | ||
"resolutionStrategy" | String | ResolutionStrategy.lowest | ||
"resolutionStrategy" | String | ResolutionStrategy.highest | ||
|
||
setter = new PropertySetterWriter(subjectUnderTestName, propertyName) | ||
.set(value, type) | ||
getter = new PropertyGetterTaskWriter(setter) | ||
} | ||
|
||
@UnityPluginTestOptions(forceMockTaskRun = false) | ||
def "skips when the resolution strategy is not set"() { | ||
|
||
when: | ||
def result = runTasks(subjectUnderTestName) | ||
|
||
then: | ||
result.wasSkipped(subjectUnderTestName) | ||
} | ||
|
||
@UnityPluginTestOptions(forceMockTaskRun = false) | ||
@Unroll | ||
def "#verb the resolution strategy #strategy"() { | ||
|
||
given: "an unity project with the manifest file set" | ||
def manifestPath = "build/test_project/Packages/manifest.json" | ||
def manifestFile = new File(projectDir, manifestPath) | ||
manifestFile.parentFile.mkdirs() | ||
manifestFile.createNewFile() | ||
|
||
and: "an existing manifest file" | ||
def packages = ["com.unity.ugui": "1.0.0"] | ||
|
||
Map<String, Object> manifestContents = [ | ||
"dependencies": packages | ||
] | ||
if (originalStrategy != _) { | ||
manifestContents["resolutionStrategy"] = originalStrategy | ||
} | ||
manifestFile << JsonOutput.toJson(manifestContents) | ||
|
||
and: "task configuration" | ||
appendToSubjectTask(""" | ||
resolutionStrategy = ${wrapValueBasedOnType(strategy, String)} | ||
projectManifestFile = ${wrapValueBasedOnType(manifestPath, File)} | ||
""".stripIndent() | ||
) | ||
|
||
when: | ||
runTasksSuccessfully(subjectUnderTestName) | ||
|
||
then: "manifest file contains resolution strategy" | ||
def actual = new JsonSlurper().parse(manifestFile)["resolutionStrategy"] | ||
actual == strategy | ||
|
||
where: | ||
originalStrategy | strategy | ||
"katzen" | "highestMinor" | ||
_ | "highestMinor" | ||
_ | "lowest" | ||
"highest" | "highestPatch" | ||
|
||
verb = originalStrategy != _ ? "overrides" : "sets" | ||
} | ||
} |
Oops, something went wrong.