Advertisement

03.01.2007 at 09:07AM PST, ID: 22421862
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Need help reading and debug a perl script

Asked by meaar in CGI Scripting, Perl Programming Language

Tags: ,

------------------------
ERROR
-------------------------
Use of uninitialized value in concatenation (.) or string at D:\Inetpub\cgi-bin\rweb\junit\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_failed.gif",
      "TESTS_FAILED" => "project/junit/tests_failed.gif",
      "BUILDING" => "project/junit/building.gif"
);


my $pageProperties;

# log script actions
open( LOG, ">project/junit/junit-summary.log");
print LOG "\n" . ctime() . "\n====================\n";

# require 5.004;

#
#======================================================================
# Subs

sub LoadProperties($)
{
      my $propertyFile = shift;
      my %properties;

      open(PROPERTIES,"<$propertyFile") 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}->{"branch.name"} = $branchSpec->{"branch.name"};
            }
            else
            {
                  print LOG "Using default branch.name\n";
                  $results->{$branch}->{"branch.name"} = $branch;
            }
            if ( defined $branchSpec->{"branch.path"} )
            {
                  print LOG "Using property branch.path\n";
                  $results->{$branch}->{"branch.path"} = $branchSpec->{"branch.path"} . "/...";
            }
            else
            {
                  print LOG "Using default branch.path\n";
                  $results->{$branch}->{"branch.path"} = "//archive/" . $branch . "/...";
            }
            print LOG "branch.name=" . $results->{$branch}->{"branch.name"} . "\n";
            print LOG "branch.path=" . $results->{$branch}->{"branch.path"} . "\n";


            # Javadoc
            if ( -d $branchRoot . "/javadoc/product" )
            {
                  $results->{$branch}->{"javadoc"}->{"product"} = Dir2URL( $branchRoot . "/javadoc/product" );
                  print LOG "Found product javadoc\n";
            }
            if ( -d $branchRoot . "/javadoc/testcases" )
            {
                  $results->{$branch}->{"javadoc"}->{"testcases"} = Dir2URL( $branchRoot . "/javadoc/testcases" );
                  print LOG "Found testcases javadoc\n";
            }


            # Code-coverage pages
            if ( -d $branchRoot . "/coverage/html" )
            {
                  $results->{$branch}->{"coverage"}->{"html"} = Dir2URL( $branchRoot . "/coverage/html" );
                  print LOG "Found HTML coverage page\n";
            }
            if ( -d $branchRoot . "/coverage/xml" )
            {
                  $results->{$branch}->{"coverage"}->{"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}->{"builds"}->{$build}->{"junit"}->{"frames"} = Dir2URL( $buildRoot . "/results/frames" );
                        print LOG "Found JUnit frames results\n";
                  }

                  if ( -d $buildRoot . "/results/noframes" )
                  {
                        $results->{$branch}->{"builds"}->{$build}->{"junit"}->{"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}->{"builds"}->{$build}->{"junit"}->{"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}->{"builds"}->{$build}->{"log"}->{"build"} = Dir2URL( $buildRoot . "/build_log.txt" );
                  }
                  else
                  {
                        print LOG "Did not find $buildRoot/build_log.txt\n";
                  }


                  # Build starttime
                  $results->{$branch}->{"builds"}->{$build}->{"starttime"} = $buildProperties->{"build.starttime"};
                  print LOG "buildstatus: " . $results->{$branch}->{"builds"}->{$build}->{"starttime"} . "\n";


                  # Build status
                  $results->{$branch}->{"builds"}->{$build}->{"status"} = $buildProperties->{"build.status"};
                  print LOG "buildstatus: " . $results->{$branch}->{"builds"}->{$build}->{"status"} . "\n";


                  # Changelists (format into an array)
                  my $tmpChangelists = $buildProperties->{"changelists"};
                  print LOG "changelists: $tmpChangelists\n";
                  my @changelists = split( /,/, $tmpChangelists);
                  $results->{$branch}->{"builds"}->{$build}->{"changelists"} = \@changelists;

            }
      }
      return $results;
}


sub Dir2URL($)
{
      my $url = shift;
      $url =~ s/$pageProperties->{"web.root.dir"}/$pageProperties->{"web.root.url"}/;
      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}->{"starttime"} } = $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/junit/junit-summary.properties");

# Get results hash:
my $allResults = GetAllResults( $pageProperties );

# URL info:
my $THIS_URL = "/cgi-bin/project/junit/summarize-junit.pl";
my $P4WEB_URL = "http://perforce-depot:21666/";

#======================================================================
#
# Perforce info:
my $P4PORT = "port-num:1666";
my $P4CLIENT = "cm-project-3_project-junit-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.path"}`;
      chomp( $tipChange);
      $tipChange =~ s/Change (\d*) .*/$1/;

      print LOG "Tip change: $tipChange\n";

print <<EOF;
        <tr>
        <th align="left" bgcolor="$GREY">$branch</th>
          <th align="center"bgcolor="$GREY">Javadoc:
EOF

      if ( defined $branchResults->{"javadoc"}->{"product"} )
      {
print <<EOF;
           <a href="$branchResults->{"javadoc"}->{"product"}/">Product</a>
EOF
      }


      if ( defined $branchResults->{"javadoc"}->{"testcases"} )
      {
print <<EOF;
           <a href="$branchResults->{"javadoc"}->{"testcases"}/">Testcases</a>
EOF
      }


#if ( $branch eq "Trunk" )
#{
#print <<EOF;
#         | <a href="http://otto2.na.wrq.com/project/javadoc/${branch}/report/">Javadoc Checker</a>
#EOF
#}


print <<EOF;
        </th>
          <th align="center" bgcolor="$GREY">Current tip: <a href="$P4WEB_URL\@md=d&cd=//&c=8rL\@/$tipChange?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:
          &nbsp;<a href="$branchResults->{"coverage"}->{"html"}">HTML</a>
EOF
            }


            # Coverage XML
            if ( defined $branchResults->{"coverage"}->{"xml"} ) {
print <<EOF;
          &nbsp;<a href="$branchResults->{"coverage"}->{"xml"}/clover-report.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->{"cgi.root.url"}/$statusMap{$buildStatus}"></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->{"changelists"}} )
            {
print <<EOF;
          <a href="$P4WEB_URL\@md=d&cd=//&c=8rL\@/$change?ac=10">$change</a>
EOF
            }


            if ( defined $buildResults->{"log"}->{"build"} )
            {
                  print LOG "Build-log present\n";

print <<EOF;
        </td>
        <td align="center">
          <a href="$buildResults->{"log"}->{"build"}">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->{"junit"}->{"frames"}/">frames</a>
        | <a href="$buildResults->{"junit"}->{"noframes"}/junit-noframes.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->{"junit"}->{"output"}">success output</a>
EOF
            }

#
# Add link to UI-validation log, if it's there:
#            if ( -f "$junitDir/project_validation.html") {
#print <<EOF;
#        | <a href="$junitUrl/project_validation.html">UI-log</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->{"cgi.root.url"}/$statusMap{"TESTS_PASSED"}"/></td><td align="left">Tests Passed</td>
          </tr><tr>
            <td><image src="$pageProperties->{"cgi.root.url"}/$statusMap{"TESTS_FAILED"}"/><td align="left">Tests Failed</td>
          </tr><tr>
            <td><image src="$pageProperties->{"cgi.root.url"}/$statusMap{"BUILD_FAILED"}"/></td><td align="left">Build Failed</td>
          </tr><tr>
            <td><image src="$pageProperties->{"cgi.root.url"}/$statusMap{"BUILDING"}"/><td 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
[+][-]03.01.2007 at 09:14AM PST, ID: 18633886

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.01.2007 at 02:06PM PST, ID: 18636370

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: CGI Scripting, Perl Programming Language
Tags: p4cmd, perl
Sign Up Now!
Solution Provided By: Perl_Diver
Participating Experts: 2
Solution Grade: A
 
 
[+][-]03.01.2007 at 02:25PM PST, ID: 18636544

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.01.2007 at 04:44PM PST, ID: 18637360

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.01.2007 at 08:25PM PST, ID: 18638145

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 11:58AM PDT, ID: 19343902

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32