Launcher.pm 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #
  2. # Software Index, Copyright 2010, Software Index Project Team
  3. # Link: http://swi.sourceforge.net
  4. #
  5. # This file is part of Software Index Tool.
  6. #
  7. # Software Index is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Software Index is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Software Index. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. use strict;
  20. use XML::Simple;
  21. use FileHandle;
  22. #
  23. # Export section
  24. #
  25. require Exporter;
  26. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $PREFERRED_PARSER);
  27. @ISA = qw(Exporter);
  28. @EXPORT = qw(swiLaunch);
  29. @EXPORT_OK = qw();
  30. $VERSION = '1.0';
  31. $PREFERRED_PARSER = undef;
  32. #
  33. # Subroutine for troubleshooting purposes
  34. #
  35. use Internal::Output;
  36. #
  37. # Include SWI libs
  38. #
  39. require SWI::Appraiser;
  40. require SWI::Converter;
  41. require SWI::Merger;
  42. require SWI::Processor;
  43. #
  44. # Global variables
  45. #
  46. my $config = undef;
  47. #
  48. # Enter point
  49. #
  50. sub swiLaunch
  51. {
  52. my $returnCode = 0;
  53. my $rootLocation = shift();
  54. my $swiConfiguration = shift();
  55. # $returnCode == 0 => no critical errors and warnings
  56. # $returnCode > 0 => no critical errors, there are warnings
  57. # $returnCode < 0 => there are critical errors
  58. if ( $returnCode >= 0 )
  59. {
  60. if ( $swiConfiguration eq "" )
  61. {
  62. STATUS("Configuration file should be specified!");
  63. $returnCode = -1;
  64. }
  65. else
  66. {
  67. STATUS("Configuration file: $swiConfiguration.");
  68. }
  69. }
  70. if ( $returnCode >= 0 )
  71. {
  72. if ( swiConfigurationValidate($swiConfiguration) != 0 )
  73. {
  74. STATUS("Wrong configuration file!");
  75. $returnCode = -2;
  76. }
  77. }
  78. if ( $returnCode >= 0 )
  79. {
  80. # Generate report for every module separately
  81. for (
  82. my $i = 0 ;
  83. $i <= $#{ $config->{"swi:modules"}->{"swi:module"} } ;
  84. $i++
  85. )
  86. {
  87. STATUS( "Processing module: '"
  88. . $config->{"swi:modules"}->{"swi:module"}[$i]
  89. ->{"swi:name"} . "'." );
  90. my $result = swiProcess( $config, $i, $rootLocation );
  91. if ( $result < 0 )
  92. {
  93. STATUS(
  94. "The are problems to report the index for the module!");
  95. $returnCode = -5;
  96. }
  97. elsif ( $result > 0 )
  98. {
  99. STATUS("The are scan warnings and/or errors.");
  100. $returnCode = $result;
  101. }
  102. else
  103. {
  104. STATUS("The module has been processed succesfully.");
  105. }
  106. }
  107. }
  108. if ( $returnCode >= 0 )
  109. {
  110. # Merge reports
  111. if ( swiMerge($config) )
  112. {
  113. STATUS("The are problems to merge files to one report!");
  114. $returnCode = -3;
  115. }
  116. else
  117. {
  118. STATUS("Merged report has been created.");
  119. }
  120. }
  121. if ( $returnCode >= 0 )
  122. {
  123. # Add average/min/max/total values and generate final XML report
  124. if ( swiAppraise($config) )
  125. {
  126. STATUS(
  127. "The are problems to add average/min/max/total values!");
  128. $returnCode = -4;
  129. }
  130. else
  131. {
  132. STATUS("Average/min/max/total values have been added.");
  133. }
  134. }
  135. if ( $returnCode >= 0 )
  136. {
  137. # Convert results
  138. my $result = swiConvert($config);
  139. if ( $result < 0 )
  140. {
  141. STATUS("The are problems to convert the report!");
  142. $returnCode = -5;
  143. }
  144. elsif ( $result > 0 )
  145. {
  146. STATUS("Report has been converted. There are exceeded limitations.");
  147. $returnCode = $result;
  148. }
  149. else
  150. {
  151. STATUS("Report has been converted.");
  152. }
  153. }
  154. return $returnCode;
  155. }
  156. sub swiConfigurationValidate
  157. {
  158. $config =
  159. XMLin( shift(),
  160. ForceArray => [ "swi:module", "swi:rule", "swi:pattern" ] );
  161. DEBUG("Configuration structure is: " . Dumper($config));
  162. return 0;
  163. }
  164. return 1;