Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364522

Summary: invalid warning for m2 import in grammar
Product: [Modeling] TMF Reporter: Meinte Boersma <meinte.boersma>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: clay, Ed.Merks, lorenzo.bettini, sebastian.zarnekow, serano.colameo, sven.efftinge
Version: 2.4.0Flags: sebastian.zarnekow: kepler+
Target Milestone: RC1   
Hardware: All   
OS: All   
Whiteboard:
Bug Depends on: 392988    
Bug Blocks:    
Attachments:
Description Flags
proposed patch for xtext repo
none
addon patch for xtend repo none

Description Meinte Boersma CLA 2011-11-22 16:30:25 EST
Build Identifier: M20110909-1335

When extending a grammar from one in another Xtext project and importing the Ecore m2 of that one, a warning "The imported package is not on the classpath of this project which may lead to follow up errors." is given. It appears that a '!' is missing on line 433 of http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/tree/plugins/org.eclipse.xtext/src/org/eclipse/xtext/xtext/XtextValidator.java

Reproducible: Always

Steps to Reproduce:
1. see details
2.
3.
Comment 1 Sebastian Zarnekow CLA 2011-11-22 16:35:49 EST
The problem is more in line 426. The package should not be checked if it was generated by a super grammar.
Comment 2 Lorenzo Bettini CLA 2011-11-27 09:53:12 EST
I have the same problem with 2.1.1, when adding import of xbase (on a new xtext project):

import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase

though xbase is in the dependencies of the project
Comment 3 Sebastian Zarnekow CLA 2011-11-27 12:15:25 EST
(In reply to comment #2)
> I have the same problem with 2.1.1, when adding import of xbase (on a new xtext
> project):
> 
> import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
> 
> though xbase is in the dependencies of the project

Is the error message the same as the one from comment #0? Does the error disappear if you close and reopen the project?
Comment 4 Lorenzo Bettini CLA 2011-11-28 04:42:34 EST
@Sebastian: no, the problem (the warning) is still there even after closing and reopening the project
Comment 5 Serano Colameo CLA 2011-11-30 09:51:35 EST
I have this problem too with xtext 2.1.1.

Any workaround?

~serano
Comment 6 Serano Colameo CLA 2011-11-30 09:53:35 EST
(In reply to comment #5)
> I have this problem too with xtext 2.1.1.
> 
> Any workaround?
> 
> ~serano

...and btw, I cannot generate my xtext grammar anymore.

25421 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel 'http://www.csg.com/cs/tools/mdgen/icm/IcmDsl' from 'platform:/resource/com.csg.cs.tools.mdgen.icm/src/com/csg/cs/tools/mdgen/icm/IcmDsl.genmodel'
java.lang.IllegalArgumentException: non-prefix new value
	at org.eclipse.emf.common.util.URI.replacePrefix(URI.java:2716)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.toPlatformResourceURI(EcoreGeneratorFragment.java:396)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.access$0(EcoreGeneratorFragment.java:390)
	at org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment$ToPlatformResourceDeresolvingURIHandler.deresolve(EcoreGeneratorFragment.java:386)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.deresolve(XMLHelperImpl.java:821)
	at org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelperImpl.java:807)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectSingle(XMLSaveImpl.java:1865)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1309)
	at org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2685)
Comment 7 Serano Colameo CLA 2011-11-30 11:17:25 EST
(In reply to comment #6)
> (In reply to comment #5)
> > I have this problem too with xtext 2.1.1.
> > 
> > Any workaround?
> > 
> > ~serano
> 
> ...and btw, I cannot generate my xtext grammar anymore.
> 
> 25421 [main] INFO  clipse.emf.mwe.utils.GenModelHelper  - Registered GenModel
> 'http://www.csg.com/cs/tools/mdgen/icm/IcmDsl' from
> 'platform:/resource/com.csg.cs.tools.mdgen.icm/src/com/csg/cs/tools/mdgen/icm/IcmDsl.genmodel'
> java.lang.IllegalArgumentException: non-prefix new value
>     at org.eclipse.emf.common.util.URI.replacePrefix(URI.java:2716)
>     at
> org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.toPlatformResourceURI(EcoreGeneratorFragment.java:396)
>     at
> org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment.access$0(EcoreGeneratorFragment.java:390)
>     at
> org.eclipse.xtext.generator.ecore.EcoreGeneratorFragment$ToPlatformResourceDeresolvingURIHandler.deresolve(EcoreGeneratorFragment.java:386)
>     at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.deresolve(XMLHelperImpl.java:821)
>     at
> org.eclipse.emf.ecore.xmi.impl.XMLHelperImpl.getHREF(XMLHelperImpl.java:807)
>     at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveEObjectSingle(XMLSaveImpl.java:1865)
>     at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveFeatures(XMLSaveImpl.java:1309)
>     at
> org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.saveElementID(XMLSaveImpl.java:2685)

------

ok, something is odd here... I guess it has to do with scanClassPath = true option.

however, the guilty method is in EcoreGeneratorFragment:

	private static URI toPlatformResourceURI(URI uri) {
		if (uri.isPlatform())
			return uri;
		Map<String, URI> map = EcorePlugin.getPlatformResourceMap();
		for (Entry<String, URI> entries : map.entrySet()) {
			final URI newPrefix = URI.createURI("platform:/resource/" + entries.getKey() + "/");
			URI uri2 = uri.replacePrefix(entries.getValue(), newPrefix);
			if (uri2 != null)
				return uri2;
		}
		return uri;
	}

the line which causes the IllegalArgumentException is the following:

     URI uri2 = uri.replacePrefix(entries.getValue(), newPrefix);

where entries.getValue() is during debugging set to 

file:/C:/Data/projects/workspaceMDGEN/MDGE/lib/com.csg.cs.tools.mdgen.icm.generator/misc/resources/setup/

and newPrefix variable is => platform:/resource/##service.name##/

I really do not know why we need to go into java projects in the workspace which have really nothing to do with the Xtext grammar project... why is this needed? there is no dependencies at all between these projects.

~serano
Comment 8 Sebastian Zarnekow CLA 2011-11-30 11:20:07 EST
They seem to be on the classpath of the launch config, otherwise they wouldn't be processed.
Comment 9 Sebastian Zarnekow CLA 2011-11-30 12:07:17 EST
Pushed to master.
Comment 10 Serano Colameo CLA 2011-12-01 03:08:57 EST
(In reply to comment #8)
> They seem to be on the classpath of the launch config, otherwise they wouldn't
> be processed.

Hi Sebastian,
thanks again for your feedbacks yesterday evening.

As you told me to do, I disabled the line with platformUri definition in my mwe2:

Workflow {
    bean = StandaloneSetup {
		scanClassPath  = true
//		platformUri = "${runtimeProject}/.."

...and now everything works fine. 

So, but then this means for me that it is better to not mix other projects in the workspace where the grammar project resides.

Best regards,
Serano
Comment 11 Lorenzo Bettini CLA 2012-09-03 12:04:10 EDT
This problem seems to show up again (apparently for the same missing '!') in Xtext 2.3.1. See for instance, the Scripting.xtext from the seven languages.
I think this bug should be reopened.
Comment 12 Sebastian Zarnekow CLA 2012-09-03 12:51:22 EDT
see comment #11
Comment 13 Michael Clay CLA 2012-10-24 14:04:06 EDT
Created attachment 222735 [details]
proposed patch for xtext repo
Comment 14 Michael Clay CLA 2012-10-24 14:04:36 EDT
Created attachment 222736 [details]
addon patch for xtend repo
Comment 15 Michael Clay CLA 2012-10-29 16:10:43 EDT
the patch becomes obsolete with 392988 because it exports the Xbase.ecore model from the src folder. the remaining part of the patch to index models, stored in external folders, from a runtime workspace is still required.

@@ -65,12 +66,23 @@ public class Storage2UriMapperJavaImpl extends Storage2UriMapperImpl implements
 
 	@Override
 	public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
+		if (isExternalPlatformResource(uri)) {
+			return cache.get(uri);
+		}
 		Iterable<Pair<IStorage, IProject>> storages = super.getStorages(uri);
 		if (!storages.iterator().hasNext()) {
 			return cache.get(uri);
 		}
 		return storages;
 	}
+
+	/**
+	 * @since 2.4
+	 */
+	protected boolean isExternalPlatformResource(URI uri) {
+		return uri.isPlatformResource() && uri.segmentCount() >= 3 && EXTERNAL_PROJECT_NAME.equals(uri.segment(1))
+				&& uri.segment(2).startsWith(LINKED_FOLDER_NAME);
+	}
Comment 16 Sven Efftinge CLA 2013-05-30 10:39:04 EDT
There're a lot of different topics covered here. 
I tried to reproduce the initial problem. This seems to be fixed.
For any other problems mentioned throughout the comments we need dedicated bugzilla entries.
Comment 17 Eclipse Webmaster CLA 2017-10-31 11:26:07 EDT
Requested via bug 522520.

-M.