Skip to content

Commit 5fe48f3

Browse files
committed
update
1 parent fdea411 commit 5fe48f3

26 files changed

+1039
-506
lines changed

JShellAPI/src/main/java/org/togetherjava/jshellapi/Config.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55

66
@ConfigurationProperties("jshellapi")
77
public record Config(
8-
long regularSessionTimeoutSeconds,
9-
long oneTimeSessionTimeoutSeconds,
10-
long evalTimeoutSeconds,
11-
long evalTimeoutValidationLeeway,
12-
int sysOutCharLimit,
13-
long maxAliveSessions,
14-
int dockerMaxRamMegaBytes,
15-
double dockerCPUsUsage,
16-
@Nullable String dockerCPUSetCPUs,
17-
long schedulerSessionKillScanRateSeconds,
18-
long dockerResponseTimeout,
19-
long dockerConnectionTimeout) {
8+
long regularSessionTimeoutSeconds,
9+
long oneTimeSessionTimeoutSeconds,
10+
long evalTimeoutSeconds,
11+
long evalTimeoutValidationLeeway,
12+
int sysOutCharLimit,
13+
long maxAliveSessions,
14+
int dockerMaxRamMegaBytes,
15+
double dockerCPUsUsage,
16+
@Nullable String dockerCPUSetCPUs,
17+
long schedulerSessionKillScanRateSeconds,
18+
long dockerResponseTimeout,
19+
long dockerConnectionTimeout
20+
) {
2021
public Config {
2122
if (regularSessionTimeoutSeconds <= 0)
2223
throw new IllegalArgumentException("Invalid value " + regularSessionTimeoutSeconds);
@@ -38,7 +39,8 @@ public record Config(
3839
throw new IllegalArgumentException("Invalid value " + dockerCPUSetCPUs);
3940
if (schedulerSessionKillScanRateSeconds <= 0)
4041
throw new IllegalArgumentException(
41-
"Invalid value " + schedulerSessionKillScanRateSeconds);
42+
"Invalid value " + schedulerSessionKillScanRateSeconds
43+
);
4244
if (dockerResponseTimeout <= 0)
4345
throw new IllegalArgumentException("Invalid value " + dockerResponseTimeout);
4446
if (dockerConnectionTimeout <= 0)
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package org.togetherjava.jshellapi.dto;
22

33
public record JShellEvalAbortion(
4-
String sourceCause, String remainingSource, JShellEvalAbortionCause cause) {}
4+
String sourceCause,
5+
String remainingSource,
6+
JShellEvalAbortionCause cause
7+
) {}

JShellAPI/src/main/java/org/togetherjava/jshellapi/dto/JShellEvalAbortionCause.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package org.togetherjava.jshellapi.dto;
22

3+
import java.util.List;
4+
35
import com.fasterxml.jackson.annotation.JsonTypeInfo;
46
import com.fasterxml.jackson.annotation.JsonTypeName;
57

6-
import java.util.List;
7-
88
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME)
99
public sealed interface JShellEvalAbortionCause {
1010

1111
@JsonTypeName("TIMEOUT")
1212
record TimeoutAbortionCause() implements JShellEvalAbortionCause {}
1313

1414
@JsonTypeName("UNCAUGHT_EXCEPTION")
15-
record UnhandledExceptionAbortionCause(String exceptionClass, String exceptionMessage)
16-
implements JShellEvalAbortionCause {}
15+
record UnhandledExceptionAbortionCause(
16+
String exceptionClass,
17+
String exceptionMessage
18+
) implements JShellEvalAbortionCause {}
1719

1820
@JsonTypeName("COMPILE_TIME_ERROR")
1921
record CompileTimeErrorAbortionCause(List<String> errors) implements JShellEvalAbortionCause {}

JShellAPI/src/main/java/org/togetherjava/jshellapi/dto/JShellResult.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package org.togetherjava.jshellapi.dto;
22

3-
import org.springframework.lang.Nullable;
4-
53
import java.util.List;
64

5+
import org.springframework.lang.Nullable;
6+
77
public record JShellResult(
8-
List<JShellSnippetResult> snippetsResults,
9-
@Nullable JShellEvalAbortion abortion,
10-
boolean stdoutOverflow,
11-
String stdout) {
8+
List<JShellSnippetResult> snippetsResults,
9+
@Nullable JShellEvalAbortion abortion,
10+
boolean stdoutOverflow,
11+
String stdout
12+
) {
1213
public JShellResult {
1314
snippetsResults = List.copyOf(snippetsResults);
1415
}

JShellAPI/src/main/java/org/togetherjava/jshellapi/dto/JShellSnippetResult.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@
33
import org.springframework.lang.Nullable;
44

55
public record JShellSnippetResult(
6-
SnippetStatus status, SnippetType type, int id, String source, @Nullable String result) {}
6+
SnippetStatus status,
7+
SnippetType type,
8+
int id,
9+
String source,
10+
@Nullable String result
11+
) {}

JShellAPI/src/main/java/org/togetherjava/jshellapi/exceptions/DockerException.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ public DockerException(Throwable cause) {
2020
}
2121

2222
public DockerException(
23-
String message,
24-
Throwable cause,
25-
boolean enableSuppression,
26-
boolean writableStackTrace) {
23+
String message,
24+
Throwable cause,
25+
boolean enableSuppression,
26+
boolean writableStackTrace
27+
) {
2728
super(message, cause, enableSuppression, writableStackTrace);
2829
}
2930
}
Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.togetherjava.jshellapi.rest;
22

3+
import java.util.List;
4+
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.http.HttpStatus;
57
import org.springframework.web.bind.annotation.*;
@@ -12,8 +14,6 @@
1214
import org.togetherjava.jshellapi.service.StartupScriptId;
1315
import org.togetherjava.jshellapi.service.StartupScriptsService;
1416

15-
import java.util.List;
16-
1717
@RequestMapping("jshell")
1818
@RestController
1919
public class JShellController {
@@ -22,63 +22,72 @@ public class JShellController {
2222

2323
@PostMapping("/eval/{id}")
2424
public JShellResult eval(
25-
@PathVariable String id,
26-
@RequestParam(required = false) StartupScriptId startupScriptId,
27-
@RequestBody String code)
28-
throws DockerException {
25+
@PathVariable String id,
26+
@RequestParam(required = false) StartupScriptId startupScriptId,
27+
@RequestBody String code
28+
) throws DockerException {
2929
validateId(id);
3030
return service.session(id, startupScriptId)
31-
.eval(code)
32-
.orElseThrow(
33-
() ->
34-
new ResponseStatusException(
35-
HttpStatus.CONFLICT, "An operation is already running"));
31+
.eval(code)
32+
.orElseThrow(
33+
() -> new ResponseStatusException(
34+
HttpStatus.CONFLICT,
35+
"An operation is already running"
36+
)
37+
);
3638
}
3739

3840
@PostMapping("/eval")
3941
public JShellResultWithId eval(
40-
@RequestParam(required = false) StartupScriptId startupScriptId,
41-
@RequestBody String code)
42-
throws DockerException {
42+
@RequestParam(required = false) StartupScriptId startupScriptId,
43+
@RequestBody String code
44+
) throws DockerException {
4345
JShellService jShellService = service.session(startupScriptId);
4446
return new JShellResultWithId(
45-
jShellService.id(),
46-
jShellService
47-
.eval(code)
48-
.orElseThrow(
49-
() ->
50-
new ResponseStatusException(
51-
HttpStatus.CONFLICT,
52-
"An operation is already running")));
47+
jShellService.id(),
48+
jShellService
49+
.eval(code)
50+
.orElseThrow(
51+
() -> new ResponseStatusException(
52+
HttpStatus.CONFLICT,
53+
"An operation is already running"
54+
)
55+
)
56+
);
5357
}
5458

5559
@PostMapping("/single-eval")
5660
public JShellResult singleEval(
57-
@RequestParam(required = false) StartupScriptId startupScriptId,
58-
@RequestBody String code)
59-
throws DockerException {
61+
@RequestParam(required = false) StartupScriptId startupScriptId,
62+
@RequestBody String code
63+
) throws DockerException {
6064
JShellService jShellService = service.oneTimeSession(startupScriptId);
6165
return jShellService
62-
.eval(code)
63-
.orElseThrow(
64-
() ->
65-
new ResponseStatusException(
66-
HttpStatus.CONFLICT, "An operation is already running"));
66+
.eval(code)
67+
.orElseThrow(
68+
() -> new ResponseStatusException(
69+
HttpStatus.CONFLICT,
70+
"An operation is already running"
71+
)
72+
);
6773
}
6874

6975
@GetMapping("/snippets/{id}")
7076
public List<String> snippets(
71-
@PathVariable String id, @RequestParam(required = false) boolean includeStartupScript)
72-
throws DockerException {
77+
@PathVariable String id,
78+
@RequestParam(required = false) boolean includeStartupScript
79+
) throws DockerException {
7380
validateId(id);
7481
if (!service.hasSession(id))
7582
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Id " + id + " not found");
7683
return service.session(id, null)
77-
.snippets(includeStartupScript)
78-
.orElseThrow(
79-
() ->
80-
new ResponseStatusException(
81-
HttpStatus.CONFLICT, "An operation is already running"));
84+
.snippets(includeStartupScript)
85+
.orElseThrow(
86+
() -> new ResponseStatusException(
87+
HttpStatus.CONFLICT,
88+
"An operation is already running"
89+
)
90+
);
8291
}
8392

8493
@DeleteMapping("/{id}")
@@ -107,8 +116,9 @@ public void setStartupScriptsService(StartupScriptsService startupScriptsService
107116
private static void validateId(String id) throws ResponseStatusException {
108117
if (!id.matches("[a-zA-Z0-9][a-zA-Z0-9_.-]+")) {
109118
throw new ResponseStatusException(
110-
HttpStatus.BAD_REQUEST,
111-
"Id " + id + " doesn't match the regex [a-zA-Z0-9][a-zA-Z0-9_.-]+");
119+
HttpStatus.BAD_REQUEST,
120+
"Id " + id + " doesn't match the regex [a-zA-Z0-9][a-zA-Z0-9_.-]+"
121+
);
112122
}
113123
}
114124
}

0 commit comments

Comments
 (0)