// manually flush out the cache for memory concerns and more accurate building
flushProjectCache( projectBuilder );
}
catch ( ProjectBuildingException e )
{
throw new ConsumerException( e.getMessage(), e );
}
DependencyNode rootNode;
try
{
// TODO: do this for different values of new ScopeArtifactFilter( scope )
ArtifactFilter artifactFilter = null;
rootNode =
dependencyTreeBuilder.buildDependencyTree( project, localArtifactRepository, artifactFactory,
artifactMetadataSource, artifactFilter, artifactCollector );
}
catch ( DependencyTreeBuilderException e )
{
throw new ConsumerException( e.getMessage(), e );
}
Document document = DocumentHelper.createDocument();
DependencyNodeVisitor visitor = new XmlSerializingDependencyNodeVisitor( document );
// TODO: remove the need for this when the serializer can calculate last nodes from visitor calls only
visitor = new BuildingDependencyNodeVisitor( visitor );
CollectingDependencyNodeVisitor collectingVisitor = new CollectingDependencyNodeVisitor();
DependencyNodeVisitor firstPassVisitor =
new FilteringDependencyNodeVisitor( collectingVisitor, StateDependencyNodeFilter.INCLUDED );
rootNode.accept( firstPassVisitor );
DependencyNodeFilter secondPassFilter = new AncestorOrSelfDependencyNodeFilter( collectingVisitor.getNodes() );
visitor = new FilteringDependencyNodeVisitor( visitor, secondPassFilter );
rootNode.accept( visitor );
FileWriter writer = null;
try
{
Artifact artifact =
artifactFactory.createProjectArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion() );
String p = layout.pathOf( artifact );
if ( !p.equals( path ) )
{
throw new ConsumerException( "Bad path: " + p + "; should be: " + path );
}
File generatedFile = new File( generatedRepositoryLocation, p + ".xml" );
generatedFile.getParentFile().mkdirs();
writer = new FileWriter( generatedFile );
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter w = new XMLWriter( writer, format );
w.write( document );
}
catch ( IOException e )
{
throw new ConsumerException( e.getMessage(), e );
}
finally
{
IOUtils.closeQuietly( writer );
}