common/tools/brag/raptorToBRAG.pl
changeset 761 3901909be1ab
parent 753 5069de517698
child 807 194ddb729c09
--- a/common/tools/brag/raptorToBRAG.pl	Fri Nov 13 15:53:47 2009 +0000
+++ b/common/tools/brag/raptorToBRAG.pl	Mon Nov 16 14:47:25 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,116 +85,34 @@
 	$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 {
-#		href => "",
-		Kids => [ bless { Text => $failure->{subcategory} }, "Characters" ]
+		Kids => [ bless { Kids => [ bless { Text => $failure->{subcategory} }, "Characters" ]}, "effect" ],
 	}, "failure";
 	if ($failure->{component})
 	{
 		$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 ">";
-}
-