Skip to content

Commit

Permalink
Updates duplicate notification handling with latest VIATRA features #26
Browse files Browse the repository at this point in the history
This change rewrites MagicDrawProjectNavigationHelper to rely on the
latest VIATRA features to cleanly suppress duplicate notification
errors.

Note: to test out the changes, we have to deploy a SNAPSHOT build to Nexus; this build temporarily relies on VIATRA v2.3.0-SNAPSHOT instead of 2.2.0/2.2.1; before this is fixed we should not create any release for V4MD.
  • Loading branch information
ujhelyiz committed Aug 23, 2019
1 parent 514176a commit e2dc6c4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 71 deletions.
4 changes: 2 additions & 2 deletions com.incquerylabs.v4md/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version=2.2.1-SNAPSHOT
buildNumber=221010
group=com.incquerylabs.v4md
viatraVersion=2.2.0
viatraIncubationVersion=0.22.0
viatraVersion=2.3.0-SNAPSHOT
viatraIncubationVersion=0.23.0-SNAPSHOT
deployUrl = "build/maven-repository"
xtextVersion=2.18.0
deployReleaseUrl=https://build.incquerylabs.com/nexus/repository/v4md-releases/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void modelSetUpdated() {
Set<Notifier> customNotifiers = scope.getCustomNotifiers().collect(Collectors.toSet());
Set<Notifier> projectRoots = scope.getProjectModels().collect(Collectors.toSet());
MagicDrawProjectNavigationHelper navigationHelper = getNavHelper(true);
Set<Notifier> actualModelRoots = navigationHelper.getModelRoots();
Set<Notifier> actualModelRoots = navigationHelper.getModelRoots().collect(Collectors.toSet());

Set<Notifier> rootsToAdd = Sets.difference(projectRoots, actualModelRoots);
Set<Notifier> rootsToRemove = Sets.difference(Sets.difference(actualModelRoots, projectRoots), customNotifiers);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package com.incquerylabs.v4md.internal;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.log4j.Logger;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.viatra.query.runtime.base.api.BaseIndexOptions;
import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexObjectFilter;
import org.eclipse.viatra.query.runtime.base.api.filters.IBaseIndexResourceFilter;
import org.eclipse.viatra.query.runtime.base.core.NavigationHelperContentAdapter;
import org.eclipse.viatra.query.runtime.base.core.NavigationHelperImpl;
import org.eclipse.viatra.query.runtime.base.exception.ViatraBaseException;

import com.nomagic.uml2.ext.jmi.EventSupport;

Expand All @@ -26,33 +18,8 @@
*/
public class MagicDrawProjectNavigationHelper extends NavigationHelperImpl {

/**
* TODO this logger wrapping is a very hacky solution, but until bug
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=549955 is fixed, it is not
* possible to overwrite the message any other way
*/
private static final class WrappedLogger extends Logger {
private WrappedLogger(Logger source) {
super(source.getName());
parent = source;
repository = source.getLoggerRepository();
}

@Override
public void error(Object message) {
if (message instanceof String && ((String)message).contains("This indicates some errors in underlying model representation.")) {
super.debug(message);
} else {
super.error(message);
}
}
}

private Logger logger;

public MagicDrawProjectNavigationHelper(Notifier emfRoot, BaseIndexOptions options, EventSupport eventSupport, Logger logger) {
super(emfRoot, options, new WrappedLogger(logger));
this.logger = logger;
super(emfRoot, options, logger);
// TODO While this change helps avoiding some duplicate notifications, it causes
// a regression when adding a new project usage to a local project: when the
// usage is added, event firing is turned off, resulting in the added profile
Expand All @@ -69,44 +36,50 @@ public MagicDrawProjectNavigationHelper(Notifier emfRoot, BaseIndexOptions optio
// };
}

Set<Notifier> getModelRoots() {
return modelRoots;
}

public boolean isIndexed(EObject element) {
return EcoreUtil.isAncestor(modelRoots, element);
return EcoreUtil.isAncestor(getModelRoots().collect(Collectors.toSet()), element);
}

@Override
public Stream<Notifier> getModelRoots() {
// Override is used to update visibility
return super.getModelRoots();
}

@Override
public void removeRoot(Notifier root) {
if (!((root instanceof EObject) || (root instanceof Resource) || (root instanceof ResourceSet))) {
throw new ViatraBaseException(ViatraBaseException.INVALID_EMFROOT);
}

if (!modelRoots.contains(root))
return;
// Override is used to update visibility
super.removeRoot(root);
}

if (root instanceof Resource) {
IBaseIndexResourceFilter resourceFilter = getBaseIndexOptions().getResourceFilterConfiguration();
if (resourceFilter != null && resourceFilter.isResourceFiltered((Resource) root))
return;
}
final IBaseIndexObjectFilter objectFilter = getBaseIndexOptions().getObjectFilterConfiguration();
if (objectFilter != null && objectFilter.isFiltered(root))
return;
@Override
protected void logIncidentAdapterRemoval(Notifier notifier) {
// Do not report such cases in MagicDraw
}

// no veto by filters
modelRoots.remove(root);
// TODO contentAdapter.removeAdapter(root); removeAdapter is not visible here
Method method;
try {
method = contentAdapter.getClass().getMethod("removeAdaper", Notifier.class);
method.setAccessible(true);
method.invoke(contentAdapter, root);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
logger.fatal("Error while updating project", e);
}
notifyBaseIndexChangeListeners();
@Override
protected void logIncidentFeatureTupleInsertion(Object value, EObject holder, Object featureKey) {
// Do not report such cases in MagicDraw
}

@Override
protected void logIncidentFeatureTupleRemoval(Object value, EObject holder, Object featureKey) {
// Do not report such cases in MagicDraw
}

@Override
protected void logIncidentInstanceInsertion(Object keyClass, EObject value) {
// Do not report such cases in MagicDraw
}

@Override
protected void logIncidentInstanceRemoval(Object keyClass, EObject value) {
// Do not report such cases in MagicDraw
}

@Override
protected void logIncidentStatRemoval(Object key) {
// Do not report such cases in MagicDraw
}


}

0 comments on commit e2dc6c4

Please sign in to comment.