Hi,

I'm developing a testcase in which I need to run Maven from within the testcase.
I don't want to run maven by executing 'm2' as a separate process via Runtime.exec() since I want my test to run correctly in an environment where maven itself is embedded in another application (e.g. Eclipse). This could mean that the 'm2' command is not available, or may refer to another version of Maven.

So I tried to embed maven (in a rather ugly way) as follows:

Declared the following dependency in the POM:

<dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>2.0-beta-1-SNAPSHOT</version>
        <scope>test</scope>
</dependency>

And added the following piece of code in the testcase:

        MavenCli cli = new MavenCli();
        cli.main( new String[] { "install" }, null );

This appears to work, except that the console from which the testcase is launched, does not echo its input anymore. After a bit of research, I found out that Maven instantiates a Plexus InputHandler which uses JLine to read from the console. JLine initializes itself by saving the current stty configuration and then executing 'stty -icanon min 1' and 'styy -echo'. When the second instance of maven is executed, this piece of code is executed again, with effect that the initial stty state is not correctly restored. For now, I've added a 'stty echo icanon' command in the m2 shell script to work around this problem.

My questions are:
- Is this a proper way to embed Maven?
- If it is, how can this JLine issue be worked around? Is it possible to 
disable the InputHandler?
- If not, how should it be done? I've studied the MavenCli class and tried to mimic its behaviour by extending the testcase from PlexusTestCase in which an instance of Maven is created with 'lookup( Maven.ROLE )'. Is this the way to go or is there a better way?

Thanks in advance,
Peter van de Hoef


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to