releasing/makecbr/COutputHandler.pm
changeset 602 3145852acc89
equal deleted inserted replaced
600:6d08f4a05d93 602:3145852acc89
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # COutputHandler
       
    15 # 
       
    16 #
       
    17 
       
    18 package COutputHandler;
       
    19 
       
    20 use strict;
       
    21 use XML::Simple;
       
    22 use File::Basename;
       
    23 use File::Spec;
       
    24 
       
    25 use constant CBROUTPUTFILE => File::Spec->catdir(File::Basename::dirname("$INC{'COutputHandler.pm'}"), 'CBROutputFile.xml');
       
    26 
       
    27 sub new {
       
    28     my $pkg = shift;
       
    29     my $self = {};
       
    30     bless $self, $pkg;
       
    31     
       
    32     $self->ParseOutputFile();
       
    33     
       
    34     return $self;
       
    35 }
       
    36 
       
    37 
       
    38 sub CheckOutput {
       
    39     my $self = shift;
       
    40     my $line = shift;
       
    41     
       
    42     chomp $line;
       
    43     
       
    44     my $amendedLine = $line;
       
    45     $amendedLine =~ s/^-?\s?(error|warning|remark|fatal error):?\s+//i;
       
    46 
       
    47     foreach my $type ('Error', 'Remark', 'Warning') {
       
    48         foreach my $toMatch (@{$self->{file}->{$type}}) {           
       
    49             if ($amendedLine =~ /^$toMatch$/) {
       
    50                 return uc($type) . ": $amendedLine\n";
       
    51             }           
       
    52         }
       
    53     }
       
    54 
       
    55     # did not match, return original line
       
    56     return "$line\n";
       
    57 }
       
    58 
       
    59 
       
    60 sub ParseOutputFile {
       
    61     my $self = shift;
       
    62     $self->{file} = XMLin(CBROUTPUTFILE);
       
    63     
       
    64     # Compile the regular expressions
       
    65     foreach my $type ('Error', 'Remark', 'Warning') {
       
    66        @{$self->{file}->{$type}} = map { qr/$_/i } @{$self->{file}->{$type}}
       
    67     }
       
    68 }
       
    69 
       
    70 1;
       
    71 
       
    72 __END__
       
    73 
       
    74 =pod
       
    75 
       
    76 =head1 NAME
       
    77 
       
    78 COutputHandler.pm
       
    79 
       
    80 =head1 DESCRIPTION
       
    81 
       
    82 A module that checks output from the CBR Tools and promotes requested errors, warnings and remarks to scanlog compatible versions.
       
    83 
       
    84 =head1 SYNOPSIS
       
    85 
       
    86  use strict;
       
    87  use COutputHandler;
       
    88  
       
    89  # Instantiate implementation of COutputHandler
       
    90  my $outputHandler = COutputHandler->new();
       
    91 
       
    92  # Pass the string through CheckOutput before printing it to the log
       
    93  $aLine = $outputHandler->CheckOutput($aLine);
       
    94  
       
    95  print $aLine;
       
    96 
       
    97 =head1 INTERFACE
       
    98 
       
    99 =head2 Object Management
       
   100 
       
   101 =head3 new
       
   102 
       
   103 To be called without any arguments.  Will parse the XML file containing error, warning and remark messages.
       
   104 
       
   105 =head2 Data Management
       
   106 
       
   107 =head3 CheckOuput
       
   108 
       
   109 To be passed a string.  The string is checked to see if it needs to be made scanlog compatible, and if so it is modified and returned.  If not then the original string is returned.
       
   110 
       
   111 =head3 ParseOutputFile
       
   112 
       
   113 Parses the XML file.
       
   114 
       
   115 =head1 COPYRIGHT
       
   116 
       
   117 Copyright (c) 2007 Symbian Software Ltd. All rights reserved.
       
   118 
       
   119 =cut