Examples of ArchetypeCatalog


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

        File outputDirectory = new File( getBasedir(), "target/internal-archetypes-projects" );
        outputDirectory.mkdirs();

        ArchetypeManager archetype = (ArchetypeManager) lookup( ArchetypeManager.class.getName() );

        ArchetypeCatalog result = archetype.getInternalCatalog();

        List<Archetype> archetypesUsed = new ArrayList<Archetype>();
        List<Archetype> archetypesRemoved = new ArrayList<Archetype>();
        int count = 1;
        for ( Archetype a : result.getArchetypes() )
        {
            Archetype ar = new Archetype();

            ar.setGroupId( a.getGroupId() );
            ar.setArtifactId( a.getArtifactId() );
            ar.setVersion( "RELEASE" );
            ar.setDescription( a.getDescription() );
            ar.setGoals( a.getGoals() );
            ar.setProperties( a.getProperties() );
            ar.setRepository( a.getRepository() );
            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() )
                    .setLocalRepository( localRepository );
                generationResult = archetype.generateProjectFromArchetype( request );
                if ( generationResult != null && generationResult.getCause() != null )
                {
                    archetypesRemoved.add( a );
                }
                else
                {
                    archetypesUsed.add( a );
                }
            }
            else
            {
                archetypesUsed.add( a );
            }
            count++;
            System.err.println( "\n\n\n\n\n" );
        }
        result.setArchetypes( archetypesUsed );

        StringWriter sw = new StringWriter();
        ArchetypeCatalogXpp3Writer acxw = new ArchetypeCatalogXpp3Writer();
        acxw.write( sw, result );
View Full Code Here

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

                return downloadCatalog( repositoryPath, filename );
            }
            catch ( Exception ex )
            {
                getLogger().warn( "Error reading archetype catalog " + repository, ex );
                return new ArchetypeCatalog();
            }
        }
    }
View Full Code Here

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

        archetypeInRepository.getParentFile().mkdirs();
        FileUtils.copyFile( archetypeArchive, archetypeInRepository );
        FileUtils.copyFile( generatedArchetypePom, archetypePomInRepository );

        // (4) create our own archetype catalog describing the archetype we just created
        ArchetypeCatalog catalog = new ArchetypeCatalog();
        Archetype generatedArchetype = new Archetype();
        generatedArchetype.setGroupId( generatedArchetypeProject.getGroupId() );
        generatedArchetype.setArtifactId( generatedArchetypeProject.getArtifactId() );
        generatedArchetype.setVersion( generatedArchetypeProject.getVersion() );
        generatedArchetype.setRepository( "http://localhost:" + port + "/repo" );
        catalog.addArchetype( generatedArchetype );

        ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();
        Writer writer = new FileWriter( catalogFile );
        catalogWriter.write( writer, catalog );
        IOUtils.closeQuietly( writer );
View Full Code Here

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

    private ArchetypeCatalogXpp3Writer catalogWriter = new ArchetypeCatalogXpp3Writer();

    public void putArchetypes( List<Archetype> archetypes, Writer writer )
        throws ArchetypeDataSinkException
    {
        ArchetypeCatalog catalog = new ArchetypeCatalog();

        for ( Archetype archetype : archetypes )
        {
            catalog.addArchetype( archetype );
        }

        try
        {
            catalogWriter.write( writer, catalog );
View Full Code Here

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

        getLogger().debug( "Using catalog " + s );

        File catalogFile = new File( s );

        ArchetypeCatalog catalog;
        if ( catalogFile.exists() )
        {
            try
            {
                getLogger().debug( "Reading the catalog " + catalogFile );
                catalog = readCatalog( ReaderFactory.newXmlReader( catalogFile ) );
            }
            catch ( FileNotFoundException ex )
            {
                getLogger().debug( "Catalog file don't exist" );
                catalog = new ArchetypeCatalog();
            }
            catch ( IOException e )
            {
                throw new ArchetypeDataSourceException( "Error reading archetype catalog.", e );
            }
        }
        else
        {
            getLogger().debug( "Catalog file don't exist" );
            catalog = new ArchetypeCatalog();
        }

        Iterator<Archetype> archetypes = catalog.getArchetypes().iterator();
        boolean found = false;
        Archetype newArchetype = archetype;
        while ( !found && archetypes.hasNext() )
        {
            Archetype a = (Archetype) archetypes.next();
            if ( a.getGroupId().equals( archetype.getGroupId() )
                && a.getArtifactId().equals( archetype.getArtifactId() ) )
            {
                newArchetype = a;
                found = true;
            }
        }
        if ( !found )
        {
            catalog.addArchetype( newArchetype );
        }

        newArchetype.setVersion( archetype.getVersion() );
        newArchetype.setRepository( archetype.getRepository() );
        newArchetype.setDescription( archetype.getDescription() );
View Full Code Here

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

                throw new ArchetypeDataSourceException( "Error reading archetype catalog.", e );
            }
        }
        else
        {
            return new ArchetypeCatalog();
        }
    }
View Full Code Here

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

    {
        // ArchetypeDataSource ads =  (ArchetypeDataSource) lookup( ArchetypeDataSource.ROLE, "wiki" );
        ArchetypeDataSource ads = new WikiArchetypeDataSource();

        // fetch and parse Wiki page content
        ArchetypeCatalog ac = ads.getArchetypeCatalog( new Properties() );

        for ( Archetype archetype : ac.getArchetypes() )
        {
            if ( "".equals( archetype.getRepository() )
                || ( archetype.getRepository() != null && archetype.getRepository().indexOf( CENTRAL.substring( 7 ) ) >= 0 ) )
            {
                archetype.setRepository( null );
            }
        }

        System.out.println( "found " + ac.getArchetypes().size() + " archetypes on http://docs.codehaus.org/display/MAVENUSER/Archetypes+List" );

        for ( Archetype archetype : ac.getArchetypes() )
        {
            System.out.println( "  " + archetype );
        }

        return ac;
View Full Code Here

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

        if ( repository == null )
        {
            throw new MojoFailureException( "The repository is not defined. Use -Drepository=/path/to/repository" );
        }

        ArchetypeCatalog catalog = crawler.crawl( repository );

        if ( catalogFile == null )
        {
            catalogFile = new File( repository, "archetype-catalog.xml" );
        }
View Full Code Here

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

        {
            getLogger().warn( "File is not a directory" );
            return null;
        }

        ArchetypeCatalog catalog = new ArchetypeCatalog();
        @SuppressWarnings( "unchecked" )
        Iterator<File> jars = FileUtils.listFiles( repository, new String[] { "jar" }, true ).iterator();

        while ( jars.hasNext() )
        {
            File jar = jars.next();
            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 );
                }
                catch ( XmlPullParserException ex )
                {
                    ex.printStackTrace();
                }
View Full Code Here

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

         {
            Set<Archetype> result = new LinkedHashSet<>();
            if (catalog.hasValue())
            {
               ArchetypeCatalogFactory catalogFactory = catalog.getValue();
               ArchetypeCatalog archetypes = catalogFactory.getArchetypeCatalog();
               if (archetypes != null)
               {
                  result.addAll(archetypes.getArchetypes());
               }
            }
            return result;
         }
      }).setDescription(new Callable<String>()
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.