11/*******************************************************************************
2- * Copyright (c) 2017, 2022 IBM Corporation and others.
2+ * Copyright (c) 2017, 2026 IBM Corporation and others.
33 * All rights reserved. This program and the accompanying materials
44 * are made available under the terms of the Eclipse Public License 2.0
55 * which accompanies this distribution, and is available at
1212 *******************************************************************************/
1313package componenttest .depchain ;
1414
15+ import java .io .BufferedReader ;
1516import java .io .File ;
1617import java .io .IOException ;
17- import java .util .Scanner ;
18+ import java .io .InputStreamReader ;
19+ import java .nio .charset .StandardCharsets ;
20+ import java .util .concurrent .Executors ;
21+ import java .util .concurrent .Future ;
1822import java .util .concurrent .TimeUnit ;
23+ import java .util .stream .Collectors ;
1924
2025import com .ibm .websphere .simplicity .log .Log ;
2126
@@ -33,7 +38,7 @@ public class FeatureList {
3338
3439 @ SuppressWarnings ("resource" )
3540 public static synchronized File get (LibertyServer server ) throws Exception {
36- final String m = "createFeatureList " ;
41+ final String m = "get " ;
3742
3843 featureList = new File (server .getUserDir () + "/servers" , FAT_FEATURE_LIST );
3944 if (featureList .exists ())
@@ -45,23 +50,38 @@ public static synchronized File get(LibertyServer server) throws Exception {
4550 Process featureListProc = new ProcessBuilder ("java" , "-jar" , featureListJar , featureList .getAbsolutePath ())
4651 .redirectErrorStream (true )
4752 .start ();
53+
54+ // Create a thread to capture the output of the process (stdout + stderr)
55+ Future <String > output = Executors .newSingleThreadExecutor ().submit (() -> {
56+ return new BufferedReader (new InputStreamReader (featureListProc .getInputStream (), StandardCharsets .UTF_8 ))
57+ .lines ()
58+ .collect (Collectors .joining (System .lineSeparator ()));
59+ });
60+
4861 boolean completed = featureListProc .waitFor (TIMEOUT_MINUTES , TimeUnit .MINUTES );
4962 if (!completed ) {
50- Exception e = new Exception ("Generating " + FAT_FEATURE_LIST + " timed out after " + TIMEOUT_MINUTES + " minutes. Aborting process." );
51- Log .error (c , m , e );
63+ // Destroy the process (still capturing output)
5264 featureListProc .destroyForcibly ();
5365 featureListProc .waitFor ();
66+
67+ //Output error
68+ Exception e = new Exception ("Generating " + FAT_FEATURE_LIST + " timed out after "
69+ + TIMEOUT_MINUTES + " minutes. Aborting process." + System .lineSeparator ()
70+ + output .get ());
71+ Log .error (c , m , e );
72+
5473 reset ();
5574 throw e ;
5675 }
76+
5777 int rc = featureListProc .exitValue ();
5878 if (rc != 0 ) {
59- String cmdOutput ;
60- try (Scanner s = new Scanner (featureListProc .getInputStream ()).useDelimiter ("\\ A" )) {
61- cmdOutput = s .hasNext () ? s .next () : "" ;
62- }
63- Exception e = new Exception ("Process failed with rc=" + rc + " for " + featureList .getAbsolutePath () + " generation:\n " + cmdOutput );
79+ //Output error
80+ Exception e = new Exception ("Process failed with rc=" + rc + " for " + featureList .getAbsolutePath ()
81+ + " generation:" + System .lineSeparator ()
82+ + output .get ());
6483 Log .error (c , m , e );
84+
6585 reset ();
6686 throw e ;
6787 }
0 commit comments