}
public void testInternalCatalog()
throws Exception
{
ArchetypeCatalog ac = fetchArchetypeCatalogFromWiki();
System.out.println( "Testing archetypes to " + outputDirectory.getPath() );
List<Archetype> validArchetypes = new ArrayList<Archetype>();
int count = 1;
List<String> errors = new ArrayList<String>();
List<String> warnings = new ArrayList<String>();
for ( Archetype a : ac.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( CENTRAL );
}
ArchetypeGenerationResult releaseGenerationResult = testArchetype( count, ar );
if ( releaseGenerationResult.getCause() != null )
{
// RELEASE version failed: try with the version specified in the Wiki
ar.setVersion( a.getVersion() );
ArchetypeGenerationResult generationResult = testArchetype( count, ar );
if ( generationResult.getCause() == null )
{
if ( !( ar.getVersion().indexOf( "SNAPSHOT" ) > 0 )
&& !( ar.getVersion().indexOf( "snapshot" ) > 0 ) )
{
validArchetypes.add( ar );
warnings.add( "#" + count + ' ' + ar + ": error for RELEASE - " + releaseGenerationResult.getCause().getMessage() );
}
}
else
{
errors.add( "#" + count + ' ' + ar + ' ' + generationResult.getCause().getMessage() );
}
}
else
{
validArchetypes.add( ar );
if ( !"RELEASE".equals( a.getVersion() ) )
{
warnings.add( "#" + count + ' ' + ar + ": Wiki page mentions " + a.getVersion() +", should be empty since RELEASE is ok." );
}
}
if ( CENTRAL.equals( ar.getRepository() ) )
{
ar.setRepository( null );
}
count++;
System.out.println( "\n\n" );
}
ArchetypeCatalog fac = new ArchetypeCatalog();
fac.setArchetypes( validArchetypes );
File catalog = new File( getBasedir(), "target/archetype-catalog.xml" );
Writer writer = null;
try
{
writer = WriterFactory.newXmlWriter( catalog );
ArchetypeCatalogXpp3Writer acxw = new ArchetypeCatalogXpp3Writer();
acxw.write( writer, fac );
}
finally
{
IOUtil.close( writer );
}
if ( warnings.size() > 0 )
{
System.err.println();
System.err.println( "Warnings: " );
for ( String warning : warnings )
{
System.err.println( " " + warning );
}
}
System.err.println();
System.err.println( "Resulting catalog file: " + catalog );
System.err.println( "This catalog contains " + fac.getArchetypes().size() + " archetypes." );
if ( ac.getArchetypes().size() > fac.getArchetypes().size() )
{
System.err.println();
System.err.println( "Removed " + ( ac.getArchetypes().size() - fac.getArchetypes().size() )
+ " archetype(s) from Wiki page:" );
List<Archetype> removedArchetypes = new ArrayList<Archetype>( ac.getArchetypes() );
removedArchetypes.removeAll( validArchetypes );