avkonst преди 11 години
родител
ревизия
3017bae226

+ 1 - 1
mainline/mpp/api.py

@@ -668,7 +668,7 @@ class Loader(object):
     def set_property(self, property_name, value):
         if self.db == None:
             return None
-        return self.db.set_property(property_name, value)
+        return self.db.set_property(property_name, str(value))
     
     def get_property(self, property_name):
         if self.db == None:

+ 3 - 1
mainline/tests/system/test_api_tutorial.py

@@ -44,10 +44,12 @@ class Test(tests.common.TestCase):
         # so, if the test is changed, html docs should be updated accordingly
         #
         
-        for step in range(8):
+        for step in range(9):
             opts = ['--log-level=INFO']
             if step > 1:
                 opts.append('--myext.magic.numbers')
+            if step > 7:
+                opts.append('--myext.magic.numbers.simplier')
             
             os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                                              'test_api_tutorial', 'ext', 'step' + str(step))

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/step8/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/step8/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

+ 75 - 0
mainline/tests/system/test_api_tutorial/ext/step8/myext/magic.py

@@ -0,0 +1,75 @@
+#
+#    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]")
+        # Add new option
+        parser.add_option("--myext.magic.numbers.simplier", "--mmns",
+            action="store_true", default=False,
+            help="Is set, 0, -1 and 1 numbers are not counted [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_numbers = options.__dict__['myext.magic.numbers']
+        # remember the option here
+        self.is_active_numbers_simplier = options.__dict__['myext.magic.numbers.simplier']
+    
+    def initialize(self):
+        pattern_to_search_java = re.compile(
+            r'''(const\s+([_$a-zA-Z][_$a-zA-Z0-9]*\s+)+[=]\s*)?[-+]?[0-9]+''')
+        pattern_to_search_cpp_cs = re.compile(
+            r'''(const\s+([_a-zA-Z][_a-zA-Z0-9]*\s+)+[=]\s*)?[-+]?[0-9]+''')
+        pattern_to_search = re.compile(
+            r'''[0-9]+''')
+        self.declare_metric(self.is_active_numbers,
+                            self.Field('numbers', int,
+                                non_zero=True),
+                            {
+                             'std.code.java': pattern_to_search_java,
+                             'std.code.cpp': pattern_to_search_cpp_cs,
+                             'std.code.cs': pattern_to_search_cpp_cs,
+                             '*': pattern_to_search
+                            },
+                            marker_type_mask=mpp.api.Marker.T.CODE,
+                            region_type_mask=mpp.api.Region.T.ANY)
+        
+        super(Plugin, self).initialize(fields=self.get_fields(),
+            # remember option settings in data file properties
+            # in order to detect changes in settings on iterative re-run
+            properties=[self.Property('number.simplier', self.is_active_numbers_simplier)])
+        
+        if self.is_active() == True:
+            self.subscribe_by_parents_interface(mpp.api.ICode)
+
+    def _numbers_count(self, alias, data, region, marker, match, count, counter_data):
+        if (match.group(0).startswith('const') or
+            # use new option to exclude 0 and 1 numbers
+            (self.is_active_numbers_simplier == True and
+             match.group(0) in ['0', '1', '-1', '+1'])):
+            return count
+        return count + 1

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_metric_plugin_api_collect_step8_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_metric_plugin_api_collect_step8_stdout.gold.txt


+ 3 - 0
mainline/tests/system/test_api_tutorial/test_metric_plugin_api_view_step8_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_metric_plugin_api_view_step8_stdout.gold.txt

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