From 6de053470378dd5500e745a8258dedc515746e9d Mon Sep 17 00:00:00 2001 From: Laszlo Gati Date: Wed, 26 Mar 2025 16:44:50 +0100 Subject: [PATCH 1/3] ST6RI-836 Added magic command to change api-base-path --- .../sysml/interactive/SysMLInteractive.java | 16 ++++++ .../interactive/SysMLInteractiveHelp.java | 11 +++- .../omg/sysml/jupyter/kernel/SysMLKernel.java | 1 + .../jupyter/kernel/magic/ApiBasePath.java | 55 +++++++++++++++++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java diff --git a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java index 2d53d57ab..c921b8854 100644 --- a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java +++ b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractive.java @@ -137,6 +137,10 @@ public void setApiBasePath(String apiBasePath) { this.apiBasePath = apiBasePath; } + public String getApiBasePath() { + return apiBasePath; + } + public int next() { this.resource = (XtextResource)this.createResource(counter + SYSML_EXTENSION); this.addInputResource(this.resource); @@ -249,6 +253,18 @@ public String help(String command) { help(command, Collections.emptyList()); } + public String apiBasePath(String apiBasePath, List help) { + if (!help.isEmpty()) { + return SysMLInteractiveHelp.getApiBasePathHelp(); + } + + if (!Strings.isNullOrEmpty(apiBasePath)) { + setApiBasePath(apiBasePath); + } + + return getApiBasePath(); + } + public String eval(String input, String targetName, List help) { if (Strings.isNullOrEmpty(input)) { this.counter++; diff --git a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java index bb33eba8d..4208adead 100644 --- a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java +++ b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java @@ -38,6 +38,7 @@ public class SysMLInteractiveHelp { private static final String GENERAL_HELP_STRING = "The following SysML v2 magic commands are available.\n" + "For help on a specific command, use \"%help \" or \"% -h\".\n\n" + + "%api-base-path\t Sets and prints the current api base path" + "%eval\t\tEvaluate a given expression.\n" + "%export\t\tSave a file of the JSON representation of the abstract syntax tree rooted in the named element.\n" + "%help\t\tGet a list of available commands or help on a specific command\n" @@ -115,6 +116,11 @@ public class SysMLInteractiveHelp { "Usage: %export \n\n" + "Save a file containing the complete JSON representation of the abstract syntax tree rooted in .\n" + " must be fully qualified.\n"; + + private static final String API_BASE_PATH_HELP_STRING = + "Usage: %api-base-path []\n\n" + + "Sets the current api base path\n" + + "If no argument is passed it prints the current api base path"; public static String getGeneralHelp() { return GENERAL_HELP_STRING; @@ -152,6 +158,10 @@ public static String getExportHelp() { return EXPORT_HELP_STRING; } + public static String getApiBasePathHelp() { + return API_BASE_PATH_HELP_STRING; + } + private static Map commandHelpMap = createCommandHelpMap(); private static Map createCommandHelpMap() { @@ -170,5 +180,4 @@ private static Map createCommandHelpMap() { public static String getHelpString(String command) { return commandHelpMap.get(command); } - } diff --git a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java index f2265c140..f77bbe2ad 100644 --- a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java @@ -80,6 +80,7 @@ public SysMLKernel() { this.magics.registerMagics(Viz.class); this.magics.registerMagics(View.class); this.magics.registerMagics(Export.class); + this.magics.registerMagics(ApiBasePath.class); this.magicParser = new MyMagicParser(); } diff --git a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java new file mode 100644 index 000000000..f40b7c54c --- /dev/null +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java @@ -0,0 +1,55 @@ +/** + * SysML 2 Pilot Implementation + * Copyright (C) 2025 Model Driven Solutions, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * @license LGPL-3.0-or-later + * + * Contributors: + * Laszlo Gati, MDS + */ +package org.omg.sysml.jupyter.kernel.magic; + +import java.util.List; +import java.util.Map; + +import org.omg.sysml.interactive.SysMLInteractive; +import org.omg.sysml.jupyter.kernel.ISysML; + +import io.github.spencerpark.jupyter.kernel.magic.registry.LineMagic; +import io.github.spencerpark.jupyter.kernel.magic.registry.MagicsArgs; + +public class ApiBasePath { + + private static final MagicsArgs SHOW_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags() + .optional("basePath") + .flag("help", 'h', "true") + .build(); + + @LineMagic("api-base-path") + public static String apiBasePath(List args) { + Map> vals = SHOW_ARGS.parse(args); + List basePaths = vals.get("basePath"); + String basePath = basePaths.isEmpty()? null: basePaths.get(0); + + SysMLInteractive interactive = ISysML.getKernelInstance().getInteractive(); + + if (basePath != null) { + interactive.setApiBasePath(basePath); + } + + return "Api base path is: " + ISysML.getKernelInstance().getInteractive().getApiBasePath(); + } +} From 7e36f1267ac4b1ea2820343aeeb3dd03a94ac7dc Mon Sep 17 00:00:00 2001 From: Laszlo Gati Date: Mon, 5 May 2025 14:44:40 +0200 Subject: [PATCH 2/3] ST6RI-836 Changed magic command 'api-base-path' to 'repo' - updated help string - fixed '-h' flag --- .../sysml/interactive/SysMLInteractiveHelp.java | 17 +++++++++++------ .../sysml/jupyter/kernel/magic/ApiBasePath.java | 14 +++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java index 4208adead..af907b22f 100644 --- a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java +++ b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java @@ -32,19 +32,20 @@ import java.util.Map; import org.omg.sysml.plantuml.SysML2PlantUMLStyle; +import org.omg.sysml.util.traversal.facade.impl.ApiElementProcessingFacade; public class SysMLInteractiveHelp { private static final String GENERAL_HELP_STRING = "The following SysML v2 magic commands are available.\n" + "For help on a specific command, use \"%help \" or \"% -h\".\n\n" - + "%api-base-path\t Sets and prints the current api base path" + + "%repo\t Set the api base path for the repository" + "%eval\t\tEvaluate a given expression.\n" + "%export\t\tSave a file of the JSON representation of the abstract syntax tree rooted in the named element.\n" + "%help\t\tGet a list of available commands or help on a specific command\n" + "%list\t\tList loaded library packages or the results of a given query\n" + "%show\t\tPrint the abstract syntax tree rooted in a named element\n" - + "%publish\tPublish to the repository the modele elements rooted in a named element\n" + + "%publish\tPublish to the repository the model elements rooted in a named element\n" + "%view\t\tRender the view specified by the named view usage\n" + "%viz\t\tVisualize the name model elements\n"; @@ -118,9 +119,12 @@ public class SysMLInteractiveHelp { + " must be fully qualified.\n"; private static final String API_BASE_PATH_HELP_STRING = - "Usage: %api-base-path []\n\n" - + "Sets the current api base path\n" - + "If no argument is passed it prints the current api base path"; + "Usage: %repo []\n\n" + + "If is not given, print the current repository base path.\r\n" + + "If is given, set the repository base path.\r\n" + + "\r\n" + + " is a URL giving the API base path for the repository access by the %projects, %publish and %load commands. \r\n" + + "For example: " + ApiElementProcessingFacade.DEFAULT_BASE_PATH; public static String getGeneralHelp() { return GENERAL_HELP_STRING; @@ -173,7 +177,8 @@ private static Map createCommandHelpMap() { map.put("%publish", PUBLISH_HELP_STRING); map.put("%viz", VIZ_HELP_STRING); map.put("%view", VIEW_HELP_STRING); - map.put("%export", EXPORT_HELP_STRING); + map.put("%export", EXPORT_HELP_STRING); + map.put("%repo", API_BASE_PATH_HELP_STRING); return map; } diff --git a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java index f40b7c54c..f0778a95e 100644 --- a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java @@ -33,23 +33,19 @@ public class ApiBasePath { - private static final MagicsArgs SHOW_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags() + private static final MagicsArgs REPO_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags() .optional("basePath") .flag("help", 'h', "true") .build(); - @LineMagic("api-base-path") + @LineMagic("repo") public static String apiBasePath(List args) { - Map> vals = SHOW_ARGS.parse(args); + Map> vals = REPO_ARGS.parse(args); List basePaths = vals.get("basePath"); + List help = vals.get("help"); String basePath = basePaths.isEmpty()? null: basePaths.get(0); SysMLInteractive interactive = ISysML.getKernelInstance().getInteractive(); - - if (basePath != null) { - interactive.setApiBasePath(basePath); - } - - return "Api base path is: " + ISysML.getKernelInstance().getInteractive().getApiBasePath(); + return interactive.apiBasePath(basePath, help); } } From 8f6cb35c4e028349a4ce097e5239dfde4624a3e3 Mon Sep 17 00:00:00 2001 From: Laszlo Gati Date: Mon, 5 May 2025 17:35:43 +0200 Subject: [PATCH 3/3] ST6RI-836 Changed api base path example in help string --- .../src/org/omg/sysml/interactive/SysMLInteractiveHelp.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java index af907b22f..471396be8 100644 --- a/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java +++ b/org.omg.sysml.interactive/src/org/omg/sysml/interactive/SysMLInteractiveHelp.java @@ -124,7 +124,7 @@ public class SysMLInteractiveHelp { + "If is given, set the repository base path.\r\n" + "\r\n" + " is a URL giving the API base path for the repository access by the %projects, %publish and %load commands. \r\n" - + "For example: " + ApiElementProcessingFacade.DEFAULT_BASE_PATH; + + "For example: https://my.domain.com/sysml_repo"; public static String getGeneralHelp() { return GENERAL_HELP_STRING;