Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Locating Cross References to Workspace Links in Headless Operation
Locating Cross References to Workspace Links in Headless Operation [message #1832289] Tue, 15 September 2020 12:00 Go to next message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 250
Registered: May 2012
Senior Member
Not sure if this is the right place to ask, but I think it's the right place to start.

I have an EMF model that makes cross references to objects of an Xtext DSL (also EMF of course). So references to another file.

I have this working well enough in my Eclipse GUI operation and as long as I have both my XMI file loaded and all my DSL files loaded,
Eclipse's workspace concept along with EMF just seems to work. Feels like magic.

But, I work with hardware design nerds and I have to make a command line version of my app - GUIs are great, but are terrible for batch processing models.

I have a fundamental problem I'm using Eclipse to build my model and thus I'm using the concept of the Eclipse Workspace to organize data. My hardware design team
also has the concept of a workspace - and it has nothing to do with eclipse. We're pulling hardware source code from git and putting it into a workspace folder.

So I need to find a method to associate the Eclipse workspace with what I'm calling the "user workspace". I have prototyped this by making a "linked resources"
folder in my Eclipse project and creating linked resources with a path variable USER_WORKSPACE.

Works great in GUI mode and I can manifest files from all kinds of different locations in the USER_WORKSPACE into my Eclipse Workspace. And users can change
the USER_WORKSPACE variable to point Eclipse to their "user workspace" and link all that stuff into the Eclipse workspace.

My Project directory structure looks like this:

My Modeling Project/ (Sirius modeling project)
--> dsl_links_folder/
--> link1
--> link2
--> my_model.xml

The link1 and link2 are described in the .project file and use the path variable USER_WORKSPACE. There aren't any simlinks in unix or anything, so the Eclipse workspace
or platform knows how to resolve those (but I don't).

My my_model.xml file has cross references like this:


When I try to load this xml resource from a headless invocation - not standalone, but I'm trying to use Eclipse to utilize all these helpful links I made and trying to load
the file so it has a hope of finding its links relative to the dsl_links_folder, I'm obviously running into issues with resolving proxies and I see this when I load and try to validate my XML file.

(note: I'm injecting a resourceSet from my DSL Injector and for the most part it seems to magically work okay and understand how to open my XML file)

I validate the EMF xml file like this (code I grabbed from the EMF tests example):

for (EObject eObject : resource.getContents()) {
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
if (diagnostic.getSeverity() != Diagnostic.OK) {
printDiagnostic(diagnostic, "");

and get an error like this:

The feature 'emfRefName' of 'anEMFObject{file:<eclipse workspace path>/<My Modeling Project>/my_model.xml#objID}' contains an unresolved proxy 'refObjID{file:<eclipse workspace path>/<My Modeling Project>/dsl_links_folder/dsl_file.dsl#/0/@emfRefName}'

What's clear here (and magic to me), is that when EMF is trying to validate this crossreference, it's already prefixed my link directory with the proper workspace location.
i.e. it's looking for the linked file in the right place. So EMF already changed the uri of emfRefName="dsl_links_folder/dsl_file.dsl#refObjID" to the right unix path - where the linked file "should be".

But of course, outside of Eclipse, and without knowledge of the eclipse Workspace and the .project files, theere's literally nothing there in the dsl_links_folder.

I have tried to build the project in my headless run:, new NullProgressMonitor());

That command doesn't break - but it also doesn't seem to do anything.

I'm missing something fundamental about how to get these Eclipse Workspace linked files into a resourceSet that EMF can understand.

Can anyone help me with that missing step?

Feels like, in pseudo code, I should be doing something like:

IFolder dsl_links_folder = prj.getFolder("dsl_links_folder");
IFile [] linkedFiles = dsl_links.folder.getLinkedFiles();

But, of course, that is a fantasy.

I'm pretty stuck.
Re: Locating Cross References to Workspace Links in Headless Operation [message #1832293 is a reply to message #1832289] Tue, 15 September 2020 13:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 32501
Registered: July 2009
Senior Member
Here's something that would load all files in the given IContainer:
  public static void load(ResourceSet resourceSet, IContainer container) throws CoreException
    for (IResource member : container.members())
      switch (member.getType())
        case IResource.FILE:
          resourceSet.getResource(URI.createPlatformResourceURI(member.getFullPath().toString(), true), true);
          load(resourceSet, (IContainer)member);
Of course IProject, IFolder, and IWorkspaceRoot are all IContainers.

I suspect you're just not creating the resource URI correctly:

I.e., the proxy URI {file:<eclipse workspace path>/<My Modeling Project>/my_model.xml#objID}' suggests you are create a file: URI not a platform:/resource URI.

Ed Merks
Professional Support:
Re: Locating Cross References to Workspace Links in Headless Operation [message #1834308 is a reply to message #1832293] Sat, 07 November 2020 03:18 Go to previous message
Brandon Lewis is currently offline Brandon LewisFriend
Messages: 250
Registered: May 2012
Senior Member
Thanks Ed,. Just wanted to follow up and say your code was what I needed to make progress.
Previous Topic:Loading UML Model with model library in standalone
Next Topic:Getting Content is not allowed in prolog
Goto Forum:

Current Time: Fri Sep 30 17:38:26 GMT 2022

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

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

Back to the top