@@ -27,13 +27,13 @@ import org.gradle.internal.io.LineBufferingOutputStream
27
27
import org.gradle.internal.io.TextStream
28
28
import org.gradle.process.ExecResult
29
29
import org.gradle.process.ExecSpec
30
- import sun.reflect.misc.FieldUtil
31
30
import wooga.gradle.unity.models.UnityCommandLineOption
32
31
import wooga.gradle.unity.traits.ArgumentsSpec
33
32
import wooga.gradle.unity.traits.UnityCommandLineSpec
34
33
import wooga.gradle.unity.traits.UnitySpec
35
34
import wooga.gradle.unity.utils.FileUtils
36
35
import wooga.gradle.unity.utils.ForkTextStream
36
+ import wooga.gradle.unity.utils.UnityLogErrorReader
37
37
import wooga.gradle.unity.utils.UnityVersionManager
38
38
39
39
abstract class UnityTask extends DefaultTask
@@ -47,21 +47,24 @@ abstract class UnityTask extends DefaultTask
47
47
// and also an additional one for our custom use
48
48
wooga_gradle_unity_traits_ArgumentsSpec__arguments = project. provider({ getUnityCommandLineOptions() })
49
49
wooga_gradle_unity_traits_ArgumentsSpec__additionalArguments = project. objects. listProperty(String )
50
- wooga_gradle_unity_traits_ArgumentsSpec__environment = project. objects. mapProperty(String , Object )
50
+ wooga_gradle_unity_traits_ArgumentsSpec__environment = project. objects. mapProperty(String , Object )
51
51
}
52
52
53
53
@TaskAction
54
54
void exec () {
55
+ // Invoked before the unity process
56
+ logger. info(" ${ name} .preExecute" )
57
+ preExecute()
58
+ // Execute the unity process
59
+ logger. info(" ${ name} .execute" )
55
60
ExecResult execResult = project. exec(new Action<ExecSpec > () {
56
61
@Override
57
62
void execute (ExecSpec exec ) {
58
63
64
+ // TODO: Should these be moved before preExecute?
59
65
if (! unityPath. present) {
60
66
throw new GradleException (" Unity path is not set" )
61
67
}
62
-
63
- preExecute()
64
-
65
68
def unityPath = unityPath. get(). asFile. absolutePath
66
69
def unityArgs = getAllArguments()
67
70
def unityEnvironment = environment. get()
@@ -76,8 +79,11 @@ abstract class UnityTask extends DefaultTask
76
79
}
77
80
}
78
81
})
79
-
80
- execResult. assertNormalExitValue()
82
+ if (execResult. exitValue != 0 ) {
83
+ handleUnityProcessError(execResult)
84
+ }
85
+ // Invoked after the unity process (even if it failed)
86
+ logger. info(" ${ name} .postExecute" )
81
87
postExecute(execResult)
82
88
}
83
89
@@ -97,6 +103,31 @@ abstract class UnityTask extends DefaultTask
97
103
protected void postExecute (ExecResult result ) {
98
104
}
99
105
106
+ /**
107
+ * Invoked whenever the Unity process executed by the task exits with an error,
108
+ * @param result The execution result of the Unity process
109
+ */
110
+ protected void handleUnityProcessError (ExecResult result ) {
111
+ logger. error(" Unity process failed with exit value ${ result.exitValue} ..." )
112
+
113
+ // Look up the log
114
+ if (! unityLogFile. isPresent()) {
115
+ logger. warn(" No log file was configured for the task ${ this.name} " )
116
+ return
117
+ }
118
+
119
+ File logFile = unityLogFile. get(). asFile
120
+ if (! logFile. exists()) {
121
+ logger. warn(" No log file was written for the task ${ this.name} " )
122
+ return
123
+ }
124
+
125
+ // TODO: Gracefully show the error here?
126
+ UnityLogErrorReader reader = new UnityLogErrorReader ()
127
+ def errorParse = reader. parse(logFile)
128
+ logger. error(errorParse. toString())
129
+ }
130
+
100
131
@Internal
101
132
protected ArtifactVersion getUnityVersion () {
102
133
File file = unityPath. present ? unityPath. get(). asFile : null
0 commit comments