Skip to content
This repository has been archived by the owner on Apr 21, 2023. It is now read-only.

Move to Maven/Tycho for projects and build infrastructure #858

Closed
LorenzoBettini opened this issue Jan 20, 2023 · 26 comments
Closed

Move to Maven/Tycho for projects and build infrastructure #858

LorenzoBettini opened this issue Jan 20, 2023 · 26 comments
Labels
Milestone

Comments

@LorenzoBettini
Copy link
Contributor

See also eclipse/xtext-lib#499 and eclipse/xtext-core#2052

Development has started in my fork's branch: https://github.com/LorenzoBettini/xtext-extras/tree/lb_2052_maven_tycho

@LorenzoBettini
Copy link
Contributor Author

@szarnekow I might need your help here for this failing test org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.testBug346035_01():

@Test
public void testBug346035_01() throws Exception {
	// @formatter:off
	String grammarAsString = 
		"grammar test with org.eclipse.xtext.common.Terminals\n" +
		"import 'platform:/resource/org.eclipse.xtext.xbase/model/Xbase.ecore' as xbase\n" +
		"generate myDsl 'uri'\n" + "Model: elements+=Element*;\n" +
		"Element returns xbase::XExpression : {Element} 'Hello';\n" +
		"terminal ID : '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;\n";
	// @formatter:on
	getResourceFromString(grammarAsString);
}

If I understand correctly, this verifies that you can import an Ecore from the classpath (as a resource). This is test is located in .extras.tests that depends on .xbase.

This test fails (it cannot locate Xbase.ecore) when executed from Eclipse (as a JUnit test), while it passes when run from Maven/Tycho, but as a JUnit test again (with maven-surefire, NOT with tycho-surefire). The fact that is succeeding with Maven looks correct to me: in this case, the classpath is built from the JAR files packaged in the previous Maven phases, and .xbase has a build.properties that instructs the build tool to package its model directory (containing Xbase.ecore) in the JAR, so the model/Xbase.ecore is found in the classpath. Instead, when running from Eclipse, Xbase.ecore cannot be found in the model directory in the classpath, because model/Xbase.ecore is nowhere in the classpath (i.e., it's not in the output folder of the .xbase project).

To make it pass ALSO from Eclipse, I created a source folder in the .extras.tests project where I copied model/Xbase.ecore (with the model directory as well) and also the required JavaVMTypes.ecore. This way, the model directory is copied in the output folder and found from the classpath.

Is this solution OK for you?

I'm wondering if this test works when run from Eclipse with the current buildship infrastructure. @cdietrich I don't have the workspace with the master branch with buildship, would you please mind trying running that? I mean as a JUnit test (i.e., NOT with gradle).

Thanks!

@cdietrich
Copy link
Member

no the test is also red in buildship based eclipse

@LorenzoBettini
Copy link
Contributor Author

@cdietrich thank you for the feedback! Then I was right.

However, my current solution does not make me feel comfortable: Having Xbase.ecore twice might undermine Plugin tests and the running workbench (started from our development environment). I'd go with a slightly different solution: put in test-ecores/model a simple .ecore of a simple DSL (which is nowhere else) and modify the test accordingly to refer to this simple .ecore. In fact, the above test has nothing to do with Xbase in general.

Of course, let's wait also for @szarnekow feedback; in the meantime, I'll apply the approach I've just mentioned and in case I'll undo it.

@cdietrich
Copy link
Member

i wonder if you added xbase to the required bundles. shouldnt it then be resolvable? have no idea how tests do uri mapping

@LorenzoBettini
Copy link
Contributor Author

If I add xbase as a required bundle (as I did at the beginning and as it is now in the buildship configuration), the test will find model/Xbase.ecore ONLY when run by the build tool, because model/Xbase.ecore is packaged in the JAR and the JAR is part of the classpath. While when run from Eclipse model/Xbase.ecore is nowhere in the classpath: it's not in the output folders nor in the target platform.

@cdietrich
Copy link
Member

thus is wonder if the test misses some mapping or so. does the second Xtext2EcoreTransformer test work?

@LorenzoBettini
Copy link
Contributor Author

all the other tests work. Which one are you referring to?

@cdietrich
Copy link
Member

org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest
we have the class twice

@LorenzoBettini
Copy link
Contributor Author

Not in this repository, right?

@cdietrich
Copy link
Member

no in core

@LorenzoBettini
Copy link
Contributor Author

OK, in that homonymous class we never use platform:resource scheme

@cdietrich
Copy link
Member

lets see what sebastian says

@LorenzoBettini
Copy link
Contributor Author

Yes, let's wait for @szarnekow .

In the meantime, I implemented an alternative solution (replacing the working one that I first described in my first comment): LorenzoBettini@7602ba7 If I understand correctly how that testcase and that specific test works, this should be equivalent.

@szarnekow
Copy link
Contributor

I’ll only have the mid next week to look into this in detail. EMF has a lot of code to interpret build.properties before packaging. The test should just work both in mvn and from Eclipse as plug-in test. I’ll follow up as soon as I understand the problems you’re seeing

@LorenzoBettini
Copy link
Contributor Author

@szarnekow I forgot to mention that I had also tried to run that as a Plug-in test and it fails as well;

Even worse, when run as plug-in tests I get also other failures in other tests.

This one that cannot resolve model/Ecore.ecore.

org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.testEcoreReference_01()

org.eclipse.xtext.resource.ClasspathUriResolutionException: org.eclipse.xtext.resource.FileNotFoundOnClasspathException: Couldn't find resource on classpath. URI was 'classpath:/model/Ecore.ecore'
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.resolve(ClassloaderClasspathUriResolver.java:50)
	at org.eclipse.xtext.resource.XtextResourceSet.resolveClasspathURI(XtextResourceSet.java:222)
	at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:285)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.normalize(ExtensibleURIConverterImpl.java:446)
	at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:291)
	at org.eclipse.xtext.resource.XtextResourceSet.getResource(XtextResourceSet.java:240)
	at org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.testEcoreReference_01(Xtext2EcoreTransformerTest.java:239)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:74)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.start(CoreTestApplication.java:28)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1440)
Caused by: org.eclipse.xtext.resource.FileNotFoundOnClasspathException: Couldn't find resource on classpath. URI was 'classpath:/model/Ecore.ecore'
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.findResourceOnClasspath(ClassloaderClasspathUriResolver.java:62)
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.resolve(ClassloaderClasspathUriResolver.java:47)
	... 48 more

And this one

org.eclipse.xtext.resource.ecore.EcoreResourceDescriptionManagerTest.testPerformance()

with this strange error about java.lang.ClassNotFoundException: org.eclipse.xtext.builder.tests.builderTestLanguage.BuilderTestLanguagePackage. Since this test loads all the EMF packages from the registry, I guess it gets confused by this other EMF packages that come from another unrelated project. That's why I was assuming that the tests in the extras.tests project had to be executed in an isolated environment, while, with plug-in test you get everything from the workbench:

org.eclipse.emf.common.util.WrappedException: java.lang.ClassNotFoundException: org.eclipse.xtext.builder.tests.builderTestLanguage.BuilderTestLanguagePackage cannot be found by org.eclipse.xtext.builder.standalone.tests_2.30.0.qualifier
	at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:309)
	at org.eclipse.emf.ecore.impl.EPackageRegistryImpl.getEPackage(EPackageRegistryImpl.java:127)
	at org.eclipse.xtext.resource.ecore.EcoreResourceDescriptionManagerTest.testPerformance(EcoreResourceDescriptionManagerTest.java:174)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.pde.internal.junit.runtime.RemotePluginTestRunner.main(RemotePluginTestRunner.java:74)
	at org.eclipse.pde.internal.junit.runtime.CoreTestApplication.start(CoreTestApplication.java:28)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1440)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.builder.tests.builderTestLanguage.BuilderTestLanguagePackage cannot be found by org.eclipse.xtext.builder.standalone.tests_2.30.0.qualifier
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:529)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:524)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:622)
	at org.eclipse.emf.common.CommonPlugin$Implementation.loadClass(CommonPlugin.java:333)
	at org.eclipse.emf.common.CommonPlugin.loadClass(CommonPlugin.java:107)
	at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:302)
	... 42 more

@LorenzoBettini
Copy link
Contributor Author

@szarnekow some additional findings: by creating the development environment with the new temporary Oomph instructions found here: eclipse/xtext-core#2054 (comment)

there's a new failure from Eclipse org.eclipse.xtext.resource.uriHell.AbstractURIHandlerTest.testLoadResourceWithPackagedURIs() when executed from org.eclipse.xtext.resource.uriHell.LoadedByClasspathFromModelFolderURITest.

Since in this setup org.eclipse.xtext is NOT in the target platform, but it's in the workbench, the error once again shows that it cannot resolve the Xtext.ecore because it's not in any output folder. When org.eclipse.xtext was in the target platform, it could find in from the JAR.

org.eclipse.xtext.resource.ClasspathUriResolutionException: org.eclipse.xtext.resource.FileNotFoundOnClasspathException: Couldn't find resource on classpath. URI was 'classpath:/org/eclipse/xtext/Xtext.ecore'
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.resolve(ClassloaderClasspathUriResolver.java:50)
	at org.eclipse.xtext.resource.XtextResourceSet.resolveClasspathURI(XtextResourceSet.java:222)
	at org.eclipse.xtext.resource.XtextResourceSet$1.normalize(XtextResourceSet.java:285)
	at org.eclipse.xtext.resource.XtextResourceSet.registerURI(XtextResourceSet.java:127)
	at org.eclipse.xtext.resource.XtextResourceSet$ResourcesList.inverseAdd(XtextResourceSet.java:153)
	at org.eclipse.xtext.resource.XtextResourceSet$ResourcesList.inverseAdd(XtextResourceSet.java:1)
	at org.eclipse.emf.common.notify.impl.NotifyingListImpl.addUnique(NotifyingListImpl.java:312)
	at org.eclipse.emf.common.util.AbstractEList.add(AbstractEList.java:304)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:435)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.createResource(ResourceSetImpl.java:423)
	at org.eclipse.xtext.resource.uriHell.AbstractURIHandlerTest.doTest(AbstractURIHandlerTest.java:109)
	at org.eclipse.xtext.resource.uriHell.AbstractURIHandlerTest.testLoadResourceWithPackagedURIs(AbstractURIHandlerTest.java:131)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.eclipse.xtext.testing.XtextRunner$1.evaluate(XtextRunner.java:50)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: org.eclipse.xtext.resource.FileNotFoundOnClasspathException: Couldn't find resource on classpath. URI was 'classpath:/org/eclipse/xtext/Xtext.ecore'
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.findResourceOnClasspath(ClassloaderClasspathUriResolver.java:62)
	at org.eclipse.xtext.resource.ClassloaderClasspathUriResolver.resolve(ClassloaderClasspathUriResolver.java:47)
	... 40 more

@LorenzoBettini
Copy link
Contributor Author

Concerning this last problem (when xtext-core and xtext-extras are in the same workbench), I found this possible solution, which can be reverted if it doesn't sound OK: eclipse/xtext-core@959bc13

The idea is to have a source folder model (but could be named anything), which DOES NOT contain physically the separate folder org that contains the Xtext.ecore and genmodel: it has a link to org. The link is enough for Eclipse to copy the linked contents in the output folder making the above test pass.

I had also try to simply put Xtext.ecore and genmodel into the main source folder respecting org/eclipse/xtext. That would work as well for the above test, but it breaks other things like some test ecore files that cannot refer to Xtext.ecore and most of all the bootstrap MWE2, which again assumes the ecore file is in the root of org.eclipse.xtext in the separate folder org/eclipse/xtext. Of course, the new breaking things could be adapted, but I'd avoid that.

The above solution does not seem to break anything: it's just a trick to force the Eclipse builder to copy the ecore file in the output folder.

@szarnekow
Copy link
Contributor

Might be a bug in the classpath URI handler. As discussed in another thread: We need to figure the root cause for this and fix that one instead of patching around the layout of the jars.

LorenzoBettini referenced this issue in eclipse/xtext-core Jan 23, 2023
In Eclipse, so that tests in org.eclipse.xtext.extras can resolve URI
"classpath:/org/eclipse/xtext/Xtext.ecore"
@LorenzoBettini
Copy link
Contributor Author

Might be a bug in the classpath URI handler. As discussed in another thread: We need to figure the root cause for this and fix that one instead of patching around the layout of the jars.

So should I revert that commit for the moment?

Note that the above solution is NOT patching the layout of the JAR, which stays the same.
It's just patching the contents of the output folders in Eclipse.

In any case, if I understand correctly, if the current classpath consists of target platform dependencies and open projects' output folders, when org.eclipse.xtext is an open project in the workspace, the Xtext.ecore file cannot be found in any output folder (that's why I tried the above solution).

@LorenzoBettini
Copy link
Contributor Author

@szarnekow actually the layout of the JAR had changed (my bad!); it should be back to the original layout with eclipse/xtext-core@585b891

However, we can always revert the change I described in my previous comments if you think it's a hack.

@szarnekow
Copy link
Contributor

Xtext2EcoreTransformerTest

This is a plugin test and therefore the classpath URI mappings in org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.doGetResource(InputStream, URI) and org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformerTest.testEcoreReference_01() are bogus. If I remove these, the test is green when running from Eclipse as plugin test.

Please note that extras.tests needs a dependency to xbase.

@szarnekow
Copy link
Contributor

However, we can always revert the change I described in my previous comments if you think it's a hack.

Yes, that looks like a hack and should not be necessary.

Please note that Bundle-ClassPath: . is missing from the xbase manifest.mf. Not sure if it's strictly necessary but most other plugins that I've seen so far do contain this entry.

@LorenzoBettini
Copy link
Contributor Author

@szarnekow sorry but I'd need you to be more specific ;)

could you please paste the version you patched of that test?

I removed all the URI mappings where you said in that test, but it fails because missing org.eclipse.xtext.tests:

		Assert.assertFalse(resourceSet.getResource(URI.createURI(
				"platform:/plugin/org.eclipse.xtext.tests/src/org/eclipse/xtext/metamodelreferencing/tests/EcorePerNsURI.ecore"),
				true).getContents().isEmpty());

@LorenzoBettini
Copy link
Contributor Author

@szarnekow I think I got it!

I added xbase as a dependency of xtext.extras and then I made this change: 8c96d42 So I couldn't remove all mappings. Is that what you meant? This way, by running extras.tests as plug-in tests (headless mode, no need of UI), they all pass. I then modify the POM so that we run its tests with tycho-surefire instead of maven-surefire.

Actually, there was another small adjustment to make:

this test org.eclipse.xtext.resource.ecore.EcoreResourceDescriptionManagerTest.testPerformance() started to fail as a plug-in test

	@Test public void testPerformance() throws Exception {
		GenericResourceDescriptionManager manager = getEmfResourceDescriptionsManager();
		Collection<String> uris = ImmutableList.copyOf(EPackage.Registry.INSTANCE.keySet());
		for(String uri: uris) {
			EPackage pack = EPackage.Registry.INSTANCE.getEPackage(uri);
			IResourceDescription description = manager.getResourceDescription(pack.eResource());
			assertNotNull(description);
			for(int i = 0; i < 10; i++) {
				Iterator<EObject> iter = EcoreUtil.getAllProperContents(pack, true);
				while(iter.hasNext()) {
					EObject next = iter.next();
					if (next instanceof ENamedElement) {
						String name = ((ENamedElement) next).getName();
//						Iterable<IEObjectDescription> objects = 
						description.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(name), false);
//						assertFalse(name + " - " + uri + " - " + next, Iterables.isEmpty(objects));
					}
				}
			}
		}
	}

Because of this exception:

Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.builder.tests.builderTestLanguage.BuilderTestLanguagePackage cannot be found by org.eclipse.xtext.builder.standalone.tests_2.30.0.qualifier
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:529)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:524)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.loadClass(EquinoxBundle.java:622)
	at org.eclipse.emf.common.CommonPlugin$Implementation.loadClass(CommonPlugin.java:333)
	at org.eclipse.emf.common.CommonPlugin.loadClass(CommonPlugin.java:107)
	at org.eclipse.emf.ecore.plugin.RegistryReader$EPackageDescriptor.getEPackage(RegistryReader.java:302)

I seem to understand that this test tries to load all EPackage contents in the running instance. It finds /org.eclipse.xtext.builder.standalone.tests/model/generated/BuilderTestLanguage.ecore but cannot load the EPackage class because I had set all the source folders of that project as test source folders. Classes of test source folders are only available for tests.

To solve that, I turned all the source folders of org.eclipse.xtext.builder.standalone.tests as main source folders and the test was green again. This forces us to run its tests with tycho-surefire instead of maven-surefire. It's not a big deal, but just something to note and remember.

Another possible solution is to filter the contents of EPackage.Registry.INSTANCE.keySet() in that test, but I don't think you like that, do you? ;)

I'll check what happens in a workspace where other projects are imported (e.g., also those of xtext-core).

@szarnekow
Copy link
Contributor

If it makes tycho happy, I'm ok with marking the source folders of test projects as regular source folders.

@cdietrich
Copy link
Member

with repo merge this is done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants