maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Raphaël Piéroni" <raphaelpier...@gmail.com>
Subject Re: Testing an archetype during build process
Date Tue, 09 Dec 2008 22:46:08 GMT
I forgot,

if you can always the archetype from the build with
create-from-archetype, you can first call test on the project
and trust the archetype plugin has not too much bugs (but it has some)

Raphaël

2008/12/9 Raphaël Piéroni <raphaelpieroni@gmail.com>:
> 2008/12/9 Simone Gianni <simoneg@apache.org>:
>> Hi Raphael,
>> I have some archetypes. They are not generated during build, they are
>> already there, made using the create-from-project originally and then
>> updated and expanded by hand from time to time.
>
> Is it possible to have a sample project and create the archetype on
> the fly or did you use some tricks, the goal can't do?
>
>>
>> Sometimes we do some refactoring here and there in the code, and while
>> all other artifacts gets compiled before being installed/deployed, and
>> the compiler warns if something is wrong, the archetypes are only
>> packaged, so no check is performed to see if the sample java classes
>> (and other stuff in them) are still valid.
>>
>> Then, from time time, some users tell us "hey, I used the archetype to
>> create a new project, but nothing is working", and we recall that we
>> didn't updated the archetypes when we renamed that class, or that
>> package, or that archetype, or whatever (we are still a lab, we still
>> can change stuff pretty radically :D )
>>
>> So, my idea is simply this, during the build, I could use the archetype
>> to create a new project (in /tmp/ for example :D ), then try to build
>> it, and see what the user see when they use our archetype. This way, at
>> least the "is a project produced using this archetype still working?"
>> question would be solved at every build.
>>
>> I already tried to do this invoking maven from inside the archetype pom,
>> but I was thinking about using the maven embedder to run the
>> archetype:create to generate the mock project, and then the "compile" or
>> even the "test" goal to see if everything goes right. Afterall, I'm
>> trying to determine if the final user of my archetype will be able to
>> generate something functional out of it, or if I forgot something (a
>> dependency, a refactoring, etc..).
>
> in the FilesetArchetypeCreator, i use the invoker to call package or
> install goal on the archetype newly generated project
>
> given you manage to create the tested project using the archetype, you
> can call whatever goal you like on that project with
>
>            InvocationRequest internalRequest = new DefaultInvocationRequest();
>            internalRequest.setPomFile( pomFile );
>            internalRequest.setGoals( Collections.singletonList( "test" ) );
>            Invoker invoker = new DefaultInvoker();
>            invoker.execute(internalRequest);
>
> To create new project from archetype, in my tests, i directly the
> plexus components used by the plugin, i know the API ;-)
>
> In ArchetypeGenerationTest
>        ArchetypeCatalog catalog = archetype.getLocalCatalog(
>            new File( getBasedir(),
> "target/test-classes/repositories/central" ).getAbsolutePath()
>                 );
>        org.apache.maven.archetype.catalog.Archetype selection =
> (org.apache.maven.archetype.catalog.Archetype)
>            catalog.getArchetypes().get( catalog.getArchetypes().size() - 1 );
>        ArchetypeGenerationRequest agr = new
> ArchetypeGenerationRequest( selection )
>            .setOutputDirectory( outputDirectory.getAbsolutePath() )
>            .setLocalRepository( localRepository )
>            .setGroupId( groupId )
>            .setArtifactId( artifactId )
>            .setVersion( version )
>            .setPackage( packageName );
>        Properties archetypeRequiredProperties = new Properties();
>        archetypeRequiredProperties.setProperty(
> "property-without-default-1", "some-value-1" );
>        agr.setProperties( archetypeRequiredProperties );
>        ArchetypeGenerationResult result =
> archetype.generateProjectFromArchetype( agr );
>
> This is the usage of the hilevel api, there is also a low level api
> which don't require repository or catalog, only a jar file.
>
>>
>> Moving it a step further, it would be nice if I could drive this from a
>> junit test, making it simpler (we are all used to writing test, aren't
>> we?) and giving me the flexibility to do whatever checks I want on the
>> produced /tmp/ project.
>>
>> Basically I would make the lifecycle of the packaging archetype
>> something like :
>> - Generate the archetype
>> - Generate e temp mock project using the archetype (run mvn
>> archetype:create )
>> - Try to run mvn on the generated project (run at least mvn compile, but
>> could even be mvn test or mvn install or anything the developer expects
>> the user to do with the generated project)
>> - Make sure the two steps above went ok :)
>> - Then package it and install and deploy and everything
>>
>> Or, as an alternative :
>> - Generate the archetype
>> - Run junit tests
>> - Give the developer a simple way to generate a temp mock project, see
>> its content, run mvn on it, from the junit using the embedder or
>> whatever else
>> - Make sure junits went ok
>> - Then package it and install and deploy and everything
>>
>> Or even both :)
>>
>> Simone
>>
>
> Do that fill some questions?
>
> Raphaël
>
>>
>>
>> Raphaël Piéroni wrote:
>>> 2008/12/9 Simone Gianni <simoneg@apache.org>:
>>>
>>>> Hi all,
>>>> in my Magma Apache Lab I'm building some Maven archetypes during the
>>>> main build process, and everything is working fine. Anyway, from time to
>>>> time, an archetype stops working properly due to a refactoring, like a
>>>> class or package name change, or some other similar event.
>>>>
>>>> What I'd like to do is to test these archetypes during the build
>>>> process. The first and easier test would be to actually use them to
>>>> create a mock project and see it build properly, even eventually testing
>>>> itself and propagating the failure to the main build process.
>>>>
>>>
>>> Can you please explain me like toa child what you try to do.
>>> during, your build, you have some sample projects that you turn into archetype
>>> using the create-from-project goal, and would like to run these archetype
>>> into new projects an then run some tests on theses new projects
>>> in order to check that your archetypes are in sync with your libraries ?
>>>
>>> Raphaël
>>>
>>>
>>>
>>>> I found in this mailing list only one thread dealing with archetype
>>>> testing, and it was invoking another mvn command, on a temporary
>>>> directory i suppose. Also, they were suggesting to use the Shitty
>>>> plugin, which actually builds some other projects to run integration tests.
>>>>
>>>> I think a possible solution could be to use the maven-embedder called
>>>> from a Junit test. This would give all the flexibility to run even more
>>>> than one build cycle (for example with different parameters) and/or to
>>>> perform more checks after the project has been created or built.
>>>>
>>>> What I'd like to know from you all is :
>>>> - have you found any other nice way of testing an archetype?
>>>> - is there an interest in this or am I the only paranoid searching for
>>>> such a solution? :D
>>>> - would it make sense to you to make at least the "build-it test" the
>>>> default test phase during archetype build? (I'm planning a contribution
>>>> here :) )
>>>>
>>>> Let me know what you think about it.
>>>>
>>>> Simone
>>>>
>>>>
>>>> --
>>>> Simone Gianni            CEO Semeru s.r.l.           Apache Committer
>>>> http://www.simonegianni.it/
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>>>>
>>
>>
>> --
>> Simone Gianni            CEO Semeru s.r.l.           Apache Committer
>> http://www.simonegianni.it/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>
Mime
View raw message