Package org.apache.maven.archetype

Examples of org.apache.maven.archetype.ArchetypeGenerationRequest


        // With the selected OldArchetype and the parameters you can create a generation request as follows:
        File outputDirectory = new File( getBasedir(), "target/test-classes/projects/archetyper-generate-1" );
        FileUtils.forceDelete(outputDirectory);

        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-with-default-1", "value-1" );
        archetypeRequiredProperties.setProperty( "property-with-default-2", "value-2" );
        archetypeRequiredProperties.setProperty( "property-with-default-3", "value-3" );
        archetypeRequiredProperties.setProperty( "property-with-default-4", "value-4" );
        archetypeRequiredProperties.setProperty( "property-without-default-1", "some-value-1" );
        archetypeRequiredProperties.setProperty( "property-without-default-2", "some-value-2" );
        archetypeRequiredProperties.setProperty( "property-without-default-3", "some-value-3" );
        archetypeRequiredProperties.setProperty( "property-without-default-4", "some-value-4" );
        agr.setProperties( archetypeRequiredProperties );

        // Then generate away!

        ArchetypeGenerationResult result = archetype.generateProjectFromArchetype( agr );
View Full Code Here


            if ( ar.getRepository() == null )
            {
                ar.setRepository( "http://repo1.maven.org/maven2" );
            }
            System.err.println( "\n\n\n\n\n\nTesting archetype " + ar );
            ArchetypeGenerationRequest request =
                new ArchetypeGenerationRequest( ar )
                .setGroupId( "groupId" + count )
                .setArtifactId( "artifactId" + count )
                .setVersion( "version" + count )
                .setPackage( "package" + count )
                .setOutputDirectory( outputDirectory.getPath() )
                .setLocalRepository( localRepository );
            ArchetypeGenerationResult generationResult = archetype.generateProjectFromArchetype( request );
            if ( generationResult != null && generationResult.getCause() != null )
            {
                ar.setVersion( a.getVersion() );
                request =
                    new ArchetypeGenerationRequest( ar )
                    .setGroupId( "groupId" + count )
                    .setArtifactId( "artifactId" + count )
                    .setVersion( "version" + count )
                    .setPackage( "package" + count )
                    .setOutputDirectory( outputDirectory.getPath() )
View Full Code Here

        String outputDirectory = new File( getBasedir(),
                                           "target" + File.separator + "test-classes" + File.separator + "projects"
                                               + File.separator + "roundtrip-multi-recreated" ).getAbsolutePath();
        FileUtils.forceDelete( outputDirectory );

        ArchetypeGenerationRequest agr = new ArchetypeGenerationRequest().setArchetypeGroupId(
            generatedArchetypeProject.getGroupId() ).setArchetypeArtifactId(
            generatedArchetypeProject.getArtifactId() ).setArchetypeVersion(
            generatedArchetypeProject.getVersion() ).setGroupId( "com.mycompany" ).setArtifactId( "myapp" ).setVersion(
            "1.0-SNAPSHOT" ).setPackage( "com.mycompany.myapp" ).setOutputDirectory(
            outputDirectory ).setLocalRepository( localRepository ).setArchetypeRepository(
View Full Code Here

    private ArchetypeGenerationResult testArchetype( int count, Archetype archetype )
        throws UnknownArchetype
    {
        System.out.println( "\n\nTesting archetype #" + count + ": " + archetype );

        ArchetypeGenerationRequest request =
            new ArchetypeGenerationRequest( archetype )
            .setGroupId( "groupId" + count )
            .setArtifactId( "artifactId" + count + "-" + archetype.getArtifactId() )
            .setVersion( "version" + count )
            .setPackage( "package" + count )
            .setOutputDirectory( outputDirectory.getPath() )
            .setLocalRepository( localRepository );

        Properties properties = new Properties();

        ArtifactRepository repository =
            arm.createRepository( archetype.getRepository(), archetype.getRepository() + "-repo" );

        if ( aam.isFileSetArchetype( archetype.getGroupId(), archetype.getArtifactId(), archetype.getVersion(),
                                     repository, localRepository, new ArrayList<ArtifactRepository>() ) )
        {
            ArchetypeDescriptor descriptor =
                aam.getFileSetArchetypeDescriptor( archetype.getGroupId(), archetype.getArtifactId(),
                                                   archetype.getVersion(), repository, localRepository,
                                                   new ArrayList<ArtifactRepository>() );

            for ( RequiredProperty prop : descriptor.getRequiredProperties() )
            {
                properties.setProperty( prop.getKey(), prop.getDefaultValue() != null
                    && !"".equals( prop.getDefaultValue() ) ? prop.getDefaultValue() : "test-value" );
            }

        }
        request.setProperties( properties );

        return plexusarchetype.generateProjectFromArchetype( request );
    }
View Full Code Here

    public void testArchetypeArtifactIdInRequest()
        throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
        ArchetypeNotDefined
    {
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();
        request.setArchetypeArtifactId( "preset-artifactId" );

        MockControl control = MockControl.createControl( ArchetypeSelectionQueryer.class );

        ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
        // expect it to not be called

        control.replay();

        selector.setArchetypeSelectionQueryer( queryer );

        selector.selectArchetype( request, Boolean.TRUE, "" );

        control.verify();

        assertEquals( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_GROUPID, request.getArchetypeGroupId() );
        assertEquals( "preset-artifactId", request.getArchetypeArtifactId() );
        assertEquals( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_VERSION, request.getArchetypeVersion() );
    }
View Full Code Here

    public void testArchetypeArtifactIdNotInRequest()
        throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
        ArchetypeNotDefined
    {
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();

        MockControl control = MockControl.createControl( ArchetypeSelectionQueryer.class );

        ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
        queryer.selectArchetype( Collections.<String, List<Archetype>> emptyMap(), new ArchetypeDefinition() );
        control.setMatcher( MockControl.ALWAYS_MATCHER );
        Archetype archetype = new Archetype();
        archetype.setArtifactId( "set-artifactId" );
        archetype.setGroupId( "set-groupId" );
        archetype.setVersion( "set-version" );
        control.setReturnValue( archetype );

        control.replay();

        selector.setArchetypeSelectionQueryer( queryer );

        selector.selectArchetype( request, Boolean.TRUE, "" );

        control.verify();

        assertEquals( "set-groupId", request.getArchetypeGroupId() );
        assertEquals( "set-artifactId", request.getArchetypeArtifactId() );
        assertEquals( "set-version", request.getArchetypeVersion() );
    }
View Full Code Here

    public void testArchetypeNotInRequestDefaultsInBatchMode()
        throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
        ArchetypeNotDefined
    {
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();

        MockControl control = MockControl.createControl( ArchetypeSelectionQueryer.class );

        ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
        // expect it to not be called

        control.replay();

        selector.setArchetypeSelectionQueryer( queryer );

        selector.selectArchetype( request, Boolean.FALSE, "" );

        control.verify();

        assertEquals( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_GROUPID, request.getArchetypeGroupId() );
        assertEquals( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_ARTIFACTID, request.getArchetypeArtifactId() );
        assertEquals( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_VERSION, request.getArchetypeVersion() );
    }
View Full Code Here

    public void testArchetypeNotInRequestDefaults()
        throws PrompterException, IOException, UnknownGroup, ArchetypeSelectionFailure, UnknownArchetype,
        ArchetypeNotDefined
    {
        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest();

        MockControl control = MockControl.createControl( ArchetypeSelectionQueryer.class );

        ArchetypeSelectionQueryer queryer = (ArchetypeSelectionQueryer) control.getMock();
        queryer.selectArchetype( Collections.<String, List<Archetype>> emptyMap(), createDefaultArchetypeDefinition() );
        control.setMatcher( createArgumentMatcher() );
        Archetype archetype = new Archetype();
        archetype.setArtifactId( "set-artifactId" );
        archetype.setGroupId( "set-groupId" );
        archetype.setVersion( "set-version" );
        control.setReturnValue( archetype );

        control.replay();

        selector.setArchetypeSelectionQueryer( queryer );

        selector.selectArchetype( request, Boolean.TRUE, "" );

        control.verify();

        assertEquals( "set-groupId", request.getArchetypeGroupId() );
        assertEquals( "set-artifactId", request.getArchetypeArtifactId() );
        assertEquals( "set-version", request.getArchetypeVersion() );
    }
View Full Code Here

            }
        }

        try
        {
            ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
                .setPackage( packageName )
                .setGroupId( groupId )
                .setArtifactId( artifactId )
                .setVersion( version )
                .setArchetypeGroupId( archetypeGroupId )
View Full Code Here

    public void execute()
        throws MojoExecutionException, MojoFailureException
    {
        Properties executionProperties = session.getExecutionProperties();

        ArchetypeGenerationRequest request = new ArchetypeGenerationRequest()
            .setArchetypeGroupId( archetypeGroupId )
            .setArchetypeArtifactId( archetypeArtifactId )
            .setArchetypeVersion( archetypeVersion )
            .setOutputDirectory( basedir.getAbsolutePath() )
            .setLocalRepository( localRepository )
            .setArchetypeRepository( archetypeRepository )
            .setRemoteArtifactRepositories( remoteArtifactRepositories )
            .setFilter( filter );

        try
        {
            if ( interactiveMode.booleanValue() )
            {
                getLog().info( "Generating project in Interactive mode" );
            }
            else
            {
                getLog().info( "Generating project in Batch mode" );
            }

            selector.selectArchetype( request, interactiveMode, archetypeCatalog );

            if ( StringUtils.isBlank( request.getArchetypeArtifactId() ) )
            {
                // no archetype found: stopping
                return;
            }

            configurator.configureArchetype( request, interactiveMode, executionProperties );

            ArchetypeGenerationResult generationResult = manager.generateProjectFromArchetype( request );

            if ( generationResult.getCause() != null )
            {
                throw new MojoFailureException( generationResult.getCause(), generationResult.getCause().getMessage(),
                                                generationResult.getCause().getMessage() );
            }
        }
        catch ( MojoFailureException ex )
        {
            throw ex;
        }
        catch ( Exception ex )
        {
            throw (MojoFailureException) new MojoFailureException( ex.getMessage() ).initCause( ex );
        }

        String artifactId = request.getArtifactId();

        String postArchetypeGenerationGoals = request.getArchetypeGoals();

        if ( StringUtils.isEmpty( postArchetypeGenerationGoals ) )
        {
            postArchetypeGenerationGoals = goals;
        }
View Full Code Here

TOP

Related Classes of org.apache.maven.archetype.ArchetypeGenerationRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.