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 04b54608e..dc7095169 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 @@ -160,6 +160,10 @@ public void setApiBasePath(String apiBasePath) { this.apiBasePath = apiBasePath; } + public String getApiBasePath() { + return apiBasePath; + } + public int next(String extension) { this.resource = this.createResource(counter + extension); this.addInputResource(this.resource); @@ -275,6 +279,25 @@ public String help(String command) { help(command, Collections.emptyList()); } + public String repo(String apiBasePath, List help) { + this.counter++; + if (!help.isEmpty()) { + return SysMLInteractiveHelp.getApiBasePathHelp(); + } + + if (!Strings.isNullOrEmpty(apiBasePath)) { + setApiBasePath(apiBasePath); + } + + return getApiBasePath() + "\n"; + } + + public String repo(String command) { + return "-h".equals(command)? + repo(null, Collections.singletonList("true")): + repo(command, Collections.emptyList()); + } + public String eval(String input, String targetName, List help) { if (Strings.isNullOrEmpty(input)) { this.counter++; @@ -466,7 +489,7 @@ protected String publish(String name) { * @return output of the command */ public String load(Map parameters) { - counter++; + this.counter++; if (parameters.containsKey(HELP_KEY)) { return SysMLInteractiveHelp.getLoadHelp(); @@ -480,6 +503,9 @@ public String load(Map parameters) { return "ERROR:Branch name and id cannot be provided at the same time\n"; } + System.out.println("API base path: " + apiBasePath); + System.out.println(); + final ProjectRepository repository = new ProjectRepository(apiBasePath); final RemoteProject project; @@ -518,10 +544,13 @@ private String load(RemoteBranch branch) { return "ERROR:Branch doesn't exist\n"; } - System.out.println("API base path: " + apiBasePath); - System.out.println(); System.out.println("Selected branch " + branch.getName() + " (" + branch.getRemoteId().toString() + ")"); + Revision headRevision = branch.getHeadRevision(); + if (!headRevision.isRemote()) { + return "ERROR:Branch has no head commit\n"; + } + if (!tracker.isLibraryTracked()) { System.out.println("Caching library UUIDs..."); tracker.trackLibraryUUIDs(getLibraryResources()); @@ -533,9 +562,6 @@ private String load(RemoteBranch branch) { tracker.trackLocalUUIDs(inputResources); System.out.println("Downloading model..."); - - RemoteProject remoteProject = branch.getRemoteProject(); - Revision headRevision = branch.getHeadRevision(); APIModel model = headRevision.fetchRemote(); EMFModelRefresher modelRefresher = new EMFModelRefresher(model, tracker); @@ -549,6 +575,7 @@ private String load(RemoteBranch branch) { addResourceToIndex(resource); }); + RemoteProject remoteProject = branch.getRemoteProject(); return "Loaded Project " + remoteProject.getProjectName() + " (" + remoteProject.getRemoteId().toString() + ")\n"; } @@ -764,6 +791,8 @@ public void run() { } } else if ("%projects".equals(command)) { System.out.print(this.projects(argument)); + } else if ("%repo".equals(command)) { + System.out.print(this.repo(argument)); } else if ("%publish".equals(command)) { if (!"".equals(argument)) { System.out.print(this.publish(argument)); 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 764548078..54f7e77ca 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 @@ -43,6 +43,7 @@ public class SysMLInteractiveHelp { + "%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" + "%load\t\tLoad a model from the repository\n" + + "%repo\t Set the api base path for the repository\n" + "%show\t\tPrint the abstract syntax tree rooted in a named element\n" + "%projects\tList projects in the repository\n" + "%publish\tPublish to the repository the modele elements rooted in a named element\n" @@ -139,6 +140,14 @@ public class SysMLInteractiveHelp { "Usage: %projects\n\n" + "Print the name and identifier of all projects in the repository.\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; } @@ -183,6 +192,10 @@ public static String getLoadHelp() { return LOAD_HELP_STRING; } + public static String getApiBasePathHelp() { + return API_BASE_PATH_HELP_STRING; + } + private static Map commandHelpMap = createCommandHelpMap(); private static Map createCommandHelpMap() { @@ -197,6 +210,7 @@ private static Map createCommandHelpMap() { map.put("%export", EXPORT_HELP_STRING); map.put("%load", LOAD_HELP_STRING); map.put("%projects", PROJECTS_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/SysMLKernel.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/SysMLKernel.java index 72f713d94..0b371b3cf 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 @@ -82,6 +82,7 @@ public SysMLKernel() { this.magics.registerMagics(Export.class); this.magics.registerMagics(Projects.class); this.magics.registerMagics(Load.class); + this.magics.registerMagics(Repo.class); this.magicParser = new MyMagicParser(); } diff --git a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Repo.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Repo.java new file mode 100644 index 000000000..6770d030e --- /dev/null +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/Repo.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 Repo { + + private static final MagicsArgs REPO_ARGS = MagicsArgs.builder().onlyKnownKeywords().onlyKnownFlags() + .optional("basePath") + .flag("help", 'h', "true") + .build(); + + @LineMagic("repo") + public static String repo(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.repo(basePath, help); + } +} diff --git a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/View.java b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/View.java index 8ec99c036..a892fb4dc 100644 --- a/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/View.java +++ b/org.omg.sysml.jupyter.kernel/src/main/java/org/omg/sysml/jupyter/kernel/magic/View.java @@ -63,6 +63,8 @@ public static DisplayData view(List args) { break; case TEXT: dd.putText(vr.getText()); + default: + break; } return dd; } diff --git a/org.omg.sysml/src/org/omg/sysml/util/repository/ProjectRepository.java b/org.omg.sysml/src/org/omg/sysml/util/repository/ProjectRepository.java index 62ba823ce..c64c23943 100644 --- a/org.omg.sysml/src/org/omg/sysml/util/repository/ProjectRepository.java +++ b/org.omg.sysml/src/org/omg/sysml/util/repository/ProjectRepository.java @@ -185,7 +185,11 @@ public RemoteProject getPRojectById(UUID projectId) { Project projectById = getProjectApi().getProjectById(projectId); return projectById == null? null: new RemoteProject(this, projectId, projectById.getName()); } catch (ApiException e) { - throw new RemoteException("Error occured while trying to query the project", e); + if (e.getCode() == 404) { + return null; + } else { + throw new RemoteException("Error occured while trying to query the project", e); + } } }