Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Edapt] DiagnosticException while migrating
[Edapt] DiagnosticException while migrating [message #1767030] Thu, 29 June 2017 17:21 Go to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 185
Registered: July 2009
Senior Member
Hi all,

I am looking for help to sovle a DiagnosticException while migrating the first time my existing ecode model files to a new version.

I had already an ecore model before starting with edapt. I need to change my ecore model and would like to use edapt to automatic migrate from the existing ecore model to the new model.

Following the documentation I need to create a initial "history" from the existing model, then do my modification and create a release. All I have done but when I invoke the migration code I get a DiagnosticException which I can not interpret.

org.eclipse.emf.edapt.migration.MigrationException: org.eclipse.emf.edapt.internal.migration.DiagnosticException: Model inconsistent
The 'validContainment' constraint is violated on 'Instance of type "Railml"'
The 'validContainment' constraint is violated on 'Instance of type "EStringToStringMapEntry"'
The 'validContainment' constraint is violated on 'Instance of type "EStringToStringMapEntry"'


My ecore model was generated from a xsd and has a DocumentRoot class, I belive it has some thing todo with it but cant figure out what to do.

index.php/fa/29820/0/

Attached you can find the ecore and history file as well as the file I need to upgrade.

Any help is appreciated!

Martin

PS: I am using Eclipse 4.6 IDE with edapt record feature 1.2.2 while my target edapt version is still 1.2.1

[Updated on: Fri, 30 June 2017 14:06]

Report message to a moderator

Re: [Edapt] DiagnosticException while migrating [message #1767077 is a reply to message #1767030] Fri, 30 June 2017 12:23 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 70
Registered: December 2013
Member
Hi,

The screenshot shows that there is also a second .ecore involved. When creating the initial history for opnengine.ecore the Edapt tooling should ask you if you want track valuetable.ecore as well. Please do so and try the migration again.
If this does not help, could you share the second ecore as well? Otherwise I can't try this.

Kind regards
Johannes


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] DiagnosticException while migrating [message #1767087 is a reply to message #1767077] Fri, 30 June 2017 14:20 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 185
Registered: July 2009
Senior Member
Hi Johannes,

thanks for your feedback. The migration fails also in case of the included history of valuetable.ecore.
I added the valuetable.ecore and valuetable.genmodel is attached to this post

In the meantime I was further investigating. I belive the main issue is the DocumentRoot Object is expected as root element of the resource set. This is tested in
org.eclipse.emf.edapt.spi.migration.util.MigrationValidator::validate_validContainment(Instance instance)

		if (instance.isProxy()) {
			return true;
		}

		// number of instances in which the instance is contained
		int container = 0;
		for (final ReferenceSlot referenceSlot : instance.getReferences()) {
			if (referenceSlot.getEReference().isContainment()) {
				container++;
			}
		}
		// number of resources of which the instance is a root element
		int resources = 0;
		final Model model = instance.getType().getModel();
		for (final ModelResource modelResource : model.getResources()) {
			if (modelResource.getRootInstances().contains(instance)) {
				resources++;
			}
		}

		final boolean valid = container == 1 && resources <= 1 || resources == 1 && container <= 1;
		return valid;


Our XML document root XML-Element is <railml> and not <DocumentRoot>.

Does this makes sense to you?
Re: [Edapt] DiagnosticException while migrating [message #1767183 is a reply to message #1767087] Mon, 03 July 2017 09:53 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 70
Registered: December 2013
Member
Hi,

thanks for the additional files. I managed to get a bit further, however I can still not reproduce your issue.
Loading of your provided file fails for me, because the rollingstockID feature can't be found. I can't see references in the ecore or history as well.
Probably there is custom stuff going on with the serialization?

Just as a hint, it is possible to provide the right resource/resourceset for loading the file with the
org.eclipse.emf.edapt.migration.execution.Migrator.setResourceSetFactory(IResourceSetFactory)
method.

Currently I can't see why not being contained in a DocumentRoot could cause this. Unless a document root is somehow created on the run by custom de/serialization code. Maybe a runnable example would help.

In the code you posted, it would be interesting to know why it is not valid, so how many containers/resources are there? What and how many root instances are there?

Regards
Johannes


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] DiagnosticException while migrating [message #1767196 is a reply to message #1767183] Mon, 03 July 2017 12:54 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 185
Registered: July 2009
Senior Member
Hi Johannes,

thanks for your feedback.

Oh yah there are some additional attribues from an much earlier implementation. These are ignored by seeting XMLResource.OPTION_RECORD_UNKNOWN_FEATUR to true

package de.bahntechnik.dd.opn.engine.util;

    /**
     * Creates an instance of the resource. <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * 
     * @generated NOT
     */
    @Override
    public Resource createResource(URI uri) {
        XMLResource result = (XMLResource) createResourceGen(uri);

        result.getDefaultSaveOptions()
                .put(XMLResource.OPTION_KEEP_DEFAULT_CONTENT, Boolean.TRUE);
        result.getDefaultLoadOptions()
                .put(XMLResource.OPTION_RECORD_UNKNOWN_FEATURE, Boolean.TRUE);

        return result;
    }

    /**
     * Creates an instance of the resource. <!-- begin-user-doc --> <!--
     * end-user-doc -->
     * 
     * @generated
     */
    public Resource createResourceGen(URI uri) {
        XMLResource result = new OpnengineResourceImpl(uri);
        result.getDefaultSaveOptions()
                .put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
        result.getDefaultLoadOptions()
                .put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);

        result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION,
                Boolean.TRUE);

        result.getDefaultLoadOptions().put(
                XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
        result.getDefaultSaveOptions().put(
                XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);

        result.getDefaultLoadOptions()
                .put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
        return result;
    }



Regarding the validate_validContainment.

instance is "Instance of Railml"
container == 0
resources == 0

final boolean valid = container == 1 && resources <= 1 || resources == 1 && container <= 1;


I belive this is because the root of the EMF model is DocumentRoot and the root of the XML is <railml>.

We do not use a own ResourceSetFactory or ResourceSet implementation.

We currently try to remove the DocumentRoot from our EMF model but this is not jet finished. As we need to make sure we still can read existing files withour problem.
thanks for your thoughts, Martin
Re: [Edapt] DiagnosticException while migrating [message #1767267 is a reply to message #1767196] Tue, 04 July 2017 11:39 Go to previous messageGo to next message
Johannes Faltermeier is currently offline Johannes FaltermeierFriend
Messages: 70
Registered: December 2013
Member
Hi Martin,

this works and now I get it. The XMLResource itself is creating the DocumentRoot and thus is causing the problem. So yes, you are right.

You can suppress this with
resource.getDefaultLoadOptions().put(XMIResource.OPTION_SUPPRESS_DOCUMENT_ROOT, Boolean.TRUE);

If you can't add this to your actuall Resource(Factory)Implementation you can use above mentioned #setResourceSetFactory method to use a slightly adjusted resource factory.

migrator.setResourceSetFactory(new IResourceSetFactory() {
	@Override
	public ResourceSet createResourceSet() {
		MyCustomResourceSetFactoryForMigrytion factory = new MyCustomResourceSetFactoryForMigrytion(); //this add the additional load option
		ResourceSetImpl resourceSetImpl = new ResourceSetImpl();
		resourceSetImpl.getResourceFactoryRegistry().getExtensionToFactoryMap().put("*", factory);
		return resourceSetImpl;
	}
});


Hope this helps
Johannes


Johannes Faltermeier

Get professional Eclipse developer support:
http://eclipsesource.com/en/services/developer-support/
Re: [Edapt] DiagnosticException while migrating [message #1767287 is a reply to message #1767267] Tue, 04 July 2017 13:06 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 185
Registered: July 2009
Senior Member
Hi Johannes,

I have set the load option
resource.getDefaultLoadOptions().put(XMIResource.OPTION_SUPPRESS_DOCUMENT_ROOT, Boolean.TRUE);


but got a NPE during migration.

java.lang.NullPointerException
	at org.eclipse.emf.edapt.internal.migration.internal.MaterializingBackwardConverter.resolveEClassifier(MaterializingBackwardConverter.java:36)
	at org.eclipse.emf.edapt.internal.migration.internal.MaterializingBackwardConverter.resolveEClass(MaterializingBackwardConverter.java:28)
	at org.eclipse.emf.edapt.internal.migration.internal.BackwardConverter.createObjects(BackwardConverter.java:79)
	at org.eclipse.emf.edapt.internal.migration.internal.BackwardConverter.initObjects(BackwardConverter.java:72)
	at org.eclipse.emf.edapt.internal.migration.internal.BackwardConverter.convert(BackwardConverter.java:61)
	at org.eclipse.emf.edapt.migration.execution.Migrator.migrateAndLoad(Migrator.java:223)
	at de.bahntechnik.dd.opn.engine.presentation.OpnengineEditor$14.run(OpnengineEditor.java:1987)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:437)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:353)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:481)
	at de.bahntechnik.dd.opn.engine.presentation.OpnengineEditor.performMigration(OpnengineEditor.java:2002)
	at de.bahntechnik.dd.opn.engine.presentation.OpnengineEditor.checkMigration(OpnengineEditor.java:1969)
	at de.bahntechnik.dd.opn.engine.presentation.OpnengineEditor.createModel(OpnengineEditor.java:963)
	at de.bahntechnik.dd.opn.engine.presentation.OpnengineEditor.createPages(OpnengineEditor.java:1051)
	at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:363)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:150)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:99)
	at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:340)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:55)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:966)
	at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:931)
	at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:151)
	at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:375)
	at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:294)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:105)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:74)
	at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:56)
	at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:975)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:651)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:757)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$0(PartRenderingEngine.java:728)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:722)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:706)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:104)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:40)
	at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:233)
	at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:145)
	at org.eclipse.swt.widgets.Display.syncExec(Display.java:4821)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:211)
	at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:36)
	at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:201)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
	at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
	at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
	at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
	at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
	at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
	at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:94)
	at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:60)
	at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
	at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:173)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:617)
	at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:581)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:770)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:401)
	at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1214)
	at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3261)
	at org.eclipse.ui.internal.WorkbenchPage.access$25(WorkbenchPage.java:3176)
	at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:3158)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3153)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3117)
	at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3107)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:563)
	at org.eclipse.ui.ide.IDE.openEditor(IDE.java:518)
	at org.eclipse.ui.actions.OpenFileAction.openFile(OpenFileAction.java:100)
	at org.eclipse.ui.actions.OpenSystemEditorAction.run(OpenSystemEditorAction.java:97)
	at org.eclipse.ui.actions.RetargetAction.run(RetargetAction.java:225)
	at org.eclipse.ui.navigator.CommonNavigatorManager$2.open(CommonNavigatorManager.java:191)
	at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:46)
	at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:855)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
	at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:852)
	at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1169)
	at org.eclipse.ui.navigator.CommonViewer.handleOpen(CommonViewer.java:451)
	at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:278)
	at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:272)
	at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:313)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4418)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4236)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3824)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:693)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:610)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1492)


Any idea how to solve this?

I have not yet tried to set the ResourceSetFactoryForMigration ....
Re: [Edapt] DiagnosticException while migrating [message #1767295 is a reply to message #1767287] Tue, 04 July 2017 13:41 Go to previous message
Martin Jacob is currently offline Martin JacobFriend
Messages: 185
Registered: July 2009
Senior Member
Hi Johannes,

it was my fault. After regenerating the EMF code all works well!

Thank you very much for your help, Martin

[Updated on: Tue, 04 July 2017 14:42]

Report message to a moderator

Previous Topic:Distinguishing "logical" Ecore elements from additional "technical" ones
Next Topic:StackOverflowError on EPackageRegistryImpl
Goto Forum:
  


Current Time: Fri Nov 17 17:48:27 GMT 2017

Powered by FUDForum. Page generated in 0.02810 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software