XML Persistence Example does not reload the model after save in Windows

Hi,

I have followed the steps outline in https://confluence.jetbrains.com/display/MPSD30/Custom+Persistence+Cookbook
to persist model in xml. I can see the model was saved in .xml but while reloading I am getting a ModelOpen Error saying relPath is Null.Below is the code snippet which causes that
@NotNull() 
@Override 
public SModel load(@NotNull() DataSource dataSource, @NotNull() Map<String, String> options) throws IOException { 
  if (!((dataSource instanceof StreamDataSource))) { throw new UnsupportedDataSourceException(dataSource); } 
  String moduleRef = options.get(ModelFactory.OPTION_MODULEREF); 
  String relPath = options.get(ModelFactory.OPTION_RELPATH); 
  String modelName = options.get(ModelFactory.OPTION_MODELNAME); 
  boolean contentOnly = "true".equals(options.get(ModelFactory.OPTION_CONTENT_ONLY)); 
  SModelReference ref; 
  if (relPath == null || moduleRef == null || modelName == null) { 
    if (!(contentOnly)) { 
      if (dataSource instanceof FileDataSource) { 
        LOG.error("cannot load " + dataSource.getLocation() + ": relPath = " + relPath, new Throwable()); 
      } 
      throw new IOException("cannot load xml model from " + dataSource.getLocation()); 
    } 
    ref = PersistenceFacade.getInstance().createModelReference(null, SModelId.generate(), "temp"); 
  } else { 
    SModelId id = PersistenceFacade.getInstance().createModelId("path:" + relPath); 
    SModuleReference mref = PersistenceFacade.getInstance().createModuleReference(moduleRef); 
    if (mref == null) { 
      // TODO fix 
      return null; 
    } 
    ref = PersistenceFacade.getInstance().createModelReference(mref, id, modelName); 
  } 
  return new CustomPersistenceSModel(ref, (StreamDataSource) dataSource, this); 
}
prettyPrint();

Any suggestions?

Thanks
10 comments
Comment actions Permalink
Hi!

Can you please explain your problem a bit more detailed?
  • are you getting exception in the console/log file? (then please post exception trace here)
  • are you getting message: "cannot load ...: relPath = null"?

How do you create this model? I've just tried to run custom XML persistence sample packages as a part of MPS 3.2 RC2 and it works without any pr0blem...
0
Comment actions Permalink
Hi Alex,

Thanks for the Reply. I tried with MPS 3.2 RC and created a sample model and it got created. When I try to reopen the same model after closing the IDE, I got below Exception.
cannot load IdeaFile{file://C:/Users/Administrator/MPSProjects/Project1/solutions/test/models/pp.xml}: relPath = null
and Below is stack trace from log file:
roject 'Project1' opened 
2015-03-10 15:46:25,384 [ 297436]   INFO - jetbrains.mps.project.StandaloneMPSProject - Initializing project 
2015-03-10 15:46:25,384 [ 297436]   INFO - jetbrains.mps.project.StandaloneMPSProject - Reading modules 
2015-03-10 15:46:25,390 [ 297442]  ERROR - jetbrains.mps.persistence.XmlModelPersistence - cannot load IdeaFile{file://C:/Users/Administrator/MPSProjects/Project1/solutions/test/models/pp.xml}: relPath = null 
java.lang.Throwable
    at jetbrains.mps.persistence.XmlModelPersistence.load(Unknown Source)
    at jetbrains.mps.persistence.DefaultModelRoot.collectModels(DefaultModelRoot.java:169)
    at jetbrains.mps.persistence.DefaultModelRoot.loadModels(DefaultModelRoot.java:84)
    at jetbrains.mps.extapi.persistence.ModelRootBase.update(ModelRootBase.java:135)
    at jetbrains.mps.extapi.persistence.ModelRootBase.attach(ModelRootBase.java:81)
    at jetbrains.mps.extapi.persistence.FileBasedModelRoot.attach(FileBasedModelRoot.java:178)
    at jetbrains.mps.project.AbstractModule.doUpdateModelsSet(AbstractModule.java:790)
    at jetbrains.mps.project.AbstractModule.updateModelsSet(AbstractModule.java:734)
    at jetbrains.mps.project.Solution.updateModelsSet(Solution.java:128)
    at jetbrains.mps.project.AbstractModule.initFacetsAndModels(AbstractModule.java:545)
    at jetbrains.mps.project.AbstractModule.attach(AbstractModule.java:662)
    at jetbrains.mps.smodel.MPSModuleRepository.registerModule(MPSModuleRepository.java:138)
    at jetbrains.mps.smodel.ModuleRepositoryFacade.registerModule(ModuleRepositoryFacade.java:202)
    at jetbrains.mps.smodel.ModuleRepositoryFacade.newSolutionInstance(ModuleRepositoryFacade.java:191)
    at jetbrains.mps.smodel.ModuleRepositoryFacade.createModule(ModuleRepositoryFacade.java:165)
    at jetbrains.mps.project.StandaloneMPSProject.readModules(StandaloneMPSProject.java:228)
    at jetbrains.mps.project.StandaloneMPSProject$3.run(StandaloneMPSProject.java:176)
    at jetbrains.mps.smodel.WriteActionDispatcher.run(WriteActionDispatcher.java:39)
    at jetbrains.mps.ide.smodel.WorkbenchModelAccess$3.run(WorkbenchModelAccess.java:155)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:977)
    at jetbrains.mps.ide.smodel.WorkbenchModelAccess.runWriteAction(WorkbenchModelAccess.java:164)
    at jetbrains.mps.smodel.ModelAccessBase.runWriteAction(ModelAccessBase.java:62)
    at jetbrains.mps.project.StandaloneMPSProject.init(StandaloneMPSProject.java:171)
    at jetbrains.mps.project.StandaloneMPSProject.initProject(StandaloneMPSProject.java:159)
    at jetbrains.mps.project.StandaloneMPSProject.projectOpened(StandaloneMPSProject.java:143)
    at com.intellij.openapi.project.impl.ProjectImpl.projectOpened(ProjectImpl.java:421)
    at com.intellij.openapi.project.impl.ProjectImpl.access$200(ProjectImpl.java:75)
    at com.intellij.openapi.project.impl.ProjectImpl$MyProjectManagerListener.projectOpened(ProjectImpl.java:456)
    at com.intellij.openapi.project.impl.ProjectManagerImpl$3.projectOpened(ProjectManagerImpl.java:157)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.fireProjectOpened(ProjectManagerImpl.java:930)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.openProject(ProjectManagerImpl.java:442)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.loadAndOpenProject(ProjectManagerImpl.java:544)
    at com.intellij.ide.impl.ProjectUtil.openProject(ProjectUtil.java:181)
    at jetbrains.mps.workbench.recent.RecentMPSProjectsManager.doOpenProject(RecentMPSProjectsManager.java:54)
    at com.intellij.ide.ReopenProjectAction.actionPerformed(ReopenProjectAction.java:61)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performActionDumbAware(ActionUtil.java:164)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter$1.run(ActionMenuItem.java:266)
    at com.intellij.openapi.wm.impl.FocusManagerImpl.runOnOwnContext(FocusManagerImpl.java:926)
    at com.intellij.openapi.wm.impl.IdeFocusManagerImpl.runOnOwnContext(IdeFocusManagerImpl.java:124)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem$ActionTransmitter.actionPerformed(ActionMenuItem.java:236)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at com.intellij.openapi.actionSystem.impl.ActionMenuItem.fireActionPerformed(ActionMenuItem.java:105)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.doClick(BegMenuItemUI.java:512)
    at com.intellij.ui.plaf.beg.BegMenuItemUI.access$300(BegMenuItemUI.java:44)
    at com.intellij.ui.plaf.beg.BegMenuItemUI$MyMouseInputHandler.mouseReleased(BegMenuItemUI.java:532)
    at java.awt.Component.processMouseEvent(Component.java:6516)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
    at java.awt.Component.processEvent(Component.java:6281)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4872)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4698)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:748)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:573)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:384)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

prettyPrint();
0
Comment actions Permalink
Hi!

It looks like you have somehow corrupted solution you are working with. I was not able to reproduce this problem.. Can you please share your project with me (if it's not too big)?
0
Comment actions Permalink
Hi Alex,

Pfa project for your reference.
Project1.zip (7.1KB)

Thanks
0
Comment actions Permalink
Hi!

I can properly load attached project into MPS 3.2 (build 139.1988) with SampleXmlPersistence plugin installed...
Looks like something is wrong in your local copy of SampleXmlPersistence project. I can suggest you to try reinstalling SampleXmlPersistence sample, re-deploy corresponding plugin and reopen this project.
0
Comment actions Permalink
Hi Alex,

I deleted all MPS folders and uninstalled MPS and installed the same version of MPS ie MPS3.2(build 139.1988). I ran on two separate machines with Windows 8 and for both machines , I got same error after reloading the model created by sample persistence plugin.
cannot load IdeaFile{file://C:/MPS-Projects/solutions/test/models/sample.xml}: relPath = null 
java.lang.Throwable
    at jetbrains.mps.persistence.XmlModelPersistence.load(Unknown Source)
    at jetbrains.mps.persistence.DefaultModelRoot.collectModels(DefaultModelRoot.java:169)
    at jetbrains.mps.persistence.DefaultModelRoot.loadModels(DefaultModelRoot.java:84)
    at jetbrains.mps.extapi.persistence.ModelRootBase.update(ModelRootBase.java:135)
    at jetbrains.mps.extapi.persistence.ModelRootBase.attach(ModelRootBase.java:81)
......
prettyPrint();

Is there any kind of per-requisite or steps to be followed. I am not sure why I am getting relPath=null.

Thanks
Kunal
0
Comment actions Permalink
Hi Alex,
Update - I tried the same in Mac and it worked fine.Not sure why in Windows I am getting relPath=null. Any idea/suggestions?

I tried with Win7 machine and still I got same exception. Please find the attached screenshot.
xmltest.png
0
Comment actions Permalink
Hi Kunal,

indeed, this looks like a problem in MPS that only shows up on Windows (https://youtrack.jetbrains.com/issue/MPS-21671). We've identified the cause and are working on a fix.
Thank you for finding this out.

Vaclav
0
Comment actions Permalink
As a workaround for now you can try writing something like:

if (relPath == null) { 
  relPath = dataSource.getLocation();
}
prettyPrint();
0
Comment actions Permalink
okay... great
Thanks
0

Please sign in to leave a comment.