tycho
tycho copied to clipboard
Enable configuring custom EquinoxLauncher
We have some SWTBot-based GUI tests. We often run these in XVFB, record video of the virtual screen and pipe all output to some log file for later analysis, however to do that we need an external launcher script around maven which does something like this:
xvfb-run -s '-screen 0 1920x1080x24' mvn clean install <bunch of -D options> | tee stdout_`date +"%H-%M-%S"`
This works fine, but I don't love not being able to just run everything using the basic mvn clean install
.
I would very much like to have some mechanism to configure this in pom.xml for the forked jvm running our eclipse product directly.
The most flexible solution that comes to mind is ability to provide custom EclipseLauncher
which gets picked up here .
Our pom could then look something like this:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<configuration>
<launcher>
<class>my.custom.GuiTestLauncher</class>
<configuration>
<!-- arbitrary xml given to instance of the launcher class -->
</configuration>
</launcher>
</configuration>
<dependencies>
<dependency>
<!-- maven artifact containing `my.custom.GuiTestLauncher` -->
</dependency>
</dependencies>
The class
has to implement EclipseLauncher
, be public and must have either a pubilc constructor taking single argument of type Xpp3Dom
or a public noarg constructor. The configuration
for the launcher gets passed to it by the optional constructor argument of type Xpp3Dom
.
The custom launcher is then free to rearrange the cli as it needs, it is also free to e.g. redirect output of the forked jvm to file.
In our case the modified cli the launcher eventually runs would look something like this:
xvfb-run -s '-screen 0 1920x1080x24' /path/to/java -Dosgi.os=linux -Dosgi.ws=gtk -jar /path/to/org.eclipse.equinox.launcher.jar ...
If you think this would be a useful feature to have in tycho I can provide the patch. Or if there already exists some way to achieve this which I have not found, please let me know.
I would very much like to have some mechanism to configure this in pom.xml for the forked jvm running our eclipse product directly.
The usual way for this is to bind anything you need to setup for your integration test to the pre-integration-test
phase of maven and shut down everything in the post-integration-test
phase.
See for example here https://github.com/Zetten/xvfb-maven-plugin even with tycho-surefire :-)
The usual way for this is to bind anything you need to setup for your integration test to the pre-integration-test phase
Yes I know that mechanism, but it is not trivial to properly set up the XVFB environment without using the wrapper script they provide. So I would prefer to use that rather than trying to re-implement it myself (or using someone else's unofficial re-implementation. I quickly scanned through the code of the xvfb plugin and can't see it doing some of the things the official wrapper does) in the pre-post phases.
This also does not solve the problem of redirecting the output of the forked jvm I think. We have many test bundles in single invocation of the mvn
command, each of which spawns own jvm fork, and it would be nice to have separate file with captured output for each test plugin.
If you want to do any manual application run then https://www.eclipse.org/tycho/sitedocs/tycho-extras/tycho-eclipserun-plugin/eclipse-run-mojo.html would be more suitable.
Hmm that is possible but then I would need to re-implement everything that I want from surefire which is also not ideal. I really like all that tycho-surefire does really, I just need to change a small bit about how it launches the forked jvm so ideally I'd like the amount of custom code/configuration required to achieve this to be proportional.
Allowing custom launcher felt right as it is very small change in tycho itself (in my opinion) and allows users great flexibility (admittedly with great possibility to break stuff for themselves too).
I would need to re-implement everything that I want from surefire
Can you please exmlain how adding the xvfb-maven-plugin does require to re-implement anything?
Can you please exmlain how adding the xvfb-maven-plugin does require to re-implement anything?
It does not, my reaction about re-implementing was to suggestion from @laeubi to use eclipse-run-mojo. Maybe I misunderstood but I thought this would mean replacing tycho-surefire by eclipse-run-mojo which would allow me to have the launcher command exactly as I want it, but at the cost of having to re-implement the way surefire assembles the command (which I want to keep, just add something to it)
There seem to be following solutions to what I want to do so far:
- Use xvfb-maven-plugin to set up the environment in pre/post phases of the run. As I explained I would prefer to not use this and rather go with the official
xvfb-run
script - Use eclipse-run-mojo which would allow me to assemble the command to launch the eclipse app exactly as I need (i.e.
xvfb-run <options for xvfb> java -jar <options for eclipse>
), however I can't see how to simply combine this with the work done by the surefire plugin - Configure custom launcher for the surefire plugin - what has been described so far in this issue, I'd prefer this option if at all possible
- And possibly one more option - provide the custom launcher class as override for the plexus
@Component
so that my custom impl gets injected into theAbstractTestMojo
. This would be fragile as it is not using any official public api of the surefire plugin and dealing with the plexus component metadata can be fiddly so I really don't like this option at all
I still think using a custom launcher is the best solution given my requirements and constraints
Use xvfb-maven-plugin to set up the environment in pre/post phases of the run. As I explained I would prefer to not use this and rather go with the official xvfb-run script
You can then use something like exec instead of the xvfb plugin to run a more custom command if you prefer.
You proposal 2 and 3 are IMO way too difficult to implement for such a simple problem. This will take some time before you reach a decent result, and that result may as well be fragile. I would recommend you start witht he xvfb plugin or whatever other command to start/stop it before/after test; and if you are still not satisfied with it, you can consider more effort. But my guess is that although it wouldn't be perfect, xvfb plugin is very likely to be good enough.
And possibly one more option - provide the custom launcher class as override for the plexus @Component so that my custom impl gets injected into the AbstractTestMojo. This would be fragile as it is not using any official public api of the surefire plugin and dealing with the plexus component metadata can be fiddly so I really don't like this option at all
One would need to check, but maybe some JUnit hook/listener can be invoked before the application under test tries to start a display. So if it's possible to receive and react to such an event early, then a solution could be to start Xvfb very early from the application under test (with eg Runtime.exec(...)
). This functionality could be wrapped in an Eclipse plugin that would be added to the application under test and the listener be enabled from the pom.xml.
One would need to check, but maybe some JUnit hook/listener can be invoked before the application under test tries to start a display.
See https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks for JUnit 5.
You can then use something like exec instead of the xvfb plugin to run a more custom command if you prefer.
See https://junit.org/junit5/docs/current/user-guide/#extensions-lifecycle-callbacks for JUnit 5.
No I can't, it seems you misunderstand the problem, or I explained it badly. The thing is the wrapper script I want to use needs to get the "thing to be run inside the xvfb environment" as parameter which it then runs itself. Think sudo
but for running command with changed X env where sudo runs command with changed privileges. So this:
>> xvfb setup by exec / as some hook,callback or listener
>> cli for forked test jvm from tycho surefire
>> xvfb teardown by exec / as some hook,callback or listener
does not work. To run the wrapper script I need to have:
>> xvfb-run cli for forked test jvm from tycho surefire
thus my need for the custom launcher to modify the command running the forked jvm.
I would recommend you start witht he xvfb plugin or whatever other command to start/stop it before/after test; and if you are still not satisfied with it, you can consider more effort
The thing is I already have it running with the xvfb-runner script (though via another wrapper script which launches the whole mvn build inside the xvfb which is not ideal) as described in the original post. Based on my previous experience with getting the xvfb to run properly I wanted to stick with using this wrapper script which I already have working rather than trying to use different way to run the xvfb to conform to how other tools think things should be done. I perceived this way as "the least effort and best chance of success". I will try the xvfb-plugin and see how that goes, maybe it will work fine