Example #1
0
    def __init__(self, fast: bool, plugins_utility=BundledPluginsUtility(), maven_callable=MavenCallable):
        plugins_stop_condition = ['plugins-version', 'pluginsVersion']
        collectors = [GrepCount('plugins.version.one.plugins', lambda x: x == 'atlassian-plugin.xml',
                                'Should not be adding new version 1 plugins',
                                ['pluginsVersion="1"', 'plugins-version="1"'], plugins_stop_condition),
                      FileCount('plugins.count', lambda x: x == 'atlassian-plugin.xml',
                                'Count of plugins in JIRA codebase.').unchecked().neutral(),
                      GrepCountWithActivator('plugins.version.web.panels.to.soy',
                                             lambda x: x == 'atlassian-plugin.xml',
                                             'Should migrate web panels to soy templates',
                                             r'<\s*resource.+type\s*=\s*"velocity"',
                                             start_count=r'<\s*web-panel', stop_count=r'<\s*/\s*web-panel\s*>',
                                             use_regex=True),
                      FileCount('bundled.jars.in.plugins', lambda x: x.endswith('.jar'),
                                'Try and use provided jars instead of bundling your own. See '
                                'https://developer.atlassian.com/display/DOCS/How+to+Speed+Up+Plugin+Startup for more '
                                'details'),
                      MissingHostComponentsXml('plugins.missing.component.import.xml',
                          'Should be specifying a atlassian-plugins-host-components.xml to bypass host component '
                          'scanning. See https://developer.atlassian.com/display/DOCS/How+to+Speed+Up+Plugin+Startup#HowtoSpeedUpPluginStartup-Bypasshostcomponentscanning '
                          'for more details').unchecked(),
                      MissingOsgiManifest('plugins.missing.osgi.instructions',
                          'Should be specifying a non-empty instructions element so the SDK will generate an OSGi '
                          'manifest. See https://developer.atlassian.com/display/DOCS/How+to+Speed+Up+Plugin+Startup#HowtoSpeedUpPluginStartup-GeneratetheOSGimanifestatbuildtime '
                          'for more details'),
                      # Won't check the plugin xml minified until AMPS 4.2.4 is released.
                      PluginXmlMinified('plugins.xml.not.minified',
                          'Should be minifiying your atlassian-plugin.xml using plugin SDK version 4.2.4 or later').unchecked().rising()]

        super().__init__(collectors, 'Scan Bundled plugins JARS')
        self.plugins_utility = plugins_utility
        self.plugin_zip = None
        self.plugin_xml_info = None
        self.fast = fast
        self.maven_callable = maven_callable
    def test_plugin_xml_minified(self):
        metric = PluginXmlMinified('test', 'plugin xml minified test', metrics_logger=Mock()).configure(Mock(), False)
        metric.pre_files_scan('good_plugin')
        # like file count, wants_file will actually read the file
        self.assertEqual(metric.wants_file(TestPluginXmlMinified.minified_plugin_xml), True, "Wants the plugin xml.")

        with open(TestPluginXmlMinified.minified_plugin_xml) as f:
            line = f.readline()
            while line:
                metric.on_read_line(line)
                line = f.readline()

        metric.post_files_scan('good_plugin')
        self.assertEqual(0, metric.value, "Shouldn't have a hit")
    def test_plugin_xml_unminified(self):
        metric = PluginXmlMinified('test', 'plugin xml minified test', metrics_logger=Mock()).configure(Mock(), False)
        metric.pre_files_scan('bad_plugin')
        # like file count, wants_file will actually read the file
        self.assertEqual(metric.wants_file(TestPluginXmlMinified.original_plugin_xml), True, "Wants the plugin xml.")

        with open(TestPluginXmlMinified.original_plugin_xml) as f:
            line = f.readline()
            while line:
                self.assertEqual(metric.on_read_line(line), True, "Should want all the lines")
                line = f.readline()

        self.assertEqual(metric.wants_file("META-INF/MANIFEST.MF"), False, "Doesn't want another file.")
        metric.post_files_scan('bad_plugin')
        self.assertEqual(1, metric.value, "Should have a hit")
Example #4
0
    def test_plugin_xml_minified(self):
        metric = PluginXmlMinified('test',
                                   'plugin xml minified test',
                                   metrics_logger=Mock()).configure(
                                       Mock(), False)
        metric.pre_files_scan('good_plugin')
        # like file count, wants_file will actually read the file
        self.assertEqual(
            metric.wants_file(TestPluginXmlMinified.minified_plugin_xml), True,
            "Wants the plugin xml.")

        with open(TestPluginXmlMinified.minified_plugin_xml) as f:
            line = f.readline()
            while line:
                metric.on_read_line(line)
                line = f.readline()

        metric.post_files_scan('good_plugin')
        self.assertEqual(0, metric.value, "Shouldn't have a hit")
Example #5
0
    def test_plugin_xml_unminified(self):
        metric = PluginXmlMinified('test',
                                   'plugin xml minified test',
                                   metrics_logger=Mock()).configure(
                                       Mock(), False)
        metric.pre_files_scan('bad_plugin')
        # like file count, wants_file will actually read the file
        self.assertEqual(
            metric.wants_file(TestPluginXmlMinified.original_plugin_xml), True,
            "Wants the plugin xml.")

        with open(TestPluginXmlMinified.original_plugin_xml) as f:
            line = f.readline()
            while line:
                self.assertEqual(metric.on_read_line(line), True,
                                 "Should want all the lines")
                line = f.readline()

        self.assertEqual(metric.wants_file("META-INF/MANIFEST.MF"), False,
                         "Doesn't want another file.")
        metric.post_files_scan('bad_plugin')
        self.assertEqual(1, metric.value, "Should have a hit")
Example #6
0
    def test_plugin_xml_unminified_in_two_modules(self):
        metric = PluginXmlMinified('test',
                                   'plugin xml minified test',
                                   metrics_logger=Mock()).configure(
                                       Mock(), False)
        # scan first module
        metric.pre_files_scan('bad_plugin')
        self.assertEqual(metric.wants_file('atlassian-plugin.xml'), True,
                         "Wants the plugin xml.")
        metric.on_read_line('<?xml version="1.0" ?>\n<xml/>')
        self.assertEqual(metric.wants_file("atlassian-plugin.xml"), False,
                         "Doesn't want another file.")
        metric.post_files_scan('bad_plugin')
        self.assertEqual(1, metric.value, "Should have a hit")

        # scan seconds module
        metric.pre_files_scan('second_bad_plugin')
        # vvv FAILS HERE vvv
        self.assertEqual(metric.wants_file('atlassian-plugin.xml'), True,
                         "Wants the plugin xml.")
        metric.on_read_line('<?xml version="1.0" ?>\n<xml/>')
        self.assertEqual(metric.wants_file("atlassian-plugin.xml"), False,
                         "Doesn't want another file.")
        metric.post_files_scan('second_bad_plugin')
        # vvv WOULD FAIL HERE TOO vvv
        self.assertEqual(2, metric.value, "Should have a hit")
    def test_plugin_xml_unminified_in_two_modules(self):
        metric = PluginXmlMinified('test', 'plugin xml minified test', metrics_logger=Mock()).configure(Mock(), False)
        # scan first module
        metric.pre_files_scan('bad_plugin')
        self.assertEqual(metric.wants_file('atlassian-plugin.xml'), True, "Wants the plugin xml.")
        metric.on_read_line('<?xml version="1.0" ?>\n<xml/>')
        self.assertEqual(metric.wants_file("atlassian-plugin.xml"), False, "Doesn't want another file.")
        metric.post_files_scan('bad_plugin')
        self.assertEqual(1, metric.value, "Should have a hit")

        # scan seconds module
        metric.pre_files_scan('second_bad_plugin')
        # vvv FAILS HERE vvv
        self.assertEqual(metric.wants_file('atlassian-plugin.xml'), True, "Wants the plugin xml.")
        metric.on_read_line('<?xml version="1.0" ?>\n<xml/>')
        self.assertEqual(metric.wants_file("atlassian-plugin.xml"), False, "Doesn't want another file.")
        metric.post_files_scan('second_bad_plugin')
        # vvv WOULD FAIL HERE TOO vvv
        self.assertEqual(2, metric.value, "Should have a hit")