diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/client/Client.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/client/Client.java index e4d88fc94ee..39ae7f10cf0 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/client/Client.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/client/Client.java @@ -89,71 +89,79 @@ public Client(MutableList replExtensions, MutableList replExtensions, MutableList completerExtensions, PlanExecutor planExecutor, Path homeDirectory) throws Exception { - this.replExtensions = replExtensions; - this.completerExtensions = completerExtensions; - this.planExecutor = planExecutor; - this.state = new ModelState(this.legendInterface, this.replExtensions); - this.terminal = TerminalBuilder.terminal(); - this.homeDirectory = homeDirectory; - - this.documentation = DocumentationGeneration.buildDocumentation(); - this.initialize(); - replExtensions.forEach(e -> e.initialize(this)); - replExtensions.forEach(e -> e.postInitialize(this)); - - this.printDebug("[DEV] Legend REPL v" + DeploymentStateAndVersions.sdlc.buildVersion + " (" + DeploymentStateAndVersions.sdlc.commitIdAbbreviated + ")"); - if (System.getProperty("legend.repl.initializationMessage") != null) + this.replExtensions = replExtensions; + this.completerExtensions = completerExtensions; + this.planExecutor = planExecutor; + this.state = new ModelState(this.legendInterface, this.replExtensions); + this.terminal = TerminalBuilder.terminal(); + this.homeDirectory = homeDirectory; + this.documentation = DocumentationGeneration.buildDocumentation(); + + this.initialize(); + replExtensions.forEach(e -> e.initialize(this)); + + this.printDebug("[DEV] Legend REPL v" + DeploymentStateAndVersions.sdlc.buildVersion + " (" + DeploymentStateAndVersions.sdlc.commitIdAbbreviated + ")"); + if (System.getProperty("legend.repl.initializationMessage") != null) + { + this.printDebug(StringEscapeUtils.unescapeJava(System.getProperty("legend.repl.initializationMessage"))); + } + this.printDebug("Press 'Enter' or type 'help' to see the list of available commands."); + this.println("\n" + Logos.logos.get((int) (Logos.logos.size() * Math.random())) + "\n"); + + // NOTE: the order here matters, the default command 'help' should always go first + // and "catch-all" command 'execute' should always go last + this.commands = replExtensions + .flatCollect(ReplExtension::getExtraCommands) + .withAll( + Lists.mutable.with( + new Ext(this), + new Debug(this), + new Doc(this), + new Graph(this), + new Execute(this) + ) + ); + this.commands.add(0, new Help(this, this.commands)); + this.reader = LineReaderBuilder.builder() + .terminal(terminal) + // Configure history file + // See https://github.com/jline/jline3/wiki/History + .variable(LineReader.HISTORY_FILE, this.getHomeDir().resolve("history")) + .variable(LineReader.HISTORY_FILE_SIZE, 1_000) + .variable(LineReader.HISTORY_IGNORE, ": *") // make sure empty space(s) are not persisted + // Disable cursor jumping to opening brace when typing closing brace + // See https://github.com/jline/jline3/issues/216 + .variable(BLINK_MATCHING_PAREN, false) + // Make sure hitting at the beginning of line will insert a tab instead of triggering a completion + // which will cause error since the completer doesn't handle such case + // See https://github.com/jline/jline3/wiki/Completion + .option(LineReader.Option.INSERT_TAB, true) + // Make sure word navigation works properly with Alt + (left/right) arrow key + .variable(LineReader.WORDCHARS, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-$") + // Make sure to not break the completer when exclamation sign is present + // Do this by disabling history expansion + // See https://github.com/jline/jline3/issues/246 + .option(LineReader.Option.DISABLE_EVENT_EXPANSION, true) + .highlighter(new JLine3Highlighter()) + .parser(new JLine3Parser()) + .completer(new JLine3Completer(this.commands)) + .build(); + + try { - this.printDebug(StringEscapeUtils.unescapeJava(System.getProperty("legend.repl.initializationMessage"))); + replExtensions.forEach(e -> e.postInitialize(this)); + + this.println("Warming up..."); + this.terminal.flush(); + ((Execute) this.commands.getLast()).execute("1+1"); + this.println("Ready!\n"); + } + catch (Exception exception) + { + this.printError("Failed to initialize REPL. Error:\n" + exception.getMessage()); + // NOTE: we let people continue even if the warm-up failed, in order to let them + // debug the issue or take some measures to recover } - this.printDebug("Press 'Enter' or type 'help' to see the list of available commands."); - this.println("\n" + Logos.logos.get((int) (Logos.logos.size() * Math.random())) + "\n"); - - // NOTE: the order here matters, the default command 'help' should always go first - // and "catch-all" command 'execute' should always go last - this.commands = replExtensions - .flatCollect(ReplExtension::getExtraCommands) - .withAll( - Lists.mutable.with( - new Ext(this), - new Debug(this), - new Doc(this), - new Graph(this), - new Execute(this) - ) - ); - - this.commands.add(0, new Help(this, this.commands)); - - this.reader = LineReaderBuilder.builder() - .terminal(terminal) - // Configure history file - // See https://github.com/jline/jline3/wiki/History - .variable(LineReader.HISTORY_FILE, this.getHomeDir().resolve("history")) - .variable(LineReader.HISTORY_FILE_SIZE, 1_000) - .variable(LineReader.HISTORY_IGNORE, ": *") // make sure empty space(s) are not persisted - // Disable cursor jumping to opening brace when typing closing brace - // See https://github.com/jline/jline3/issues/216 - .variable(BLINK_MATCHING_PAREN, false) - // Make sure hitting at the beginning of line will insert a tab instead of triggering a completion - // which will cause error since the completer doesn't handle such case - // See https://github.com/jline/jline3/wiki/Completion - .option(LineReader.Option.INSERT_TAB, true) - // Make sure word navigation works properly with Alt + (left/right) arrow key - .variable(LineReader.WORDCHARS, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-$") - // Make sure to not break the completer when exclamation sign is present - // Do this by disabling history expansion - // See https://github.com/jline/jline3/issues/246 - .option(LineReader.Option.DISABLE_EVENT_EXPANSION, true) - .highlighter(new JLine3Highlighter()) - .parser(new JLine3Parser()) - .completer(new JLine3Completer(this.commands)) - .build(); - - this.println("Warming up..."); - this.terminal.flush(); - ((Execute) this.commands.getLast()).execute("1+1"); - this.println("Ready!\n"); } private void initialize() diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/core/ReplExtension.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/core/ReplExtension.java index 6f2350c3332..558afe726d2 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/core/ReplExtension.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-client/src/main/java/org/finos/legend/engine/repl/core/ReplExtension.java @@ -52,7 +52,7 @@ default void initialize(Client client) { } - // This method is called after all extensions have been initialized + // This method is called after all extensions and the client have been initialized. // This is useful for cases where we need to invoke initialization-type tasks from one extension // that might depend on another extension. This is for now the preferred approach over specifying // a dependency graph to determine the order of initialization. diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/commands/DB.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/commands/DB.java index ada6a2b2807..1a568ecad18 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/commands/DB.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/commands/DB.java @@ -70,7 +70,7 @@ public boolean process(String line) throws Exception try (Connection connection = ConnectionHelper.getConnection(databaseConnection, client.getPlanExecutor())) { this.client.println( - getTables(connection).collect(c -> c.schema + "." + c.name + "(" + c.columns.collect(col -> col.name + " " + col.type).makeString(", ") + ")").makeString("\n") + getTables(connection).collect(c -> c.schema + "." + c.name + "(" + c.columns.collect(col -> PureGrammarComposerUtility.convertIdentifier(col.name, true) + " " + col.type).makeString(", ") + ")").makeString("\n") ); } return true; diff --git a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/local/LocalConnectionManagement.java b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/local/LocalConnectionManagement.java index 531f97a52a0..e1f91c61b50 100644 --- a/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/local/LocalConnectionManagement.java +++ b/legend-engine-config/legend-engine-repl/legend-engine-repl-relational/src/main/java/org/finos/legend/engine/repl/relational/local/LocalConnectionManagement.java @@ -74,7 +74,7 @@ public MutableList generateDynamicContent(String code) res.add("###Relational\n" + "Database local::" + conn + "Database" + "(" + - getTables(connection).collect(table -> "Table " + table.name + "(" + table.columns.collect(c -> (c.name.contains(" ") ? "\"" + c.name + "\"" : c.name) + " " + c.type).makeString(",") + ")").makeString("\n") + + getTables(connection).collect(table -> "Table " + table.name + "(" + table.columns.collect(c -> PureGrammarComposerUtility.convertIdentifier(c.name, true) + " " + c.type).makeString(",") + ")").makeString("\n") + ")\n"); } catch (SQLException e) diff --git a/pom.xml b/pom.xml index cc056c6fee6..e99d989c3ea 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ 5.20.0 0.25.6 - 12.51.0 + 12.54.0 legend-engine