------------------------
ERROR
-------------------------
Use of uninitialized value in concatenation (.) or string at D:\Inetpub\cgi-bin\rweb\ju
nit\junit-
summary.pl
line 481.
--------------------------
SCRIPT
--------------------------
#!/usr/bin/perl -w
#
# Displays the results of continuous JUnit testing.
#=========================
==========
==========
==========
==========
=====
use strict;
use File::stat;
use Time::localtime;
use Time::gmtime;
# Define colors
my $GREY = "#BBBBBB";
my $WHITE = "#FFFFFF";
my %statusMap = (
"TESTS_PASSED" => "project/junit/success.gif
",
"BUILD_FAILED" => "project/junit/build_faile
d.gif",
"TESTS_FAILED" => "project/junit/tests_faile
d.gif",
"BUILDING" => "project/junit/building.gi
f"
);
my $pageProperties;
# log script actions
open( LOG, ">project/junit/junit-summ
ary.log");
print LOG "\n" . ctime() . "\n====================\n"
;
# require 5.004;
#
#=========================
==========
==========
==========
==========
=====
# Subs
sub LoadProperties($)
{
my $propertyFile = shift;
my %properties;
open(PROPERTIES,"<$propert
yFile") or die "Could not open $propertyFile\n";
while(<PROPERTIES>)
{
if (/^(\S+)=(.+)/)
{
$properties{$1}=$2;
}
}
close PROPERTIES;
return \%properties;
}
sub GetSubdirs($)
{
my $root = shift;
my @subdirs=();
if ( -d $root )
{
my @dirs = `find $root -type d -maxdepth 1`;
foreach (@dirs)
{
chomp;
if ($_ ne $root)
{
# Just keep the directory name, not the entire path.
s/^.*[\/]([^\/]*)/$1/;
push @subdirs, $_;
}
}
}
return \@subdirs;
}
sub GetAllResults($)
{
my $pageProperties = shift;
my $results;
# Get list of branches
my @branchDirs = @{ GetSubdirs( $pageProperties->{"report.
root.dir"}
) };
# Get list of builds for each branch
foreach my $branch (@branchDirs)
{
my $branchRoot = $pageProperties->{"report.
root.dir"}
. "/" . $branch;
print LOG "\n\nGetting info for branch $branch\n";
# Branch name and depot path
my $branchSpec;
if ( -f $branchRoot . "/branch.properties" )
{
print LOG "Reading branch.properties\n";
$branchSpec = LoadProperties( $branchRoot . "/branch.properties" );
}
else
{
print LOG "Could not find branch.properties\n";
}
if ( defined $branchSpec->{"branch.name
"} )
{
print LOG "Using property branch.name\n";
$results->{$branch}->{"bra
nch.name"}
= $branchSpec->{"branch.name
"};
}
else
{
print LOG "Using default branch.name\n";
$results->{$branch}->{"bra
nch.name"}
= $branch;
}
if ( defined $branchSpec->{"branch.path
"} )
{
print LOG "Using property branch.path\n";
$results->{$branch}->{"bra
nch.path"}
= $branchSpec->{"branch.path
"} . "/...";
}
else
{
print LOG "Using default branch.path\n";
$results->{$branch}->{"bra
nch.path"}
= "//archive/" . $branch . "/...";
}
print LOG "branch.name=" . $results->{$branch}->{"bra
nch.name"}
. "\n";
print LOG "branch.path=" . $results->{$branch}->{"bra
nch.path"}
. "\n";
# Javadoc
if ( -d $branchRoot . "/javadoc/product" )
{
$results->{$branch}->{"jav
adoc"}->{"
product"} = Dir2URL( $branchRoot . "/javadoc/product" );
print LOG "Found product javadoc\n";
}
if ( -d $branchRoot . "/javadoc/testcases" )
{
$results->{$branch}->{"jav
adoc"}->{"
testcases"
} = Dir2URL( $branchRoot . "/javadoc/testcases" );
print LOG "Found testcases javadoc\n";
}
# Code-coverage pages
if ( -d $branchRoot . "/coverage/html" )
{
$results->{$branch}->{"cov
erage"}->{
"html"} = Dir2URL( $branchRoot . "/coverage/html" );
print LOG "Found HTML coverage page\n";
}
if ( -d $branchRoot . "/coverage/xml" )
{
$results->{$branch}->{"cov
erage"}->{
"xml"} = Dir2URL( $branchRoot . "/coverage/xml" );
print LOG "Found XML coverage page\n";
}
#
# Get the detail from each build
my @buildDirs = @{ GetSubdirs( $branchRoot . "/builds" ) };
foreach my $build (@buildDirs)
{
my $buildRoot = $branchRoot . "/builds/" . $build;
next if ( ! -f $buildRoot . "/ci.properties");
my $buildProperties = LoadProperties( $buildRoot . "/ci.properties" );
print LOG "Getting info for build $build\n";
# JUnit results
if ( -d $buildRoot . "/results/frames" )
{
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"j
unit"}->{"
frames"} = Dir2URL( $buildRoot . "/results/frames" );
print LOG "Found JUnit frames results\n";
}
if ( -d $buildRoot . "/results/noframes" )
{
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"j
unit"}->{"
noframes"}
= Dir2URL( $buildRoot . "/results/noframes" );
print LOG "Found JUnit no-frames results\n";
}
if ( -f $buildRoot . "/results/output.log" )
{
print LOG "Found $buildRoot/results/output.
log\n";
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"j
unit"}->{"
output"} = Dir2URL( $buildRoot . "/results/output.log" );
}
else
{
print LOG "Did not find $buildRoot/results/output.
log\n";
}
# Build log
if ( -f "$buildRoot/build_log.txt"
)
{
print LOG "Found $buildRoot/build_log.txt\n
";
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"l
og"}->{"bu
ild"} = Dir2URL( $buildRoot . "/build_log.txt" );
}
else
{
print LOG "Did not find $buildRoot/build_log.txt\n
";
}
# Build starttime
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"s
tarttime"}
= $buildProperties->{"build.
starttime"
};
print LOG "buildstatus: " . $results->{$branch}->{"bui
lds"}->{$b
uild}->{"s
tarttime"}
. "\n";
# Build status
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"s
tatus"} = $buildProperties->{"build.
status"};
print LOG "buildstatus: " . $results->{$branch}->{"bui
lds"}->{$b
uild}->{"s
tatus"} . "\n";
# Changelists (format into an array)
my $tmpChangelists = $buildProperties->{"change
lists"};
print LOG "changelists: $tmpChangelists\n";
my @changelists = split( /,/, $tmpChangelists);
$results->{$branch}->{"bui
lds"}->{$b
uild}->{"c
hangelists
"} = \@changelists;
}
}
return $results;
}
sub Dir2URL($)
{
my $url = shift;
$url =~ s/$pageProperties->{"web.r
oot.dir"}/
$pagePrope
rties->{"w
eb.root.ur
l"}/;
return $url;
}
#
# Sort the builds from latest to earliest. The build-time should already
# be formatted for sorting.
#
sub SortBuildsByStarttime($)
{
my $results = shift;
my @keys;
# Reverse the hash: starttime is key; branch is value
my %tempHash;
foreach my $build (keys %$results)
{
$tempHash{ $results->{$build}->{"star
ttime"} } = $build;
}
# Sort the keys (starttime)
my @sorted = sort { $b <=> $a } keys %tempHash;
foreach my $key (@sorted)
{
push @keys, $tempHash{$key};
}
return \@keys;
}
# End subs
#=========================
==========
==========
==========
==========
=====
# Main
# Sync to latest files
#system("p4 sync");
# Load the properties
$pageProperties = LoadProperties("project/ju
nit/junit-
summary.pr
operties")
;
# Get results hash:
my $allResults = GetAllResults( $pageProperties );
# URL info:
my $THIS_URL = "/cgi-bin/project/junit/su
mmarize-ju
nit.pl";
my $P4WEB_URL = "
http://perforce-depot:21666/";
#=========================
==========
==========
==========
==========
=====
#
# Perforce info:
my $P4PORT = "port-num:1666";
my $P4CLIENT = "cm-project-3_project-juni
t-summary"
;
my $P4USER = "buser";
my $P4CMD = "p4 -p $P4PORT -c $P4CLIENT -u $P4USER";
$ENV{P4PORT} = $P4PORT;
$ENV{P4CLIENT} = $P4CLIENT;
$ENV{P4USER} = $P4USER;
#=========================
==========
==========
==========
==========
=====
#
# Present the page
print LOG "\n\nCreating webpage ...\n";
print <<EOF;
Content-type: text/html
<html>
<head/>
<body bgcolor=$WHITE>
<center><h1>Continuous JUnit Results</h1></center>
<table border="0" width="100%">
EOF
#=========================
==========
==========
==========
==========
=====
#
# Column headings
print <<EOF;
<tr>
<td colspan="5">
<table width="100%" align="left" border="0">
<tr>
<th align="left">Builds</th>
<th align="center">Start Time</th>
<th align="center">Changelists
</th>
<th align="center">Logs</th>
<th align="center">Reports</th
>
</tr>
EOF
#=========================
==========
==========
==========
==========
=====
#
# Present data from each branch
foreach my $branch (sort keys %$allResults ) {
print LOG "Branch: $branch\n";
my $branchResults = $allResults->{$branch};
my $reportRoot = $pageProperties->{"report.
root.dir"}
. "/" . $branch;
my $reportRootUrl = $pageProperties->{"report.
root.url"}
. "/" . $branch;
#
# Get the current tip change for this branch
my $tipChange = `$P4CMD changes -m 1 -s submitted $branchResults->{"branch.p
ath"}`;
chomp( $tipChange);
$tipChange =~ s/Change (\d*) .*/$1/;
print LOG "Tip change: $tipChange\n";
print <<EOF;
<tr>
<th align="left" bgcolor="$GREY">$branch</t
h>
<th align="center"bgcolor="$GR
EY">Javado
c:
EOF
if ( defined $branchResults->{"javadoc"
}->{"produ
ct"} )
{
print <<EOF;
<a href="$branchResults->{"ja
vadoc"}->{
"product"}
/">Product
</a>
EOF
}
if ( defined $branchResults->{"javadoc"
}->{"testc
ases"} )
{
print <<EOF;
<a href="$branchResults->{"ja
vadoc"}->{
"testcases
"}/">Testc
ases</a>
EOF
}
#if ( $branch eq "Trunk" )
#{
#print <<EOF;
# | <a href="
http://otto2.na.wrq.com/project/javadoc/${branch}/
report/">J
avadoc Checker</a>
#EOF
#}
print <<EOF;
</th>
<th align="center" bgcolor="$GREY">Current tip: <a href="$P4WEB_URL\@md=d&cd=
//&c=8rL\@
/$tipChang
e?ac=10">$
tipChange<
/a></th>
EOF
# Code-coverage column
print <<EOF;
<th bgcolor="$GREY"/><th align="center" bgcolor="$GREY">
EOF
# Coverage HTML
if ( defined $branchResults->{"coverage
"}->{"html
"} ) {
print <<EOF;
Clover:
<a href="$branchResults->{"co
verage"}->
{"html"}">
HTML</a>
EOF
}
# Coverage XML
if ( defined $branchResults->{"coverage
"}->{"xml"
} ) {
print <<EOF;
<a href="$branchResults->{"co
verage"}->
{"xml"}/cl
over-repor
t.xml">XML
</a>
EOF
}
print <<EOF;
</th>
</tr>
EOF
# Get the list of output dirs for this branch, in order of latest to earliest:
my $ref_buildList = SortBuildsByStarttime( $branchResults->{"builds"}
);
# Iterate through the builds, displaying links to the reports:
foreach my $build (@$ref_buildList)
{
print LOG "build: $build\n";
my $buildResults = $branchResults->{"builds"}
->{$build}
;
my $buildStatus = $buildResults->{"status"};
print <<EOF;
<tr>
<td align="left"><image src="$pageProperties->{"cg
i.root.url
"}/$status
Map{$build
Status}"><
/td>
EOF
my $starttime = "";
if ( defined $buildResults->{"starttime
"} )
{
$starttime = $buildResults->{"starttime
"};
$starttime =~ s/^\d\d(\d\d)(\d\d)(\d\d)(
\d\d)(\d\d
)\d\d$/$2\
/$3\/$1 $4:$5/;
print LOG "starttime: $starttime\n";
}
else
{
print LOG "No starttime\n";
$starttime = $build;
}
print <<EOF;
<td align="center">$starttime<
/td>
<td align="center">
EOF
foreach my $change ( @{$buildResults->{"changel
ists"}} )
{
print <<EOF;
<a href="$P4WEB_URL\@md=d&cd=
//&c=8rL\@
/$change?a
c=10">$cha
nge</a>
EOF
}
if ( defined $buildResults->{"log"}->{"
build"} )
{
print LOG "Build-log present\n";
print <<EOF;
</td>
<td align="center">
<a href="$buildResults->{"log
"}->{"buil
d"}">build
</a>
</td>
EOF
}
else
{
print LOG "Build-log not defined\n";
}
#=========================
==========
==========
==========
==========
=====
#
#
# Add link to unit tests if they exist
if ( defined $buildResults->{"junit"} )
{
print <<EOF;
<td align="center">
<a href="$buildResults->{"jun
it"}->{"fr
ames"}/">f
rames</a>
| <a href="$buildResults->{"jun
it"}->{"no
frames"}/j
unit-nofra
mes.html">
no-frames<
/a>
EOF
}
#
# Add link to successful test output log, if it's there:
if ( defined $buildResults->{"junit"}->
{"output"}
) {
print <<EOF;
| <a href="$buildResults->{"jun
it"}->{"ou
tput"}">su
ccess output</a>
EOF
}
#
# Add link to UI-validation log, if it's there:
# if ( -f "$junitDir/project_validat
ion.html")
{
#print <<EOF;
# | <a href="$junitUrl/project_va
lidation.h
tml">UI-lo
g</a>
#EOF
# }
print <<EOF;
</td>
</tr>
EOF
}
# close HISTLOG or warn "Couldn't close $bldhistlog after reading: $!";
}
print <<EOF;
<tr>
<td colspan="5">
<hr/>
<table align="left" border="0">
<tr>
<th colspan="2" align="left">Legend</th>
</tr><tr>
<td><image src="$pageProperties->{"cg
i.root.url
"}/$status
Map{"TESTS
_PASSED"}"
/></td><td
align="left">Tests Passed</td>
</tr><tr>
<td><image src="$pageProperties->{"cg
i.root.url
"}/$status
Map{"TESTS
_FAILED"}"
/><td align="left">Tests Failed</td>
</tr><tr>
<td><image src="$pageProperties->{"cg
i.root.url
"}/$status
Map{"BUILD
_FAILED"}"
/></td><td
align="left">Build Failed</td>
</tr><tr>
<td><image src="$pageProperties->{"cg
i.root.url
"}/$status
Map{"BUILD
ING"}"/><t
d align="left">Build in progress</td>
</tr>
</table>
</td>
</tr>
EOF
#=========================
==========
==========
==========
==========
=====
#
# Add the footer
print <<EOF;
</table>
</td></tr>
</table>
</body>
</html>
EOF
exit(0);
Start Free Trial