-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MBS-9952 Add gradle configuration errors to the build verdict (#674)
- Loading branch information
1 parent
5159e3d
commit 246b6f3
Showing
17 changed files
with
603 additions
and
132 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
18 changes: 18 additions & 0 deletions
18
...ild-verdict/src/main/kotlin/com/avito/android/build_verdict/internal/BaseBuildListener.kt
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,18 @@ | ||
package com.avito.android.build_verdict.internal | ||
|
||
import org.gradle.BuildListener | ||
import org.gradle.BuildResult | ||
import org.gradle.api.initialization.Settings | ||
import org.gradle.api.invocation.Gradle | ||
|
||
abstract class BaseBuildListener : BuildListener { | ||
override fun buildStarted(gradle: Gradle) {} | ||
|
||
override fun settingsEvaluated(settings: Settings) {} | ||
|
||
override fun projectsLoaded(gradle: Gradle) {} | ||
|
||
override fun projectsEvaluated(gradle: Gradle) {} | ||
|
||
override fun buildFinished(result: BuildResult) {} | ||
} |
19 changes: 19 additions & 0 deletions
19
...main/kotlin/com/avito/android/build_verdict/internal/BuildConfigurationFailureListener.kt
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,19 @@ | ||
package com.avito.android.build_verdict.internal | ||
|
||
import com.avito.android.build_verdict.internal.writer.BuildVerdictWriter | ||
import org.gradle.BuildResult | ||
|
||
internal class BuildConfigurationFailureListener( | ||
private val writer: BuildVerdictWriter | ||
) : BaseBuildListener() { | ||
|
||
override fun buildFinished(result: BuildResult) { | ||
result.failure?.let { failure -> | ||
writer.write( | ||
BuildVerdict.Configuration( | ||
error = Error.from(failure) | ||
) | ||
) | ||
} | ||
} | ||
} |
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
20 changes: 11 additions & 9 deletions
20
...le/build-verdict/src/main/kotlin/com/avito/android/build_verdict/internal/BuildVerdict.kt
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 |
---|---|---|
@@ -1,18 +1,20 @@ | ||
package com.avito.android.build_verdict.internal | ||
|
||
internal data class Error( | ||
val message: String, | ||
val stackTrace: String | ||
) | ||
internal sealed class BuildVerdict { | ||
|
||
internal data class BuildVerdict( | ||
val rootError: Error, | ||
val failedTasks: List<FailedTask> | ||
) | ||
abstract val error: Error | ||
|
||
data class Configuration(override val error: Error) : BuildVerdict() | ||
|
||
data class Execution( | ||
override val error: Error, | ||
val failedTasks: List<FailedTask> | ||
) : BuildVerdict() | ||
} | ||
|
||
internal data class FailedTask( | ||
val name: String, | ||
val projectPath: String, | ||
val errorOutput: String, | ||
val originalError: Error | ||
val error: Error | ||
) |
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
39 changes: 39 additions & 0 deletions
39
...ts/gradle/build-verdict/src/main/kotlin/com/avito/android/build_verdict/internal/Error.kt
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,39 @@ | ||
package com.avito.android.build_verdict.internal | ||
|
||
import com.avito.utils.getCausesRecursively | ||
import com.avito.utils.getStackTraceString | ||
import org.gradle.internal.exceptions.MultiCauseException | ||
|
||
internal sealed class Error { | ||
|
||
abstract val message: String | ||
|
||
data class Multi( | ||
override val message: String, | ||
val errors: List<Single> | ||
) : Error() | ||
|
||
data class Single( | ||
override val message: String, | ||
val stackTrace: String, | ||
val causes: List<Cause> | ||
) : Error() | ||
|
||
data class Cause(val message: String) | ||
|
||
companion object { | ||
fun from(throwable: Throwable) = when { | ||
throwable is MultiCauseException && throwable.causes.size > 1 -> Multi( | ||
message = throwable.localizedMessage, | ||
errors = throwable.causes.map { it.toSingle() } | ||
) | ||
else -> throwable.toSingle() | ||
} | ||
|
||
private fun Throwable.toSingle() = Single( | ||
message = localizedMessage, | ||
stackTrace = getStackTraceString(), | ||
causes = getCausesRecursively().map { Cause(it.localizedMessage ?: "${it::class.java} (no error message)") } | ||
) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...lin/com/avito/android/build_verdict/internal/writer/BuildVerdictConfigurationPlainText.kt
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,44 @@ | ||
package com.avito.android.build_verdict.internal.writer | ||
|
||
import com.avito.android.build_verdict.internal.BuildVerdict | ||
import com.avito.android.build_verdict.internal.Error | ||
|
||
internal fun BuildVerdict.Configuration.plainText(): String { | ||
return error.plainText().trimIndent() | ||
} | ||
|
||
private fun Error.plainText() = when (this) { | ||
is Error.Single -> buildString { | ||
appendln("FAILURE: Build failed with an exception.") | ||
appendln() | ||
appendln("* What went wrong:") | ||
append(plainText()) | ||
} | ||
is Error.Multi -> plainText() | ||
} | ||
|
||
private fun Error.Single.plainText(): String { | ||
return buildString { | ||
appendln(message) | ||
causes.forEachIndexed { index, cause -> | ||
append("\t".repeat(index + 1)) | ||
append("> ") | ||
appendln(cause.message.trimIndent()) | ||
} | ||
} | ||
} | ||
|
||
private fun Error.Multi.plainText(): String { | ||
return buildString { | ||
appendln("FAILURE: $message") | ||
appendln() | ||
errors.forEachIndexed { index, error -> | ||
appendln("${index + 1}: Task failed with an exception.") | ||
appendln("-----------") | ||
appendln(error.plainText().trimIndent()) | ||
if (index < errors.size - 1) { | ||
appendln() | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.