5959import org .omg .kerml .xtext .KerMLStandaloneSetup ;
6060import org .omg .kerml .xtext .library .ILibraryIndexProvider ;
6161import org .omg .kerml .xtext .naming .KerMLQualifiedNameConverter ;
62- import org .omg .sysml .ApiException ;
6362import org .omg .sysml .execution .expressions .ExpressionEvaluator ;
6463import org .omg .sysml .lang .sysml .Element ;
6564import org .omg .sysml .lang .sysml .Expression ;
@@ -365,7 +364,7 @@ public Object show(String name, List<String> styles, List<String> help) {
365364 else if (matchStyle (styles , "JSON" )) {
366365 JsonElementProcessingFacade processingFacade = this .getJsonElementProcessingFacade ();
367366 processingFacade .getTraversal ().visit (element );
368- return processingFacade .toJsonTree ();
367+ return processingFacade .toJsonTree (true );
369368 }
370369 else if (styles .isEmpty () || matchStyle (styles , "TREE" )){
371370 return SysMLInteractiveUtil .formatTree (element );
@@ -389,7 +388,7 @@ public Object export(String name, List<String> help) {
389388 }
390389 JsonElementProcessingFacade processingFacade = this .getJsonElementProcessingFacade ();
391390 processingFacade .getTraversal ().visit (element );
392- return processingFacade .toJsonTree ();
391+ return processingFacade .toJsonTree (true );
393392 } catch (Exception e ) {
394393 return SysMLInteractiveUtil .formatException (e );
395394 }
@@ -409,7 +408,7 @@ public String show(String name) {
409408 show (name , Collections .emptyList (), Collections .emptyList ()));
410409 }
411410
412- public String publish (String elementName , String projectName , List <String > help ) {
411+ public String publish (String elementName , String projectName , String branchName , List <String > help ) {
413412 this .counter ++;
414413 if (Strings .isNullOrEmpty (elementName )) {
415414 return help .isEmpty ()? "" : SysMLInteractiveHelp .getPublishHelp ();
@@ -423,7 +422,7 @@ public String publish(String elementName, String projectName, List<String> help)
423422 } else {
424423 String remoteProjectName = projectName == null ? element .getDeclaredName () + " " + new Date () : projectName ;
425424
426- ApiElementProcessingFacade processingFacade = this .getApiElementProcessingFacade (remoteProjectName );
425+ ApiElementProcessingFacade processingFacade = this .getApiElementProcessingFacade (remoteProjectName , branchName );
427426 processingFacade .getTraversal ().visit (element );
428427 processingFacade .commit (element );
429428 System .out .println ();
@@ -436,11 +435,11 @@ public String publish(String elementName, String projectName, List<String> help)
436435
437436 protected String publish (String name ) {
438437 return "-h" .equals (name )?
439- publish (null , null , Collections .singletonList ("true" )):
440- publish (name , null , Collections .emptyList ());
438+ publish (null , null , null , Collections .singletonList ("true" )):
439+ publish (name , null , null , Collections .emptyList ());
441440 }
442441
443- public String loadByName (String projectName , List <String > help ) {
442+ public String loadByName (String projectName , String branchName , List <String > help ) {
444443 if (Strings .isNullOrEmpty (projectName )) {
445444 return help .isEmpty ()? "" : SysMLInteractiveHelp .getLoadHelp ();
446445 }
@@ -454,75 +453,94 @@ public String loadByName(String projectName, List<String> help) {
454453 return "ERROR:Project doesn't exist." ;
455454 }
456455
457- return load (repositoryProject );
456+ return load (repositoryProject , branchName );
458457 }
459458
460- public String loadById (String projectId , List <String > help ) {
459+ public String loadById (String projectId , String branchId , List <String > help ) {
461460 if (Strings .isNullOrEmpty (projectId )) {
462461 return help .isEmpty ()? "" : SysMLInteractiveHelp .getLoadHelp ();
463462 }
464463
465464 ProjectRepository repository = new ProjectRepository (apiBasePath );
466465
467466 System .out .println ("Locating model" );
468- RemoteProject repositoryProject = repository .getPRojectById (UUID .fromString (projectId ));
467+ RemoteProject remoteProject = repository .getPRojectById (UUID .fromString (projectId ));
469468
470- if (repositoryProject == null ) {
469+ if (remoteProject == null ) {
471470 return "ERROR:Project doesn't exist." ;
472471 }
473472
474- return load (repositoryProject );
473+ if (branchId == null ) {
474+ return load (remoteProject , (UUID ) null );
475+ } else {
476+ UUID branchUUID = UUID .fromString (branchId );
477+ return load (remoteProject , branchUUID );
478+ }
479+ }
480+
481+ private String load (RemoteProject remoteProject , String branchName ) {
482+ final RemoteBranch branch ;
483+ if (branchName == null ) {
484+ branch = remoteProject .getDefaultBranch ();
485+ } else {
486+ branch = remoteProject .getBranch (branchName );
487+ }
488+ return load (branch );
489+ }
490+
491+ private String load (RemoteProject remoteProject , UUID branchId ) {
492+ final RemoteBranch branch ;
493+ if (branchId == null ) {
494+ branch = remoteProject .getDefaultBranch ();
495+ } else {
496+ branch = remoteProject .getBranch (branchId );
497+ }
498+ return load (branch );
475499 }
476500
477- private String load (RemoteProject repositoryProject ) {
478- try {
479- RemoteBranch defaultBranch = repositoryProject .getDefaultBranch ();
480- Revision headRevision = defaultBranch .getHeadRevision ();
481- APIModel model = headRevision .fetchRemote ();
482-
483- System .out .println ("Collecting UUIDs..." );
484- if (!tracker .isLibraryTracked ()) {
485- tracker .trackLibraryUUIDs (getLibraryResources ());
486- }
487-
488- tracker .clear ();
489- List <Resource > inputResources = getInputResources ();
490- //UUIDS coming from resources that were added later in time will shadow previous ones
491- tracker .trackLocalUUIDs (inputResources );
492-
493- EMFModelRefresher fetcher = new EMFModelRefresher (model , tracker );
494-
495- System .out .println ("Downloading model..." );
496- EMFModelDelta delta = fetcher .create ();
497-
498- System .out .println ("Adding model to index" );
499- delta .getProjectRoots ().forEach ((eObject , dto ) -> {
500- next (SYSMLX_EXTENSION );
501- Resource xmiResource = getResource ();
502- if (eObject instanceof Namespace ) {
503- xmiResource .getContents ().add (eObject );
504- } else {
505- Namespace root = SysMLFactory .eINSTANCE .createNamespace ();
506- NamespaceUtil .addOwnedMemberTo (root , (Element ) eObject );
507- xmiResource .getContents ().add (root );
508- }
509- addResourceToIndex (xmiResource );
510- });
511-
512- return "Project loaded: " + repositoryProject .getProjectName () + ", " + repositoryProject .getRemoteId ().toString ();
513- } catch (NoSuchElementException e ) {
514- e .printStackTrace ();
515- return "Requested model doesn't exist." ;
516- } catch (ApiException e ) {
517- e .printStackTrace ();
518- return "Error occured while trying to load model" ;
501+ private String load (RemoteBranch branch ) {
502+ RemoteProject remoteProject = branch .getRemoteProject ();
503+ Revision headRevision = branch .getHeadRevision ();
504+ APIModel model = headRevision .fetchRemote ();
505+
506+ System .out .println ("Selected branch " + branch .getName ());
507+
508+ System .out .println ("Collecting UUIDs..." );
509+ if (!tracker .isLibraryTracked ()) {
510+ tracker .trackLibraryUUIDs (getLibraryResources ());
519511 }
512+
513+ tracker .clear ();
514+ List <Resource > inputResources = getInputResources ();
515+ //UUIDS coming from resources that were added later in time will shadow previous ones
516+ tracker .trackLocalUUIDs (inputResources );
517+
518+ EMFModelRefresher fetcher = new EMFModelRefresher (model , tracker );
519+
520+ System .out .println ("Downloading model..." );
521+ EMFModelDelta delta = fetcher .create ();
522+
523+ System .out .println ("Adding model to index" );
524+ delta .getProjectRoots ().forEach ((eObject , dto ) -> {
525+ next (SYSMLX_EXTENSION );
526+ Resource xmiResource = getResource ();
527+ if (eObject instanceof Namespace ) {
528+ xmiResource .getContents ().add (eObject );
529+ } else {
530+ Namespace root = SysMLFactory .eINSTANCE .createNamespace ();
531+ NamespaceUtil .addOwnedMemberTo (root , (Element ) eObject );
532+ xmiResource .getContents ().add (root );
533+ }
534+ addResourceToIndex (xmiResource );
535+ });
536+
537+ return "Project loaded: " + remoteProject .getProjectName () + ", " + remoteProject .getRemoteId ().toString ();
520538 }
521539
522540 protected String download (String name ) {
523541 return "-h" .equals (name )?
524- loadByName (null , Collections .singletonList ("true" )):
525- loadByName (name , Collections .emptyList ());
542+ loadByName (null , null , Collections .singletonList ("true" )):
543+ loadByName (name , null , Collections .emptyList ());
526544 }
527545
528546 public String listPublications (List <String > help ) {
@@ -535,9 +553,9 @@ public String listPublications(List<String> help) {
535553 .collect (Collectors .joining ("\n " ));
536554 }
537555
538- protected ApiElementProcessingFacade getApiElementProcessingFacade (String modelName ) {
556+ protected ApiElementProcessingFacade getApiElementProcessingFacade (String modelName , String branchName ) {
539557 System .out .println ("API base path: " + this .apiBasePath );
540- ApiElementProcessingFacade processingFacade = new ApiElementProcessingFacade (modelName , this .apiBasePath );
558+ ApiElementProcessingFacade processingFacade = new ApiElementProcessingFacade (modelName , branchName , this .apiBasePath );
541559 processingFacade .setIsIncludeDerived (true );
542560 processingFacade .setTraversal (new Traversal (processingFacade ));
543561 return processingFacade ;
0 commit comments