@@ -27,6 +27,7 @@ public class JShellService implements Closeable {
2727 private final long evalTimeout ;
2828 private boolean doingOperation ;
2929 private final DockerService dockerService ;
30+ private final int startupScriptSize ;
3031
3132 public JShellService (DockerService dockerService , JShellSessionService sessionService , String id , long timeout , boolean renewable , long evalTimeout , long evalTimeoutValidationLeeway , int sysOutCharLimit , int maxMemory , double cpus , String startupScript ) throws DockerException {
3233 this .dockerService = dockerService ;
@@ -38,7 +39,7 @@ public JShellService(DockerService dockerService, JShellSessionService sessionSe
3839 this .evalTimeoutValidationLeeway = evalTimeoutValidationLeeway ;
3940 this .lastTimeoutUpdate = Instant .now ();
4041 if (!dockerService .isDead (containerName ())) {
41- LOGGER .error ("Tried to create an existing container {}." , containerName ());
42+ LOGGER .warn ("Tried to create an existing container {}." , containerName ());
4243 throw new DockerException ("The session isn't completely destroyed, try again later." );
4344 }
4445 try {
@@ -58,9 +59,12 @@ public JShellService(DockerService dockerService, JShellSessionService sessionSe
5859 reader = new BufferedReader (new InputStreamReader (containerOutput ));
5960 writer .write (sanitize (startupScript ));
6061 writer .newLine ();
61- } catch (IOException | InterruptedException e ) {
62+ writer .flush ();
63+ checkContainerOK ();
64+ startupScriptSize = Integer .parseInt (reader .readLine ());
65+ } catch (Exception e ) {
6266 LOGGER .warn ("Unexpected error during creation." , e );
63- throw new DockerException (e );
67+ throw new DockerException ("Creation of the session failed." , e );
6468 }
6569 this .doingOperation = false ;
6670 }
@@ -136,7 +140,7 @@ private JShellResult readResult() throws IOException, NumberFormatException, Doc
136140 return new JShellResult (snippetResults , abortion , stdoutOverflow , stdout );
137141 }
138142
139- public Optional <List <String >> snippets () throws DockerException {
143+ public Optional <List <String >> snippets (boolean includeStartupScript ) throws DockerException {
140144 synchronized (this ) {
141145 if (!tryStartOperation ()) {
142146 return Optional .empty ();
@@ -155,7 +159,9 @@ public Optional<List<String>> snippets() throws DockerException {
155159 while (!(snippet = reader .readLine ()).isEmpty ()) {
156160 snippets .add (cleanCode (snippet ));
157161 }
158- return Optional .of (snippets );
162+ return Optional .of (
163+ includeStartupScript ? snippets : snippets .subList (startupScriptSize , snippets .size ())
164+ );
159165 } catch (IOException ex ) {
160166 LOGGER .warn ("Unexpected error." , ex );
161167 close ();
0 commit comments