Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » problems for JvmType references when executing tests with Tycho
problems for JvmType references when executing tests with Tycho [message #831090] Wed, 28 March 2012 13:02 Go to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I've just started using Tycho (and Jenkins) for building and testing my
Xtext languages (I'm a Tycho newbie so I don't know whether the problem
lies in Xtext or Tycho).

In my DSL I use Xbase expressions and I have some tests for my Dsl that
refer to JvmType (relying also on imports), say something like this:

import org.eclipse.emf.ecore.*
import my.own.plugin.MyClass

....

var EClass eClass
var MyClass myClass

and of course my test plugin project has a dependency on my.own.plugin

when I run Junit tests (non UI) from Eclipse I have no problems with
such test files (by using ParserHelper and ValidatorHelper);

but when those tests are run using Maven/Tycho, every reference to a
Java class of my.own.plugin produces an error (Couldn't resolve
reference to JvmType 'MyClass'); while there are no problems for
referring to ecore Java classes...

in Tycho I execute the test using a suite, something like

<configuration>
<testSuite>mydslplugin.tests</testSuite>
<testClass>mydslplugin.tests.suites.AllTests</testClass>
<useUIHarness>false</useUIHarness>
<useUIThread>false</useUIThread>
</configuration>

am I missing something?

thanks in advance
Lorenzo

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems for JvmType references when executing tests with Tycho [message #832572 is a reply to message #831090] Fri, 30 March 2012 09:42 Go to previous messageGo to next message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
Hi

I found the solution myself, and I thought that it might help others

first of all, an easy way to reproduce the problem in eclipse is to run
the Junit tests as Junit Plugin tests, without changing the injector
(i.e., DON'T use the ui injector provider). This seems to recreate the
situation when these headless tests are run by Maven/Tycho.

In order to make the tests work (i.e., make xbase expressions be able to
refer to external Java classes, on which the test plugin explicitly
depends), you need to follow the same approach of the domain model test
plugin: have a custom standalonesetup and a custom injector provider
which bindClassLoaderToInstance (I had always wondered why you need to
customize the injector provider like that :)

for instance (with Xtext 2.3 the customization is different, but again
you can take a look at the domain model example shipped with Xtext 2.3)

public class MyDslInjectorProviderCustom extends
MyDslInjectorProvider {

public static class MyDslStandaloneSetupForTests extends
MyDslStandaloneSetup {
@Override
public Injector createInjector() {
return Guice.createInjector(new MyDslRuntimeModule() {
@Override
public ClassLoader bindClassLoaderToInstance() {
return MyDslInjectorProviderCustom.class
.getClassLoader();
}
});
}
}

private Injector injector = new MyDslStandaloneSetupForTests()
.createInjectorAndDoEMFRegistration();

public Injector getInjector() {
return injector;
}
}

I separated also the customized standalonesetup so that you can use the
custom setup in tests using AbstractXtextTests, e.g.,
with(MyDslStandaloneSetupForTests.class)

for the tests that use XtextRunner, you simply use the custom injector
provider

@InjectWith(typeof(MyDslInjectorProviderCustom))
@RunWith(typeof(XtextRunner))

hope this helps :)

cheers
Lorenzo


On 03/28/2012 03:02 PM, Lorenzo Bettini wrote:
> Hi
>
> I've just started using Tycho (and Jenkins) for building and testing my
> Xtext languages (I'm a Tycho newbie so I don't know whether the problem
> lies in Xtext or Tycho).
>
> In my DSL I use Xbase expressions and I have some tests for my Dsl that
> refer to JvmType (relying also on imports), say something like this:
>
> import org.eclipse.emf.ecore.*
> import my.own.plugin.MyClass
>
> ...
>
> var EClass eClass
> var MyClass myClass
>
> and of course my test plugin project has a dependency on my.own.plugin
>
> when I run Junit tests (non UI) from Eclipse I have no problems with
> such test files (by using ParserHelper and ValidatorHelper);
>
> but when those tests are run using Maven/Tycho, every reference to a
> Java class of my.own.plugin produces an error (Couldn't resolve
> reference to JvmType 'MyClass'); while there are no problems for
> referring to ecore Java classes...
>
> in Tycho I execute the test using a suite, something like
>
> <configuration>
> <testSuite>mydslplugin.tests</testSuite>
> <testClass>mydslplugin.tests.suites.AllTests</testClass>
> <useUIHarness>false</useUIHarness>
> <useUIThread>false</useUIThread>
> </configuration>
>
> am I missing something?
>
> thanks in advance
> Lorenzo
>


--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Re: problems for JvmType references when executing tests with Tycho [message #895632 is a reply to message #832572] Fri, 13 July 2012 21:11 Go to previous messageGo to next message
Cristiano Gavião is currently offline Cristiano GaviãoFriend
Messages: 279
Registered: July 2009
Senior Member
Hi Lorenzo,

are you using tycho-surefire-plugin ?

if so, could you share the entire plugin configuration?

thanks,

Cristiano
Re: problems for JvmType references when executing tests with Tycho [message #895675 is a reply to message #895632] Sat, 14 July 2012 17:30 Go to previous message
Lorenzo Bettini is currently offline Lorenzo BettiniFriend
Messages: 1812
Registered: July 2009
Location: Firenze, Italy
Senior Member
On 07/13/2012 11:11 PM, Cristiano Gaviao wrote:
> Hi Lorenzo,
> are you using tycho-surefire-plugin ?
>
> if so, could you share the entire plugin configuration?
>
> thanks,
>
> Cristiano

Cristiano

I abandoned tycho in favor of Buckminster (thanks to the wizard shipped
with Xtext 2.3.0) and I don't have strange building and testing problems
anymore :)

cheers
Lore

--
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134 (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net


Previous Topic:Xcore validation
Next Topic:Completion from POJO
Goto Forum:
  


Current Time: Fri Apr 19 22:25:08 GMT 2024

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

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

Back to the top