Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Error loading a resource file(A "Resource xxx does not exist" Exception occurs in PlatformResourceURIHandlerImpl)
Error loading a resource file [message #894761] Tue, 10 July 2012 12:32 Go to next message
Stefan Mertins is currently offline Stefan Mertins
Messages: 11
Registered: March 2012
Junior Member
Hello,

I work on a plugin JUnit Test (for a eclipse rcp). I need to load an external model file. To do so, I used example code form www.vogella.com/articles/EclipseEMFPersistence/article.html that shows how to load a file.

How ever, I always get an "org.eclipse.core.internal.resources.ResourceException: Resource '/home/sme/PSManager.ifg' does not exist." Exception thrown in PlatformResourceURIHandlerImpl.

My first atempts looked like this:
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("ifg", new XMIResourceFactoryImpl());

// Obtain a new resource set
ResourceSet resSet = new ResourceSetImpl();

//load the Resource
//URI ifgURI1 = URI.createURI(this.getClass().getResource(IFG_FILE).toURI().getPath());
URI ifgURI2 = URI.createURI(new File(IFG_FILE_ABSOLUT_PATH).getAbsolutePath());
Resource ifgResource = resSet.getResource(ifgURI2, true);


After checking the files and permissions double I moved on to check the Internet for solutions. I found a post (www.eclipsezone.com/eclipse/forums/t116946.rhtml) stating its an Linux problem (I also use a linux system) and can be fixed by setting up a project in the workspace for the file.

IWorkspace ws = ResourcesPlugin.getWorkspace();
IProject project = ws.getRoot().getProject("res");
if (!project.exists())
    project.create(null);
if (!project.isOpen())
    project.open(null);
IPath location = new Path(IFG_FILE_ABSOLUT_PATH);
IFile iFile = project.getFile(location.lastSegment());
iFile.createLink(location, IResource.NONE, null); 


But still the error remains. After a couple of other tries I decided to copy the portion of the Class PlatformResourceURIHandlerImpl that causes the crash into my code, to be able to debug better. It's the Method
 public static InputStream createPlatformResourceInputStream(String platformResourcePath, Map<?, ?> options) throws IOException 

Expecially the Part where the InputStream is created:
try{
    if (!file.isSynchronized(IResource.DEPTH_ONE)){ 
        file.refreshLocal(IResource.DEPTH_ONE, null);
    }
    InputStream result = file.getContents();
}
catch (Exception e){
    e.printStackTrace();
}


Guess what? The code runs just fine in my Class, but crashs in PlatformResourceURIHandlerImpl.

Anyone has a idea what I do wrong here or what I can do better?

Greetings
Stefan

Stack Trace:

org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/home/sme/git/probate/org.infai.probate.testplan.export.test/res/PSManager.ifg' does not exist.
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
at org.infai.probate.testplan.export.test.TestplanGeneratorTest.loadTestModel(TestplanGeneratorTest.java:101)
at org.infai.probate.testplan.export.test.TestplanGeneratorTest.createTestplanTest(TestplanGeneratorTest.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
at org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:54)
at org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:41)
at org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:48)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Re: Error loading a resource file [message #894797 is a reply to message #894761] Tue, 10 July 2012 14:40 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26046
Registered: July 2009
Senior Member
Stefan,

Comments below.
On 10/07/2012 2:32 PM, Stefan Mertins wrote:
> Hello,
>
> I work on a plugin JUnit Test (for a eclipse rcp). I need to load an
> external model file. To do so, I used example code form
> www.vogella.com/articles/EclipseEMFPersistence/article.html that shows
> how to load a file.
> How ever, I always get an
> "org.eclipse.core.internal.resources.ResourceException: Resource
> '/home/sme/PSManager.ifg' does not exist." Exception thrown in
> PlatformResourceURIHandlerImpl.
You can only use platform:/resource URIs if you have a workspace. If
you're dealing with files, you'll want a file: URI.
>
> My first atempts looked like this:
>
> Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
> Map<String, Object> m = reg.getExtensionToFactoryMap();
> m.put("ifg", new XMIResourceFactoryImpl());
>
> // Obtain a new resource set
> ResourceSet resSet = new ResourceSetImpl();
>
> //load the Resource
> //URI ifgURI1 =
> URI.createURI(this.getClass().getResource(IFG_FILE).toURI().getPath());
> URI ifgURI2 = URI.createURI(new
> File(IFG_FILE_ABSOLUT_PATH).getAbsolutePath());
> Resource ifgResource = resSet.getResource(ifgURI2, true);
You'll want createFileURI; a file system path is not a URI...
>
>
> After checking the files and permissions double I moved on to check
> the Internet for solutions. I found a post
> (www.eclipsezone.com/eclipse/forums/t116946.rhtml) stating its an
> Linux problem (I also use a linux system) and can be fixed by setting
> up a project in the workspace for the file.
>
>
> IWorkspace ws = ResourcesPlugin.getWorkspace();
> IProject project = ws.getRoot().getProject("res");
> if (!project.exists())
> project.create(null);
> if (!project.isOpen())
> project.open(null);
> IPath location = new Path(IFG_FILE_ABSOLUT_PATH);
> IFile iFile = project.getFile(location.lastSegment());
> iFile.createLink(location, IResource.NONE, null);
>
> But still the error remains. After a couple of other tries I decided
> to copy the portion of the Class PlatformResourceURIHandlerImpl that
> causes the crash into my code, to be able to debug better. It's the
> Method public static InputStream
> createPlatformResourceInputStream(String platformResourcePath, Map<?,
> ?> options) throws IOException Expecially the Part where the
> InputStream is created:
> try{
> if (!file.isSynchronized(IResource.DEPTH_ONE)){
> file.refreshLocal(IResource.DEPTH_ONE, null);
> }
> InputStream result = file.getContents();
> }
> catch (Exception e){
> e.printStackTrace();
> }
>
>
> Guess what? The code runs just fine in my Class, but crashs in
> PlatformResourceURIHandlerImpl.
>
> Anyone has a idea what I do wrong here or what I can do better?
>
> Greetings
> Stefan
>
> Stack Trace:
>
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
> org.eclipse.core.internal.resources.ResourceException: Resource
> '/home/sme/git/probate/org.infai.probate.testplan.export.test/res/PSManager.ifg'
> does not exist.
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
> at
> org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
> at
> org.infai.probate.testplan.export.test.TestplanGeneratorTest.loadTestModel(TestplanGeneratorTest.java:101)
> at
> org.infai.probate.testplan.export.test.TestplanGeneratorTest.createTestplanTest(TestplanGeneratorTest.java:42)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:62)
> at
> org.eclipse.pde.internal.junit.runtime.PlatformUITestHarness$1.run(PlatformUITestHarness.java:47)
> at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
> at
> org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
> at
> org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3563)
> at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3212)
> at
> org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
> at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
> at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
> at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
> at
> org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
> at
> org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
> at
> org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
> at
> org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
> at
> org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.runApp(NonUIThreadTestApplication.java:54)
> at
> org.eclipse.pde.internal.junit.runtime.UITestApplication.runApp(UITestApplication.java:41)
> at
> org.eclipse.pde.internal.junit.runtime.NonUIThreadTestApplication.start(NonUIThreadTestApplication.java:48)
> at
> org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
> at
> org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
> at
> org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:601)
> at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
> at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
> at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
> at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Previous Topic:Problem with images instead shapes
Next Topic:[EEF] Questions about 1_1 containment relation and EEF generation
Goto Forum:
  


Current Time: Tue Sep 16 13:36:32 GMT 2014

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

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