Examples of Archetype


Examples of org.apache.maven.archetype.catalog.Archetype

    }

    public Archetype selectArchetype( Map<String, List<Archetype>> catalogs, ArchetypeDefinition defaultDefinition )
        throws PrompterException
    {
        Archetype selection = null;
        Map<String, List<Archetype>> filteredCatalogs = catalogs;

        do
        {
            StringBuilder query = new StringBuilder( "Choose archetype:\n" );

            Set<String> archetypeKeys = new HashSet<String>();
            List<String> answers = new ArrayList<String>();
            Map<String, Archetype> archetypeAnswerMap = new HashMap<String, Archetype>();

            int counter = 0;
            int defaultSelection = 0;

            for ( Map.Entry<String, List<Archetype>> entry : filteredCatalogs.entrySet() )
            {
                String catalog = entry.getKey();

                for ( Archetype archetype : entry.getValue() )
                {
                    String archetypeKey = archetype.getGroupId() + ":" + archetype.getArtifactId();

                    if ( !archetypeKeys.add( archetypeKey ) )
                    {
                        continue;
                    }

                    counter++;

                    String description = archetype.getDescription();
                    if ( description == null )
                    {
                        description = "-";
                    }

                    String answer = String.valueOf( counter );

                    query.append( answer + ": " + catalog + " -> " + archetype.getGroupId() + ":"
                        + archetype.getArtifactId() + " (" + description + ")\n" );

                    answers.add( answer );

                    archetypeAnswerMap.put( answer, archetype );

                    // the version is not tested. This is intentional.
                    if ( defaultDefinition != null && archetype.getGroupId().equals( defaultDefinition.getGroupId() )
                        && archetype.getArtifactId().equals( defaultDefinition.getArtifactId() ) )
                    {
                        defaultSelection = counter;
                    }
                }
            }

            if ( counter == 0 )
            {
                query.append( "   Your filter doesn't match any archetype (hint: enter to return to initial list)\n" );
            }

            query.append( "Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): " );

            String answer;
            if ( defaultSelection == 0 )
            {
                answer = prompter.prompt( query.toString() );
            }
            else
            {
                answer = prompter.prompt( query.toString(), Integer.toString( defaultSelection ) );
            }

            if ( NumberUtils.isNumber( answer ) )
            {
                selection = archetypeAnswerMap.get( answer );
            }
            else
            {
                // not a number so apply filter and ask again
                filteredCatalogs = ArchetypeSelectorUtils.getFilteredArchetypesByCatalog( catalogs, answer );
            }
        }
        while ( selection == null );

        return selectVersion( catalogs, selection.getGroupId(), selection.getArtifactId() );
    }
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

        String mapKey = null;

        for ( Map.Entry<ArtifactVersion, Archetype> entry : archetypeVersionsMap.entrySet() )
        {
            ArtifactVersion version = entry.getKey();
            Archetype archetype = entry.getValue();

            mapKey = String.valueOf( counter );

            query.append( mapKey + ": " + version + "\n" );

            answers.add( mapKey );

            answerMap.put( mapKey, archetype );

            counter++;
        }

        query.append( "Choose a number: " );

        Archetype archetype = null;

        do
        {
            String answer = prompter.prompt( query.toString(), answers, mapKey );
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

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

Examples of org.apache.maven.archetype.catalog.Archetype

    }

    private Map.Entry<String, Archetype> findArchetype( Map<String, List<Archetype>> archetypes, String groupId,
                                                        String artifactId )
    {
        Archetype example = new Archetype();
        example.setGroupId( groupId );
        example.setArtifactId( artifactId );

        for ( Map.Entry<String, List<Archetype>> entry : archetypes.entrySet() )
        {
            List<Archetype> catalog = entry.getValue();

            if ( catalog.contains( example ) )
            {
                Archetype archetype = catalog.get( catalog.indexOf( example ) );

                return newMapEntry( entry.getKey(), archetype );
            }
        }
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

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

Examples of org.apache.maven.archetype.catalog.Archetype

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

Examples of org.apache.maven.archetype.catalog.Archetype

    private MavenProject project;

    public void execute()
        throws MojoExecutionException
    {
        Archetype archetype = new Archetype();
        archetype.setGroupId( project.getGroupId() );
        archetype.setArtifactId( project.getArtifactId() );
        archetype.setVersion( project.getVersion() );

        if ( StringUtils.isNotEmpty( project.getDescription() ) )
        {
            archetype.setDescription( project.getDescription() );
        }
        else
        {
            archetype.setDescription( project.getName() );
        }

        manager.updateLocalCatalog( archetype );
    }
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

            getLogger().info( "Scanning " + jar );
            if ( archetypeArtifactManager.isFileSetArchetype( jar ) || archetypeArtifactManager.isOldArchetype( jar ) )
            {
                try
                {
                    Archetype archetype = new Archetype();

                    Model pom = archetypeArtifactManager.getArchetypePom( jar );

                    if ( archetypeArtifactManager.isFileSetArchetype( jar ) )
                    {
                        org.apache.maven.archetype.metadata.ArchetypeDescriptor descriptor =
                            archetypeArtifactManager.getFileSetArchetypeDescriptor( jar );
                        archetype.setDescription( descriptor.getName() );
                    }
                    else
                    {
                        org.apache.maven.archetype.old.descriptor.ArchetypeDescriptor descriptor =
                            archetypeArtifactManager.getOldArchetypeDescriptor( jar );
                        archetype.setDescription( descriptor.getId() );
                    }
                    if ( pom != null )
                    {
                        if ( pom.getGroupId() != null )
                        {
                            archetype.setGroupId( pom.getGroupId() );
                        }
                        else
                        {
                            archetype.setGroupId( pom.getParent().getGroupId() );
                        }
                        archetype.setArtifactId( pom.getArtifactId() );
                        if ( pom.getVersion() != null )
                        {
                            archetype.setVersion( pom.getVersion() );
                        }
                        else
                        {
                            archetype.setVersion( pom.getParent().getVersion() );
                        }
                        getLogger().info( "\tArchetype " + archetype + " found in pom" );
                    }
                    else
                    {
                        String version = jar.getParentFile().getName();

                        String artifactId = jar.getParentFile().getParentFile().getName();

                        String groupIdSep =
                            StringUtils.replace( jar.getParentFile().getParentFile().getParentFile().getPath(),
                                                 repository.getPath(), "" );
                        String groupId = groupIdSep.replace( File.separatorChar, '.' );
                        groupId = groupId.startsWith( "." ) ? groupId.substring( 1 ) : groupId;
                        groupId = groupId.endsWith( "." ) ? groupId.substring( 0, groupId.length() - 1 ) : groupId;

                        archetype.setGroupId( groupId );
                        archetype.setArtifactId( artifactId );
                        archetype.setVersion( version );

                        getLogger().info( "\tArchetype " + archetype + " defined by repository path" );
                    } // end if-else

                    catalog.addArchetype( archetype );
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

      }).setDescription(new Callable<String>()
      {
         @Override
         public String call() throws Exception
         {
            Archetype value = archetype.getValue();
            return value == null ? null : value.getDescription();
         }
      });
      builder.add(catalog).add(archetype);
   }
View Full Code Here

Examples of org.apache.maven.archetype.catalog.Archetype

   @Override
   public Result execute(UIExecutionContext context) throws Exception
   {
      UIContext uiContext = context.getUIContext();
      Project project = (Project) uiContext.getAttributeMap().get(Project.class);
      Archetype chosenArchetype = archetype.getValue();
      String coordinate = chosenArchetype.getGroupId() + ":" + chosenArchetype.getArtifactId() + ":"
               + chosenArchetype.getVersion();
      DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate);
      String repository = chosenArchetype.getRepository();
      if (!Strings.isNullOrEmpty(repository))
      {
         if (repository.endsWith(".xml"))
         {
            int lastRepositoryPath = repository.lastIndexOf('/');
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.