Examples of ArchetypeDefinition


Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        control.setReturnValue( "1" );
        queryer.setPrompter( prompter );

        control.replay();

        ArchetypeDefinition defaultDefinition = new ArchetypeDefinition();
        defaultDefinition.setGroupId( "default-groupId" );
        defaultDefinition.setArtifactId( "default-artifactId" );
        defaultDefinition.setVersion( "default-version" );
        Archetype archetype = queryer.selectArchetype( map, defaultDefinition );

        control.verify();

        assertEquals( "set-groupId", archetype.getGroupId() );
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        control.setReturnValue( "2" );
        queryer.setPrompter( prompter );

        control.replay();

        ArchetypeDefinition defaultDefinition = new ArchetypeDefinition();
        defaultDefinition.setGroupId( "default-groupId" );
        defaultDefinition.setArtifactId( "default-artifactId" );
        defaultDefinition.setVersion( "default-version" );
        Archetype archetype = queryer.selectArchetype( map, defaultDefinition );

        control.verify();

        assertEquals( "default-groupId", archetype.getGroupId() );
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        control.setReturnValue( "1" );
        queryer.setPrompter( prompter );

        control.replay();

        ArchetypeDefinition defaultDefinition = new ArchetypeDefinition();
        defaultDefinition.setGroupId( "invalid-groupId" );
        defaultDefinition.setArtifactId( "invalid-artifactId" );
        defaultDefinition.setVersion( "invalid-version" );
        Archetype archetype = queryer.selectArchetype( map, defaultDefinition );

        control.verify();

        assertEquals( "set-groupId", archetype.getGroupId() );
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

                                                  List<String> languages )
        throws IOException, ArchetypeNotDefined, ArchetypeNotConfigured, PrompterException, TemplateCreationException
    {
        Properties properties = initialiseArchetypeProperties( commandLineProperties, propertyFile );

        ArchetypeDefinition archetypeDefinition = archetypeFactory.createArchetypeDefinition( properties );

        if ( !archetypeDefinition.isDefined() )
        {
            archetypeDefinition = defineDefaultArchetype( project, properties );
        }

        ArchetypeConfiguration archetypeConfiguration =
            archetypeFactory.createArchetypeConfiguration( project, archetypeDefinition, properties );

        String resolvedPackage = archetypeFilesResolver.resolvePackage( project.getBasedir(), languages );

        if ( !archetypeConfiguration.isConfigured() )
        {
            archetypeConfiguration =
                defineDefaultConfiguration( project, archetypeDefinition, resolvedPackage, properties );
        }

        if ( interactiveMode.booleanValue() )
        {
            getLogger().debug( "Entering interactive mode" );

            boolean confirmed = false;
            while ( !confirmed )
            {
                if ( !archetypeDefinition.isDefined() )// <editor-fold text="...">
                {
                    getLogger().debug( "Archetype is yet not defined" );
                    if ( !archetypeDefinition.isGroupDefined() )
                    {
                        getLogger().debug( "Asking for archetype's groupId" );
                        archetypeDefinition.setGroupId( archetypeCreationQueryer.getArchetypeGroupId( project.getGroupId() ) );
                    }
                    if ( !archetypeDefinition.isArtifactDefined() )
                    {
                        getLogger().debug( "Asking for archetype's artifactId" );
                        archetypeDefinition.setArtifactId( archetypeCreationQueryer.getArchetypeArtifactId( project.getArtifactId()
                            + Constants.ARCHETYPE_SUFFIX ) );
                    }
                    if ( !archetypeDefinition.isVersionDefined() )
                    {
                        getLogger().debug( "Asking for archetype's version" );
                        archetypeDefinition.setVersion( archetypeCreationQueryer.getArchetypeVersion( project.getVersion() ) );
                    }

                    archetypeFactory.updateArchetypeConfiguration( archetypeConfiguration, archetypeDefinition );
                } // </editor-fold>

                if ( !archetypeConfiguration.isConfigured() )// <editor-fold text="...">
                {
                    getLogger().debug( "Archetype is not yet configured" );
                    if ( !archetypeConfiguration.isConfigured( Constants.GROUP_ID ) )
                    {
                        getLogger().debug( "Asking for project's groupId" );
                        archetypeConfiguration.setProperty(
                                                            Constants.GROUP_ID,
                                                            archetypeCreationQueryer.getGroupId( archetypeConfiguration.getDefaultValue( Constants.GROUP_ID ) ) );
                    }
                    if ( !archetypeConfiguration.isConfigured( Constants.ARTIFACT_ID ) )
                    {
                        getLogger().debug( "Asking for project's artifactId" );
                        archetypeConfiguration.setProperty(
                                                            Constants.ARTIFACT_ID,
                                                            archetypeCreationQueryer.getArtifactId( archetypeConfiguration.getDefaultValue( Constants.ARTIFACT_ID ) ) );
                    }
                    if ( !archetypeConfiguration.isConfigured( Constants.VERSION ) )
                    {
                        getLogger().debug( "Asking for project's version" );
                        archetypeConfiguration.setProperty(
                                                            Constants.VERSION,
                                                            archetypeCreationQueryer.getVersion( archetypeConfiguration.getDefaultValue( Constants.VERSION ) ) );
                    }
                    if ( !archetypeConfiguration.isConfigured( Constants.PACKAGE ) )
                    {
                        getLogger().debug( "Asking for project's package" );
                        archetypeConfiguration.setProperty(
                                                            Constants.PACKAGE,
                                                            archetypeCreationQueryer.getPackage( StringUtils.isEmpty( resolvedPackage ) ? archetypeConfiguration.getDefaultValue( Constants.PACKAGE )
                                                                            : resolvedPackage ) );
                    }
                } // </editor-fold>

                boolean stopAddingProperties = false;
                while ( !stopAddingProperties )
                {
                    getLogger().debug( "Asking for another required property" );
                    stopAddingProperties = !archetypeCreationQueryer.askAddAnotherProperty();

                    if ( !stopAddingProperties )
                    {
                        getLogger().debug( "Asking for required property key" );

                        String propertyKey = archetypeCreationQueryer.askNewPropertyKey();
                        getLogger().debug( "Asking for required property value" );

                        String replacementValue =
                            archetypeCreationQueryer.askReplacementValue(
                                                                          propertyKey,
                                                                          archetypeConfiguration.getDefaultValue( propertyKey ) );
                        archetypeConfiguration.setDefaultProperty( propertyKey, replacementValue );
                        archetypeConfiguration.setProperty( propertyKey, replacementValue );
                    }
                }

                getLogger().debug( "Asking for configuration confirmation" );
                if ( archetypeCreationQueryer.confirmConfiguration( archetypeConfiguration ) )
                {
                    confirmed = true;
                }
                else
                {
                    getLogger().debug( "Reseting archetype's definition and configuration" );
                    archetypeConfiguration.reset();
                    archetypeDefinition.reset();
                }
            } // end while
        }
        else
        {
            getLogger().debug( "Entering batch mode" );
            if ( !archetypeDefinition.isDefined() )
            {
                throw new ArchetypeNotDefined( "The archetype is not defined" );
            }
            else if ( !archetypeConfiguration.isConfigured() )
            {
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

    public void selectArchetype( ArchetypeGenerationRequest request, Boolean interactiveMode, String catalogs )
        throws ArchetypeNotDefined, UnknownArchetype, UnknownGroup, IOException, PrompterException,
        ArchetypeSelectionFailure
    {
        ArchetypeDefinition definition = new ArchetypeDefinition( request );

        if ( definition.isDefined() && StringUtils.isNotEmpty( request.getArchetypeRepository() ) )
        {
            getLogger().info( "Archetype defined by properties" );
            return;
        }

        Map<String, List<Archetype>> archetypes = getArchetypesByCatalog( catalogs );

        if ( StringUtils.isNotBlank( request.getFilter() ) )
        {
            // applying some filtering depending on filter parameter
            archetypes = ArchetypeSelectorUtils.getFilteredArchetypesByCatalog( archetypes, request.getFilter() );
            if ( archetypes.isEmpty() )
            {
                getLogger().info( "Your filter doesn't match any archetype, so try again with another value." );
                return;
            }
        }

        if ( definition.isDefined() && StringUtils.isEmpty( request.getArchetypeRepository() ) )
        {
            Map.Entry<String, Archetype> found =
                findArchetype( archetypes, request.getArchetypeGroupId(), request.getArchetypeArtifactId() );

            if ( found != null )
            {
                String catalogKey = found.getKey();
                Archetype archetype = found.getValue();

                updateRepository( definition, archetype, catalogKey );

                getLogger().info( "Archetype repository missing. Using the one from " + archetype + " found in catalog "
                                      + catalogKey );
            }
            else
            {
                getLogger().warn(
                    "Archetype not found in any catalog. Falling back to central repository (http://repo1.maven.org/maven2)." );
                getLogger().warn(
                    "Use -DarchetypeRepository=<your repository> if archetype's repository is elsewhere." );

                definition.setRepository( "http://repo1.maven.org/maven2" );
            }
        }

        if ( !definition.isDefined() && definition.isPartiallyDefined() )
        {
            Map.Entry<String, Archetype> found =
                findArchetype( archetypes, request.getArchetypeGroupId(), request.getArchetypeArtifactId() );

            if ( found != null )
            {
                String catalogKey = found.getKey();
                Archetype archetype = found.getValue();

                updateDefinition( definition, archetype, catalogKey );

                getLogger().info( "Archetype " + archetype + " found in catalog " + catalogKey );
            }
            else
            {
                getLogger().warn( "Specified archetype not found." );
                if ( interactiveMode.booleanValue() )
                {
                    definition.setVersion( null );
                    definition.setGroupId( null );
                    definition.setArtifactId( null );
                }
            }
        }

        // set the defaults - only group and version can be auto-defaulted
        if ( definition.getGroupId() == null )
        {
            definition.setGroupId( DEFAULT_ARCHETYPE_GROUPID );
        }
        if ( definition.getVersion() == null )
        {
            definition.setVersion( DEFAULT_ARCHETYPE_VERSION );
        }

        if ( !definition.isPartiallyDefined() )
        {
            // if artifact ID is set to its default, we still prompt to confirm
            if ( definition.getArtifactId() == null )
            {
                getLogger().info(
                    "No archetype defined. Using " + DEFAULT_ARCHETYPE_ARTIFACTID + " (" + definition.getGroupId() + ":"
                        + DEFAULT_ARCHETYPE_ARTIFACTID + ":" + definition.getVersion() + ")" );
                definition.setArtifactId( DEFAULT_ARCHETYPE_ARTIFACTID );
            }

            if ( interactiveMode.booleanValue() && ( archetypes.size() > 0 ) )
            {
                Archetype selectedArchetype = archetypeSelectionQueryer.selectArchetype( archetypes, definition );

                String catalogKey = getCatalogKey( archetypes, selectedArchetype );

                updateDefinition( definition, selectedArchetype, catalogKey );
            }

            // Make sure the groupId and artifactId are valid, the version may just default to
            // the latest release.
            if ( !definition.isPartiallyDefined() )
            {
                throw new ArchetypeSelectionFailure( "No valid archetypes could be found to choose." );
            }
        }

        // finally update the request with gathered information
        definition.updateRequest( request );
    }
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        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" );
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        assertEquals( "set-version", request.getArchetypeVersion() );
    }

    private ArchetypeDefinition createDefaultArchetypeDefinition()
    {
        ArchetypeDefinition definition = new ArchetypeDefinition();
        definition.setGroupId( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_GROUPID );
        definition.setArtifactId( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_ARTIFACTID );
        definition.setVersion( DefaultArchetypeSelector.DEFAULT_ARCHETYPE_VERSION );
        return definition;
    }
View Full Code Here

Examples of org.apache.maven.archetype.ui.ArchetypeDefinition

        List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>();

        Properties properties = new Properties( executionProperties );

        ArchetypeDefinition ad = new ArchetypeDefinition( request );

        if ( !ad.isDefined() )
        {
            if ( !interactiveMode.booleanValue() )
            {
                throw new ArchetypeNotDefined( "No archetype was chosen" );
            }
            else
            {
                throw new ArchetypeNotDefined( "The archetype is not defined" );
            }
        }
        if ( request.getArchetypeRepository() != null )
        {
            archetypeRepository =
                archetypeRegistryManager.createRepository( request.getArchetypeRepository(),
                                                           ad.getArtifactId() + "-repo" );
            repositories.add( archetypeRepository );
        }
        if ( request.getRemoteArtifactRepositories() != null )
        {
            repositories.addAll( request.getRemoteArtifactRepositories() );
        }

        if ( !archetypeArtifactManager.exists( ad.getGroupId(), ad.getArtifactId(), ad.getVersion(),
                                               archetypeRepository, localRepository, repositories ) )
        {
            throw new UnknownArchetype( "The desired archetype does not exist (" + ad.getGroupId() + ":"
                + ad.getArtifactId() + ":" + ad.getVersion() + ")" );
        }

        request.setArchetypeVersion( ad.getVersion() );

        ArchetypeConfiguration archetypeConfiguration;

        if ( archetypeArtifactManager.isFileSetArchetype( ad.getGroupId(), ad.getArtifactId(), ad.getVersion(),
                                                          archetypeRepository, localRepository, repositories ) )
        {
            org.apache.maven.archetype.metadata.ArchetypeDescriptor archetypeDescriptor =
                archetypeArtifactManager.getFileSetArchetypeDescriptor( ad.getGroupId(), ad.getArtifactId(),
                                                                        ad.getVersion(), archetypeRepository,
                                                                        localRepository, repositories );

            archetypeConfiguration = archetypeFactory.createArchetypeConfiguration( archetypeDescriptor, properties );
        }
        else if ( archetypeArtifactManager.isOldArchetype( ad.getGroupId(), ad.getArtifactId(), ad.getVersion(),
                                                           archetypeRepository, localRepository, repositories ) )
        {
            org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor archetypeDescriptor =
                archetypeArtifactManager.getOldArchetypeDescriptor( ad.getGroupId(), ad.getArtifactId(),
                                                                    ad.getVersion(), archetypeRepository,
                                                                    localRepository, repositories );

            archetypeConfiguration = archetypeFactory.createArchetypeConfiguration( archetypeDescriptor, properties );
        }
        else
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.