Skip to content
This repository has been archived by the owner on Jan 9, 2025. It is now read-only.

Commit

Permalink
Improve Unity version fallback to project version with revision hash (#…
Browse files Browse the repository at this point in the history
…41)

Description
===========

This is a very small patch. In order to be able to install
Unity versions which may not yet be tracked by the versions service, the
unity version manager tool introduced some changed to fetch the project version
with the needed revision hash. This allows a smoother update process for the user.
Most developers user Unity Hub locally to install the newest versions. Or they
install custom versions from other Unity sources (Beta fix releaseses). Unity
will write the revision hash of the used version in the `ProjectVersion.txt` file.
This allows to install Unity Editor without any network requests against the
custom versions service.

> Note: Unity created a new endpoint to query for released versions, one reason why
> the current solution is not always returning up-to-date results. There is a plan
> to support this new endpoint nativly as well.

The `net.wooga.unity-version-manger-jni` lib exposes a new API to request the
project version with said revision hash.

Changes
=======

* ![UPDATE] `net.wooga.unity-version-manager-jni` to min version `1.5.0`
* ![IMPROVE] fetch project version with revision hash
  • Loading branch information
Larusso authored Dec 8, 2022
1 parent a9d64f5 commit 9c9879f
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ repositories {
}

dependencies {
implementation 'net.wooga:unity-version-manager-jni:[1.4.1,2['
implementation 'net.wooga:unity-version-manager-jni:[1.5.0,2['
implementation "net.wooga.gradle:unity:[3,4["
implementation "com.wooga.gradle:gradle-commons:[1,2["
implementation 'org.apache.maven:maven-artifact:3.8.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class UnityVersionManagerPlugin implements Plugin<Project> {
def extension = project.extensions.create(UnityVersionManagerExtension, EXTENSION_NAME, DefaultUnityVersionManagerExtension, project)
extension.unityProjectDir.convention(project.layout.projectDirectory)
extension.unityVersion.convention(UnityVersionManagerConventions.unityVersion.getStringValueProvider(project).orElse(project.provider({
UnityVersionManager.detectProjectVersion(extension.unityProjectDir.get().asFile)
UnityVersionManager.detectProjectVersion(extension.unityProjectDir.get().asFile, true)
})))

extension.unityInstallBaseDir.convention(UnityVersionManagerConventions.unityInstallBaseDir.getDirectoryValueProvider(project).orElse(project.layout.buildDirectory.dir("unity_installations")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,136 @@

package wooga.gradle.unity.version.manager.tasks

import com.wooga.gradle.BaseSpec
import net.wooga.uvm.Component
import net.wooga.uvm.Installation
import net.wooga.uvm.UnityVersionManager
import org.gradle.api.DefaultTask
import org.gradle.api.file.Directory
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import wooga.gradle.unity.UnityPluginExtension
import wooga.gradle.unity.version.manager.error.UvmInstallException

class UvmCheckInstallation extends DefaultTask {
class UvmCheckInstallation extends DefaultTask implements BaseSpec {

private final Property<String> unityVersion = objects.property(String)

@Input
@Optional
final Property<String> unityVersion
Property<String> getUnityVersion() {
unityVersion
}

void setUnityVersion(Provider<String> value) {
unityVersion.set(value)
}

void setUnityVersion(String value) {
unityVersion.set(value)
}

private final Provider<String> unityVersionWithoutRevision = unityVersion.map({ it.split(/( |\/)/).first() })

@Internal
Provider<String> getUnityVersionWithoutRevision() {
unityVersionWithoutRevision
}

private final Property<UnityPluginExtension> unityExtension = objects.property(UnityPluginExtension)

@Input
@Optional
final Property<UnityPluginExtension> unityExtension
Property<UnityPluginExtension> getUnityExtension() {
unityExtension
}

void setUnityExtension(Provider<UnityPluginExtension> value) {
unityExtension.set(value)
}

void setUnityExtension(UnityPluginExtension value) {
unityExtension.set(value)
}

private final Property<Boolean> autoSwitchUnityEditor = objects.property(Boolean)

@Input
final Property<Boolean> autoSwitchUnityEditor
Property<Boolean> getAutoSwitchUnityEditor() {
autoSwitchUnityEditor
}

void setAutoSwitchUnityEditor(Provider<Boolean> value) {
autoSwitchUnityEditor.set(value)
}

void setAutoSwitchUnityEditor(Boolean value) {
autoSwitchUnityEditor.set(value)
}

private final Property<Boolean> autoInstallUnityEditor = objects.property(Boolean)

@Input
final Property<Boolean> autoInstallUnityEditor
Property<Boolean> getAutoInstallUnityEditor() {
autoInstallUnityEditor
}

void setAutoInstallUnityEditor(Provider<Boolean> value) {
autoInstallUnityEditor.set(value)
}

void setAutoInstallUnityEditor(Boolean value) {
autoInstallUnityEditor.set(value)
}


private final DirectoryProperty unityInstallBaseDir = objects.directoryProperty()

@Input
final DirectoryProperty unityInstallBaseDir
DirectoryProperty getUnityInstallBaseDir() {
unityInstallBaseDir
}

void setUnityInstallBaseDir(Provider<Directory> value) {
unityInstallBaseDir.set(value)
}

void setUnityInstallBaseDir(File value) {
unityInstallBaseDir.set(value)
}

private final SetProperty<Component> buildRequiredUnityComponents = objects.setProperty(Component)

@Input
@Optional
final SetProperty<Component> buildRequiredUnityComponents
SetProperty<Component> getBuildRequiredUnityComponents() {
buildRequiredUnityComponents
}

void setBuildRequiredUnityComponents(Provider<Iterable<Component>> value) {
buildRequiredUnityComponents.set(value)
}

void setBuildRequiredUnityComponents(Iterable<Component> value) {
buildRequiredUnityComponents.set(value)
}

UvmCheckInstallation() {
unityVersion = project.objects.property(String)
unityExtension = project.objects.property(UnityPluginExtension)
autoSwitchUnityEditor = project.objects.property(Boolean)
autoInstallUnityEditor = project.objects.property(Boolean)
unityInstallBaseDir = project.objects.directoryProperty()
buildRequiredUnityComponents = project.objects.setProperty(Component)
void buildRequiredUnityComponents(Component value) {
buildRequiredUnityComponents.add(value)
}

void buildRequiredUnityComponents(Component... value) {
buildRequiredUnityComponents.addAll(value)
}

void buildRequiredUnityComponents(Iterable<Component> value) {
buildRequiredUnityComponents.addAll(value)
}

@TaskAction
Expand All @@ -71,6 +157,8 @@ class UvmCheckInstallation extends DefaultTask {
}

def version = unityVersion.get()
// The version string may contain a version revision. Lets clean this out.
def version_without_revision = unityVersionWithoutRevision.get()
Installation installation = UnityVersionManager.locateUnityInstallation(version)

boolean needInstall = false
Expand All @@ -88,23 +176,23 @@ class UvmCheckInstallation extends DefaultTask {
}

if (autoSwitchUnityEditor.get() && autoInstallUnityEditor.get() && needInstall) {
def destination = unityInstallBaseDir.file(version).get().asFile
def destination = unityInstallBaseDir.file(version_without_revision).get().asFile
def components = buildRequiredUnityComponents.getOrElse(new HashSet<Component>()).toArray() as Component[]
logger.info("install unity ${version}")
if(components.size() > 0) {
logger.info("install unity ${version_without_revision}")
if (components.size() > 0) {
logger.info("with components: ")
logger.info("${components.join("\n")}")
}
logger.info("to destination: ${destination}")

installation = UnityVersionManager.installUnityEditor(version, destination, components)
if(!installation) {
logger.error("Unable to install requested unity version ${version}")
throw new UvmInstallException("Unable to install requested unity version ${version}")
if (!installation) {
logger.error("Unable to install requested unity version ${version_without_revision}")
throw new UvmInstallException("Unable to install requested unity version ${version_without_revision}")
}
}

if(!installation) {
if (!installation) {
return
}

Expand All @@ -113,7 +201,7 @@ class UvmCheckInstallation extends DefaultTask {
return
}

if(unityExtension.present) {
if (unityExtension.present) {
logger.info("update path to unity installtion ${installation.location}")
def extension = unityExtension.get()
extension.unityPath.set(installation.executable)
Expand Down

0 comments on commit 9c9879f

Please sign in to comment.