common/tools/brag/raptorToBRAG.pl
changeset 752 1f07674ec99f
parent 665 ddca63d8e13c
child 753 5069de517698
--- a/common/tools/brag/raptorToBRAG.pl	Thu Nov 12 11:56:20 2009 +0000
+++ b/common/tools/brag/raptorToBRAG.pl	Tue Nov 10 16:52:27 2009 +0000
@@ -18,10 +18,12 @@
 
 use FindBin;
 use lib "$FindBin::Bin/../lib";
+use lib "$FindBin::Bin";
 
 use Getopt::Long;
 use Text::CSV;
 
+use ToBrag;
 
 my $raptorSummary;
 my $help = 0;
@@ -39,24 +41,9 @@
 }
 
 # Start to build structure to be output as XML (same format as XML::Parser would create for us)
-my $xmlNewline = bless { Text => "\n" }, "Characters";
-my $buildStatus =
-[
-	bless
-	{
-		Kids =>
-		[
-			$xmlNewline,
-			bless
-			{
-				name => "Build",
-				Kids => [ $xmlNewline ]
-			}, "phase",
-		]
-	}, "buildStatus"
-];
-# Get a shortcut reference to the bit we will use a lot
-my $buildPhase = $buildStatus->[0]->{Kids}->[-1];
+my $buildStatus = ToBrag::createBuildStatus();
+# Obtain a phase object
+my $buildPhase = ToBrag::ensurePhase($buildStatus, "Build");
 
 # READ SUMMARY.CSV FILE
 open(CSV, $raptorSummary);
@@ -98,47 +85,15 @@
 	$failure->{subcategory} ||= 'uncategorized';
 	$failure->{severity} ||= 'unknown';
 	
-	# Look through the steps to see if we already have one to match this config
-	my $step;
-	foreach (@{$buildPhase->{Kids}})
-	{
-		next unless ref $_ eq "step";
-		if ($_->{name} eq $failure->{config})
-		{
-			$step = $_;
-			last;
-		}
-	}
-	unless ($step)
-	{
-		# First item found in this step - create step entry
-		$step = bless { name => $failure->{config}, Kids => [ $xmlNewline ] }, "step";
-		push @{$buildPhase->{Kids}}, $step, $xmlNewline;
-		# Also create empty <failures> tags with severities in a sensible order
-		foreach my $severity (qw{critical major minor})
-		{
-			my $failureSet = bless { level => $severity, Kids => [ $xmlNewline ] }, "failures";
-			push @{$step->{Kids}}, $failureSet, $xmlNewline;
-		}
-	}
+	# Obtain a matching step
+	my $step = ToBrag::ensureStep($buildPhase, $failure->{config});
+	# Also create empty <failures> tags with severities in a sensible order
+	ToBrag::ensureFailureSet($step, "critical");
+	ToBrag::ensureFailureSet($step, "major");
+	ToBrag::ensureFailureSet($step, "minor");
 	
-	# Look through the sets of failures in this step to see if we hve one which matches this severity
-	my $failureSet;
-	foreach (@{$step->{Kids}})
-	{
-		next unless ref $_ eq "failures";
-		if ($_->{level} eq $failure->{severity})
-		{
-			$failureSet = $_;
-			last;
-		}
-	}
-	unless ($failureSet)
-	{
-		# First item found at this severity - create failures entry
-		$failureSet = bless { level => $failure->{severity}, Kids => [ $xmlNewline ] }, "failures";
-		push @{$step->{Kids}}, $failureSet, $xmlNewline;
-	}
+	# Obtain a set of failures which matches this severity
+	my $failureSet = ToBrag::ensureFailureSet($step, $failure->{severity});
 
 	# Now create the failure itself, and add it to this failure set
 	my $failureItem = bless {
@@ -150,64 +105,15 @@
 		$failure->{component} =~ s{^(/sf/.*?/.*?)/.*$}{$1};
 		$failureItem->{package} = $failure->{component};
 	}
-	push @{$failureSet->{Kids}}, $failureItem, $xmlNewline;
+	push @{$failureSet->{Kids}}, $failureItem, $ToBrag::xmlNewline;
 }
 close(CSV);
 
 # Print XML
 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 print "<?xml-stylesheet type='text/xsl' href='brag.xsl'?>\n";
-printTree($buildStatus->[0]);
+ToBrag::printTree($buildStatus->[0]);
 print "\n";
 
 exit(0);
 
-sub printTree
-{
-	my $tree = shift or die;
-	die unless ref $tree;
-
-	my $tagName = ref $tree;
-	$tagName =~ s{^main::}{};
-	if ($tagName eq "Characters")
-	{
-		print $tree->{Text};
-		return;
-	}
-	
-	print "<$tagName";
-
-	foreach my $attr (
-		sort {
-			my $order = "name level start stop href";
-			my $ixA = index $order, $a;
-			my $ixB = index $order, $b;
-			die "$a $b" if $ixA + $ixB == -2;
-			$ixA - $ixB;
-		}
-		grep {
-			! ref $tree->{$_}
-		}
-		keys %$tree)
-	{
-		print " $attr=\"$tree->{$attr}\"";
-	}
-
-	my $children = $tree->{Kids} || [];
-	if (scalar @$children)
-	{
-		print ">";
-		foreach my $child (@$children)
-		{
-			printTree($child);
-		}
-		print "</$tagName";
-	}
-	else
-	{
-		print "/"
-	}
-
-	print ">";
-}
-