From f6647bf7e7548c494734663377b768fd20a94d41 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Tue, 27 Aug 2024 17:19:58 +0200 Subject: [PATCH 1/3] GLSP-1380: Remove dependency to Guava Removes the dependency to Google Guava. We mostly used collection creation which can be done with native Java now almost as conveniently. Other than that we only used the BiMap for source model indexing in EMF. While Guavas BIMaps are powerful most of their functionality is not required for our usecases therefore the useage got replaced with a custom BiIndex implementation. - Replaces usage of Lists.newArrayList etc. with Java native calls - Guava Preconditions were only used in two places -> replaced with in method exception handling - Introduce a `BIIndex` helper class that serves as a replacement for Guavas BIMap in source model indexing - Add test cases for the new BiIndex - Update target platforms Fixes https://github.com/eclipse-glsp/glsp/issues/1380 Contributed on behalf of AxonIvy AG --- .../dependency-reduced-pom.xml | 156 +++++++++++++++++ .../WorkflowCommandPaletteActionProvider.java | 47 +++--- .../WorkflowContextMenuItemProvider.java | 4 +- .../TaskEditContextActionProvider.java | 14 +- .../META-INF/MANIFEST.MF | 3 +- plugins/org.eclipse.glsp.graph/pom.xml | 5 - .../graph/gson/GModelElementTypeAdapter.java | 4 +- .../glsp/graph/impl/GModelIndexImpl.java | 6 +- .../META-INF/MANIFEST.MF | 3 +- .../eclipse/glsp/layout/ElkLayoutEngine.java | 16 +- .../glsp/layout/GLSPLayoutConfigurator.java | 7 +- .../server/emf/EMFCreateOperationHandler.java | 4 +- .../glsp/server/emf/EMFModelIndex.java | 8 +- .../emf/notation/EMFNotationModelIndex.java | 10 +- .../glsp/server/actions/ActionHandler.java | 6 +- .../eclipse/glsp/server/di/ServerModule.java | 7 +- .../undoredo/UndoRedoActionHandler.java | 4 +- ...tractGModelCreateNodeOperationHandler.java | 4 +- .../gmodel/GModelCreateOperationHandler.java | 4 +- .../DefaultToolPaletteItemProvider.java | 6 +- .../AbstractCreateOperationHandler.java | 5 +- .../server/operations/CompoundOperation.java | 5 +- .../operations/CreateOperationHandler.java | 5 +- .../eclipse/glsp/server/utils/BiIndex.java | 144 ++++++++++++++++ pom.xml | 6 - releng/org.eclipse.glsp.feature/feature.xml | 1 - .../r2021-09_minimum-baseline.target | 75 ++++----- targetplatforms/r2021-09_minimum-baseline.tpd | 1 - targetplatforms/r2022-12.target | 75 ++++----- targetplatforms/r2022-12.tpd | 1 - targetplatforms/r2023-09.target | 159 +++++++++--------- targetplatforms/r2023-09.tpd | 1 - .../graph/ReadAndWriteSModelJsonTest.java | 4 +- .../META-INF/MANIFEST.MF | 3 +- .../glsp/server/utils/BiIndexTest.java | 155 +++++++++++++++++ 35 files changed, 699 insertions(+), 259 deletions(-) create mode 100644 examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml create mode 100644 plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java create mode 100644 tests/org.eclipse.glsp.server.test/src/org/eclipse/glsp/server/utils/BiIndexTest.java diff --git a/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml b/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml new file mode 100644 index 00000000..b650b922 --- /dev/null +++ b/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml @@ -0,0 +1,156 @@ + + + + org.eclipse.glsp.parent + org.eclipse.glsp + 2.3.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + org.eclipse.glsp.example + org.eclipse.glsp.example.workflow + ${package-type} + GLSP Workflow Server + https://www.eclipse.org/glsp + + + Eclipse GLSP Project + glsp-dev@eclipse.org + Eclipse GLSP + https://projects.eclipse.org/projects/ecd.glsp + + + + + Eclipse Public License - v 2.0 + http://www.eclipse.org/legal/epl-v20.html + repo + + + + scm:git@github.com:eclipse-glsp/glsp-server.git + scm:git@github.com:eclipse-glsp/glsp-server.git + https://github.com/eclipse-glsp/glsp-server + + + + m2 + + + + maven-deploy-plugin + ${maven.deploy.version} + + false + + + + org.codehaus.mojo + build-helper-maven-plugin + ${buildhelper.maven.version} + + + add-resource + generate-resources + + add-resource + + + + + model + model + + + + + + + + + + jar + + + + fatjar + + + + maven-shade-plugin + ${maven.shade.version} + + + package + + shade + + + + + + + org.eclipse.glsp.example.workflow.launch.WorkflowServerLauncher + + true + + + + + + jakarta.websocket:jakarta.websocket-api + javax.websocket:javax.websocket-api + log4j:log4j + + + + + *:* + + META-INF/MANIFEST.MF + META-INF/DEPENDENCIES + META-INF/ECLIPSE_* + META-INF/LICENSE* + META-INF/services/javax.servlet.ServletContainerInitializer + META-INF/services/jakarta.servlet.ServletContainerInitializer* + META-INF/services/org.eclipse.jetty.webapp.Configuration* + META-INF/services/org.eclipse.elk.core.data.ILayoutMetaDataProvider* + META-INF/versions/9/module-info.class + META-INF/NOTICE* + .options + .api_description + *.profile + *.html + about.* + about_files/* + plugin.xml + modeling32.png + systembundle.properties + profile.list + module-info.class + plugin.properties + **/*._trace + **/*.g + **/*.tokens + **/*.mwe2 + **/*.xtext + **/*.xtextbin + META-INF/*.SF + META-INF/*.RSA + META-INF/*.INF + + + + true + glsp + false + + + + + + + + eclipse-plugin + + diff --git a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowCommandPaletteActionProvider.java b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowCommandPaletteActionProvider.java index 0d93aff3..c763d5ea 100644 --- a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowCommandPaletteActionProvider.java +++ b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowCommandPaletteActionProvider.java @@ -18,7 +18,10 @@ import static org.eclipse.glsp.graph.DefaultTypes.EDGE; import static org.eclipse.glsp.graph.util.GraphUtil.point; +import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashSet; import java.util.List; import java.util.Optional; import java.util.Set; @@ -38,8 +41,6 @@ import org.eclipse.glsp.server.operations.DeleteOperation; import org.eclipse.glsp.server.types.EditorContext; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import com.google.inject.Inject; public class WorkflowCommandPaletteActionProvider implements CommandPaletteActionProvider { @@ -50,7 +51,7 @@ public class WorkflowCommandPaletteActionProvider implements CommandPaletteActio @Override @SuppressWarnings("checkstyle:CyclomaticComplexity") public List getActions(final EditorContext editorContext) { - List actions = Lists.newArrayList(); + List actions = new ArrayList<>(); if (modelState.isReadonly()) { return actions; } @@ -60,20 +61,22 @@ public List getActions(final EditorContext editorContext) { Set selectedElements = index.getAll(selectedIds); // Create node actions are always possible - actions.addAll(Sets.newHashSet( - new LabeledAction("Create Automated Task", Lists.newArrayList( + actions.addAll(new HashSet<>(Set.of( + new LabeledAction("Create Automated Task", new ArrayList<>(List.of( new CreateNodeOperation(ModelTypes.AUTOMATED_TASK, - lastMousePosition.orElse(point(0, 0)), "fa-plus-square"))), + lastMousePosition.orElse(point(0, 0)), "fa-plus-square")))), new LabeledAction("Create Manual Task", - Lists.newArrayList(new CreateNodeOperation(ModelTypes.MANUAL_TASK, lastMousePosition.orElse(point(0, 0)), - "fa-plus-square"))), + new ArrayList<>( + List.of(new CreateNodeOperation(ModelTypes.MANUAL_TASK, lastMousePosition.orElse(point(0, 0)), + "fa-plus-square")))), new LabeledAction("Create Merge Node", - Lists.newArrayList(new CreateNodeOperation(ModelTypes.MERGE_NODE, lastMousePosition.orElse(point(0, 0)), - "fa-plus-square"))), - new LabeledAction("Create Decision Node", Lists.newArrayList(new CreateNodeOperation( - ModelTypes.DECISION_NODE, lastMousePosition.orElse(point(0, 0)), "fa-plus-square"))), - new LabeledAction("Create Category", Lists.newArrayList(new CreateNodeOperation( - ModelTypes.CATEGORY, lastMousePosition.orElse(point(0, 0)), "fa-plus-square"))))); + new ArrayList<>( + List.of(new CreateNodeOperation(ModelTypes.MERGE_NODE, lastMousePosition.orElse(point(0, 0)), + "fa-plus-square")))), + new LabeledAction("Create Decision Node", new ArrayList<>(List.of(new CreateNodeOperation( + ModelTypes.DECISION_NODE, lastMousePosition.orElse(point(0, 0)), "fa-plus-square")))), + new LabeledAction("Create Category", new ArrayList<>(List.of(new CreateNodeOperation( + ModelTypes.CATEGORY, lastMousePosition.orElse(point(0, 0)), "fa-plus-square"))))))); // Create edge actions between two nodes if (selectedElements.size() == 1) { @@ -96,17 +99,19 @@ public List getActions(final EditorContext editorContext) { // Delete action if (selectedElements.size() == 1) { actions - .add(new LabeledAction("Delete", Lists.newArrayList(new DeleteOperation(selectedIds)), "fa-minus-square")); + .add(new LabeledAction("Delete", new ArrayList<>(List.of(new DeleteOperation(selectedIds))), + "fa-minus-square")); } else if (selectedElements.size() > 1) { actions.add( - new LabeledAction("Delete All", Lists.newArrayList(new DeleteOperation(selectedIds)), "fa-minus-square")); + new LabeledAction("Delete All", new ArrayList<>(List.of(new DeleteOperation(selectedIds))), + "fa-minus-square")); } return actions; } private Set createEdgeActions(final GNode source, final Set targets) { - Set actions = Sets.newLinkedHashSet(); + Set actions = new LinkedHashSet<>(); // add first all edge, then all weighted edge actions to keep a nice order targets.forEach(node -> actions.add(createEdgeAction("Create Edge to " + getLabel(node), source, node))); targets.forEach(node -> actions @@ -115,13 +120,13 @@ private Set createEdgeActions(final GNode source, final Set(List.of( + new CreateEdgeOperation(ModelTypes.WEIGHTED_EDGE, source.getId(), node.getId()))), "fa-plus-square"); } private LabeledAction createEdgeAction(final String label, final GNode source, final GNode node) { - return new LabeledAction(label, Lists.newArrayList( - new CreateEdgeOperation(EDGE, source.getId(), node.getId())), "fa-plus-square"); + return new LabeledAction(label, new ArrayList<>(List.of( + new CreateEdgeOperation(EDGE, source.getId(), node.getId()))), "fa-plus-square"); } private String getLabel(final GNode node) { diff --git a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowContextMenuItemProvider.java b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowContextMenuItemProvider.java index 34b8ee33..d7a90b17 100644 --- a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowContextMenuItemProvider.java +++ b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/provider/WorkflowContextMenuItemProvider.java @@ -18,6 +18,7 @@ import static org.eclipse.glsp.example.workflow.utils.ModelTypes.AUTOMATED_TASK; import static org.eclipse.glsp.example.workflow.utils.ModelTypes.MANUAL_TASK; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -30,7 +31,6 @@ import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.operations.CreateNodeOperation; -import com.google.common.collect.Lists; import com.google.inject.Inject; public class WorkflowContextMenuItemProvider implements ContextMenuItemProvider { @@ -50,7 +50,7 @@ public List getItems(final List selectedElementIds, final GPoi MenuItem newManTask = new MenuItem("newManualTask", "Manual Task", Arrays.asList(new CreateNodeOperation(MANUAL_TASK, snappedPosition)), true); MenuItem newChildMenu = new MenuItem("new", "New", Arrays.asList(newAutTask, newManTask), "add", "0_new"); - return Lists.newArrayList(newChildMenu); + return new ArrayList<>(List.of(newChildMenu)); } } diff --git a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/taskedit/TaskEditContextActionProvider.java b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/taskedit/TaskEditContextActionProvider.java index c3643464..516491e1 100644 --- a/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/taskedit/TaskEditContextActionProvider.java +++ b/examples/org.eclipse.glsp.example.workflow/src/org/eclipse/glsp/example/workflow/taskedit/TaskEditContextActionProvider.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.example.workflow.taskedit; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -26,7 +27,6 @@ import org.eclipse.glsp.server.model.GModelState; import org.eclipse.glsp.server.types.EditorContext; -import com.google.common.collect.Lists; import com.google.inject.Inject; public class TaskEditContextActionProvider implements ContextActionsProvider { @@ -51,18 +51,20 @@ public List getActions(final EditorContext editorContex } if (text.startsWith(TYPE_PREFIX)) { String id = taskNode.get().getId(); - return Lists.newArrayList( - new LabeledAction("type:automated", Lists.newArrayList(new EditTaskOperation(id, "taskType", "automated"))), - new LabeledAction("type:manual", Lists.newArrayList(new EditTaskOperation(id, "taskType", "manual")))); + return new ArrayList<>(List.of( + new LabeledAction("type:automated", + new ArrayList<>(List.of(new EditTaskOperation(id, "taskType", "automated")))), + new LabeledAction("type:manual", + new ArrayList<>(List.of(new EditTaskOperation(id, "taskType", "manual")))))); } if (text.startsWith(DURATION_PREFIX)) { return Collections.emptyList(); } String taskType = taskNode.get().getType().substring(TASK_PREFIX.length()); int duration = taskNode.get().getDuration(); - return Lists.newArrayList( + return new ArrayList<>(List.of( new SetAutoCompleteValueAction("type:", "", TYPE_PREFIX + taskType), - new SetAutoCompleteValueAction("duration:", "", DURATION_PREFIX + duration)); + new SetAutoCompleteValueAction("duration:", "", DURATION_PREFIX + duration))); } } diff --git a/plugins/org.eclipse.glsp.graph/META-INF/MANIFEST.MF b/plugins/org.eclipse.glsp.graph/META-INF/MANIFEST.MF index b09c1edf..c6bdf71f 100644 --- a/plugins/org.eclipse.glsp.graph/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.glsp.graph/META-INF/MANIFEST.MF @@ -8,8 +8,7 @@ Automatic-Module-Name: org.eclipse.glsp.graph Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.emf.common;bundle-version="2.23.0", com.google.gson;bundle-version="2.8.7", - org.eclipse.emf.ecore;bundle-version="2.25.0";visibility:=reexport, - com.google.guava;bundle-version="[30.1.0,33.0.0)";visibility:=reexport + org.eclipse.emf.ecore;bundle-version="2.25.0";visibility:=reexport Export-Package: org.eclipse.glsp.graph, org.eclipse.glsp.graph, org.eclipse.glsp.graph.builder, diff --git a/plugins/org.eclipse.glsp.graph/pom.xml b/plugins/org.eclipse.glsp.graph/pom.xml index 0ad4e4c7..3eeefe6b 100644 --- a/plugins/org.eclipse.glsp.graph/pom.xml +++ b/plugins/org.eclipse.glsp.graph/pom.xml @@ -42,11 +42,6 @@ - - com.google.guava - guava - ${google.guava.version} - org.eclipse.emf org.eclipse.emf.common diff --git a/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/gson/GModelElementTypeAdapter.java b/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/gson/GModelElementTypeAdapter.java index a76d559e..5f267aaf 100644 --- a/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/gson/GModelElementTypeAdapter.java +++ b/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/gson/GModelElementTypeAdapter.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; @@ -33,7 +34,6 @@ import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.glsp.graph.GModelElement; -import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.TypeAdapter; @@ -92,7 +92,7 @@ protected GModelElement createInstance(final String type) { protected Optional findEClassForType(final String type) { EClass eClass = typeMap.get(type); if (eClass == null) { - List subtypes = Lists.newArrayList(type.split(delimiter)); + List subtypes = new ArrayList<>(List.of(type.split(delimiter))); while (eClass == null && !subtypes.isEmpty()) { subtypes.remove(subtypes.size() - 1); eClass = typeMap.get(String.join(delimiter, subtypes)); diff --git a/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/impl/GModelIndexImpl.java b/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/impl/GModelIndexImpl.java index d7060e33..fc3d0141 100644 --- a/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/impl/GModelIndexImpl.java +++ b/plugins/org.eclipse.glsp.graph/src/org/eclipse/glsp/graph/impl/GModelIndexImpl.java @@ -40,8 +40,6 @@ import org.eclipse.glsp.graph.GModelIndex; import org.eclipse.glsp.graph.GModelRoot; -import com.google.common.base.Preconditions; - /** * Default implementation of {@link GModelIndex}. Registers itself as adapter of the {@link GModelRoot} * to receive change notifications. This enables auto updating of the internal index if a child elements is @@ -54,7 +52,9 @@ public class GModelIndexImpl extends ECrossReferenceAdapter implements GModelInd protected final GModelElement root; public GModelIndexImpl(final EObject target) { - Preconditions.checkArgument(target instanceof GModelElement); + if (!(target instanceof GModelElement)) { + throw new IllegalArgumentException(); + } this.root = (GModelElement) target; addIfGModelElement(target); } diff --git a/plugins/org.eclipse.glsp.layout/META-INF/MANIFEST.MF b/plugins/org.eclipse.glsp.layout/META-INF/MANIFEST.MF index f98b5d80..2d01b452 100644 --- a/plugins/org.eclipse.glsp.layout/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.glsp.layout/META-INF/MANIFEST.MF @@ -8,6 +8,5 @@ Automatic-Module-Name: org.eclipse.glsp.layout Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Bundle: org.eclipse.glsp.server;bundle-version="[2.0.0,3.0.0)", org.eclipse.elk.core;bundle-version="0.8.1", - org.eclipse.elk.graph;bundle-version="0.8.1", - com.google.guava;bundle-version="[30.1.0,33.0.0)" + org.eclipse.elk.graph;bundle-version="0.8.1" Export-Package: org.eclipse.glsp.layout diff --git a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java index 89ce3e93..5e349821 100644 --- a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java +++ b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java @@ -20,6 +20,8 @@ import static org.eclipse.glsp.graph.util.GraphUtil.point; import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -62,7 +64,6 @@ import org.eclipse.glsp.server.layout.LayoutEngine; import org.eclipse.glsp.server.model.GModelState; -import com.google.common.collect.Maps; import com.google.inject.Inject; /** @@ -271,7 +272,12 @@ protected void handleClientLayout(final GBoundsAware element, final GLayouting s * Resolve cross-references in the ELK graph. */ protected void resolveReferences(final LayoutContext context) { - Map id2NodeMap = Maps.newHashMapWithExpectedSize(context.shapeMap.size()); + // Per default a map will resize when 75% of its capacticy is filled. By dividing the expected size with the load + // factor + // we can create a map with enough capacity to avoid resizing + int initialCapactiy = (int) Math.ceil(context.shapeMap.size() / 0.75); + Map id2NodeMap = new HashMap<>(initialCapactiy); + for (Map.Entry entry : context.shapeMap.entrySet()) { String id = entry.getKey().getId(); if (id != null && entry.getValue() instanceof ElkConnectableShape) { @@ -604,9 +610,9 @@ protected GPoint getOffset(final GModelElement gelem, final ElkGraphElement elkE protected static class LayoutContext { public GGraph ggraph; public ElkNode elkGraph; - public final Map parentMap = Maps.newHashMap(); - public final Map shapeMap = Maps.newLinkedHashMap(); - public final Map edgeMap = Maps.newLinkedHashMap(); + public final Map parentMap = new HashMap<>(); + public final Map shapeMap = new LinkedHashMap<>(); + public final Map edgeMap = new LinkedHashMap<>(); } } diff --git a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/GLSPLayoutConfigurator.java b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/GLSPLayoutConfigurator.java index cf76d156..968fc8be 100644 --- a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/GLSPLayoutConfigurator.java +++ b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/GLSPLayoutConfigurator.java @@ -16,6 +16,7 @@ ********************************************************************************/ package org.eclipse.glsp.layout; +import java.util.HashMap; import java.util.Map; import java.util.regex.Pattern; @@ -24,8 +25,6 @@ import org.eclipse.elk.graph.properties.IPropertyHolder; import org.eclipse.elk.graph.properties.MapPropertyHolder; -import com.google.common.collect.Maps; - /** * Note: adaptation of org.eclipse.sprotty.layout.SprottyLayoutConfigurator * @@ -46,8 +45,8 @@ public static String toElkId(final String gmodelId) { return ID_REPLACE_PATTERN.matcher(gmodelId).replaceAll("_"); } - protected final Map idOptionMap = Maps.newHashMap(); - protected final Map typeOptionMap = Maps.newHashMap(); + protected final Map idOptionMap = new HashMap<>(); + protected final Map typeOptionMap = new HashMap<>(); /* * Configure layout options for the model element with the given id. diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFCreateOperationHandler.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFCreateOperationHandler.java index c036c60a..fd5edc9a 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFCreateOperationHandler.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFCreateOperationHandler.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.emf; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -27,7 +28,6 @@ import org.eclipse.glsp.server.operations.CreateOperation; import org.eclipse.glsp.server.operations.CreateOperationHandler; -import com.google.common.collect.Lists; import com.google.inject.Inject; public abstract class EMFCreateOperationHandler @@ -39,7 +39,7 @@ public abstract class EMFCreateOperationHandler protected List handledElementTypeIds; public EMFCreateOperationHandler(final String... elementTypeIds) { - this(Lists.newArrayList(elementTypeIds)); + this(new ArrayList<>(List.of(elementTypeIds))); } public EMFCreateOperationHandler(final List handledElementTypeIds) { diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelIndex.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelIndex.java index b6fd266a..ad1c3c3a 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelIndex.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/EMFModelIndex.java @@ -21,9 +21,7 @@ import org.eclipse.glsp.graph.GModelElement; import org.eclipse.glsp.graph.impl.GModelIndexImpl; import org.eclipse.glsp.graph.util.RootAdapterUtil; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; +import org.eclipse.glsp.server.utils.BiIndex; /** * Is used to index all child elements of an arbitrary EMF source model. @@ -33,11 +31,11 @@ public class EMFModelIndex extends GModelIndexImpl { protected EMFIdGenerator idGenerator; - protected BiMap eObjectIndex; + protected BiIndex eObjectIndex; protected EMFModelIndex(final EObject target, final EMFIdGenerator idGenerator) { super(target); - this.eObjectIndex = HashBiMap.create(); + this.eObjectIndex = new BiIndex<>(); this.idGenerator = idGenerator; } diff --git a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/notation/EMFNotationModelIndex.java b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/notation/EMFNotationModelIndex.java index f1116f3c..e9502a38 100644 --- a/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/notation/EMFNotationModelIndex.java +++ b/plugins/org.eclipse.glsp.server.emf/src/org/eclipse/glsp/server/emf/notation/EMFNotationModelIndex.java @@ -30,9 +30,7 @@ import org.eclipse.glsp.server.emf.model.notation.NotationFactory; import org.eclipse.glsp.server.emf.model.notation.SemanticElementReference; import org.eclipse.glsp.server.emf.notation.util.NotationUtil; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; +import org.eclipse.glsp.server.utils.BiIndex; /** * Is used to index all child elements of a semantic and notation model. @@ -41,12 +39,12 @@ public class EMFNotationModelIndex extends EMFModelIndex { protected static Logger LOGGER = LogManager.getLogger(EMFNotationModelIndex.class); - protected BiMap notationIndex; + protected BiIndex notationIndex; protected final EMFSemanticIdConverter idConverter; protected EMFNotationModelIndex(final EObject target, final EMFSemanticIdConverter idConverter) { super(target, idConverter); - this.notationIndex = HashBiMap.create(); + this.notationIndex = new BiIndex<>(); this.idConverter = idConverter; } @@ -100,7 +98,7 @@ protected void indexNotation(final NotationElement notationElement) { if (!NotationUtil.isUnresolved(notationElement)) { EObject semanticElement = notationElement.getSemanticElement().getResolvedSemanticElement(); notationIndex.put(semanticElement, notationElement); - eObjectIndex.inverse().putIfAbsent(semanticElement, getOrCreateId(semanticElement)); + eObjectIndex.putIfAbsent(getOrCreateId(semanticElement), semanticElement); } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ActionHandler.java index 66db3ea5..2143159f 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/actions/ActionHandler.java @@ -16,8 +16,6 @@ package org.eclipse.glsp.server.actions; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; @@ -66,7 +64,7 @@ default boolean handles(final Action action) { * @return The given action objects as list. */ default List listOf(final Action... action) { - return Arrays.asList(action); + return new ArrayList<>(List.of(action)); } /** @@ -87,7 +85,7 @@ default List listOf(final Optional optionalAction) { * @return An empty action list. */ default List none() { - return Collections.emptyList(); + return new ArrayList<>(); } /** diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java index 20623e5c..fcdf5292 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java @@ -33,7 +33,6 @@ import org.eclipse.glsp.server.session.ClientSessionManager; import org.eclipse.glsp.server.utils.ModuleUtil; -import com.google.common.base.Preconditions; import com.google.inject.Module; import com.google.inject.Provides; import com.google.inject.Singleton; @@ -87,8 +86,10 @@ public class ServerModule extends GLSPModule { */ public ServerModule configureDiagramModule(final DiagramModule diagramModule, final Module... mixinModules) { String diagramType = diagramModule.getDiagramType(); - Preconditions.checkState(!diagramModules.containsKey(diagramType), - "A module configuration is already present for diagram type: " + diagramType); + if (!diagramModules.containsKey(diagramType)) { + throw new IllegalArgumentException( + "A module configuration is already present for diagram type: " + diagramType); + } Module combinedModule = ModuleUtil.mixin(diagramModule, mixinModules); diagramModules.put(diagramType, combinedModule); diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java index 5d7fc38a..ed538796 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/features/undoredo/UndoRedoActionHandler.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.features.undoredo; +import java.util.ArrayList; import java.util.List; import org.apache.logging.log4j.LogManager; @@ -25,7 +26,6 @@ import org.eclipse.glsp.server.features.core.model.ModelSubmissionHandler; import org.eclipse.glsp.server.model.GModelState; -import com.google.common.collect.Lists; import com.google.inject.Inject; public class UndoRedoActionHandler implements ActionHandler { @@ -52,6 +52,6 @@ public List execute(final Action action) { @Override public List> getHandledActionTypes() { - return Lists.newArrayList(UndoAction.class, RedoAction.class); + return new ArrayList<>(List.of(UndoAction.class, RedoAction.class)); } } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java index 960369e6..a99b19ba 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/AbstractGModelCreateNodeOperationHandler.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.gmodel; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Optional; @@ -28,7 +29,6 @@ import org.eclipse.glsp.server.operations.CreateNodeOperation; import org.eclipse.glsp.server.utils.LayoutUtil; -import com.google.common.collect.Lists; import com.google.inject.Inject; /** @@ -44,7 +44,7 @@ public abstract class AbstractGModelCreateNodeOperationHandler protected ActionDispatcher actionDispatcher; public AbstractGModelCreateNodeOperationHandler(final String... elementTypeIds) { - super(Lists.newArrayList(elementTypeIds)); + super(new ArrayList<>(List.of(elementTypeIds))); } public AbstractGModelCreateNodeOperationHandler(final List handledElementTypeIds) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateOperationHandler.java index 740d3324..e88e4314 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/gmodel/GModelCreateOperationHandler.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.gmodel; +import java.util.ArrayList; import java.util.List; import org.eclipse.glsp.server.actions.ActionDispatcher; @@ -23,7 +24,6 @@ import org.eclipse.glsp.server.operations.CreateOperationHandler; import org.eclipse.glsp.server.operations.GModelOperationHandler; -import com.google.common.collect.Lists; import com.google.inject.Inject; /** @@ -38,7 +38,7 @@ public abstract class GModelCreateOperationHandler protected List handledElementTypeIds; public GModelCreateOperationHandler(final String... elementTypeIds) { - this(Lists.newArrayList(elementTypeIds)); + this(new ArrayList<>(List.of(elementTypeIds))); } public GModelCreateOperationHandler(final List handledElementTypeIds) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/toolpalette/DefaultToolPaletteItemProvider.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/toolpalette/DefaultToolPaletteItemProvider.java index 1c662b49..d59597b6 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/toolpalette/DefaultToolPaletteItemProvider.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/internal/toolpalette/DefaultToolPaletteItemProvider.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.internal.toolpalette; +import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -29,7 +30,6 @@ import org.eclipse.glsp.server.operations.CreateOperationHandler; import org.eclipse.glsp.server.operations.OperationHandlerRegistry; -import com.google.common.collect.Lists; import com.google.inject.Inject; public class DefaultToolPaletteItemProvider implements ToolPaletteItemProvider { @@ -49,9 +49,9 @@ public List getItems(final Map args) { counter = 0; List nodes = createPaletteItems(handlers, CreateNodeOperation.class); List edges = createPaletteItems(handlers, CreateEdgeOperation.class); - return Lists.newArrayList( + return new ArrayList<>(List.of( PaletteItem.createPaletteGroup("node-group", "Nodes", nodes, "symbol-property", "A"), - PaletteItem.createPaletteGroup("edge-group", "Edges", edges, "symbol-property", "B")); + PaletteItem.createPaletteGroup("edge-group", "Edges", edges, "symbol-property", "B"))); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/AbstractCreateOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/AbstractCreateOperationHandler.java index 085d0691..5b3d7c5b 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/AbstractCreateOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/AbstractCreateOperationHandler.java @@ -15,12 +15,11 @@ ********************************************************************************/ package org.eclipse.glsp.server.operations; +import java.util.ArrayList; import java.util.List; import org.eclipse.glsp.server.gmodel.GModelCreateOperationHandler; -import com.google.common.collect.Lists; - /** * @deprecated Use {@link GModelCreateOperationHandler} */ @@ -31,7 +30,7 @@ public abstract class AbstractCreateOperationHandler protected List handledElementTypeIds; public AbstractCreateOperationHandler(final String... elementTypeIds) { - this(Lists.newArrayList(elementTypeIds)); + this(new ArrayList<>(List.of(elementTypeIds))); } public AbstractCreateOperationHandler(final List handledElementTypeIds) { diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CompoundOperation.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CompoundOperation.java index 6c8542de..78186bac 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CompoundOperation.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CompoundOperation.java @@ -15,10 +15,9 @@ ********************************************************************************/ package org.eclipse.glsp.server.operations; +import java.util.ArrayList; import java.util.List; -import com.google.common.collect.Lists; - public class CompoundOperation extends Operation { public static final String KIND = "compound"; @@ -27,7 +26,7 @@ public class CompoundOperation extends Operation { public CompoundOperation() { super(KIND); - operationList = Lists.newArrayList(); + operationList = new ArrayList<>(); } public List getOperationList() { return operationList; } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CreateOperationHandler.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CreateOperationHandler.java index 915bdd3e..cc544ca6 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CreateOperationHandler.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/operations/CreateOperationHandler.java @@ -15,6 +15,7 @@ ********************************************************************************/ package org.eclipse.glsp.server.operations; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -22,8 +23,6 @@ import org.eclipse.glsp.server.actions.TriggerElementCreationAction; import org.eclipse.glsp.server.actions.TriggerNodeCreationAction; -import com.google.common.collect.Lists; - /** * A special {@link OperationHandler} that is responsible for the handling of {@link CreateOperation}s. Depending on its * operation type the triggered actions are {@link TriggerNodeCreationAction} or {@link TriggerEdgeCreationAction}s. @@ -41,7 +40,7 @@ default List getTriggerActions() { } else if (CreateEdgeOperation.class.isAssignableFrom(getHandledOperationType())) { return getHandledElementTypeIds().stream().map(TriggerEdgeCreationAction::new).collect(Collectors.toList()); } - return Lists.newArrayList(); + return new ArrayList<>(); } /** diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java new file mode 100644 index 00000000..c2ff95c2 --- /dev/null +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java @@ -0,0 +1,144 @@ +/******************************************************************************** + * Copyright (c) 2024 EclipseSource and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ +package org.eclipse.glsp.server.utils; + +import java.util.HashMap; +import java.util.Map; + +/** + * A BiIndex maintains a bidirectional map i.e a map that preserves the uniqueness of its values as well as + * that of its keys. It offers a subset of the {@link Map} API to query, add and remove elements to/from the index. + * In addition, provides immutable access to the underlying key-value map and its inverse map. + * + * This implementation is taylored towards the use in (source) model indexing and is not intended as a general purpose + * bi-map. + * + */ +public class BiIndex { + + protected Map map = new HashMap<>(); + protected Map inverseMap = new HashMap<>(); + + public Map map() { + return Map.copyOf(map); + } + + public Map inverseMap() { + return Map.copyOf(inverseMap); + } + + public int size() { + return map.size(); + } + + public boolean isEmpty() { return map.isEmpty(); } + + public boolean containsKey(final Object key) { + return map.containsKey(key); + } + + public boolean containsValue(final Object value) { + return inverseMap.containsKey(value); + } + + public V get(final Object key) { + return map.get(key); + } + + public K getKey(final Object value) { + return inverseMap.get(value); + } + + /** + * Behaves similar to {@link Map#put} but throws an expection if the given value is already associated with a + * different key. + * + * @throws IllegalArgumentException if the given value is already bound to a different key in this + * index. To avoid this exception, call {@link + * #forcePut} instead. + */ + public V put(final K key, final V value) { + K existingKey = inverseMap.get(value); + if (existingKey != null && existingKey != key) { + throw new IllegalArgumentException("Value already present: " + value); + } + V result = map.put(key, value); + inverseMap.put(value, key); + return result; + } + + /** + * Force implementation of {@link #put}(). Removes any exsting entry for the given value + * before continuing with the put operation i.e. it overrides any existing entries. + */ + public V forcePut(final K key, final V value) { + K existingKey = inverseMap.remove(value); + if (existingKey != null) { + map.remove(existingKey); + + } + return put(key, value); + } + + public void clear() { + map.clear(); + inverseMap.clear(); + } + + public V remove(final Object key) { + V value = map.remove(key); + if (value != null) { + inverseMap.remove(value); + } + return value; + } + + public K removeValue(final Object value) { + K key = inverseMap.remove(value); + if (key != null) { + map.remove(key); + } + return key; + + } + + public boolean remove(final Object key, final Object value) { + Object currentValue = map.get(key); + Object currentKey = inverseMap.get(value); + if (currentValue.equals(value) && currentKey.equals(key)) { + map.remove(key); + inverseMap.remove(value); + return true; + } + return false; + } + + /** + * Similar to {@link Map#putIfAbsent}. In addition to the key, it + * also checks if the value is absent and only continues with the put operation if + * both are absent. + */ + public V putIfAbsent(final K key, final V value) { + V v = get(key); + + if (v == null && !inverseMap.containsKey(value)) { + v = put(key, value); + } + + return v; + } + +} diff --git a/pom.xml b/pom.xml index 5bd51ea0..7751acf0 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ [2.25.0,) 2.16.0 2.0.0 - [30.1-jre,) [5.0.1,) [2.8.7,) [5.7.1,6.0.0) @@ -274,11 +273,6 @@ log4j-core ${apache.logging.log4j.version} - - com.google.guava - guava - ${google.guava.version} - org.apache.logging.log4j log4j-slf4j2-impl diff --git a/releng/org.eclipse.glsp.feature/feature.xml b/releng/org.eclipse.glsp.feature/feature.xml index 4e0ada16..fa969d92 100644 --- a/releng/org.eclipse.glsp.feature/feature.xml +++ b/releng/org.eclipse.glsp.feature/feature.xml @@ -323,7 +323,6 @@ version(s), and exceptions or additional permissions here}." - - + @@ -9,7 +9,6 @@ - @@ -34,46 +33,46 @@ - - - org.apache.aries.spifly - org.apache.aries.spifly.dynamic.bundle - 1.3.6 - jar - - + + + org.apache.aries.spifly + org.apache.aries.spifly.dynamic.bundle + 1.3.6 + jar + + - - - org.slf4j - slf4j-api - 2.0.0 - jar - - + + + org.slf4j + slf4j-api + 2.0.0 + jar + + - - - org.apache.logging.log4j - log4j-slf4j2-impl - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-core - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-api - 2.19.0 - jar - - + + + org.apache.logging.log4j + log4j-slf4j2-impl + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-core + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-api + 2.19.0 + jar + + diff --git a/targetplatforms/r2021-09_minimum-baseline.tpd b/targetplatforms/r2021-09_minimum-baseline.tpd index 8a8bc843..3d19995d 100644 --- a/targetplatforms/r2021-09_minimum-baseline.tpd +++ b/targetplatforms/r2021-09_minimum-baseline.tpd @@ -8,7 +8,6 @@ location "http://download.eclipse.org/releases/2021-09" { org.eclipse.lsp4j.websocket [0.11.0,1.0.0) org.apache.commons.cli [1.4.0,2.0.0) com.google.gson [2.8.7,3.0.0) - com.google.guava [30.1.0,31.0.0) } location "https://download.eclipse.org/tools/orbit/downloads/drops/R20210825222808/repository/" { diff --git a/targetplatforms/r2022-12.target b/targetplatforms/r2022-12.target index 8692a1db..4738871e 100644 --- a/targetplatforms/r2022-12.target +++ b/targetplatforms/r2022-12.target @@ -1,7 +1,7 @@ - + @@ -10,7 +10,6 @@ - @@ -34,46 +33,46 @@ - - - org.apache.aries.spifly - org.apache.aries.spifly.dynamic.bundle - 1.3.6 - jar - - + + + org.apache.aries.spifly + org.apache.aries.spifly.dynamic.bundle + 1.3.6 + jar + + - - - org.slf4j - slf4j-api - 2.0.0 - jar - - + + + org.slf4j + slf4j-api + 2.0.0 + jar + + - - - org.apache.logging.log4j - log4j-slf4j2-impl - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-core - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-api - 2.19.0 - jar - - + + + org.apache.logging.log4j + log4j-slf4j2-impl + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-core + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-api + 2.19.0 + jar + + diff --git a/targetplatforms/r2022-12.tpd b/targetplatforms/r2022-12.tpd index 87091adf..cd04b85f 100644 --- a/targetplatforms/r2022-12.tpd +++ b/targetplatforms/r2022-12.tpd @@ -9,7 +9,6 @@ location "http://download.eclipse.org/releases/2022-12" { org.apache.commons.cli [1.4.0,2.0.0) com.google.gson[2.8.7,3.0.0) com.google.inject [5.0.1,5.0.2) - com.google.guava [30.1.0,31.0.0) } location "https://download.eclipse.org/tools/orbit/downloads/drops/R20221123021534/repository/" { diff --git a/targetplatforms/r2023-09.target b/targetplatforms/r2023-09.target index ff0232c0..4a41da80 100644 --- a/targetplatforms/r2023-09.target +++ b/targetplatforms/r2023-09.target @@ -1,80 +1,79 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - org.apache.aries.spifly - org.apache.aries.spifly.dynamic.bundle - 1.3.6 - jar - - - - - - - org.slf4j - slf4j-api - 2.0.0 - jar - - - - - - - org.apache.logging.log4j - log4j-slf4j2-impl - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-core - 2.19.0 - jar - - - org.apache.logging.log4j - log4j-api - 2.19.0 - jar - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + org.apache.aries.spifly + org.apache.aries.spifly.dynamic.bundle + 1.3.6 + jar + + + + + + + org.slf4j + slf4j-api + 2.0.0 + jar + + + + + + + org.apache.logging.log4j + log4j-slf4j2-impl + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-core + 2.19.0 + jar + + + org.apache.logging.log4j + log4j-api + 2.19.0 + jar + + + + + diff --git a/targetplatforms/r2023-09.tpd b/targetplatforms/r2023-09.tpd index 6d14f32d..f8567b99 100644 --- a/targetplatforms/r2023-09.tpd +++ b/targetplatforms/r2023-09.tpd @@ -9,7 +9,6 @@ location "http://download.eclipse.org/releases/2023-09" { org.apache.commons.cli [1.4.0,2.0.0) com.google.gson[2.8.7,3.0.0) com.google.inject [7.0.0,8.0.0) - com.google.guava [32.0.0,33.0.0) jakarta.inject.jakarta.inject-api [2.0.1,3.0.0) } diff --git a/tests/org.eclipse.glsp.graph.test/src/org/eclipse/glsp/graph/ReadAndWriteSModelJsonTest.java b/tests/org.eclipse.glsp.graph.test/src/org/eclipse/glsp/graph/ReadAndWriteSModelJsonTest.java index 71c8edcf..c7047ea8 100644 --- a/tests/org.eclipse.glsp.graph.test/src/org/eclipse/glsp/graph/ReadAndWriteSModelJsonTest.java +++ b/tests/org.eclipse.glsp.graph.test/src/org/eclipse/glsp/graph/ReadAndWriteSModelJsonTest.java @@ -24,6 +24,7 @@ import java.io.FileReader; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.eclipse.emf.ecore.EClass; @@ -31,7 +32,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -113,7 +113,7 @@ void testWritingGraphWithTwoNodesAndOneEdge() { edge.setSourceId(node1.getId()); edge.setTargetId(node2.getId()); - graph.getChildren().addAll(Lists.newArrayList(node1, node2, edge)); + graph.getChildren().addAll(List.of(node1, node2, edge)); JsonObject jsonGraph = writeToJson(graph).getAsJsonObject(); assertEquals("graphId", jsonGraph.get("id").getAsString()); diff --git a/tests/org.eclipse.glsp.server.test/META-INF/MANIFEST.MF b/tests/org.eclipse.glsp.server.test/META-INF/MANIFEST.MF index f981ef09..e21f551f 100644 --- a/tests/org.eclipse.glsp.server.test/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.glsp.server.test/META-INF/MANIFEST.MF @@ -10,4 +10,5 @@ Bundle-Vendor: Eclipse GLSP Export-Package: org.eclipse.glsp.server.features.sourcemodelwatcher Import-Package: org.junit;version="4.12.0", - org.junit.jupiter.api;version="5.0.0" + org.junit.jupiter.api;version="5.0.0", + org.junit.jupiter.api.function;version="5.0.0" diff --git a/tests/org.eclipse.glsp.server.test/src/org/eclipse/glsp/server/utils/BiIndexTest.java b/tests/org.eclipse.glsp.server.test/src/org/eclipse/glsp/server/utils/BiIndexTest.java new file mode 100644 index 00000000..0d9f4bda --- /dev/null +++ b/tests/org.eclipse.glsp.server.test/src/org/eclipse/glsp/server/utils/BiIndexTest.java @@ -0,0 +1,155 @@ +/******************************************************************************** + * Copyright (c) 2020 EclipseSource and others. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the Eclipse + * Public License v. 2.0 are satisfied: GNU General Public License, version 2 + * with the GNU Classpath Exception which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + ********************************************************************************/ +package org.eclipse.glsp.server.utils; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class BiIndexTest { + + private final BiIndex index = new BiIndex<>(); + + @BeforeEach + public void beforeEach() { + index.clear(); + } + + @Test + void putNewKeyValuePair() { + String key = "key"; + String value = "value"; + assertEquals(0, index.size()); + assertTrue(index.isEmpty()); + assertFalse(index.containsKey(key)); + assertFalse(index.containsValue(value)); + index.put(key, value); + assertEquals(1, index.size()); + assertFalse(index.isEmpty()); + assertTrue(index.containsKey(key)); + assertTrue(index.containsValue(value)); + assertEquals(key, index.getKey(value)); + assertEquals(value, index.get(key)); + + } + + @Test + void putConflictingKeyValuePair_shouldThrowExpection() { + String key = "key"; + String value = "value"; + index.put(key, value); + assertThrows(IllegalArgumentException.class, () -> index.put("AnotherKey", value)); + } + + @Test + void putDuplicateKeyValuePair() { + String key = "key"; + String value = "value"; + index.put(key, value); + index.put(key, value); + assertEquals(1, index.size()); + assertFalse(index.isEmpty()); + assertTrue(index.containsKey(key)); + assertTrue(index.containsValue(value)); + } + + @Test + void forcePutConflictingKeyValuePair() { + String key = "key"; + String value = "value"; + String key2 = "anotherKey"; + index.put(key, value); + index.forcePut(key2, value); + assertFalse(index.containsKey(key)); + assertTrue(index.containsKey(key2)); + assertTrue(index.containsValue(value)); + } + + @Test + void clearIndex() { + index.put("k", "v"); + index.put("s", "f"); + assertFalse(index.isEmpty()); + index.clear(); + assertTrue(index.isEmpty()); + assertTrue(index.map.isEmpty()); + assertTrue(index.inverseMap.isEmpty()); + } + + @Test + void removeKey() { + String key = "key"; + String value = "value"; + index.put(key, value); + assertFalse(index.isEmpty()); + index.remove(key); + assertTrue(index.isEmpty()); + assertFalse(index.containsKey(key)); + assertFalse(index.containsValue(value)); + } + + @Test + void removeValue() { + String key = "key"; + String value = "value"; + index.put(key, value); + assertFalse(index.isEmpty()); + index.removeValue(value); + assertTrue(index.isEmpty()); + assertFalse(index.containsKey(key)); + assertFalse(index.containsValue(value)); + } + + @Test + void removeKeyValuePair() { + String key = "key"; + String value = "value"; + index.put(key, value); + assertFalse(index.isEmpty()); + index.remove(key, value); + assertTrue(index.isEmpty()); + assertFalse(index.containsKey(key)); + assertFalse(index.containsValue(value)); + } + + @Test + void putIfAbsentWithAbsentKeyValuePair() { + String key = "key"; + String value = "value"; + index.putIfAbsent(key, value); + assertFalse(index.isEmpty()); + assertTrue(index.containsKey(key)); + assertTrue(index.containsValue(value)); + } + + @Test + void putIfAbsentWithPresentKeyAndOrValue() { + String key = "key"; + String value = "value"; + index.put(key, value); + index.putIfAbsent(key, "anotherValue"); + assertTrue(index.containsValue(value)); + assertEquals(index.get(key), value); + index.putIfAbsent("anotherKey", value); + assertTrue(index.containsKey(key)); + assertEquals(index.getKey(value), key); + } + +} From b91deaddb982e67d81fafeba4d65ce747cbc73c1 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Wed, 28 Aug 2024 09:54:16 +0200 Subject: [PATCH 2/3] Fix wrong precondition --- .../src/org/eclipse/glsp/server/di/ServerModule.java | 2 +- .../src/org/eclipse/glsp/server/utils/BiIndex.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java index fcdf5292..3fe57e37 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/di/ServerModule.java @@ -86,7 +86,7 @@ public class ServerModule extends GLSPModule { */ public ServerModule configureDiagramModule(final DiagramModule diagramModule, final Module... mixinModules) { String diagramType = diagramModule.getDiagramType(); - if (!diagramModules.containsKey(diagramType)) { + if (diagramModules.containsKey(diagramType)) { throw new IllegalArgumentException( "A module configuration is already present for diagram type: " + diagramType); } diff --git a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java index c2ff95c2..832bf30b 100644 --- a/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java +++ b/plugins/org.eclipse.glsp.server/src/org/eclipse/glsp/server/utils/BiIndex.java @@ -32,10 +32,16 @@ public class BiIndex { protected Map map = new HashMap<>(); protected Map inverseMap = new HashMap<>(); + /** + * Returns an unmodifiable map of the currently indexed key-value pairs. + */ public Map map() { return Map.copyOf(map); } + /** + * Returns an unmodifiable inversed map (value to key) of the currently indexed key-value pairs. + */ public Map inverseMap() { return Map.copyOf(inverseMap); } From 1a200f9f69c44b9662766a9cd62faccc21d78529 Mon Sep 17 00:00:00 2001 From: Tobias Ortmayr Date: Thu, 29 Aug 2024 16:15:05 +0200 Subject: [PATCH 3/3] Address review feedback --- .../dependency-reduced-pom.xml | 156 ------------------ .../eclipse/glsp/layout/ElkLayoutEngine.java | 3 +- 2 files changed, 1 insertion(+), 158 deletions(-) delete mode 100644 examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml diff --git a/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml b/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml deleted file mode 100644 index b650b922..00000000 --- a/examples/org.eclipse.glsp.example.workflow/dependency-reduced-pom.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - org.eclipse.glsp.parent - org.eclipse.glsp - 2.3.0-SNAPSHOT - ../../pom.xml - - 4.0.0 - org.eclipse.glsp.example - org.eclipse.glsp.example.workflow - ${package-type} - GLSP Workflow Server - https://www.eclipse.org/glsp - - - Eclipse GLSP Project - glsp-dev@eclipse.org - Eclipse GLSP - https://projects.eclipse.org/projects/ecd.glsp - - - - - Eclipse Public License - v 2.0 - http://www.eclipse.org/legal/epl-v20.html - repo - - - - scm:git@github.com:eclipse-glsp/glsp-server.git - scm:git@github.com:eclipse-glsp/glsp-server.git - https://github.com/eclipse-glsp/glsp-server - - - - m2 - - - - maven-deploy-plugin - ${maven.deploy.version} - - false - - - - org.codehaus.mojo - build-helper-maven-plugin - ${buildhelper.maven.version} - - - add-resource - generate-resources - - add-resource - - - - - model - model - - - - - - - - - - jar - - - - fatjar - - - - maven-shade-plugin - ${maven.shade.version} - - - package - - shade - - - - - - - org.eclipse.glsp.example.workflow.launch.WorkflowServerLauncher - - true - - - - - - jakarta.websocket:jakarta.websocket-api - javax.websocket:javax.websocket-api - log4j:log4j - - - - - *:* - - META-INF/MANIFEST.MF - META-INF/DEPENDENCIES - META-INF/ECLIPSE_* - META-INF/LICENSE* - META-INF/services/javax.servlet.ServletContainerInitializer - META-INF/services/jakarta.servlet.ServletContainerInitializer* - META-INF/services/org.eclipse.jetty.webapp.Configuration* - META-INF/services/org.eclipse.elk.core.data.ILayoutMetaDataProvider* - META-INF/versions/9/module-info.class - META-INF/NOTICE* - .options - .api_description - *.profile - *.html - about.* - about_files/* - plugin.xml - modeling32.png - systembundle.properties - profile.list - module-info.class - plugin.properties - **/*._trace - **/*.g - **/*.tokens - **/*.mwe2 - **/*.xtext - **/*.xtextbin - META-INF/*.SF - META-INF/*.RSA - META-INF/*.INF - - - - true - glsp - false - - - - - - - - eclipse-plugin - - diff --git a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java index 5e349821..387ab2d4 100644 --- a/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java +++ b/plugins/org.eclipse.glsp.layout/src/org/eclipse/glsp/layout/ElkLayoutEngine.java @@ -273,8 +273,7 @@ protected void handleClientLayout(final GBoundsAware element, final GLayouting s */ protected void resolveReferences(final LayoutContext context) { // Per default a map will resize when 75% of its capacticy is filled. By dividing the expected size with the load - // factor - // we can create a map with enough capacity to avoid resizing + // factor we can create a map with enough capacity to avoid resizing int initialCapactiy = (int) Math.ceil(context.shapeMap.size() / 0.75); Map id2NodeMap = new HashMap<>(initialCapactiy);