Merger.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 FileHandle;
  21. use XML::Simple;
  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(swiMerge);
  29. @EXPORT_OK = qw();
  30. $VERSION = '1.0';
  31. $PREFERRED_PARSER = undef;
  32. #
  33. # Enter point
  34. #
  35. sub swiMerge
  36. {
  37. my $config = shift();
  38. my $reportLocation =
  39. $config->{"swi:report"}->{"swi:destination"} . "/"
  40. . $config->{"swi:report"}->{"swi:xml"}->{"swi:name"};
  41. my $fh = new FileHandle( $reportLocation . ".x", "w" ) or die ("Can not open output file '$reportLocation'!");
  42. print $fh "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
  43. print $fh "<swi:report>\n";
  44. print $fh "\n";
  45. print $fh " <swi:info>\n";
  46. print $fh " <swi:version>1.0</swi:version>\n";
  47. if (defined($ENV{USER}))
  48. {
  49. print $fh " <swi:user>" . $ENV{USER} . "</swi:user>\n";
  50. }
  51. print $fh " <swi:generator>SWI/MERGER</swi:generator>\n";
  52. print $fh " </swi:info>\n";
  53. print $fh "\n";
  54. my $modulesCount = $#{ $config->{"swi:modules"}->{"swi:module"} } + 1;
  55. my $filesCount = 0;
  56. my $functionsCount = 0;
  57. for ( my $i = 0 ; $i < $modulesCount ; $i++ )
  58. {
  59. my $modFh = new FileHandle( "$reportLocation.$i", "r" ) or die ("Can not open input file '$reportLocation.$i'!");
  60. my @lines = <$modFh>;
  61. $modFh->close();
  62. for ( my $j = 3 ; $j < $#lines ; $j++ )
  63. {
  64. print $fh $lines[$j];
  65. if ($lines[$j] =~ m/^[ ]*<swi:count>[ ]*$/)
  66. {
  67. if ($lines[$j+1] =~ m/^[ ]*<swi:files[ ]+swi:exact="([0-9]*)"[ ]*\/>[ ]*$/)
  68. {
  69. my $numFilesInModule = $1;
  70. if ($lines[$j+2] =~ m/^[ ]*<swi:functions[ ]+swi:exact="([0-9]*)"[ ]*\/>[ ]*$/)
  71. {
  72. my $numFunctionsInModule = $1;
  73. $functionsCount += $numFunctionsInModule;
  74. $filesCount += $numFilesInModule;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. print $fh " <swi:statistic>\n";
  81. print $fh " <swi:count>\n";
  82. print $fh " <swi:modules swi:exact=\"" . $modulesCount . "\" />\n";
  83. print $fh " <swi:files swi:exact=\"" . $filesCount . "\" />\n";
  84. print $fh " <swi:functions swi:exact=\"" . $functionsCount . "\" />\n";
  85. print $fh " </swi:count>\n";
  86. print $fh " </swi:statistic>\n";
  87. print $fh "\n";
  88. print $fh "</swi:report>\n";
  89. $fh->close();
  90. return 0;
  91. }
  92. return 1;