Resource is not getting using resourceset

484 Views Asked by At

I tried to fetch the input contents of the input file using the resource.I wrote the below code for that

val resourceSet = new AutosarResourceSetImpl();

var uri = URI.createFileURI(inputfilepath); 

resource = resourceSet.getResource(uri,true)

resourceSet.resources.add(resource);

Here, If I place my input files in any folder other than default workspace it's working.But if I place the input file in Workspace folder(By default it's creating every time) the following exception I am getting.

!MESSAGE IllegalArgumentException occurred when invoking code from plug-in "org.eclipse.sphinx.emf": Path must include project and resource name: /inputfile.arxml.
!STACK 0
java.lang.IllegalArgumentException: Path must include project and resource name: /inputfile.arxml
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2074)
    at org.eclipse.core.internal.resources.Container.getFile(Container.java:193)
    at org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(WorkspaceSynchronizer.java:344)
    at org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(WorkspaceSynchronizer.java:273)
    at org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile(EcorePlatformUtil.java:916)
    at org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile(EcorePlatformUtil.java:902)
    at org.eclipse.sphinx.emf.resource.SphinxManagedModelFileContentHandlerImpl.canHandle(SphinxManagedModelFileContentHandlerImpl.java:55)
    at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.contentDescription(URIHandlerImpl.java:280)
    at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.contentDescription(ExtensibleURIConverterImpl.java:372)
    at org.eclipse.sphinx.emf.util.EcoreResourceUtil.getContentTypeId(EcoreResourceUtil.java:333)
    at org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.demandCreateResource(ExtendedResourceSetImpl.java:290)
    at org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.getResource(ExtendedResourceSetImpl.java:264)
    at com.avin.ecuc.gautosar.codegen.xtend.headless.BswCodeGenApplication.bswSearchBswModel(BswCodeGenApplication.java:127)
    at com.avin.ecuc.gautosar.codegen.xtend.headless.BswCodeGenApplication.interrogate(BswCodeGenApplication.java:684)
    at org.eclipse.sphinx.platform.cli.AbstractCLIApplication.doRun(AbstractCLIApplication.java:224)
    at org.eclipse.sphinx.platform.cli.AbstractCLIApplication.start(AbstractCLIApplication.java:182)
    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)
!SUBENTRY 1 org.eclipse.sphinx.emf 4 0 2018-03-29 14:55:36.615
!MESSAGE Path must include project and resource name: /inputfile.arxml
!STACK 0
java.lang.IllegalArgumentException: Path must include project and resource name: /inputfile.arxml
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2074)
    at org.eclipse.core.internal.resources.Container.getFile(Container.java:193)
    at org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(WorkspaceSynchronizer.java:344)
    at org.eclipse.emf.workspace.util.WorkspaceSynchronizer.getFile(WorkspaceSynchronizer.java:273)
    at org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile(EcorePlatformUtil.java:916)
    at org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile(EcorePlatformUtil.java:902)
    at org.eclipse.sphinx.emf.resource.SphinxManagedModelFileContentHandlerImpl.canHandle(SphinxManagedModelFileContentHandlerImpl.java:55)
    at org.eclipse.emf.ecore.resource.impl.URIHandlerImpl.contentDescription(URIHandlerImpl.java:280)
    at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.contentDescription(ExtensibleURIConverterImpl.java:372)
    at org.eclipse.sphinx.emf.util.EcoreResourceUtil.getContentTypeId(EcoreResourceUtil.java:333)
    at org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.demandCreateResource(ExtendedResourceSetImpl.java:290)
    at org.eclipse.sphinx.emf.resource.ExtendedResourceSetImpl.getResource(ExtendedResourceSetImpl.java:264)
    at com.avin.ecuc.gautosar.codegen.xtend.headless.BswCodeGenApplication.bswSearchBswModel(BswCodeGenApplication.java:127)
    at com.avin.ecuc.gautosar.codegen.xtend.headless.BswCodeGenApplication.interrogate(BswCodeGenApplication.java:684)
    at org.eclipse.sphinx.platform.cli.AbstractCLIApplication.doRun(AbstractCLIApplication.java:224)
    at org.eclipse.sphinx.platform.cli.AbstractCLIApplication.start(AbstractCLIApplication.java:182)
    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)
2

There are 2 best solutions below

0
Hauke On

Your code uses special sphinx code, which might do some magic in org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile depending what type of URL you get. It calls WorkspaceSynchronizer.getFile which states that it requires a platform-resource URI.

So as the error message suggests, your URL /inputfile.arxml does not follow the scheme. You need to add more specific workspace-related information to the URL, like the plugin or resource following the aforementioned platform-URI schema like

platform:/plugin/org.eclipse.mybundle/inputfile.arxml 
0
Romain Bernard On

Reading the exception, the problem probably comes from the way you express the URI.

java.lang.IllegalArgumentException: Path must include project and resource name: /inputfile.arxml

If you want to use a File URI, as in your example, you should have something like:

var uri = URI.createFileURI("c:/path/to/inputfile.arxml");

You should have a look at the various create methods of the URI class to choose the most relevant for you.

Btw, you don't need to add your resource inside the resourceSet after getting the resource from the resourceSet...

    resource = resourceSet.getResource(uri,true)
    //resourceSet.resources.add(resource);