forked from eclipse-sirius/sirius-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[4652] Add support for project to library dependencies
Bug: eclipse-sirius#4652 Signed-off-by: Gwendal Daniel <[email protected]>
- Loading branch information
Showing
22 changed files
with
657 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...java/org/eclipse/sirius/web/application/library/services/EditingContextLibraryLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.library.services; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
import org.eclipse.sirius.web.application.UUIDParser; | ||
import org.eclipse.sirius.web.application.editingcontext.EditingContext; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IEditingContextMigrationParticipantPredicate; | ||
import org.eclipse.sirius.web.application.editingcontext.services.api.IResourceLoader; | ||
import org.eclipse.sirius.web.application.library.services.api.IEditingContextLibraryLoader; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.library.Library; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.library.services.api.ILibrarySearchService; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticData; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.SemanticDataDependency; | ||
import org.eclipse.sirius.web.domain.boundedcontexts.semanticdata.services.api.ISemanticDataSearchService; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Loads libraries into the editing context. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class EditingContextLibraryLoader implements IEditingContextLibraryLoader { | ||
|
||
private final ISemanticDataSearchService semanticDataSearchService; | ||
|
||
private final ILibrarySearchService librarySearchService; | ||
|
||
private final IResourceLoader resourceLoader; | ||
|
||
private final List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates; | ||
|
||
public EditingContextLibraryLoader(ISemanticDataSearchService semanticDataSearchService, ILibrarySearchService librarySearchService, IResourceLoader resourceLoader, List<IEditingContextMigrationParticipantPredicate> migrationParticipantPredicates) { | ||
this.semanticDataSearchService = Objects.requireNonNull(semanticDataSearchService); | ||
this.librarySearchService = Objects.requireNonNull(librarySearchService); | ||
this.resourceLoader = Objects.requireNonNull(resourceLoader); | ||
this.migrationParticipantPredicates = Objects.requireNonNull(migrationParticipantPredicates); | ||
} | ||
|
||
@Override | ||
public void loadLibraries(IEditingContext editingContext) { | ||
if (editingContext instanceof EditingContext siriusWebEditingContext) { | ||
Set<Library> librariesToLoad = this.getLibrariesToLoad(siriusWebEditingContext); | ||
for (Library library : librariesToLoad) { | ||
Optional<SemanticData> librarySemanticData = this.semanticDataSearchService.findById(library.getSemanticData().getId()); | ||
if (librarySemanticData.isPresent()) { | ||
librarySemanticData.get().getDocuments().forEach(document -> { | ||
URI libraryResourceURI = URI.createURI(LIBRARY_SCHEME + ":///" + document.getId().toString()); | ||
if (siriusWebEditingContext.getDomain().getResourceSet().getResource(libraryResourceURI, false) == null) { | ||
Optional<Resource> resource = this.resourceLoader.toResource(siriusWebEditingContext.getDomain().getResourceSet(), document.getId().toString(), document.getName(), document.getContent(), | ||
this.migrationParticipantPredicates.stream().anyMatch(predicate -> predicate.test(editingContext.getId()))); | ||
resource.ifPresent(r -> { | ||
siriusWebEditingContext.getDomain().getResourceSet().getURIConverter().getURIMap().put(r.getURI(), libraryResourceURI); | ||
r.setURI(libraryResourceURI); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private Set<Library> getLibrariesToLoad(EditingContext editingContext) { | ||
Set<Library> librariesToLoad = new LinkedHashSet<>(); | ||
List<Library> editingContextLibraries = new UUIDParser().parse(editingContext.getId()) | ||
.flatMap(semanticDataId -> this.semanticDataSearchService.findById(semanticDataId)) | ||
.map(SemanticData::getDependencies) | ||
.orElse(List.of()) | ||
.stream() | ||
.map(SemanticDataDependency::libraryId) | ||
.map(this.librarySearchService::findById) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.toList(); | ||
|
||
for (Library library : editingContextLibraries) { | ||
librariesToLoad.add(library); | ||
librariesToLoad.addAll(this.librarySearchService.findAllTransitiveDependencyLibrariesByLibrary(library)); | ||
} | ||
return librariesToLoad; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...org/eclipse/sirius/web/application/library/services/api/IEditingContextLibraryLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.library.services.api; | ||
|
||
import org.eclipse.sirius.components.core.api.IEditingContext; | ||
|
||
/** | ||
* Loads libraries into the editing context. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IEditingContextLibraryLoader { | ||
|
||
String LIBRARY_SCHEME = "library"; | ||
|
||
void loadLibraries(IEditingContext editingContext); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...a/org/eclipse/sirius/web/application/object/services/ComposedReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import org.eclipse.sirius.web.application.object.services.api.IDefaultReadOnlyObjectPredicate; | ||
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicate; | ||
import org.eclipse.sirius.web.application.object.services.api.IReadOnlyObjectPredicateDelegate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* Implementation of {@link IReadOnlyObjectPredicate} which delegates to {@link IReadOnlyObjectPredicateDelegate} or fallback to | ||
* {@link IDefaultReadOnlyObjectPredicate}. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class ComposedReadOnlyObjectPredicate implements IReadOnlyObjectPredicate { | ||
|
||
private final List<IReadOnlyObjectPredicateDelegate> readOnlyObjectPredicateDelegate; | ||
|
||
private final IDefaultReadOnlyObjectPredicate defaultReadOnlyObjectPredicate; | ||
|
||
public ComposedReadOnlyObjectPredicate(List<IReadOnlyObjectPredicateDelegate> readOnlyObjectPredicateDelegate, IDefaultReadOnlyObjectPredicate defaultReadOnlyObjectPredicate) { | ||
this.readOnlyObjectPredicateDelegate = Objects.requireNonNull(readOnlyObjectPredicateDelegate); | ||
this.defaultReadOnlyObjectPredicate = Objects.requireNonNull(defaultReadOnlyObjectPredicate); | ||
} | ||
|
||
@Override | ||
public boolean test(Object object) { | ||
var optionalDelegate = this.readOnlyObjectPredicateDelegate.stream() | ||
.filter(delegate -> delegate.canHandle(object)) | ||
.findFirst(); | ||
if (optionalDelegate.isPresent()) { | ||
return optionalDelegate.get().test(object); | ||
} | ||
return this.defaultReadOnlyObjectPredicate.test(object); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...va/org/eclipse/sirius/web/application/object/services/DefaultReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services; | ||
|
||
import java.util.Objects; | ||
import java.util.Optional; | ||
|
||
import org.eclipse.emf.common.util.URI; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.resource.Resource; | ||
import org.eclipse.sirius.web.application.library.services.api.IEditingContextLibraryLoader; | ||
import org.eclipse.sirius.web.application.object.services.api.IDefaultReadOnlyObjectPredicate; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* The default service used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
@Service | ||
public class DefaultReadOnlyObjectPredicate implements IDefaultReadOnlyObjectPredicate { | ||
|
||
@Override | ||
public boolean test(Object object) { | ||
boolean result = false; | ||
if (object instanceof EObject eObject) { | ||
result = Optional.ofNullable(eObject.eResource()) | ||
.map(Resource::getURI) | ||
.map(URI::scheme) | ||
.filter(scheme -> Objects.equals(scheme, IEditingContextLibraryLoader.LIBRARY_SCHEME)) | ||
.isPresent(); | ||
} else if (object instanceof Resource resource) { | ||
result = Objects.equals(resource.getURI().scheme(), IEditingContextLibraryLoader.LIBRARY_SCHEME); | ||
} | ||
return result; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...g/eclipse/sirius/web/application/object/services/api/IDefaultReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* The default service used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IDefaultReadOnlyObjectPredicate extends Predicate<Object> { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...java/org/eclipse/sirius/web/application/object/services/api/IReadOnlyObjectPredicate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IReadOnlyObjectPredicate extends Predicate<Object> { | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
.../eclipse/sirius/web/application/object/services/api/IReadOnlyObjectPredicateDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Obeo. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.web.application.object.services.api; | ||
|
||
import java.util.function.Predicate; | ||
|
||
/** | ||
* Used to test if an object is read-only. | ||
* | ||
* @author gdaniel | ||
*/ | ||
public interface IReadOnlyObjectPredicateDelegate extends Predicate<Object> { | ||
|
||
boolean canHandle(Object object); | ||
|
||
} |
Oops, something went wrong.