Skip to content

Commit 2057d21

Browse files
gdanielAxelRICHARD
authored andcommitted
[1258] Add required libraries as dependencies when publishing a project
Bug: #1258 Signed-off-by: Gwendal Daniel <gwendal.daniel@obeosoft.com>
1 parent 104313b commit 2057d21

10 files changed

Lines changed: 488 additions & 94 deletions

File tree

CHANGELOG.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
=== Bug fixes
1414

15+
- https://github.com/eclipse-syson/syson/issues/1258[#1258] [publication] Add required libraries as dependencies when publishing a project.
16+
Publishing a project that has a dependency to a library now correctly produces a library with the same dependency.
17+
1518
=== Improvements
1619

1720
- https://github.com/eclipse-syson/syson/issues/1192[#1192] [general-view] Add `ConnectionDefinition` in _General View_ diagram
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.publication;
14+
15+
import org.eclipse.emf.ecore.EReference;
16+
import org.eclipse.emf.ecore.resource.Resource;
17+
import org.eclipse.emf.ecore.resource.ResourceSet;
18+
import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
19+
import org.eclipse.sirius.web.application.library.services.LibraryMetadataAdapter;
20+
import org.eclipse.sirius.web.application.studio.services.library.api.DependencyGraph;
21+
import org.eclipse.syson.application.publication.api.ISysONLibraryDependencyCollector;
22+
import org.springframework.stereotype.Service;
23+
24+
/**
25+
* Collects the dependencies between SysON {@link Resource}.
26+
*
27+
* @author gdaniel
28+
*/
29+
@Service
30+
public class SysONLibraryDependencyCollector implements ISysONLibraryDependencyCollector {
31+
32+
@Override
33+
public DependencyGraph<Resource> collectDependencies(ResourceSet resourceSet) {
34+
DependencyGraph<Resource> dependencyGraph = new DependencyGraph<>();
35+
for (Resource resource : resourceSet.getResources()) {
36+
if (this.isLibrary(resource)) {
37+
resource.getAllContents().forEachRemaining(eObject -> {
38+
ECrossReferenceAdapter.getCrossReferenceAdapter(eObject).getInverseReferences(eObject)
39+
.forEach(setting -> {
40+
if (setting.getEStructuralFeature() instanceof EReference reference
41+
&& !reference.isContainment()) {
42+
Resource dependentResource = setting.getEObject().eResource();
43+
if (dependentResource != null && resource != dependentResource) {
44+
// implicit have null resource
45+
dependencyGraph.addEdge(dependentResource, resource);
46+
}
47+
}
48+
});
49+
});
50+
}
51+
}
52+
return dependencyGraph;
53+
}
54+
55+
private boolean isLibrary(Resource resource) {
56+
return resource.eAdapters().stream()
57+
.anyMatch(LibraryMetadataAdapter.class::isInstance);
58+
}
59+
60+
}

backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SySONLibraryPublicationHandler.java renamed to backend/application/syson-application-configuration/src/main/java/org/eclipse/syson/application/publication/SysONLibraryPublicationHandler.java

Lines changed: 55 additions & 92 deletions
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.publication.api;
14+
15+
import org.eclipse.emf.ecore.resource.Resource;
16+
import org.eclipse.emf.ecore.resource.ResourceSet;
17+
import org.eclipse.sirius.web.application.studio.services.library.api.DependencyGraph;
18+
19+
/**
20+
* Collects the dependencies between SysON {@link Resource}.
21+
*
22+
* @author gdaniel
23+
*/
24+
public interface ISysONLibraryDependencyCollector {
25+
26+
DependencyGraph<Resource> collectDependencies(ResourceSet resourceSet);
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.data;
14+
15+
/**
16+
* Identifiers for the "ProjectWithBatmobileLibraryDependency" project.
17+
*
18+
* @author gdaniel
19+
*/
20+
public class ProjectWithUnusedBatmobileLibraryDependencyTestProjectData {
21+
22+
public static final String SCRIPT_PATH = "/scripts/database-content/SysMLv2-ProjectWithUnusedBatmobileLibraryDependency.sql";
23+
24+
public static final String PROJECT_NAME = "SysMLv2-ProjectWithUnusedBatmobileLibraryDependency";
25+
26+
public static final String PROJECT_ID = "7c4245ac-4fac-4592-80eb-f6c67e3fd98a";
27+
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.syson.application.data;
14+
15+
/**
16+
* Identifiers for the "ProjectWithBatmobileLibraryDependency" project.
17+
*
18+
* @author gdaniel
19+
*/
20+
public class ProjectWithUsedBatmobileLibraryDependencyTestProjectData {
21+
22+
public static final String SCRIPT_PATH = "/scripts/database-content/SysMLv2-ProjectWithUsedBatmobileLibraryDependency.sql";
23+
24+
public static final String PROJECT_NAME = "SysMLv2-ProjectWithUsedBatmobileLibraryDependency";
25+
26+
public static final String PROJECT_ID = "d1df5921-0ad7-4864-94b0-609609f92a24";
27+
28+
}

backend/application/syson-application/src/test/java/org/eclipse/syson/application/publication/SySONLibraryPublicationTests.java renamed to backend/application/syson-application/src/test/java/org/eclipse/syson/application/libraries/publication/SySONLibraryPublicationTests.java

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Contributors:
1111
* Obeo - initial API and implementation
1212
*******************************************************************************/
13-
package org.eclipse.syson.application.publication;
13+
package org.eclipse.syson.application.libraries.publication;
1414

1515
import static org.assertj.core.api.Assertions.assertThat;
1616

@@ -39,11 +39,16 @@
3939
import org.eclipse.sirius.web.domain.boundedcontexts.library.services.api.ILibrarySearchService;
4040
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.Document;
4141
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData;
42+
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticDataDependency;
4243
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService;
4344
import org.eclipse.sirius.web.tests.graphql.PublishLibrariesMutationRunner;
4445
import org.eclipse.sirius.web.tests.services.api.IGivenInitialServerState;
4546
import org.eclipse.syson.AbstractIntegrationTests;
47+
import org.eclipse.syson.application.data.ProjectWithUnusedBatmobileLibraryDependencyTestProjectData;
48+
import org.eclipse.syson.application.data.ProjectWithUsedBatmobileLibraryDependencyTestProjectData;
4649
import org.eclipse.syson.application.data.SimpleProjectElementsTestProjectData;
50+
import org.eclipse.syson.application.publication.SysONLibraryPublicationHandler;
51+
import org.eclipse.syson.application.publication.SysONLibraryPublicationListener;
4752
import org.eclipse.syson.sysml.SysmlPackage;
4853
import org.junit.jupiter.api.BeforeEach;
4954
import org.junit.jupiter.api.DisplayName;
@@ -59,12 +64,13 @@
5964
/**
6065
* Integration tests for the publication of the SysML contents of a project as a library.
6166
*
62-
* @see SySONLibraryPublicationHandler
67+
* @see SysONLibraryPublicationHandler
6368
* @see SysONLibraryPublicationListener
6469
* @author flatombe
6570
*/
6671
@Transactional
6772
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
73+
@SuppressWarnings("checkstyle:MultipleStringLiterals")
6874
public class SySONLibraryPublicationTests extends AbstractIntegrationTests {
6975

7076
private static final String IMPORTED_PROJECT = "afffb8f5-3db6-4b47-b295-55a36984db2e";
@@ -247,4 +253,69 @@ public void givenProjectWithImportedResourceWhenLibraryIsPublishedThenLibraryDoe
247253
.allSatisfy(document -> assertThat(document.getContent()).doesNotContain("\"source\":\"org.eclipse.syson.sysml.imported\""));
248254
}
249255

256+
@Test
257+
@DisplayName("Given a project with an used dependency to a library, when the library is published, then the library has the same dependency")
258+
@Sql(scripts = { ProjectWithUsedBatmobileLibraryDependencyTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
259+
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
260+
public void givenProjectWithUsedDependencyToLibraryWhenLibraryIsPublishedThenItHasTheSameDependency() {
261+
var input = new PublishLibrariesInput(UUID.randomUUID(), ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, PUBLICATION_KIND, "1.0.0", "");
262+
var result = this.publishLibrariesMutationRunner.run(input);
263+
String typename = JsonPath.read(result, "$.data.publishLibraries.__typename");
264+
assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName());
265+
TestTransaction.flagForCommit();
266+
TestTransaction.end();
267+
TestTransaction.start();
268+
269+
Optional<SemanticData> projectLibrarySemanticData = this.librarySearchService.findByNamespaceAndNameAndVersion(ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, ProjectWithUsedBatmobileLibraryDependencyTestProjectData.PROJECT_NAME, "1.0.0")
270+
.map(Library::getSemanticData)
271+
.map(AggregateReference::getId)
272+
.flatMap(this.semanticDataSearchService::findById);
273+
274+
assertThat(projectLibrarySemanticData).isPresent();
275+
assertThat(projectLibrarySemanticData.get().getDependencies()).hasSize(1);
276+
SemanticDataDependency dependency = projectLibrarySemanticData.get().getDependencies().get(0);
277+
278+
// Check that the dependency is in the published library.
279+
Optional<Library> dependencyLibrary = this.librarySearchService.findBySemanticData(dependency.dependencySemanticDataId());
280+
assertThat(dependencyLibrary).isPresent();
281+
assertThat(dependencyLibrary.get().getName()).isEqualTo("Batmobile");
282+
283+
// Check that the library contains a single document (its proper content).
284+
Set<Document> documents = projectLibrarySemanticData.get().getDocuments();
285+
assertThat(documents)
286+
.hasSize(1)
287+
.allSatisfy(document -> assertThat(document.getName()).isEqualTo("SysMLv2.sysml"));
288+
}
289+
290+
@Test
291+
@DisplayName("Given a project with an unused dependency to a library, when the library is published, then the library has no dependency")
292+
@Sql(scripts = { ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.SCRIPT_PATH }, executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
293+
@Sql(scripts = { "/scripts/cleanup.sql" }, executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD, config = @SqlConfig(transactionMode = SqlConfig.TransactionMode.ISOLATED))
294+
public void givenProjectWithUnusedDependencyToLibraryWhenLibraryIsPublishedThenItHasNoDependency() {
295+
var input = new PublishLibrariesInput(UUID.randomUUID(), ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, PUBLICATION_KIND, "1.0.0", "");
296+
var result = this.publishLibrariesMutationRunner.run(input);
297+
String typename = JsonPath.read(result, "$.data.publishLibraries.__typename");
298+
assertThat(typename).isEqualTo(SuccessPayload.class.getSimpleName());
299+
TestTransaction.flagForCommit();
300+
TestTransaction.end();
301+
TestTransaction.start();
302+
303+
Optional<SemanticData> projectLibrarySemanticData = this.librarySearchService
304+
.findByNamespaceAndNameAndVersion(ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_ID, ProjectWithUnusedBatmobileLibraryDependencyTestProjectData.PROJECT_NAME,
305+
"1.0.0")
306+
.map(Library::getSemanticData)
307+
.map(AggregateReference::getId)
308+
.flatMap(this.semanticDataSearchService::findById);
309+
310+
assertThat(projectLibrarySemanticData).isPresent();
311+
// Check that there is no dependency in the published library.
312+
assertThat(projectLibrarySemanticData.get().getDependencies()).isEmpty();
313+
314+
// Check that the library contains a single document (its proper content).
315+
Set<Document> documents = projectLibrarySemanticData.get().getDocuments();
316+
assertThat(documents)
317+
.hasSize(1)
318+
.allSatisfy(document -> assertThat(document.getName()).isEqualTo("SysMLv2.sysml"));
319+
320+
}
250321
}

backend/application/syson-application/src/test/resources/scripts/database-content/SysMLv2-ProjectWithUnusedBatmobileLibraryDependency.sql

Lines changed: 105 additions & 0 deletions
Large diffs are not rendered by default.

backend/application/syson-application/src/test/resources/scripts/database-content/SysMLv2-ProjectWithUsedBatmobileLibraryDependency.sql

Lines changed: 105 additions & 0 deletions
Large diffs are not rendered by default.

doc/content/modules/user-manual/pages/release-notes/2025.6.0.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Future contributions are planned to introduce enhanced capabilities for editing
1919

2020
== Bug fixes
2121

22+
- Fix an issue that made published libraries' dependencies always empty.
23+
Publishing a project with a dependency to a library now correctly produces a library with the same dependency.
24+
2225

2326
== New features
2427

0 commit comments

Comments
 (0)