资源没有使用资源集

时间:2018-03-29 09:28:44

标签: java emf xtend eclipse-sphinx

我尝试使用资源获取输入文件的输入内容。我为此编写了以下代码

val resourceSet = new AutosarResourceSetImpl();

var uri = URI.createFileURI(inputfilepath); 

resource = resourceSet.getResource(uri,true)

resourceSet.resources.add(resource);

在这里,如果我将输入文件放在默认工作区以外的任何文件夹中,那么它正在工作。但是如果我将输入文件放在Workspace文件夹中(默认情况下它每次都在创建),我会得到以下异常。

!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 个答案:

答案 0 :(得分:1)

您的代码使用特殊的sphinx代码,这可能会在org.eclipse.sphinx.emf.util.EcorePlatformUtil.getFile中产生一些魔力,具体取决于您获得的URL类型。它调用WorkspaceSynchronizer.getFile表示它需要platform-resource URI

因此,正如错误消息所示,您的网址/inputfile.arxml未遵循该方案。您需要向URL添加更多特定的工作空间相关信息,例如遵循上述平台-URI架构的插件或资源,如

platform:/plugin/org.eclipse.mybundle/inputfile.arxml 

答案 1 :(得分:1)

阅读异常,问题可能来自您表达URI的方式。

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

如果你想使用文件URI,就像你的例子一样,你应该有:

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

您应该查看URI类的各种create方法,以便为您选择最相关的方法。

顺便说一下,在从resourceSet获取资源后,您不需要在resourceSet中添加资源...

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