mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 07:27:52 +01:00
prevent blocking of process with large amount of errors.
This commit is contained in:
parent
bb4ffa7842
commit
6b309dac9f
@ -333,7 +333,7 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
}
|
}
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
nodeModulePath = readStream( process.getInputStream() ).trim(); // module install path
|
nodeModulePath = readStream( process.getInputStream(), false ).trim(); // module install path
|
||||||
System.out.println( "node global module path: " + nodeModulePath );
|
System.out.println( "node global module path: " + nodeModulePath );
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
if( exitCode != 0 ) {
|
if( exitCode != 0 ) {
|
||||||
fail( readStream( process.getErrorStream() ) + "\nExit code: " + exitCode + " from: " + processBuilder.command().get( 0 ) );
|
fail( readStream( process.getErrorStream(), false ) + "\nExit code: " + exitCode + " from: " + processBuilder.command().get( 0 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
private File createScript( ScriptEngine script, String name, String placeholder, String value ) throws IOException {
|
private File createScript( ScriptEngine script, String name, String placeholder, String value ) throws IOException {
|
||||||
File file = newFile( script.name() + "Test.js" );
|
File file = newFile( script.name() + "Test.js" );
|
||||||
URL scriptUrl = getClass().getResource( name );
|
URL scriptUrl = getClass().getResource( name );
|
||||||
String template = readStream( scriptUrl.openStream() );
|
String template = readStream( scriptUrl.openStream(), true );
|
||||||
template = template.replace( placeholder, value );
|
template = template.replace( placeholder, value );
|
||||||
try (FileOutputStream scriptStream = new FileOutputStream( file )) {
|
try (FileOutputStream scriptStream = new FileOutputStream( file )) {
|
||||||
scriptStream.write( template.getBytes( StandardCharsets.UTF_8 ) );
|
scriptStream.write( template.getBytes( StandardCharsets.UTF_8 ) );
|
||||||
@ -572,15 +572,15 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
String errorMessage = "";
|
String errorMessage = "";
|
||||||
do {
|
do {
|
||||||
if( process.getInputStream().available() > 0 ) {
|
if( process.getInputStream().available() > 0 ) {
|
||||||
stdoutMessage += readStream( process.getInputStream() );
|
stdoutMessage += readStream( process.getInputStream(), false );
|
||||||
}
|
}
|
||||||
if( process.getErrorStream().available() > 0 ) {
|
if( process.getErrorStream().available() > 0 ) {
|
||||||
errorMessage += readStream( process.getErrorStream() );
|
errorMessage += readStream( process.getErrorStream(), false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while( !process.waitFor( 10, TimeUnit.MILLISECONDS ) );
|
while( !process.waitFor( 10, TimeUnit.MILLISECONDS ) );
|
||||||
stdoutMessage += readStream( process.getInputStream() );
|
stdoutMessage += readStream( process.getInputStream(), false );
|
||||||
errorMessage += readStream( process.getErrorStream() );
|
errorMessage += readStream( process.getErrorStream(), false );
|
||||||
int exitCode = process.exitValue();
|
int exitCode = process.exitValue();
|
||||||
if( exitCode != 0 || !stdoutMessage.isEmpty() || !errorMessage.isEmpty() ) {
|
if( exitCode != 0 || !stdoutMessage.isEmpty() || !errorMessage.isEmpty() ) {
|
||||||
System.err.println( stdoutMessage );
|
System.err.println( stdoutMessage );
|
||||||
@ -715,11 +715,11 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
* if an I/O error occurs.
|
* if an I/O error occurs.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings( "resource" )
|
@SuppressWarnings( "resource" )
|
||||||
public static String readStream( InputStream input ) throws IOException {
|
public static String readStream( InputStream input, boolean all ) throws IOException {
|
||||||
byte[] bytes = new byte[8192];
|
byte[] bytes = new byte[8192];
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
int count;
|
int count;
|
||||||
while( (count = input.read( bytes )) > 0 ) {
|
while( (all || input.available() > 0) && (count = input.read( bytes )) > 0 ) {
|
||||||
stream.write( bytes, 0, count );
|
stream.write( bytes, 0, count );
|
||||||
}
|
}
|
||||||
return new String( stream.toByteArray() );
|
return new String( stream.toByteArray() );
|
||||||
|
@ -66,7 +66,7 @@ class Wat2Wasm {
|
|||||||
URL url = new URL( "https://github.com/WebAssembly/wabt/releases/latest" );
|
URL url = new URL( "https://github.com/WebAssembly/wabt/releases/latest" );
|
||||||
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
|
||||||
InputStream input = conn.getInputStream();
|
InputStream input = conn.getInputStream();
|
||||||
String data = WasmRule.readStream( input );
|
String data = WasmRule.readStream( input, true );
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile( "/WebAssembly/wabt/releases/download/[0-9.]*/wabt-[0-9.]*-" + fileName );
|
Pattern pattern = Pattern.compile( "/WebAssembly/wabt/releases/download/[0-9.]*/wabt-[0-9.]*-" + fileName );
|
||||||
Matcher matcher = pattern.matcher( data );
|
Matcher matcher = pattern.matcher( data );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user