Bug 510274 - DTD file loaded as semantic ressources
Summary: DTD file loaded as semantic ressources
Status: NEW
Alias: None
Product: Sirius
Classification: Modeling
Component: Diagram (show other bugs)
Version: 4.1.0   Edit
Hardware: PC Windows NT
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-01-11 09:55 EST by Julien Dupont CLA
Modified: 2017-01-13 09:27 EST (History)
3 users (show)

See Also:


Attachments
Description file (5.15 KB, application/zip)
2017-01-11 09:55 EST, Julien Dupont CLA
no flags Details
Test file (3.67 KB, application/zip)
2017-01-11 09:56 EST, Julien Dupont CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Dupont CLA 2017-01-11 09:55:51 EST
Created attachment 266249 [details]
Description file

When an xsd editor is installed in Sirius, Sirius try to loaded the DTD file as semantic resources.

Steps to reproduce:
- Install an xsd editor in Sirius (example Eclipse XML Editors and Tools 3.8.2 from the eclipse market place)
- Import the project my.project.design
- Launch a runtime and import project test. (This project contains à dtd file)
- Open the representation diagram.
- Remove the Modeling Project Nature
- Add the Modeling Project Nature 
- The representation is dirty. Save it.An popup appears "'Saving Models and Representation for project test' has encountered a problem." KO

If you try do repeat action with no xsd editor, there is no problem.
Comment 1 Julien Dupont CLA 2017-01-11 09:56:12 EST
Created attachment 266250 [details]
Test file
Comment 2 Laurent Fasani CLA 2017-01-12 11:39:17 EST
bug reproduced on OD 9.1.1
Comment 3 Pierre-Charles David CLA 2017-01-13 03:43:50 EST
(In reply to Laurent Fasani from comment #2)
> bug reproduced on OD 9.1.1

To clarify, this corresponds to Sirius 4.1 (probably 4.1.2).
Comment 4 Laurent Redor CLA 2017-01-13 08:51:15 EST
In org.eclipse.sirius.business.api.resource.LoadEMFResource.shouldBeAbleToLoad(),
the factory for dtd file is org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl (returned by set.getResourceFactoryRegistry().getFactory(uri, null).getClass()).
So org.eclipse.sirius.business.internal.resource.parser.XMIModelFileSaxParser is used to detect if it is loadable.

If the factory is another class, this is the case when "Eclipse XML Editors and Tools" are installed (factory used for dtd file is org.eclipse.wst.dtd.core.internal.emf.util.DTDResourceFactoryImpl), Sirius automatically considered the file as loadable.

The error during save in the initial description is:
java.lang.UnsupportedOperationException
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.doSave(ResourceImpl.java:1462)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
	at org.eclipse.sirius.business.internal.session.danalysis.ResourceSaveDiagnose.hasDifferentSerialization(ResourceSaveDiagnose.java:84)
	at org.eclipse.sirius.business.internal.session.IsModifiedSavingPolicy.hasDifferentSerialization(IsModifiedSavingPolicy.java:210)
	at org.eclipse.sirius.business.internal.session.IsModifiedSavingPolicy.computeResourcesToSave(IsModifiedSavingPolicy.java:191)
	at org.eclipse.sirius.business.api.session.AbstractSavingPolicy.save(AbstractSavingPolicy.java:57)
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl$1.run(DAnalysisSessionImpl.java:804)
	at org.eclipse.emf.transaction.impl.TransactionalEditingDomainImpl.runExclusive(TransactionalEditingDomainImpl.java:328)
	at org.eclipse.sirius.business.internal.session.danalysis.DAnalysisSessionImpl.doSave(DAnalysisSessionImpl.java:814)


I think there is a bug in "Eclipse XML Editors and Tools".
Without it, if you open the log4j.dtd with the "Sample Ecore Mode Editor", you have directly an error:
org.xml.sax.SAXParseException publicId: platform:/resource/Bbbbbbbb/log4j.dtd; systemId: platform:/resource/Bbbbbbbb/log4j.dtd; lineNumber: 9; columnNumber: 3; Le balisage du document précédant l'élément racine doit avoir un format correct.
With it, it is possible to open the file, you can modify it with the porperties view. But when you try to save it, you have an error similar to the Sirius error:
java.lang.UnsupportedOperationException
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.doSave(ResourceImpl.java:1462)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1430)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.saveOnlyIfChangedWithMemoryBuffer(ResourceImpl.java:1144)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:985)
	at org.eclipse.emf.ecore.presentation.EcoreEditor$15.execute(EcoreEditor.java:1669)
	at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:108)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
	at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:130)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
	
The method doSave of DTDResourceImpl is not overridden so at each save, an UnsupportedOperationException is thrown.
Comment 5 Laurent Redor CLA 2017-01-13 08:55:46 EST
Sample of my TP to add "Eclipse XML Editors and Tools" in my env dev: 
...
<location>
...
<unit id="org.eclipse.wst.xml_ui.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.wst.common_ui.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.wst.common_core.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.wst.xml_core.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.wst.xml_userdoc.feature.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xsd.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xsd.editor.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xsd.edit.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.emf.facet.common.source.feature.group" version="0.0.0"/>
<unit id="org.eclipse.xsd.sdk.feature.group" version="0.0.0"/>
<repository location="http://download.eclipse.org/releases/mars"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.wst.common.fproj.sdk.feature.group" version="0.0.0"/>
<repository location="http://download.eclipse.org/webtools/repository/mars/"/>
</location>
...
Comment 6 Laurent Redor CLA 2017-01-13 09:03:40 EST
From a Sirius point of view, there is no bug. Without "Eclipse XML Editors and Tools", the method LoadEMFResource.shouldBeAbleToLoad() answers false. With "Eclipse XML Editors and Tools", the method LoadEMFResource.shouldBeAbleToLoad() anwers true.
The problem is that the resource is loadable but NOT savable. This is currently not expected for Sirius.
Comment 7 Laurent Redor CLA 2017-01-13 09:27:17 EST
A solution would be to ignore resources with save problem during  IsModifiedSavingPolicy.computeResourcesToSave but there is no way to detect if some other saved resources will have references to these not "saved resources".