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..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 @@ -32,18 +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" + + "%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"; @@ -115,6 +117,14 @@ 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: %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: https://my.domain.com/sysml_repo"; public static String getGeneralHelp() { return GENERAL_HELP_STRING; @@ -152,6 +162,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() { @@ -163,12 +177,12 @@ 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; } 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..f0778a95e --- /dev/null +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/ApiBasePath.java @@ -0,0 +1,51 @@ +/** + * 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 REPO_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags() + .optional("basePath") + .flag("help", 'h', "true") + .build(); + + @LineMagic("repo") + public static String apiBasePath(List 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(); + return interactive.apiBasePath(basePath, help); + } +}