Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
fix to the resolution strategy (#68)
Browse files Browse the repository at this point in the history
* fix to the resolution strategy

* chang manifest file to be optional
  • Loading branch information
Robin-Hentschel-Wooga authored Feb 14, 2023
1 parent 0c0567b commit 2129afb
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ cveHandler {
}

dependencies {
implementation 'org.apache.maven:maven-artifact:3.8.5'
implementation "net.wooga.gradle:dotnet-sonarqube:[0.4,0.5["
implementation "net.wooga.gradle:unity:[3,4["
implementation "commons-io:commons-io:2.11.0"
Expand Down
34 changes: 21 additions & 13 deletions src/main/groovy/wooga/gradle/wdk/unity/WdkUnityPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ import wooga.gradle.unity.UnityPluginExtension
import wooga.gradle.unity.UnityTask
import wooga.gradle.unity.models.UnityProjectManifest
import wooga.gradle.unity.tasks.Activate
import wooga.gradle.unity.tasks.ProjectManifestTask
import wooga.gradle.unity.tasks.ReturnLicense
import wooga.gradle.unity.tasks.Unity
import wooga.gradle.wdk.unity.actions.AndroidResourceCopyAction
import wooga.gradle.wdk.unity.actions.IOSResourceCopyAction
import wooga.gradle.wdk.unity.actions.WebGLResourceCopyAction
import wooga.gradle.wdk.unity.config.SonarQubeConfiguration
import wooga.gradle.wdk.unity.tasks.DefaultResourceCopyTask
import wooga.gradle.wdk.unity.tasks.ResolveUnityPackages

import javax.inject.Inject

Expand Down Expand Up @@ -98,7 +100,7 @@ class WdkUnityPlugin implements Plugin<Project> {
createExternalResourcesConfigurations(project)
configureCleanObjects(project, extension)
addResourceCopyTasks(project)
configureUnityTaskDependencies(project)
configureUnityTaskDependencies(project, unityPluginExtension)
createTestBuildTasks(project, extension, unityPluginExtension)
configureSonarqubeTasks(project)
}
Expand Down Expand Up @@ -190,43 +192,49 @@ class WdkUnityPlugin implements Plugin<Project> {
assembleTask.dependsOn iOSResourceCopy, androidResourceCopy, webglResourceCopy
}

private static void configureUnityTaskDependencies(Project project) {
private static void configureUnityTaskDependencies(Project project, final UnityPluginExtension unityPluginExtension) {

// We declare a lifecycle-like task that we can use to control how the unity project is setup;
// this can be used in downstream projects
def setupTask = project.tasks.named(SETUP_TASK_NAME)

// We want to ensure that the unity project's packages are resolved
// if the setup task is executed by itself, since if ANY other unity task is invoked, we need not do this
def resolvePackages = project.tasks.register(RESOLVE_PACKAGES_TASK_NAME, UnityTask) {
def resolvePackages = project.tasks.register(RESOLVE_PACKAGES_TASK_NAME, ResolveUnityPackages) {
it.group = GROUP
it.batchMode.set(true)
it.onlyIf {
def unityTasks = project.gradle.taskGraph.allTasks.findAll({
Task t ->
t instanceof UnityTask && !(t instanceof Activate) && !(t instanceof ReturnLicense)
t instanceof UnityTask && !(t instanceof Activate) && !(t instanceof ReturnLicense) && !(t.name == RESOLVE_PACKAGES_TASK_NAME)
})
def shouldExecute = unityTasks.size() == 1
def shouldExecute = unityTasks.size() <= 1
if (!shouldExecute) {
logger.info("Will be skipped since there's more than one Unity task present [${unityTasks}]")
}
shouldExecute
}
it.manifest.convention(unityPluginExtension.projectManifestFile)
it.packageLock.convention(unityPluginExtension.projectLockFile)
}
setupTask.configure({
it.dependsOn resolvePackages
})

def resolutionStrategy = project.tasks.named(UnityPlugin.Tasks.setResolutionStrategy.toString())
project.tasks.withType(UnityTask).configureEach{
if(!(it instanceof Activate || it instanceof ReturnLicense || it instanceof ProjectManifestTask || it.name == UnityPlugin.Tasks.ensureProjectManifest.toString())) {
it.dependsOn(resolutionStrategy)
}
}

// Make every other Unity task depend on the setup task defined by this plugin
project.tasks.withType(UnityTask, new Action<UnityTask>() {
@Override
void execute(UnityTask task) {
if (task.name != RESOLVE_PACKAGES_TASK_NAME
&& !(task instanceof Activate)) {
task.dependsOn setupTask
}
project.tasks.withType(UnityTask).configureEach { task ->
if (task.name != RESOLVE_PACKAGES_TASK_NAME && task.name && !(task.name == UnityPlugin.Tasks.ensureProjectManifest.name())
&& !(task instanceof Activate)) {
task.dependsOn setupTask
}
})
}
}

static void createTestBuildTasks(final Project project, final WdkPluginExtension extension, final UnityPluginExtension unityPluginExtension) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package wooga.gradle.wdk.unity.tasks

import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import wooga.gradle.unity.UnityTask

class ResolveUnityPackages extends UnityTask {

@InputFiles
@SkipWhenEmpty
FileCollection getInputFiles() {
project.files(manifest)
}

private final RegularFileProperty manifest = objects.fileProperty()

@Internal
RegularFileProperty getManifest() {
manifest
}

void setManifest(Provider<RegularFile> value) {
manifest.set(value)
}

void setManifest(File value) {
manifest.set(value)
}
private final RegularFileProperty packageLock = objects.fileProperty()

@OutputFile
RegularFileProperty getPackageLock() {
packageLock
}

void setPackageLock(Provider<RegularFile> value) {
packageLock.set(value)
}

void setPackageLock(File value) {
packageLock.set(value)
}

@TaskAction
protected resolve() {
packageLock.get().asFile.delete()
exec()
}
}

0 comments on commit 2129afb

Please sign in to comment.