Skip to content

Commit b68d8bf

Browse files
flatombeAxelRICHARD
authored andcommitted
[2027] Make library publication dependencies computation more extensible
Bug: #2027 Signed-off-by: Florent Latombe <florent.latombe@obeo.fr>
1 parent 918d393 commit b68d8bf

2 files changed

Lines changed: 69 additions & 13 deletions

File tree

CHANGELOG.adoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ The following methods have been added:
2222

2323
- https://github.com/eclipse-syson/syson/issues/1988[#1988] [syson] Extract Elasticsearch container initialization in a dedicated abstract test class.
2424
The property `SysONTestsProperties#ELASTICSEARCH` has been removed, tests that require Elasticsearch should extend `AbstractIntegrationTestsWithElasticsearch`.
25+
- https://github.com/eclipse-syson/syson/issues/2027[#2027] [publication] `org.eclipse.syson.application.publication.SysONSysMLLibraryPublisher` has been reworked to be more extensible.
26+
As a result, the following method has been deleted:
27+
28+
** `getDependencies(DependencyGraph<Resource>, Set<Resource>)`
29+
+
30+
And the following methods have been added:
31+
+
32+
** `getDependenciesForPublishedLibrary(IEMFEditingContext, Set<Resource>)`
33+
** `getDependenciesBasedOnResources(IEMFEditingContext, Set<Resource>)`
2534

2635
- [validation] The following classes have been renamed, and some of them reworked:
2736

@@ -32,6 +41,16 @@ The property `SysONTestsProperties#ELASTICSEARCH` has been removed, tests that r
3241
** `org.eclipse.syson.sysml.validation.SysONQueryServices`: renamed into `org.eclipse.syson.sysml.validation.rules.SysMLValidationRuleQueryServices`.
3342
** `org.eclipse.syson.sysml.validation.SysMLv2ValidatorConfiguration`: renamed into `org.eclipse.syson.sysml.validation.SysMLValidatorRegistrationConfiguration` and now expects an injected `org.eclipse.syson.sysml.validation.rules.api.ISysMLValidationRulesProvider`, for which SysON provides default implementation `org.eclipse.syson.sysml.validation.rules.SysONValidationRulesProvider`.
3443

44+
- https://github.com/eclipse-syson/syson/issues/2027[#2027] [publication] `org.eclipse.syson.application.publication.SysONSysMLLibraryPublisher` has been reworked to be more extensible.
45+
As a result, the following method has been deleted:
46+
47+
** `getDependencies(DependencyGraph<Resource>, Set<Resource>)`
48+
+
49+
And the following methods have been added:
50+
+
51+
** `getDependenciesForPublishedLibrary(IEMFEditingContext, Set<Resource>)`
52+
** `getDependenciesBasedOnResources(IEMFEditingContext, Set<Resource>)`
53+
3554

3655
=== Dependency update
3756

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONSysMLLibraryPublisher.java

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ public IPayload publish(final ICause cause, final IEditingContext libraryAuthori
145145
protected IPayload doPublish(final ICause cause, final IEMFEditingContext emfEditingContext, final String libraryNamespace, final String libraryName,
146146
final String libraryVersion, final String libraryDescription) {
147147
final Set<Resource> resourcesToPublish = this.getResourcesToPublish(emfEditingContext);
148-
final DependencyGraph<Resource> dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet());
149148

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

152151
final Optional<SemanticData> maybePublishedLibrarySemanticData = this.publishAsLibrary(cause, resourcesToPublish, libraryNamespace, libraryName, libraryVersion, libraryDescription,
153-
dependencies);
152+
dependenciesOfPublishedLibrary);
154153
// After this transaction is done, SysONLibraryPublicationListener reacts by also creating the
155154
// associated Library metadata.
156155

@@ -162,7 +161,54 @@ protected IPayload doPublish(final ICause cause, final IEMFEditingContext emfEdi
162161
List.of(new Message("Failed to publish library '%s:%s@%s'.".formatted(libraryNamespace, libraryName, libraryVersion), MessageLevel.ERROR))));
163162
}
164163

165-
protected List<AggregateReference<SemanticData, UUID>> getDependencies(final DependencyGraph<Resource> dependencyGraph, final Set<Resource> resourcesToPublish) {
164+
/**
165+
* Provides the resources to include in the contents of the library being published.
166+
* <p>
167+
* <b>Note:</b> If this implementation gets extended to include additional resources, consider also extending
168+
* {@link #getDependenciesForPublishedLibrary(IEMFEditingContext, Set)} to express the impact on the dependencies to
169+
* include.
170+
* </p>
171+
*
172+
* @param emfEditingContext
173+
* the (non-{@code null}) {@link IEMFEditingContext} that authors the library.
174+
* @return a (non-{@code null}) {@link Set} of {@link Resource}, most likely a subset of the resources in
175+
* {@code emfEditingContext}.
176+
*/
177+
protected Set<Resource> getResourcesToPublish(final IEMFEditingContext emfEditingContext) {
178+
return emfEditingContext.getDomain().getResourceSet().getResources().stream()
179+
.filter(Predicate.not(ElementUtil::isStandardLibraryResource))
180+
.filter(resource -> !this.sysONResourceService.isFromReferencedLibrary(emfEditingContext, resource))
181+
// Only the ".sysml" resources can be published.
182+
.filter(this.sysONResourceService::isSysML)
183+
.collect(Collectors.toCollection(LinkedHashSet::new));
184+
}
185+
186+
/**
187+
* Provides the dependencies to set up for the library being published.
188+
*
189+
* @param emfEditingContext
190+
* the (non-{@code null}) {@link IEMFEditingContext} that authors the library.
191+
* @param resourcesToPublish
192+
* the (non-{@code null}) {@link Set} of {@link Resource} to include as contents of the library.
193+
* @return a (non-{@code null}) {@link List} of the desired dependencies for the library.
194+
*/
195+
protected List<AggregateReference<SemanticData, UUID>> getDependenciesForPublishedLibrary(final IEMFEditingContext emfEditingContext, final Set<Resource> resourcesToPublish) {
196+
return this.getDependenciesBasedOnResources(emfEditingContext, resourcesToPublish);
197+
}
198+
199+
/**
200+
* Provides the dependencies based on the existing actual EMF cross-references from the resources being published to
201+
* resources coming from published libraries.
202+
*
203+
* @param emfEditingContext
204+
* the (non-{@code null}) {@link IEMFEditingContext} that authors the library.
205+
* @param resourcesToPublish
206+
* the (non-{@code null}) {@link Set} of {@link Resource} to include as contents of the library.
207+
* @return a (non-{@code null}) {@link List} of the dependencies required for the library, if we want
208+
* {@code resourcesToPublish} to not have any unresolved proxies.
209+
*/
210+
protected List<AggregateReference<SemanticData, UUID>> getDependenciesBasedOnResources(final IEMFEditingContext emfEditingContext, final Set<Resource> resourcesToPublish) {
211+
final DependencyGraph<Resource> dependencyGraph = this.sysONLibraryDependencyCollector.collectDependencies(emfEditingContext.getDomain().getResourceSet());
166212
final List<AggregateReference<SemanticData, UUID>> dependencies = new ArrayList<>();
167213

168214
for (final Resource resourceToPublish : resourcesToPublish) {
@@ -225,15 +271,6 @@ protected Optional<SemanticData> createSemanticData(final ICause cause, final Co
225271
}
226272
}
227273

228-
protected Set<Resource> getResourcesToPublish(final IEMFEditingContext emfEditingContext) {
229-
return emfEditingContext.getDomain().getResourceSet().getResources().stream()
230-
.filter(Predicate.not(ElementUtil::isStandardLibraryResource))
231-
.filter(resource -> !this.sysONResourceService.isFromReferencedLibrary(emfEditingContext, resource))
232-
// Only the ".sysml" resources can be published.
233-
.filter(this.sysONResourceService::isSysML)
234-
.collect(Collectors.toCollection(LinkedHashSet::new));
235-
}
236-
237274
protected Optional<LibraryMetadataAdapter> getLibraryMetadata(final Resource resource) {
238275
return resource.eAdapters().stream()
239276
.filter(LibraryMetadataAdapter.class::isInstance)

0 commit comments

Comments
 (0)