diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 572a369bb..ba1443ff2 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -84,6 +84,7 @@ Instead SysON will now use the inherited elements without redefining them first, - https://github.com/eclipse-syson/syson/issues/1994[1994] [syson] Add support for excluding libraries in the _Search_ view. The _Search in libraries_ toggle in the _Search_ view allows to include elements from user and standard libraries in the search. This toggle is de-activated by default. +- https://github.com/eclipse-syson/syson/issues/2027[#2027] [publication] Make `SysONSysMLLibraryPublisher` a bit more easily extensible when it comes to the way it computes the desired dependencies for the published library. === New features diff --git a/backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java b/backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java index bd5b0a317..cb8c2a995 100644 --- a/backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java +++ b/backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java @@ -145,12 +145,11 @@ public IPayload publish(final ICause cause, final IEditingContext libraryAuthori protected IPayload doPublish(final ICause cause, final IEMFEditingContext emfEditingContext, final String libraryNamespace, final String libraryName, final String libraryVersion, final String libraryDescription) { final Set resourcesToPublish = this.getResourcesToPublish(emfEditingContext); - final DependencyGraph dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet()); - final List> dependencies = this.getDependencies(dependencyGraph, resourcesToPublish); + final List> dependenciesOfPublishedLibrary = this.getDependenciesForPublishedLibrary(emfEditingContext, resourcesToPublish); final Optional maybePublishedLibrarySemanticData = this.publishAsLibrary(cause, resourcesToPublish, libraryNamespace, libraryName, libraryVersion, libraryDescription, - dependencies); + dependenciesOfPublishedLibrary); // After this transaction is done, SysONLibraryPublicationListener reacts by also creating the // associated Library metadata. @@ -162,7 +161,54 @@ protected IPayload doPublish(final ICause cause, final IEMFEditingContext emfEdi List.of(new Message("Failed to publish library '%s:%s@%s'.".formatted(libraryNamespace, libraryName, libraryVersion), MessageLevel.ERROR)))); } - protected List> getDependencies(final DependencyGraph dependencyGraph, final Set resourcesToPublish) { + /** + * Provides the resources to include in the contents of the library being published. + *

+ * Note: If this implementation gets extended to include additional resources, consider also extending + * {@link #getDependenciesForPublishedLibrary(IEMFEditingContext, Set)} to express the impact on the dependencies to + * include. + *

+ * + * @param emfEditingContext + * the (non-{@code null}) {@link IEMFEditingContext} that authors the library. + * @return a (non-{@code null}) {@link Set} of {@link Resource}, most likely a subset of the resources in + * {@code emfEditingContext}. + */ + protected Set getResourcesToPublish(final IEMFEditingContext emfEditingContext) { + return emfEditingContext.getDomain().getResourceSet().getResources().stream() + .filter(Predicate.not(ElementUtil::isStandardLibraryResource)) + .filter(resource -> !this.sysONResourceService.isFromReferencedLibrary(emfEditingContext, resource)) + // Only the ".sysml" resources can be published. + .filter(this.sysONResourceService::isSysML) + .collect(Collectors.toCollection(LinkedHashSet::new)); + } + + /** + * Provides the dependencies to set up for the library being published. + * + * @param emfEditingContext + * the (non-{@code null}) {@link IEMFEditingContext} that authors the library. + * @param resourcesToPublish + * the (non-{@code null}) {@link Set} of {@link Resource} to include as contents of the library. + * @return a (non-{@code null}) {@link List} of the desired dependencies for the library. + */ + protected List> getDependenciesForPublishedLibrary(final IEMFEditingContext emfEditingContext, final Set resourcesToPublish) { + return this.getDependenciesBasedOnResources(emfEditingContext, resourcesToPublish); + } + + /** + * Provides the dependencies based on the existing actual EMF cross-references from the resources being published to + * resources coming from published libraries. + * + * @param emfEditingContext + * the (non-{@code null}) {@link IEMFEditingContext} that authors the library. + * @param resourcesToPublish + * the (non-{@code null}) {@link Set} of {@link Resource} to include as contents of the library. + * @return a (non-{@code null}) {@link List} of the dependencies required for the library, if we want + * {@code resourcesToPublish} to not have any unresolved proxies. + */ + protected List> getDependenciesBasedOnResources(final IEMFEditingContext emfEditingContext, final Set resourcesToPublish) { + final DependencyGraph dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet()); final List> dependencies = new ArrayList<>(); for (final Resource resourceToPublish : resourcesToPublish) { @@ -225,15 +271,6 @@ protected Optional createSemanticData(final ICause cause, final Co } } - protected Set getResourcesToPublish(final IEMFEditingContext emfEditingContext) { - return emfEditingContext.getDomain().getResourceSet().getResources().stream() - .filter(Predicate.not(ElementUtil::isStandardLibraryResource)) - .filter(resource -> !this.sysONResourceService.isFromReferencedLibrary(emfEditingContext, resource)) - // Only the ".sysml" resources can be published. - .filter(this.sysONResourceService::isSysML) - .collect(Collectors.toCollection(LinkedHashSet::new)); - } - protected Optional getLibraryMetadata(final Resource resource) { return resource.eAdapters().stream() .filter(LibraryMetadataAdapter.class::isInstance)