Skip to content

Commit

Permalink
fix: use exec providers
Browse files Browse the repository at this point in the history
  • Loading branch information
ChipWolf committed Dec 17, 2024
1 parent a8aa516 commit 0b1ae95
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jobs:
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ data class McpExecutor(
}

override fun javaexec(configurator: Action<in JavaExecSpec>) {
SubprocessExecutor.exec(project, configurator).rethrowFailure().assertNormalExitValue()
SubprocessExecutor.exec(project, configurator)
.get()
.rethrowFailure()
.assertNormalExitValue()
}

override val minecraftLibraries: Set<File>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,44 @@ import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.ShowStacktrace
import org.gradle.process.ExecResult
import org.gradle.process.JavaExecSpec
import org.gradle.process.ExecOperations
import org.gradle.api.provider.Provider

object SubprocessExecutor {
fun shouldShowVerboseStdout(project: Project): Boolean {

private fun shouldShowVerboseStdout(project: Project): Boolean {
// if running with INFO or DEBUG logging
return project.gradle.startParameter.logLevel < LogLevel.LIFECYCLE
}

fun shouldShowVerboseStderr(project: Project): Boolean {
private fun shouldShowVerboseStderr(project: Project): Boolean {
// if stdout is shown or stacktraces are visible so that errors printed to stderr show up
return shouldShowVerboseStdout(project) || project.gradle.startParameter.showStacktrace != ShowStacktrace.INTERNAL_EXCEPTIONS
}

/**
* Executes a [javaexec][Project.javaexec] action with suppressed output.
* Executes a [javaexec][ExecOperations.javaexec] action with suppressed output.
*
* @param project the project
* @param configurator the `javaexec` configuration action
* @return the execution result
* @return a Provider of the execution result
*/
fun exec(project: Project, configurator: Action<in JavaExecSpec>): ExecResult {
return project.javaexec { spec: JavaExecSpec ->
fun exec(project: Project, configurator: Action<JavaExecSpec>): ExecResult {
val execOperations = project.extensions.getByType(ExecOperations::class.java)

return execOperations.javaexec { spec: JavaExecSpec ->
spec.workingDir(project.rootProject.projectDir)
configurator.execute(spec)
if (shouldShowVerboseStdout(project)) {
spec.standardOutput = System.out
spec.standardOutput = if (shouldShowVerboseStdout(project)) {
System.out
} else {
spec.standardOutput = NullOutputStream.NULL_OUTPUT_STREAM
NullOutputStream.NULL_OUTPUT_STREAM
}
if (shouldShowVerboseStderr(project)) {
spec.errorOutput = System.err
spec.errorOutput = if (shouldShowVerboseStderr(project)) {
System.err
} else {
spec.errorOutput = NullOutputStream.NULL_OUTPUT_STREAM
NullOutputStream.NULL_OUTPUT_STREAM
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,21 @@ open class JarModAgentMinecraftTransformer(
try {
val classpath = (task as RemapJarTaskImpl).provider.sourceSet.runtimeClasspath.files.toMutableSet()

val result = SubprocessExecutor.exec(project) {
val resultProvider = SubprocessExecutor.exec(project) {
it.jvmArgs = listOf(
"-D${JMA_TRANSFORMERS}=${transforms.joinToString(File.pathSeparator)}",
"-D${JMA_DEBUG}=true")
"-D${JMA_DEBUG}=true"
)
it.args = listOf(
input.absolutePathString(),
classpath.joinToString(File.pathSeparator) { it.absolutePath },
output.absolutePathString(),
output.absolutePathString()
)
it.mainClass.set("xyz.wagyourtail.unimined.jarmodagent.JarModAgent")
it.classpath = jarModAgent
}

val result = resultProvider.get()
if (result.exitValue != 0) {
throw IOException("Failed to run JarModAgent transformer: ${result.exitValue}")
}
Expand Down

0 comments on commit 0b1ae95

Please sign in to comment.