Forráskód Böngészése

code samples for api docs

avkonst 11 éve
szülő
commit
fa17ef193f
33 módosított fájl, 607 hozzáadás és 1 törlés
  1. 1 0
      mainline/ext/std/code/complexity.py
  2. 99 0
      mainline/tests/system/test_api_tutorial.py
  3. 18 0
      mainline/tests/system/test_api_tutorial/ext/step1/myext/__init__.py
  4. 27 0
      mainline/tests/system/test_api_tutorial/ext/step1/myext/magic.ini
  5. 26 0
      mainline/tests/system/test_api_tutorial/ext/step1/myext/magic.py
  6. 18 0
      mainline/tests/system/test_api_tutorial/ext/step2/myext/__init__.py
  7. 27 0
      mainline/tests/system/test_api_tutorial/ext/step2/myext/magic.ini
  8. 34 0
      mainline/tests/system/test_api_tutorial/ext/step2/myext/magic.py
  9. 18 0
      mainline/tests/system/test_api_tutorial/ext/step3/myext/__init__.py
  10. 27 0
      mainline/tests/system/test_api_tutorial/ext/step3/myext/magic.ini
  11. 37 0
      mainline/tests/system/test_api_tutorial/ext/step3/myext/magic.py
  12. 18 0
      mainline/tests/system/test_api_tutorial/ext/step4/myext/__init__.py
  13. 27 0
      mainline/tests/system/test_api_tutorial/ext/step4/myext/magic.ini
  14. 53 0
      mainline/tests/system/test_api_tutorial/ext/step4/myext/magic.py
  15. 18 0
      mainline/tests/system/test_api_tutorial/ext/step5/myext/__init__.py
  16. 27 0
      mainline/tests/system/test_api_tutorial/ext/step5/myext/magic.ini
  17. 58 0
      mainline/tests/system/test_api_tutorial/ext/step5/myext/magic.py
  18. 20 0
      mainline/tests/system/test_api_tutorial/sources/test.cpp
  19. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step1_stderr.gold.txt
  20. 1 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step1_stdout.gold.txt
  21. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step2_stderr.gold.txt
  22. 1 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step2_stdout.gold.txt
  23. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step3_stderr.gold.txt
  24. 1 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step3_stdout.gold.txt
  25. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step4_stderr.gold.txt
  26. 0 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step4_stdout.gold.txt
  27. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step5_stderr.gold.txt
  28. 0 0
      mainline/tests/system/test_api_tutorial/test_basic_collect_step5_stdout.gold.txt
  29. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_view_step4_stderr.gold.txt
  30. 14 0
      mainline/tests/system/test_api_tutorial/test_basic_view_step4_stdout.gold.txt
  31. 3 0
      mainline/tests/system/test_api_tutorial/test_basic_view_step5_stderr.gold.txt
  32. 14 0
      mainline/tests/system/test_api_tutorial/test_basic_view_step5_stdout.gold.txt
  33. 2 1
      mainline/tests/system/test_boost_parts.py

+ 1 - 0
mainline/ext/std/code/complexity.py

@@ -62,6 +62,7 @@ class Plugin(mpp.api.Plugin, mpp.api.MetricPluginMixin, mpp.api.Child, mpp.api.I
                                 'java': self.pattern_indent,
                             },
                             marker_type_mask=mpp.api.Marker.T.CODE,
+                            # TODO shall scan all regions?, it is likely actual to functions
                             region_type_mask=mpp.api.Region.T.ANY)
         
         super(Plugin, self).initialize(fields=self.get_fields())

+ 99 - 0
mainline/tests/system/test_api_tutorial.py

@@ -0,0 +1,99 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import unittest
+import os
+
+import tests.common
+
+class Test(tests.common.TestCase):
+
+    def test_basic(self):
+        
+        #
+        # WARNING:
+        # files generated by this test are used by project documents page
+        # so, if the test is changed, html docs should be updated accordingly
+        #
+        METRIXPLUSPLUS_PATH = None
+        if 'METRIXPLUSPLUS_PATH' in os.environ.keys():
+            METRIXPLUSPLUS_PATH = os.environ['METRIXPLUSPLUS_PATH']
+        
+        os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                         'test_api_tutorial', 'ext', 'step1')
+        runner = tests.common.ToolRunner('collect',
+                                         ['--log-level=INFO'],
+                                         prefix='step1',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+        os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                         'test_api_tutorial', 'ext', 'step2')
+        runner = tests.common.ToolRunner('collect',
+                                         ['--log-level=INFO',
+                                          '--myext.magic.numbers'],
+                                         prefix='step2',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+        os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                         'test_api_tutorial', 'ext', 'step3')
+        runner = tests.common.ToolRunner('collect',
+                                         ['--log-level=INFO',
+                                          '--myext.magic.numbers'],
+                                         prefix='step3',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+        os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                         'test_api_tutorial', 'ext', 'step4')
+        runner = tests.common.ToolRunner('collect',
+                                         ['--log-level=INFO',
+                                          '--myext.magic.numbers'],
+                                         prefix='step4',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+        runner = tests.common.ToolRunner('view',
+                                         ['--log-level=INFO'],
+                                         prefix='step4',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+        os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                         'test_api_tutorial', 'ext', 'step5')
+        runner = tests.common.ToolRunner('collect',
+                                         ['--log-level=INFO',
+                                          '--myext.magic.numbers'],
+                                         prefix='step5',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+        runner = tests.common.ToolRunner('view',
+                                         ['--log-level=INFO'],
+                                         prefix='step5',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+
+        if METRIXPLUSPLUS_PATH != None:
+            os.environ['METRIXPLUSPLUS_PATH'] = METRIXPLUSPLUS_PATH
+
+if __name__ == '__main__':
+    unittest.main()
+    

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step1/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/step1/myext/magic.ini

@@ -0,0 +1,27 @@
+;
+;    Metrix++, Copyright 2009-2013, Metrix++ Project
+;    Link: http://metrixplusplus.sourceforge.net
+;    
+;    This file is a part of Metrix++ Tool.
+;    
+;    Metrix++ 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.
+;    
+;    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+;
+
+[Plugin]
+version: 1.0
+package: myext
+module:  magic
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 26 - 0
mainline/tests/system/test_api_tutorial/ext/step1/myext/magic.py

@@ -0,0 +1,26 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import mpp.api
+
+class Plugin(mpp.api.Plugin):
+    
+    def initialize(self):
+        print "Hello world"
+

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step2/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/step2/myext/magic.ini

@@ -0,0 +1,27 @@
+;
+;    Metrix++, Copyright 2009-2013, Metrix++ Project
+;    Link: http://metrixplusplus.sourceforge.net
+;    
+;    This file is a part of Metrix++ Tool.
+;    
+;    Metrix++ 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.
+;    
+;    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+;
+
+[Plugin]
+version: 1.0
+package: myext
+module:  magic
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 34 - 0
mainline/tests/system/test_api_tutorial/ext/step2/myext/magic.py

@@ -0,0 +1,34 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import mpp.api
+
+class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
+    
+    def declare_configuration(self, parser):
+        parser.add_option("--myext.magic.numbers", "--mmn", action="store_true", default=False,
+                         help="Enables collection of magic numbers metric [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_numbers = options.__dict__['myext.magic.numbers']
+    
+    def initialize(self):
+        if self.is_active_numbers == True:
+            print "Hello world"
+

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step3/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/step3/myext/magic.ini

@@ -0,0 +1,27 @@
+;
+;    Metrix++, Copyright 2009-2013, Metrix++ Project
+;    Link: http://metrixplusplus.sourceforge.net
+;    
+;    This file is a part of Metrix++ Tool.
+;    
+;    Metrix++ 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.
+;    
+;    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+;
+
+[Plugin]
+version: 1.0
+package: myext
+module:  magic
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 37 - 0
mainline/tests/system/test_api_tutorial/ext/step3/myext/magic.py

@@ -0,0 +1,37 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import mpp.api
+
+class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.Child):
+    
+    def declare_configuration(self, parser):
+        parser.add_option("--myext.magic.numbers", "--mmn", action="store_true", default=False,
+                         help="Enables collection of magic numbers metric [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_numbers = options.__dict__['myext.magic.numbers']
+    
+    def initialize(self):
+        if self.is_active_numbers == True:
+            self.subscribe_by_parents_interface(mpp.api.ICode, 'callback')
+
+    def callback(self, parent, data, is_updated):
+        print parent, data.get_path(), is_updated
+        

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step4/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/step4/myext/magic.ini

@@ -0,0 +1,27 @@
+;
+;    Metrix++, Copyright 2009-2013, Metrix++ Project
+;    Link: http://metrixplusplus.sourceforge.net
+;    
+;    This file is a part of Metrix++ Tool.
+;    
+;    Metrix++ 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.
+;    
+;    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+;
+
+[Plugin]
+version: 1.0
+package: myext
+module:  magic
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 53 - 0
mainline/tests/system/test_api_tutorial/ext/step4/myext/magic.py

@@ -0,0 +1,53 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import mpp.api
+import re
+
+class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.Child, mpp.api.MetricPluginMixin):
+    
+    def declare_configuration(self, parser):
+        parser.add_option("--myext.magic.numbers", "--mmn", action="store_true", default=False,
+                         help="Enables collection of magic numbers metric [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_numbers = options.__dict__['myext.magic.numbers']
+    
+    def initialize(self):
+        # declare metric rules
+        self.declare_metric(self.is_active_numbers, # to count if active in callback
+                            self.Field('numbers', int), # field name and type in the database
+                            re.compile(r'''[0-9]+'''), # pattern to search
+                            marker_type_mask=mpp.api.Marker.T.CODE, # search in code
+                            region_type_mask=mpp.api.Region.T.ANY) # search in all types of regions
+        
+        # use superclass facilities to initialize everything using declared fields
+        super(Plugin, self).initialize(fields=self.get_fields())
+        
+        # subscribe to all code parsers if at least one metric is active
+        if self.is_active() == True:
+            self.subscribe_by_parents_interface(mpp.api.ICode, 'callback')
+    
+    def callback(self, parent, data, is_updated):
+        # count if metric is enabled, 
+        # and (optimization for the case of iterative rescan:)
+        # if file is updated or this plugin's settings are updated
+        if is_updated or self.is_updated:
+            self.count_if_active('numbers', data)
+        

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step5/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/step5/myext/magic.ini

@@ -0,0 +1,27 @@
+;
+;    Metrix++, Copyright 2009-2013, Metrix++ Project
+;    Link: http://metrixplusplus.sourceforge.net
+;    
+;    This file is a part of Metrix++ Tool.
+;    
+;    Metrix++ 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.
+;    
+;    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+;
+
+[Plugin]
+version: 1.0
+package: myext
+module:  magic
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 58 - 0
mainline/tests/system/test_api_tutorial/ext/step5/myext/magic.py

@@ -0,0 +1,58 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ 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.
+#    
+#    Metrix++ 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 Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import mpp.api
+import re
+
+class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.Child, mpp.api.MetricPluginMixin):
+    
+    def declare_configuration(self, parser):
+        parser.add_option("--myext.magic.numbers", "--mmn", action="store_true", default=False,
+                         help="Enables collection of magic numbers metric [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_numbers = options.__dict__['myext.magic.numbers']
+    
+    def initialize(self):
+        pattern_to_search = re.compile(r'''(const\s+([_a-zA-Z][_a-zA-Z0-9]*\s+)+[=]\s*)?[-+]?[0-9]+''')
+        # declare metric rules
+        self.declare_metric(self.is_active_numbers, # to count if active in callback
+                            self.Field('numbers', int), # field name and type in the database
+                            pattern_to_search, 
+                            marker_type_mask=mpp.api.Marker.T.CODE, # search in code
+                            region_type_mask=mpp.api.Region.T.ANY) # search in all types of regions
+        
+        # use superclass facilities to initialize everything using declared fields
+        super(Plugin, self).initialize(fields=self.get_fields())
+        
+        # subscribe to all code parsers if at least one metric is active
+        if self.is_active() == True:
+            self.subscribe_by_parents_interface(mpp.api.ICode, 'callback')
+    
+    def callback(self, parent, data, is_updated):
+        # count if metric is enabled, 
+        # and (optimization for the case of iterative rescan:)
+        # if file is updated or this plugin's settings are updated
+        if is_updated or self.is_updated:
+            self.count_if_active('numbers', data)
+        
+    def _numbers_count(self, data, alias, text, begin, end, m, count, counter_data, region, marker):
+        if m.group(0).startswith('const'):
+            return count
+        return count + 1

+ 20 - 0
mainline/tests/system/test_api_tutorial/sources/test.cpp

@@ -0,0 +1,20 @@
+
+
+const unsigned int c = 3;
+unsigned int c = 3;
+int c = 3;
+
+
+int main(int a = 1, int b = -2)
+{
+	const unsigned int c = 3;
+
+	for (int i = 0; i < 100; ++i)
+	{
+
+	}
+	while (1)
+	{
+		a = 4;
+	}
+}

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step1_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 1 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step1_stdout.gold.txt

@@ -0,0 +1 @@
+Hello world

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step2_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 1 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step2_stdout.gold.txt

@@ -0,0 +1 @@
+Hello world

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step3_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 1 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step3_stdout.gold.txt

@@ -0,0 +1 @@
+<std.code.cpp.Plugin object at 0x0000000002746B70> ./test.cpp True

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step4_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 0 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step4_stdout.gold.txt


+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step5_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 0 - 0
mainline/tests/system/test_api_tutorial/test_basic_collect_step5_stdout.gold.txt


+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_view_step4_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: 
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 14 - 0
mainline/tests/system/test_api_tutorial/test_basic_view_step4_stdout.gold.txt

@@ -0,0 +1,14 @@
+:: info: Overall metrics for 'myext.magic:numbers' metric
+	Average        : 5.0
+	Minimum        : 3
+	Maximum        : 7
+	Total          : 10.0
+	Distribution   : 2 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+	             3 : 0.500 : 0.500 : 1	||||||||||||||||||||||||||||||||||||||||||||||||||
+	             7 : 0.500 : 1.000 : 1	||||||||||||||||||||||||||||||||||||||||||||||||||
+
+:: info: Directory content:
+	Directory      : .
+
+

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_basic_view_step5_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: 
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 14 - 0
mainline/tests/system/test_api_tutorial/test_basic_view_step5_stdout.gold.txt

@@ -0,0 +1,14 @@
+:: info: Overall metrics for 'myext.magic:numbers' metric
+	Average        : 4.0
+	Minimum        : 2
+	Maximum        : 6
+	Total          : 8.0
+	Distribution   : 2 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+	             2 : 0.500 : 0.500 : 1	||||||||||||||||||||||||||||||||||||||||||||||||||
+	             6 : 0.500 : 1.000 : 1	||||||||||||||||||||||||||||||||||||||||||||||||||
+
+:: info: Directory content:
+	Directory      : .
+
+

+ 2 - 1
mainline/tests/system/test_boost_parts.py

@@ -135,4 +135,5 @@ class Test(tests.common.TestCase):
         self.assertExec(runner.run())
 
 if __name__ == '__main__':
-    unittest.main()
+    unittest.main()
+