You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Peter van de Hoef <pv...@springsite.com> on 2005/07/23 22:37:10 UTC

[m2] Embedding Maven 2

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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] Embedding Maven 2

Posted by Peter van de Hoef <pv...@springsite.com>.
Thank you very much, I am eagerly looking forward to these docs.

Adding the -B flag when executing MavenCli.main() solved the JLine problem.
The JLine problem occurs only when the -o flag is also used.

When using the PlexusTestCase in combination with 'lookup( Maven.ROLE )', the JLine problem appears again.
It appears that the constructor of the DefaultMaven class is constructing the InputHandler.
For now, I can live with this and will wait for the documentation on embedding Maven.

Greetings,
Peter

Brett Porter wrote:
> On 7/24/05, Peter van de Hoef <pv...@springsite.com> wrote:
> 
>>- If it is, how can this JLine issue be worked around? Is it possible to disable the InputHandler?
> 
> 
> I think the batch mode flag should turn that off. If not, I'd consider
> that a bug. We should also consider fixing the problem with jline if
> possible.
> 
> 
>>- 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?
> 
> 
> That's closer to the expected way it will be done. We're expecting to
> formalise and document how to embed Maven during the approaching beta
> cycle.
> 
> Cheers,
> Brett
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] Embedding Maven 2

Posted by Brett Porter <br...@gmail.com>.
I'm including this as one of the use cases as we work through
http://jira.codehaus.org/browse/MNG-591

- Brett

On 7/24/05, Stephane Nicoll <st...@gmail.com> wrote:
> Guys,
> 
> I am also trying to create testcases for an m2 plugin. For this I need
> an initialized MavenProject instance inside my test case (so that I
> have access to getArtifacts and co). Best would be to be able to
> initialize a Mojo with a particular POM.
> 
> Any idea how to do this?
> 
> Thanks,
> Stéphane
> 
> On 7/24/05, Brett Porter <br...@gmail.com> wrote:
> > On 7/24/05, Peter van de Hoef <pv...@springsite.com> wrote:
> > > - If it is, how can this JLine issue be worked around? Is it possible to disable the InputHandler?
> >
> > I think the batch mode flag should turn that off. If not, I'd consider
> > that a bug. We should also consider fixing the problem with jline if
> > possible.
> >
> > > - 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?
> >
> > That's closer to the expected way it will be done. We're expecting to
> > formalise and document how to embed Maven during the approaching beta
> > cycle.
> >
> > Cheers,
> > Brett
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> 
> 
> --
> .::You're welcome ::.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] Embedding Maven 2

Posted by Stephane Nicoll <st...@gmail.com>.
Guys,

I am also trying to create testcases for an m2 plugin. For this I need
an initialized MavenProject instance inside my test case (so that I
have access to getArtifacts and co). Best would be to be able to
initialize a Mojo with a particular POM.

Any idea how to do this?

Thanks,
Stéphane

On 7/24/05, Brett Porter <br...@gmail.com> wrote:
> On 7/24/05, Peter van de Hoef <pv...@springsite.com> wrote:
> > - If it is, how can this JLine issue be worked around? Is it possible to disable the InputHandler?
> 
> I think the batch mode flag should turn that off. If not, I'd consider
> that a bug. We should also consider fixing the problem with jline if
> possible.
> 
> > - 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?
> 
> That's closer to the expected way it will be done. We're expecting to
> formalise and document how to embed Maven during the approaching beta
> cycle.
> 
> Cheers,
> Brett
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 


-- 
.::You're welcome ::.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [m2] Embedding Maven 2

Posted by Brett Porter <br...@gmail.com>.
On 7/24/05, Peter van de Hoef <pv...@springsite.com> wrote:
> - If it is, how can this JLine issue be worked around? Is it possible to disable the InputHandler?

I think the batch mode flag should turn that off. If not, I'd consider
that a bug. We should also consider fixing the problem with jline if
possible.

> - 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?

That's closer to the expected way it will be done. We're expecting to
formalise and document how to embed Maven during the approaching beta
cycle.

Cheers,
Brett

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org