Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Resource> resourcesToPublish = this.getResourcesToPublish(emfEditingContext);
final DependencyGraph<Resource> dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet());

final List<AggregateReference<SemanticData, UUID>> dependencies = this.getDependencies(dependencyGraph, resourcesToPublish);
final List<AggregateReference<SemanticData, UUID>> dependenciesOfPublishedLibrary = this.getDependenciesForPublishedLibrary(emfEditingContext, resourcesToPublish);

final Optional<SemanticData> 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.

Expand All @@ -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<AggregateReference<SemanticData, UUID>> getDependencies(final DependencyGraph<Resource> dependencyGraph, final Set<Resource> resourcesToPublish) {
/**
* Provides the resources to include in the contents of the library being published.
* <p>
* <b>Note:</b> 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.
* </p>
*
* @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<Resource> 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<AggregateReference<SemanticData, UUID>> getDependenciesForPublishedLibrary(final IEMFEditingContext emfEditingContext, final Set<Resource> 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<AggregateReference<SemanticData, UUID>> getDependenciesBasedOnResources(final IEMFEditingContext emfEditingContext, final Set<Resource> resourcesToPublish) {
final DependencyGraph<Resource> dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet());
final List<AggregateReference<SemanticData, UUID>> dependencies = new ArrayList<>();

for (final Resource resourceToPublish : resourcesToPublish) {
Expand Down Expand Up @@ -225,15 +271,6 @@ protected Optional<SemanticData> createSemanticData(final ICause cause, final Co
}
}

protected Set<Resource> 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<LibraryMetadataAdapter> getLibraryMetadata(final Resource resource) {
return resource.eAdapters().stream()
.filter(LibraryMetadataAdapter.class::isInstance)
Expand Down
Loading