Skip to content

Commit

Permalink
Fix compatibility for gradle > 4.4 (#43)
Browse files Browse the repository at this point in the history
Description
===========

We used some internal API's that changed in gradle 4.4.
The API `resolveLater` in `PathToFileResolver` is gone so we replicate
this API with `new Factory<File>` invocations instead for now.
The default constructor for `DefaultExecHandleBuilder` changed in a way
that backwards compatibility is no longer possible. I added a delegate
to a new field `execHandleBuilder` which gets created with a
`DefaultExecActionFactory`

Changes
=======

![FIX] usage of removed API `resolveLater`
![CHANGE] internal `BatchModeAction` exec handle builder logic
![CHANGE] use `FileResolver` instead of `PathToFileResolver` in code
  • Loading branch information
Larusso committed May 18, 2018
1 parent 5c5b85b commit f7508e3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 29 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ Tested with Oracle JDK8
| 4.2 | ![yes] |
| 4.3 | ![yes] |
| 4.4 | ![yes] |
| 4.5 | ![no] |
| 4.6 | ![no] |
| 4.5 | ![yes] |
| 4.6 | ![yes] |
| 4.7 | ![yes] |


Development
Expand Down
2 changes: 1 addition & 1 deletion gradle_check_versions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

versions=("2.14" "3.0" "3.2" "3.3" "3.4" "3.4.1" "3.5" "3.5.1" "4.0" "4.1" "4.2" "4.3" "4.4" "4.5" "4.6")
versions=("3.0" "3.2" "3.3" "3.4" "3.4.1" "3.5" "3.5.1" "4.0" "4.1" "4.2" "4.3" "4.4" "4.5" "4.6" "4.7")
for i in "${versions[@]}"
do
echo "test gradle version $i"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package wooga.gradle.unity.batchMode.internal
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.internal.file.PathToFileResolver
import org.gradle.api.internal.file.FileResolver
import org.gradle.process.ExecResult
import org.gradle.process.internal.ExecException
import org.gradle.process.internal.ExecHandle
Expand Down Expand Up @@ -57,7 +57,7 @@ class DefaultActivationAction extends DefaultBatchModeAction implements Activati
return this
}

DefaultActivationAction(Project project, PathToFileResolver fileResolver, UnityAuthentication authentication) {
DefaultActivationAction(Project project, FileResolver fileResolver, UnityAuthentication authentication) {
super(project, fileResolver)
this.authentication = authentication
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,37 @@ import org.gradle.api.Project
import org.gradle.api.internal.ConventionAwareHelper
import org.gradle.api.internal.ConventionMapping
import org.gradle.api.internal.IConventionAware
import org.gradle.api.internal.file.FileResolver
import org.gradle.internal.Factory
import org.gradle.internal.file.PathToFileResolver
import org.gradle.internal.io.LineBufferingOutputStream
import org.gradle.internal.io.TextStream
import org.gradle.process.ExecResult
import org.gradle.process.internal.DefaultExecHandleBuilder
import org.gradle.process.ExecSpec
import org.gradle.process.internal.DefaultExecActionFactory
import org.gradle.process.internal.ExecException
import org.gradle.process.internal.ExecHandle
import wooga.gradle.unity.UnityActionConvention
import wooga.gradle.unity.utils.internal.FileUtils
import org.gradle.process.internal.ExecHandleBuilder
import wooga.gradle.unity.UnityPlugin
import wooga.gradle.unity.UnityPluginExtension
import wooga.gradle.unity.batchMode.BaseBatchModeSpec
import wooga.gradle.unity.batchMode.BatchModeAction
import wooga.gradle.unity.batchMode.BatchModeFlags
import wooga.gradle.unity.batchMode.BatchModeSpec
import wooga.gradle.unity.batchMode.BuildTarget
import wooga.gradle.unity.utils.internal.FileUtils
import wooga.gradle.unity.utils.internal.ForkTextStream

class DefaultBatchModeAction extends DefaultExecHandleBuilder implements BatchModeAction, IConventionAware {
class DefaultBatchModeAction implements BatchModeAction, IConventionAware {
private final UnityPluginExtension extension
private final PathToFileResolver fileResolver
protected final FileResolver fileResolver
private final ConventionMapping conventionMapping

private File customUnityPath
private File customProjectPath
private BuildTarget customBuildTarget
private String logCategory

@Delegate()
ExecHandleBuilder execHandleBuilder

File getUnityPath() {
if (customUnityPath) {
return customUnityPath
Expand Down Expand Up @@ -92,7 +94,12 @@ class DefaultBatchModeAction extends DefaultExecHandleBuilder implements BatchMo
void setLogFile(Object file) {
logFile = null
if (file) {
logFile = fileResolver.resolveLater(file)
logFile = new Factory<File>() {
@Override
File create() {
return fileResolver.resolve(file)
}
}
}
}

Expand Down Expand Up @@ -142,15 +149,16 @@ class DefaultBatchModeAction extends DefaultExecHandleBuilder implements BatchMo
Boolean batchMode = true
Boolean noGraphics = false

DefaultBatchModeAction(Project project, PathToFileResolver fileResolver) {
super(fileResolver)
DefaultBatchModeAction(Project project, FileResolver fileResolver) {
this.fileResolver = fileResolver
this.extension = project.getExtensions().findByName(UnityPlugin.EXTENSION_NAME) as UnityPluginExtension
this.conventionMapping = new ConventionAwareHelper(this, project.getConvention())
def execFactory = new DefaultExecActionFactory(fileResolver)
this.execHandleBuilder = execFactory.newExec()
}

ExecResult execute() {
def additionalArguments = getAllArguments()
def additionalArguments = getArgs()
def batchModeArgs = []

if (getUnityPath() == null || !getUnityPath().exists()) {
Expand Down Expand Up @@ -197,7 +205,7 @@ class DefaultBatchModeAction extends DefaultExecHandleBuilder implements BatchMo
if (getRedirectStdOut()) {
TextStream handler = new ForkTextStream()
def outStream = new LineBufferingOutputStream(handler)
this.standardOutput = outStream
this.setStandardOutput(outStream)

if (getLogFile()) {
handler.addWriter(getLogFile().newPrintWriter())
Expand Down Expand Up @@ -279,19 +287,25 @@ class DefaultBatchModeAction extends DefaultExecHandleBuilder implements BatchMo

@Override
DefaultBatchModeAction args(Object... args) {
super.args(args)
execHandleBuilder.args(args)
this
}

@Override
DefaultBatchModeAction args(Iterable<?> args) {
super.args(args)
execHandleBuilder.args(args)
return this
}

@Override
DefaultBatchModeAction setArgs(List<String> arguments) {
execHandleBuilder.setArgs(arguments)
return this
}

@Override
DefaultBatchModeAction setArgs(Iterable<?> arguments) {
super.setArgs(arguments)
execHandleBuilder.setArgs(arguments)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DefaultUnityPluginExtension implements UnityPluginExtension, UnityPluginAc
private Boolean autoActivateUnity

private final Instantiator instantiator
private final FileResolver fileResolver
protected final FileResolver fileResolver
private final Project project
private final UnityAuthentication authentication

Expand Down Expand Up @@ -107,11 +107,16 @@ class DefaultUnityPluginExtension implements UnityPluginExtension, UnityPluginAc
}

void setUnityPath(File unityPath) {
customUnityPath = fileResolver.resolveLater(unityPath)
setUnityPath(unityPath as Object)
}

void setUnityPath(Object path) {
customUnityPath = fileResolver.resolveLater(path)
customUnityPath = new Factory<File>() {
@Override
File create() {
fileResolver.resolve(path)
}
}
}

private static Boolean getRedirectStdOutFromEnv(Map<String, ?> properties, Map<String, String> env) {
Expand Down Expand Up @@ -157,11 +162,21 @@ class DefaultUnityPluginExtension implements UnityPluginExtension, UnityPluginAc
}

void setReportsDir(File file) {
reportsDir = fileResolver.resolveLater(file)
reportsDir = new Factory<File>() {
@Override
File create() {
fileResolver.resolve(file)
}
}
}

void setReportsDir(Object file) {
reportsDir = fileResolver.resolveLater(file)
reportsDir = new Factory<File>() {
@Override
File create() {
fileResolver.resolve(file)
}
}
}

UnityPluginExtension reportsDir(Object reportsDir) {
Expand All @@ -178,7 +193,12 @@ class DefaultUnityPluginExtension implements UnityPluginExtension, UnityPluginAc
}

void setPluginsDir(File path) {
pluginsDir = fileResolver.resolveLater(path)
pluginsDir = new Factory<File>() {
@Override
File create() {
fileResolver.resolve(path)
}
}
}

UnityPluginExtension pluginsDir(Object path) {
Expand All @@ -195,7 +215,12 @@ class DefaultUnityPluginExtension implements UnityPluginExtension, UnityPluginAc
}

void setAssetsDir(File path) {
assetsDir = fileResolver.resolveLater(path)
assetsDir = new Factory<File>() {
@Override
File create() {
return fileResolver.resolve(path)
}
}
}

UnityPluginExtension assetsDir(Object path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package wooga.gradle.unity.batchMode
import org.gradle.api.Action
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.internal.file.PathToFileResolver
import spock.lang.Specification
Expand All @@ -38,7 +39,7 @@ class DefaultActivationActionSpec extends Specification {
static String DEFAULT_SERIAL = "test-serial"

def projectProperties = [:]
def fileResolver = Mock(PathToFileResolver)
def fileResolver = Mock(FileResolver)
def authentication = new DefaultUnityAuthentication(DEFAULT_USER, DEFAULT_PASSWORD, DEFAULT_SERIAL)
def extension = Mock(UnityPluginExtension)
def extensions = Mock(ExtensionContainer)
Expand Down

0 comments on commit f7508e3

Please sign in to comment.