Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problems with Cross-Reference resolving in standalone app
Problems with Cross-Reference resolving in standalone app [message #1009137] Thu, 14 February 2013 14:17 Go to next message
Marcin Mozdyniewicz is currently offline Marcin MozdyniewiczFriend
Messages: 5
Registered: February 2013
Junior Member
Hi All,

I've got such a case.
In our project, we use xText defined language for configuration purposes.
There's a Declaration part in separate file (i.e. declaration.mydsl) and a bunch of configuration files (one for every instance of our app - so, *.mydsl) tied with declaration by import clause (
Import platform:/resource/xxx/declaration.mydsl
)
So far it was used only in Eclipse environment in a traditional way (editor stuff, eclipse plugins stuff and so on).
Now, my task is to gather all separate config files via standalone java app (.jar file with arguments configured in CI) and print out a report or so.

The problem I've encountered is that when I iterate through the elements of config files, the names and values defined in declaration file are not being resolved (I'm getting nulls).
Now that is quite obvious, because platform: URI pattern is not available outside Eclipse-Env.
When I've changed import clause to
Import file:/hardcoded/path/to/declaration.mydsl
it is working fine.

Ok, so finally to the point. My question is, how can I make it work in both worlds (Standalone vs. Eclipse) not to break resolving mechanism in any?

I've read quite a few posts on the forum, but any gave my good direction.
I've also read an article about "Xtext cross references and scoping" on itemis blog, but unfortunately that gave me more doubts. I'm rather example or step-by-step-case type of guy.

Regards,
Marcin

PS. I hope that above makes sense, please let me know when more info would be needed.
Re: Problems with Cross-Reference resolving in standalone app [message #1009189 is a reply to message #1009137] Thu, 14 February 2013 16:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6544
Registered: July 2009
Senior Member
Hi you may use MWe

New StandaloneSetup().setplatformUri to fake a workspace in
standalone mode

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Problems with Cross-Reference resolving in standalone app [message #1009542 is a reply to message #1009189] Fri, 15 February 2013 09:47 Go to previous messageGo to next message
Marcin Mozdyniewicz is currently offline Marcin MozdyniewiczFriend
Messages: 5
Registered: February 2013
Junior Member
Hello Christian,

Thanks for the answer.
I've already tried that, but I got then:
0    [main] INFO  lipse.emf.mwe.utils.StandaloneSetup  - Registering platform uri 'C:\dev\workspace-rcp\tmp'
Exception in thread "main" org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: java.io.IOException: The path '/com.example.client/Declaration.ofd2' is unmapped

Am I doing something wrong here?

I've noticed that it's possible to override URI mapping by
EcoreUtil.getPlatformResourceMap().put("project", URI.createURI("file:///C:/location/"));

Maybe I could try that?

Regards,
Marcin
Re: Problems with Cross-Reference resolving in standalone app [message #1009546 is a reply to message #1009189] Fri, 15 February 2013 09:49 Go to previous messageGo to next message
Jos Warmer is currently offline Jos WarmerFriend
Messages: 108
Registered: October 2010
Senior Member
Hi,

For this purpose I use the org.eclipselabs.spray.xtext.util.ReaderExt.java workflow component from the Spray project. This can be used in an MWE2 workflow to ensure all Xtext files are put in one resource set. When this is done, references resolve ok, at least for me.

Jos
Re: Problems with Cross-Reference resolving in standalone app [message #1009582 is a reply to message #1009546] Fri, 15 February 2013 10:46 Go to previous messageGo to next message
Marcin Mozdyniewicz is currently offline Marcin MozdyniewiczFriend
Messages: 5
Registered: February 2013
Junior Member
Hi Jos,

Thanks for the Tip, but I've already added all necessary xtext files to the same resorceSet and then use
EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);

but that doesn't work.

Here's my example class:
public class XtextTest
{

    public static void main(String[] args)
    {
        new StandaloneSetup().setPlatformUri("c:/dev/workspace-rcp/tmp/");
        Injector injector = new FeatureDsl2StandaloneSetup().createInjectorAndDoEMFRegistration();
        XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
        resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
        testRun(resourceSet);
    }

    static void testRun(ResourceSet resourceSet)
    {
        Resource commonResource =
                resourceSet.getResource(URI.createURI("platform:/resource/com.example.client/Declaration.ofd2"), true);
        Resource resource =
                resourceSet.getResource(URI.createURI("platform:/resource/com.example.client.base/client.ofd2"), true);

        EcoreUtil2.resolveLazyCrossReferences(resource, CancelIndicator.NullImpl);

        for (Resource res : resourceSet.getResources())
        {
            System.out.println("res: " + res);
        }

        Entity root = (Entity) resource.getContents().get(0);
        Installation installation = root.getInst();
        System.out.println("inst: " + installation.getWarehouseID());
        EList < Perspective > perspectives = installation.getPerspectives();
        System.out.println("perspectives: " + perspectives.size());
        for (Perspective perspective : perspectives)
        {
            System.out.println(perspective.getName());
            EList < ViewClass > views = perspective.getViews();
            for (ViewClass viewClass : views)
            {
                System.out.println("view name: " + viewClass.getName());

            }
        }

        System.out.println("------------------------------------------------");
        List < Variation > allVariations = OfdTools.getAllVariations(installation);
        for (Variation variation : allVariations)
        {
            System.out.println("var: " + variation);
            // VariationPoint variationPoint = OfdTools.getVariationPoint(variation);
        }

    }
}


Any suggestions?

Regards,
Marcin
Re: Problems with Cross-Reference resolving in standalone app [message #1009611 is a reply to message #1009582] Fri, 15 February 2013 11:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6544
Registered: July 2009
Senior Member
/com.example.client/Declaration.ofd2

means:

the folder c:/dev/workspace-rcp/tmp/ does not seem to contain a subfolder com.example.client with a file Declaration.ofd2
Re: Problems with Cross-Reference resolving in standalone app [message #1009662 is a reply to message #1009611] Fri, 15 February 2013 13:36 Go to previous messageGo to next message
Marcin Mozdyniewicz is currently offline Marcin MozdyniewiczFriend
Messages: 5
Registered: February 2013
Junior Member
Hi,

It contains one, I've double checked it.
I've also changed a folder name (com.example.client -> client) to avoid eventual dot-naming problems, but it gives me the same exception.

Regards,
Marcin
Re: Problems with Cross-Reference resolving in standalone app [message #1009672 is a reply to message #1009662] Fri, 15 February 2013 13:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6544
Registered: July 2009
Senior Member
can you share a complete reproducable example? (zip file etc)
Re: Problems with Cross-Reference resolving in standalone app [message #1010813 is a reply to message #1009672] Mon, 18 February 2013 09:31 Go to previous message
Marcin Mozdyniewicz is currently offline Marcin MozdyniewiczFriend
Messages: 5
Registered: February 2013
Junior Member
Unfortunately, I'm not allowed to share client code, but guess I've found the solution for me, so I'll share that.

What worked for me is that I've changed:
new StandaloneSetup().setPlatformUri(myPath);

to
Mapping uriMap = new Mapping();
uriMap.setFrom("platform:/resource/");
uriMap.setTo(myPath));
new StandaloneSetup().addUriMap(uriMap);


and for now it works fine.

Thank for help and good directions.

Regards,
Marcin
Previous Topic:plans to switching to ANTLR4?
Next Topic:Optional arguments
Goto Forum:
  


Current Time: Fri Dec 19 01:48:04 GMT 2014

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

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