Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions jjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@
</filesets>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
--add-opens jdk.jshell/jdk.jshell=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
6 changes: 1 addition & 5 deletions jjava/src/main/java/org/dflib/jjava/JJavaExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public class JJavaExtension implements Extension {

@Override
public void install(BaseKernel kernel) {
try {
kernel.eval(STARTUP_SCRIPT);
} catch (Exception e) {
throw new RuntimeException(e);
}
kernel.eval(STARTUP_SCRIPT);
}
}
19 changes: 9 additions & 10 deletions jjava/src/main/java/org/dflib/jjava/JavaKernel.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public boolean autoLoadExtensions() {
}

@Override
public List<String> formatError(Exception e) {
public List<String> formatError(Throwable e) {
if (e instanceof CompilationException) {
return formatCompilationException((CompilationException) e);
} else if (e instanceof IncompleteSourceException) {
Expand Down Expand Up @@ -331,22 +331,21 @@ private List<String> formatEvaluationInterruptedException(EvaluationInterruptedE
return fmt;
}

public Object evalRaw(String expr) throws Exception {
public Object evalRaw(String expr) {
expr = this.magicsTransformer.transformMagics(expr);

return this.evaluator.eval(expr);
}

@Override
public DisplayData eval(String expr) throws Exception {
public DisplayData eval(String expr) {
Object result = this.evalRaw(expr);

if (result != null)
return result instanceof DisplayData
? (DisplayData) result
: this.getRenderer().render(result);

return null;
if (result == null) {
return null;
}
return result instanceof DisplayData
? (DisplayData) result
: this.getRenderer().render(result);
}

@Override
Expand Down
12 changes: 6 additions & 6 deletions jjava/src/main/java/org/dflib/jjava/execution/CodeEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ private SourceCodeAnalysis.CompletionInfo analyzeCompletion(String source) {
return this.sourceAnalyzer.analyzeCompletion(source);
}

private void init() throws Exception {
private void init() {
for (String script : this.startupScripts)
eval(script);

this.startupScripts.clear();
}

protected Object evalSingle(String code) throws Exception {
protected Object evalSingle(String code) {
JJavaExecutionControl executionControl =
this.executionControlProvider.getRegisteredControlByID(this.executionControlID);

Expand Down Expand Up @@ -139,11 +139,11 @@ protected Object evalSingle(String code) throws Exception {
case JJavaExecutionControl.EXECUTION_INTERRUPTED_NAME:
throw new EvaluationInterruptedException(code.trim());
default:
throw e;
throw new RuntimeException(e);
}
}

throw e;
throw new RuntimeException(e);
}

if (!event.status().isDefined())
Expand All @@ -154,7 +154,7 @@ protected Object evalSingle(String code) throws Exception {
return result;
}

public Object eval(String code) throws Exception {
public Object eval(String code) {
// The init() method runs some code in the shell to initialize the environment. As such
// it is deferred until the first user requested evaluation to cleanly return errors when
// they happen.
Expand All @@ -178,7 +178,7 @@ public Object eval(String code) throws Exception {
/**
* Try to clean up information linked to a code snippet and the snippet itself
*/
private void dropSnippet(Snippet snippet) throws Exception {
private void dropSnippet(Snippet snippet) {
JJavaExecutionControl executionControl =
this.executionControlProvider.getRegisteredControlByID(this.executionControlID);
this.shell.drop(snippet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import jdk.jshell.SnippetEvent;

public class CompilationException extends Exception {
public class CompilationException extends RuntimeException {
private final SnippetEvent badSnippetCompilation;

public CompilationException(SnippetEvent badSnippetCompilation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.dflib.jjava.execution;

public class EvaluationInterruptedException extends Exception {
public class EvaluationInterruptedException extends RuntimeException {
private final String source;

public EvaluationInterruptedException(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import java.util.concurrent.TimeUnit;

public class EvaluationTimeoutException extends Exception {
public class EvaluationTimeoutException extends RuntimeException {
private final long duration;
private final TimeUnit unit;
private final String source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
package org.dflib.jjava.execution;

public class IncompleteSourceException extends Exception {
public class IncompleteSourceException extends RuntimeException {
private final String source;

public IncompleteSourceException(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Object takeResult(String key) {
return result == NULL ? null : result;
}

private Object execute(String key, Method doitMethod) throws TimeoutException, Exception {
private Object execute(String key, Method doitMethod) throws Exception {
Future<Object> runningTask = this.executor.submit(() -> doitMethod.invoke(null));

this.running.put(key, runningTask);
Expand Down Expand Up @@ -137,7 +137,7 @@ private Object execute(String key, Method doitMethod) throws TimeoutException, E
else if (cause instanceof SPIResolutionException)
throw new ResolutionException(((SPIResolutionException) cause).id(), cause.getStackTrace());
else
throw new UserException(String.valueOf(cause.getMessage()), String.valueOf(cause.getClass().getName()), cause.getStackTrace());
throw new UserException(String.valueOf(cause.getMessage()), cause.getClass().getName(), cause.getStackTrace());
} catch (TimeoutException e) {
throw new UserException(
String.format("Execution timed out after configured timeout of %d %s.", this.timeoutTime, this.timeoutUnit.toString().toLowerCase()),
Expand Down Expand Up @@ -199,7 +199,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
return loaderDelegate.findClass(name);
}

void unloadClass(String className) throws ClassNotFoundException {
void unloadClass(String className) {
this.loaderDelegate.unloadClass(className);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@

public abstract class BaseKernel {
protected final AtomicInteger executionCount = new AtomicInteger(1);
protected static final Map<String, String> KERNEL_META = ((Supplier<Map<String, String>>) () -> {
protected static final Map<String, String> KERNEL_META;

static {
Map<String, String> meta = null;

InputStream metaStream = BaseKernel.class.getClassLoader().getResourceAsStream("kernel-metadata.json");
Expand All @@ -83,8 +85,8 @@ public abstract class BaseKernel {
meta.put("project", "unknown");
}

return meta;
}).get();
KERNEL_META = meta;
}

private final JupyterIO io;
private boolean shouldReplaceStdStreams;
Expand Down Expand Up @@ -161,7 +163,28 @@ public HistoryManager getHistoryManager() {
return null;
}

public abstract DisplayData eval(String expr) throws Exception;
/**
* Evaluates a code expression in the kernel's language environment and returns the result
* as display data. This is the core evaluation method called when executing code cells
* in a Jupyter notebook.
*
* <p>The implementation should:
* <ul>
* <li>Parse and evaluate the provided expression string</li>
* <li>Convert the evaluation result into appropriate display data formats</li>
* <li>Handle any language-specific evaluation context/scope</li>
* </ul>
*
* <p>The returned {@link DisplayData} can contain multiple representations of the result
* (e.g. text/plain, text/html, image/png) to allow rich display in the notebook.
* Return null if the expression produces no displayable result.
*
* @param expr The code expression to evaluate as received from the Jupyter frontend
*
* @return A {@link DisplayData} object containing the evaluation result in one or more
* MIME formats, or null if there is no displayable result
*/
public abstract DisplayData eval(String expr);

/**
* Inspect the code to get things such as documentation for a function. This is
Expand All @@ -178,10 +201,9 @@ public HistoryManager getHistoryManager() {
*
* @return an output bundle for displaying the documentation or null if nothing is found
*
* @throws Exception if the code cannot be inspected for some reason (such as it not
* compiling)
* @throws RuntimeException if the code cannot be inspected for some reason (such as it not compiling)
*/
public DisplayData inspect(String code, int at, boolean extraDetail) throws Exception {
public DisplayData inspect(String code, int at, boolean extraDetail) {
return null;
}

Expand All @@ -204,11 +226,11 @@ public DisplayData inspect(String code, int at, boolean extraDetail) throws Exce
* @return the replacement options containing a list of replacement texts and a
* source range to overwrite with a user selected replacement from the list
*
* @throws Exception if code cannot be completed due to code compilation issues, or
* similar. This should not be thrown if not replacements are available but rather just
* an empty replacements returned.
* @throws RuntimeException if code cannot be completed due to code compilation issues, or similar.
* This should not be thrown if not replacements are available but rather just
* an empty replacements returned.
*/
public ReplacementOptions complete(String code, int at) throws Exception {
public ReplacementOptions complete(String code, int at) {
return null;
}

Expand Down Expand Up @@ -283,7 +305,7 @@ public void interrupt() {
* not include strings with newlines but rather separate strings each to go on a
* new line.
*/
public List<String> formatError(Exception e) {
public List<String> formatError(Throwable e) {
List<String> lines = new LinkedList<>();
lines.add(this.errorStyler.secondary("---------------------------------------------------------------------------"));

Expand Down
Loading