123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- #
- # Software Index, Copyright 2010, Software Index Project Team
- # Link: http://swi.sourceforge.net
- #
- # This file is part of Software Index Tool.
- #
- # Software Index is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 3 of the License.
- #
- # Software Index is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with Software Index. If not, see <http://www.gnu.org/licenses/>.
- #
- use strict;
- use XML::Simple;
- use FileHandle;
- #
- # Export section
- #
- require Exporter;
- use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $PREFERRED_PARSER);
- @ISA = qw(Exporter);
- @EXPORT = qw(swiLaunch);
- @EXPORT_OK = qw();
- $VERSION = '1.0';
- $PREFERRED_PARSER = undef;
- #
- # Subroutine for troubleshooting purposes
- #
- use Internal::Output;
- #
- # Include SWI libs
- #
- require SWI::Appraiser;
- require SWI::Converter;
- require SWI::Merger;
- require SWI::Processor;
- #
- # Global variables
- #
- my $config = undef;
- #
- # Enter point
- #
- sub swiLaunch
- {
- my $returnCode = 0;
- my $rootLocation = shift();
- my $swiConfiguration = shift();
- # $returnCode == 0 => no critical errors and warnings
- # $returnCode > 0 => no critical errors, there are warnings
- # $returnCode < 0 => there are critical errors
- if ( $returnCode >= 0 )
- {
- if ( $swiConfiguration eq "" )
- {
- STATUS("Configuration file should be specified!");
- $returnCode = -1;
- }
- else
- {
- STATUS("Configuration file: $swiConfiguration.");
- }
- }
- if ( $returnCode >= 0 )
- {
- if ( swiConfigurationValidate($swiConfiguration) != 0 )
- {
- STATUS("Wrong configuration file!");
- $returnCode = -2;
- }
- }
- if ( $returnCode >= 0 )
- {
- # Generate report for every module separately
- for (
- my $i = 0 ;
- $i <= $#{ $config->{"swi:modules"}->{"swi:module"} } ;
- $i++
- )
- {
- STATUS( "Processing module: '"
- . $config->{"swi:modules"}->{"swi:module"}[$i]->{"swi:name"}
- . "'." );
- my $result = swiProcess( $config, $i, $rootLocation );
- if ( $result < 0 )
- {
- STATUS("The are problems to report the index for the module!");
- $returnCode = -5;
- }
- elsif ( $result > 0 )
- {
- STATUS("The are scan warnings and/or errors.");
- $returnCode += $result;
- }
- else
- {
- STATUS("The module has been processed succesfully.");
- }
- }
- }
- if ( $returnCode >= 0 )
- {
- # Merge reports
- if ( swiMerge($config) )
- {
- STATUS("The are problems to merge files to one report!");
- $returnCode = -3;
- }
- else
- {
- STATUS("Merged report has been created.");
- }
- }
- if ( $returnCode >= 0 )
- {
- # Add average/min/max/total values and generate final XML report
- if ( swiAppraise($config) )
- {
- STATUS("The are problems to add average/min/max/total values!");
- $returnCode = -4;
- }
- else
- {
- STATUS("Average/min/max/total values have been added.");
- }
- }
- if ( $returnCode >= 0 )
- {
- # Convert results
- my $result = swiConvert($config);
- if ( $result < 0 )
- {
- STATUS("The are problems to convert the report!");
- $returnCode = -5;
- }
- elsif ( $result > 0 )
- {
- STATUS(
- "Report has been converted. There are exceeded limitations.");
- $returnCode += $result;
- }
- else
- {
- STATUS("Report has been converted.");
- }
- }
- STATUS("Execution completed with exit code '$returnCode'.");
- return $returnCode;
- }
- sub swiConfigurationValidate
- {
- my $result = 0;
- $config =
- XMLin( shift(),
- ForceArray => [ "swi:module", "swi:rule", "swi:pattern" ] );
- if ( !defined( $config->{'swi:info'} ) )
- {
- STATUS("Wrong configuration: 'swi:info' section missed.");
- $result++;
- }
- else
- {
- if ( !defined( $config->{'swi:info'}->{'swi:version'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:info/swi:version' section missed.");
- $result++;
- }
- elsif ( $config->{'swi:info'}->{'swi:version'} != 1 )
- {
- STATUS(
- "Wrong configuration: Unsupported version of the configuration file. Check 'swi:info/swi:version' section."
- );
- $result++;
- }
- if ( !defined( $config->{'swi:info'}->{'swi:project'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:info/swi:project' section missed.");
- $result++;
- }
- else
- {
- if (
- !defined(
- $config->{'swi:info'}->{'swi:project'}->{'swi:name'}
- )
- )
- {
- STATUS(
- "Wrong configuration: 'swi:info/swi:project/swi:name' section missed."
- );
- $result++;
- }
- elsif ( $config->{'swi:info'}->{'swi:project'}->{'swi:name'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:info/swi:project/swi:name' is empty."
- );
- $result++;
- }
- }
- }
- if ( !defined( $config->{'swi:general'} )
- || ref( $config->{'swi:general'} ) ne 'HASH' )
- {
- $config->{'swi:general'} = {};
- }
- if ( !defined( $config->{'swi:general'}->{'swi:debug'} )
- || ref( $config->{'swi:general'}->{'swi:debug'} ) ne 'HASH' )
- {
- $config->{'swi:general'}->{'swi:debug'} = {};
- }
- if ( !defined( $config->{'swi:general'}->{'swi:debug'}->{'swi:enabled'} ) )
- {
- $config->{'swi:general'}->{'swi:debug'}->{'swi:enabled'} = 'off';
- }
- DEBUG_ENABLED(
- ( $config->{'swi:general'}->{'swi:debug'}->{'swi:enabled'} eq 'on' )
- ? 1
- : 0
- );
- if ( !defined( $config->{'swi:modules'} )
- || ref( $config->{'swi:modules'} ) ne 'HASH' )
- {
- STATUS("Wrong configuration: 'swi:modules' section missed.");
- $result++;
- }
- else
- {
- if ( !defined( $config->{'swi:modules'}->{'swi:module'} )
- || ref( $config->{'swi:modules'}->{'swi:module'} ) ne 'ARRAY' )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module' section missed."
- );
- $result++;
- }
- else
- {
- my $moduleId = 0;
- foreach my $module ( @{ $config->{'swi:modules'}->{'swi:module'} } )
- {
- if ( !defined( $module->{'swi:name'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:name' section missed."
- );
- $result++;
- }
- if ( !defined( $module->{'swi:location'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:location' section missed."
- );
- $result++;
- }
- if ( !defined( $module->{'swi:files'} )
- || ref( $module->{'swi:files'} ) ne 'HASH' )
- {
- $module->{'swi:files'} = {};
- }
- if ( !defined( $module->{'swi:files'}->{'swi:include'} ) )
- {
- $module->{'swi:files'}->{'swi:include'} = '.*';
- }
- if ( !defined( $module->{'swi:files'}->{'swi:exclude'} ) )
- {
- $module->{'swi:files'}->{'swi:exclude'} = '';
- }
- if ( !defined( $module->{'swi:preprocessor'} )
- || ref( $module->{'swi:preprocessor'} ) ne 'HASH' )
- {
- $module->{'swi:preprocessor'} = {};
- }
- if ( !defined( $module->{'swi:preprocessor'}->{'swi:rule'} ) )
- {
- $module->{'swi:preprocessor'}->{'swi:rule'} = [];
- }
- my $ruleId = 0;
- foreach
- my $rule ( @{ $module->{'swi:preprocessor'}->{'swi:rule'} } )
- {
- if ( !defined( $rule->{'swi:filepattern'} )
- || $rule->{'swi:filepattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:preprocessor/swi:rule[$ruleId]/swi:filepattern' section missed."
- );
- $result++;
- }
- if ( !defined( $rule->{'swi:searchpattern'} )
- || $rule->{'swi:searchpattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:preprocessor/swi:rule[$ruleId]/swi:searchpattern' section missed."
- );
- $result++;
- }
- if ( !defined( $rule->{'swi:replacepattern'} )
- || $rule->{'swi:replacepattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:preprocessor/swi:rule[$ruleId]/swi:replacepattern' section missed."
- );
- $result++;
- }
- $ruleId++;
- }
- if ( !defined( $module->{'swi:scanner'} )
- || ref( $module->{'swi:scanner'} ) ne 'HASH' )
- {
- $module->{'swi:scanner'} = {};
- }
- if ( !defined( $module->{'swi:scanner'}->{'swi:rule'} ) )
- {
- $module->{'swi:scanner'}->{'swi:rule'} = [];
- }
- $ruleId = 0;
- foreach my $rule ( @{ $module->{'swi:scanner'}->{'swi:rule'} } )
- {
- if ( !defined( $rule->{'swi:filepattern'} )
- || $rule->{'swi:filepattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:rule[$ruleId]/swi:filepattern' section missed."
- );
- $result++;
- }
- if ( !defined( $rule->{'swi:searchpattern'} )
- || $rule->{'swi:searchpattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:rule[$ruleId]/swi:searchpattern' section missed."
- );
- $result++;
- }
- if ( !defined( $rule->{'swi:messagepattern'} )
- || $rule->{'swi:messagepattern'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:rule[$ruleId]/swi:messagepattern' section missed."
- );
- $result++;
- }
- if ( !defined( $rule->{'swi:codecontent'} )
- || $rule->{'swi:codecontent'} eq "" )
- {
- $rule->{'swi:codecontent'} = 'purified';
- }
- $ruleId++;
- }
- if ( !defined( $module->{'swi:scanner'}->{'swi:suppress'} ) )
- {
- $module->{'swi:scanner'}->{'swi:suppress'} = {};
- }
- if (
- !defined(
- $module->{'swi:scanner'}->{'swi:suppress'}
- ->{'swi:pattern'}
- )
- )
- {
- $module->{'swi:scanner'}->{'swi:suppress'}
- ->{'swi:pattern'} = [];
- }
- my $patternId = 0;
- foreach my $pattern (
- @{
- $module->{'swi:scanner'}->{'swi:suppress'}
- ->{'swi:pattern'}
- }
- )
- {
- if ( ref($pattern) ne 'HASH' )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:suppress/swi:pattern[$patternId]' section is incorrect."
- );
- $result++;
- }
- else
- {
- if ( !defined( $pattern->{'swi:message'} )
- || $pattern->{'swi:message'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:suppress/swi:pattern[$patternId]/swi:message' field is empty."
- );
- $result++;
- }
- if ( !defined( $pattern->{'content'} )
- || $pattern->{'content'} eq "" )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:scanner/swi:suppress/swi:pattern[$patternId]' object pattern is empty."
- );
- $result++;
- }
- }
- $patternId++;
- }
- if ( !defined( $module->{'swi:indexer:common'} )
- || ref( $module->{'swi:indexer:common'} ) ne 'HASH' )
- {
- $module->{'swi:indexer:common'} = {};
- }
- if ( !defined( $module->{'swi:indexer:dup'} )
- || ref( $module->{'swi:indexer:dup'} ) ne 'HASH' )
- {
- $module->{'swi:indexer:dup'} = {};
- }
- if (
- !defined(
- $module->{'swi:indexer:dup'}->{'swi:codecontent'}
- )
- )
- {
- $module->{'swi:indexer:dup'}->{'swi:codecontent'} =
- 'purified';
- }
- if ( !defined( $module->{'swi:indexer:dup'}->{'swi:enabled'} ) )
- {
- $module->{'swi:indexer:dup'}->{'swi:enabled'} = 'on';
- }
- if ( !defined( $module->{'swi:indexer:dup'}->{'swi:minlength'} )
- )
- {
- $module->{'swi:indexer:dup'}->{'swi:minlength'} = 100;
- }
- if ( $module->{'swi:indexer:dup'}->{'swi:minlength'} <= 0 )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:indexer:dup/swi:minlength' can not be less than or equal to zero."
- );
- $result++;
- }
- if ( !defined( $module->{'swi:indexer:dup'}->{'swi:proximity'} )
- )
- {
- $module->{'swi:indexer:dup'}->{'swi:proximity'} = 100;
- }
- if ( $module->{'swi:indexer:dup'}->{'swi:proximity'} <= 0
- || $module->{'swi:indexer:dup'}->{'swi:proximity'} > 100 )
- {
- STATUS(
- "Wrong configuration: 'swi:modules/swi:module[$moduleId]/swi:indexer:dup/swi:proximity' should be in the range from 1 till 100."
- );
- $result++;
- }
- if (
- !defined(
- $module->{'swi:indexer:dup'}->{'swi:globalcode'}
- )
- )
- {
- $module->{'swi:indexer:dup'}->{'swi:globalcode'} = 'off';
- }
- if ( !defined( $module->{'swi:indexer:gcov'} )
- || ref( $module->{'swi:indexer:gcov'} ) ne 'HASH' )
- {
- $module->{'swi:indexer:gcov'} = {};
- }
- if ( !defined( $module->{'swi:indexer:gcov'}->{'swi:enabled'} ) )
- {
- $module->{'swi:indexer:gcov'}->{'swi:enabled'} = 'off';
- }
- if ( !defined( $module->{'swi:indexer:gcov'}->{'swi:filepattern'} ) )
- {
- $module->{'swi:indexer:gcov'}->{'swi:filepattern'} = '.*';
- }
- if ( !defined( $module->{'swi:indexer:gcov'}->{'swi:sourcefile'} ) )
- {
- $module->{'swi:indexer:gcov'}->{'swi:sourcefile'} = '(.*)[.][cChH][pP]?[pP]?';
- }
- if ( !defined( $module->{'swi:indexer:gcov'}->{'swi:gcdafile'} ) )
- {
- $module->{'swi:indexer:gcov'}->{'swi:gcdafile'} = '${1}.gcda';
- }
- $moduleId++;
- }
- }
- }
- if ( !defined( $config->{'swi:report'} )
- || ref( $config->{'swi:report'} ) ne 'HASH' )
- {
- STATUS("Wrong configuration: 'swi:report' section missed.");
- $result++;
- }
- else
- {
- if ( !defined( $config->{'swi:report'}->{'swi:destination'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:report/swi:destination' section missed."
- );
- $result++;
- }
- if ( !defined( $config->{'swi:report'}->{'swi:xml'} ) )
- {
- STATUS("Wrong configuration: 'swi:report/swi:xml' section missed.");
- $result++;
- }
- else
- {
- if (
- !defined( $config->{'swi:report'}->{'swi:xml'}->{'swi:name'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:report/swi:xml/swi:name' section is empty."
- );
- $result++;
- }
- }
- if ( !defined( $config->{'swi:report'}->{'swi:notifications'} ) )
- {
- STATUS(
- "Wrong configuration: 'swi:report/swi:notifications' section missed."
- );
- $result++;
- }
- else
- {
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:name'}
- )
- )
- {
- STATUS(
- "Wrong configuration: 'swi:report/swi:notifications/swi:name' section is empty."
- );
- $result++;
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}
- )
- || ref(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}
- ) ne 'HASH'
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'} =
- {};
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}->{'swi:added'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'}
- ->{'swi:added'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}->{'swi:removed'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'}
- ->{'swi:removed'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}->{'swi:modified'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'}
- ->{'swi:modified'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}->{'swi:cloned'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'}
- ->{'swi:cloned'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:error'}->{'swi:unmodified'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:error'}
- ->{'swi:unmodified'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:print'}
- )
- || ref(
- $config->{'swi:report'}->{'swi:notifications'}
- ->{'swi:print'}
- ) ne 'HASH'
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'} =
- {};
- }
- swiUtilConfigFill_PrintSection($config, 'swi:added');
- swiUtilConfigFill_PrintSection($config, 'swi:removed');
- swiUtilConfigFill_PrintSection($config, 'swi:modified');
- swiUtilConfigFill_PrintSection($config, 'swi:cloned');
- swiUtilConfigFill_PrintSection($config, 'swi:unmodified');
-
- }
- }
-
- # swi:limits section is verified in runtime
- # no precheck currently
- DEBUG( "Configuration structure is: " . Dumper($config) );
- return $result;
- }
- sub swiUtilConfigFill_PrintSection
- {
- my $config = shift();
- my $modType = shift();
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}
- )
- || ref(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}
- ) ne 'HASH'
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType} = {};
- }
-
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:failures'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:failures'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:modifications'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:modifications'} = 'on';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:duplications'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:duplications'} = 'off';
- }
- if (
- !defined(
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:scanmessages'}
- )
- )
- {
- $config->{'swi:report'}->{'swi:notifications'}->{'swi:print'}
- ->{$modType}->{'swi:scanmessages'} = 'on';
- }
- }
- return 1;
|