Skip to content

Commit

Permalink
HHH-14083 Fix error detection in executeGitCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere authored and dreab8 committed Jun 22, 2020
1 parent fe6a20d commit 921e4ca
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions release/release.gradle
@@ -1,3 +1,5 @@
import java.nio.charset.StandardCharsets

import groovy.json.JsonSlurper

/*
Expand Down Expand Up @@ -321,13 +323,28 @@ task ciRelease() {
ciRelease.dependsOn updateChangeLogFile, release
release.mustRunAfter updateChangeLogFile

void executeGitCommand(String command, String errorMessage){
static void executeGitCommand(String command, String errorMessage){
def proc = command.execute()
def errorsStringBuffer = new StringBuffer()
proc.waitFor()
proc.consumeProcessErrorStream( errorsStringBuffer )
if ( errorsStringBuffer.toString( ) != "" ) {
throw new GradleException( errorMessage + " " + b );
def code = proc.waitFor()
def stdout = inputStreamToString( proc.getInputStream() )
def stderr = inputStreamToString( proc.getErrorStream() )
if ( code != 0 ) {
throw new GradleException( errorMessage + "\n\nstdout:\n" + stdout + "\n\nstderr:\n" + stderr )
}
}

static String inputStreamToString(InputStream inputStream) {
inputStream.withCloseable { ins ->
new BufferedInputStream(ins).withCloseable { bis ->
new ByteArrayOutputStream().withCloseable { buf ->
int result = bis.read();
while (result != -1) {
buf.write((byte) result);
result = bis.read();
}
return buf.toString( StandardCharsets.UTF_8.name());
}
}
}
}

Expand Down

0 comments on commit 921e4ca

Please sign in to comment.