def setup_clang_format_tool_plugin_non_default():
    """Initialize and return an instance of the clang-format plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )
    arg_parser.add_argument("--clang-format-bin", dest="clang_format_bin")
    arg_parser.add_argument(
        "--clang-format-raise-exception",
        dest="clang_format_raise_exception",
        action="store_true",
        default=False,
    )
    arg_parser.add_argument("--output-directory", dest="output_directory")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    cftp = ClangFormatToolPlugin()
    cftp.set_plugin_context(plugin_context)
    return cftp
def setup_cppcheck_tool_plugin(use_plugin_context=True, binary=None):
    """Initialize and return an instance of the cppcheck plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )
    arg_parser.add_argument("--cppcheck-bin", dest="cppcheck_bin")
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cctp = CppcheckToolPlugin()
    if binary:
        plugin_context.args.cppcheck_bin = binary
    if use_plugin_context:
        cctp.set_plugin_context(plugin_context)
    return cctp
def setup_uncrustify_tool_plugin(extra_path=None,
                                 use_plugin_context=True,
                                 binary=None):
    """Initialize and return an instance of the uncrustify plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--uncrustify-bin", dest="uncrustify_bin")
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )

    paths = []
    if extra_path:
        paths.append(extra_path)
    paths.append(
        os.path.join(os.path.dirname(statick_tool.__file__), "plugins"))
    resources = Resources(paths)
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    utp = UncrustifyToolPlugin()
    if binary:
        plugin_context.args.uncrustify_bin = binary
    if use_plugin_context:
        utp.set_plugin_context(plugin_context)
    return utp
Esempio n. 4
0
def fortify_tool_plugin():
    """Create an instance of the fortify plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output",
                            dest="show_tool_output",
                            action="store_true",
                            help="Show tool output")
    arg_parser.add_argument("--fortify-python",
                            dest="fortify_python",
                            type=int)
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            default=None)
    arg_parser.add_argument("--fortify-version",
                            dest="fortify_version",
                            default="18.20")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), 'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    ftp = FortifyToolPlugin()
    ftp.set_plugin_context(plugin_context)
    return ftp
Esempio n. 5
0
def setup_clang_format_tool_plugin(use_plugin_context=True,
                                   binary=None,
                                   do_raise=False):
    """Initialize and return an instance of the clang-format plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--clang-format-bin", dest="clang_format_bin")
    if do_raise:
        arg_parser.add_argument(
            "--clang-format-raise-exception",
            dest="clang_format_raise_exception",
            action="store_false",
        )
    else:
        arg_parser.add_argument(
            "--clang-format-raise-exception",
            dest="clang_format_raise_exception",
            action="store_true",
        )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cftp = ClangFormatToolPlugin()
    if binary is not None:
        plugin_context.args.clang_format_bin = binary
    if use_plugin_context:
        cftp.set_plugin_context(plugin_context)
    return cftp
def setup_bandit_tool_plugin(binary=None):
    """Create an instance of the bandit plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )
    arg_parser.add_argument("--bandit-bin", dest="bandit_bin")
    arg_parser.add_argument(
        "--mapping-file-suffix", dest="mapping_file_suffix", type=str
    )

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    btp = BanditToolPlugin()
    if binary:
        plugin_context.args.bandit_bin = binary
    btp.set_plugin_context(plugin_context)
    return btp
Esempio n. 7
0
def test_tool_dependencies():
    """Verify that dependencies are reported correctly."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources([os.path.join(os.path.dirname(__file__), 'user_flags_config')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    assert tp.get_tool_dependencies() == []
Esempio n. 8
0
def test_tool_plugin_get_user_flags_invalid_level():
    """Test that we return an empty list for invalid levels."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources([os.path.join(os.path.dirname(__file__), 'user_flags_config')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags('level2', name='test')
    assert flags == []
Esempio n. 9
0
def test_tool_plugin_load_mapping_missing():
    """Test that we return an empty dict for missing files."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    resources = Resources([os.path.join(os.path.dirname(__file__), 'missing_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert not mapping
Esempio n. 10
0
def test_tool_plugin_load_mapping_invalid():
    """Test that we correctly skip invalid entries."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    resources = Resources([os.path.join(os.path.dirname(__file__), 'bad_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert not mapping
Esempio n. 11
0
def test_tool_plugin_load_mapping_suffixed():
    """Test that we can load the warnings mapping with a suffix."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str, default='experimental')
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'b': 'TST2-NO'}
Esempio n. 12
0
def test_tool_plugin_load_mapping_suffixed_fallback():
    """Test that we fall back to the non-suffixed file if we can't find a mapping file with an appropriate suffix."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str, default='gibberish')
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'a': 'TST1-NO'}
Esempio n. 13
0
def test_tool_plugin_get_user_flags_valid_flags():
    """Test that we return a list of user flags."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources(
        [os.path.join(os.path.dirname(__file__), "user_flags_config")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags("level", name="test")
    assert flags == ["look", "a", "flag"]
Esempio n. 14
0
def test_tool_plugin_load_mapping_valid():
    """Test that we can load the warnings mapping."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    arg_parser.add_argument("--output-directory", dest="output_directory")
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'a': 'TST1-NO'}
def setup_yamllint_tool_plugin():
    """Construct and return an instance of the YAMLLint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_true", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    yltp = YamllintToolPlugin()
    yltp.set_plugin_context(plugin_context)
    return yltp
Esempio n. 16
0
def setup_cpplint_tool_plugin():
    """Initialize and return an instance of the cpplint plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    ctp = CpplintToolPlugin()
    ctp.set_plugin_context(plugin_context)
    return ctp
Esempio n. 17
0
def setup_json_reporting_plugin(file_path, use_plugin_context=True):
    """Create an instance of the file writer plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")

    resources = Resources([os.path.join(os.path.dirname(__file__), "config")])
    config = Config(resources.get_file("config.yaml"))
    jrp = JsonReportingPlugin()
    if use_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([file_path]),
                                       resources, config)
        jrp.set_plugin_context(plugin_context)
    return jrp
Esempio n. 18
0
def setup_mypy_tool_plugin():
    """Create and return an instance of the Mypy plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")]
    )
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    mtp = MypyToolPlugin()
    mtp.set_plugin_context(plugin_context)
    return mtp
Esempio n. 19
0
def setup_pydocstyle_tool_plugin():
    """Initialize and return a PyCodeStyle plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    pdstp = PydocstyleToolPlugin()
    pdstp.set_plugin_context(plugin_context)
    return pdstp
Esempio n. 20
0
def setup_jshint_tool_plugin():
    """Initialize and return an instance of the jshint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__), 'plugins'),
                           os.path.join(os.path.dirname(__file__), 'valid_package')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin = JSHintToolPlugin()
    plugin.set_plugin_context(plugin_context)
    return plugin
Esempio n. 21
0
def setup_cmake_discovery_plugin():
    """Create an instance of the CMake discovery plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cmdp = CMakeDiscoveryPlugin()
    cmdp.set_plugin_context(plugin_context)
    return cmdp
Esempio n. 22
0
def setup_pyflakes_tool_plugin():
    """Initialize and return a Pyflakes plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    pftp = PyflakesToolPlugin()
    pftp.set_plugin_context(plugin_context)
    return pftp
Esempio n. 23
0
def setup_json_reporting_plugin():
    """Create an instance of the xmllint plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_true", help="Show tool output")

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([os.getcwd()]), resources, config)
    jrarp = JSONRiskAssessmentReportingPlugin()
    jrarp.set_plugin_context(plugin_context)
    return jrarp
Esempio n. 24
0
def setup_write_jenkins_warnings_ng_reporting_plugin(file_path,
                                                     use_plugin_context=True):
    """Create an instance of the file writer plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("output_directory")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    wfrp = WriteJenkinsWarningsNGReportingPlugin()
    if use_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([file_path]),
                                       resources, config)
        wfrp.set_plugin_context(plugin_context)
    return wfrp
Esempio n. 25
0
def setup_cmake_discovery_plugin(add_plugin_context=True, cmake_flags=""):
    """Create an instance of the CMake discovery plugin."""
    arg_parser = argparse.ArgumentParser()

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    cmdp = CMakeDiscoveryPlugin()
    if add_plugin_context:
        plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                       config)
        plugin_context.args.output_directory = os.path.dirname(__file__)
        plugin_context.args.cmake_flags = cmake_flags
        cmdp.set_plugin_context(plugin_context)
    return cmdp
def setup_pycodestyle_tool_plugin():
    """Create and return an instance of the PyCodeStyle plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output",
                            dest="show_tool_output",
                            action="store_true",
                            help="Show tool output")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), 'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    pcstp = PycodestyleToolPlugin()
    pcstp.set_plugin_context(plugin_context)
    return pcstp
Esempio n. 27
0
def setup_make_tool_plugin():
    """Construct and return an instance of the Make plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    mtp = MakeToolPlugin()
    mtp.set_plugin_context(plugin_context)
    return mtp
Esempio n. 28
0
def setup_lizard_tool_plugin(custom_rsc_path=None):
    """Initialize and return an instance of the lizard plugin."""
    arg_parser = argparse.ArgumentParser()

    if custom_rsc_path is not None:
        resources = Resources([custom_rsc_path])
    else:
        resources = Resources(
            [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    ltp = LizardToolPlugin()
    ltp.set_plugin_context(plugin_context)
    return ltp
Esempio n. 29
0
def setup_shellcheck_tool_plugin(binary=None):
    """Construct and return an instance of the Shellcheck plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--shellcheck-bin", dest="shellcheck_bin")

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    sctp = ShellcheckToolPlugin()
    if binary:
        plugin_context.args.shellcheck_bin = binary
    sctp.set_plugin_context(plugin_context)
    return sctp
Esempio n. 30
0
def setup_spotbugs_tool_plugin():
    """Initialize and return a spotbugs plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument("--show-tool-output", dest="show_tool_output",
                            action="store_false", help="Show tool output")
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)

    resources = Resources([os.path.join(os.path.dirname(statick_tool.__file__),
                                        'plugins')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    sbtp = SpotbugsToolPlugin()
    sbtp.set_plugin_context(plugin_context)
    return sbtp