# Path: javatools/jardiff.py
# def cli_jars_diff(options, left, right):
#     from .report import quick_report, Reporter
#     from .report import JSONReportFormat, TextReportFormat
# 
#     reports = getattr(options, "reports", tuple())
#     if reports:
#         rdir = options.report_dir or "./"
# 
#         rpt = Reporter(rdir, JarReport.report_name, options)
#         rpt.add_formats_by_name(reports)
# 
#         delta = JarReport(left, right, rpt)
# 
#     else:
#         delta = JarChange(left, right)
# 
#     delta.check()
# 
#     if not options.silent:
#         if options.json:
#             quick_report(JSONReportFormat, delta, options)
#         else:
#             quick_report(TextReportFormat, delta, options)
# 
#     if (not delta.is_change()) or delta.is_ignored(options):
#         return 0
#     else:
#         return 1
# 
# def main(args=sys.argv):
#     """
#     main entry point for the jardiff CLI
#     """
# 
#     parser = create_optparser(args[0])
#     return cli(parser.parse_args(args[1:]))


import os
from unittest import TestCase
from . import get_data_fn
from javatools.jardiff import cli_jars_diff, main

    options.silent = True
    options.ignore_jar_signature = False

    # Two identical JARs (in different files, just in case)
    def test_identical_jars(self):
        self.cli_jardiff_wrap(0, "test_jardiff/ec.jar", "test_jardiff/ec-copied.jar",
            "Identical JARs reported as different")

    def test_sig_block_file_tampered(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-tampered.jar",
            "Change in signature block file is not detected")

    def test_sig_block_file_removed(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-sig-block-removed.jar",
            "Removal of signature block file is not detected")

    def test_sig_manifest_tampered(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-sig-mf-tampered.jar",
            "Change in manifest signature file is not detected")

    def test_generic_file_change(self):
        self.options.ignore_jar_entry = []  # Needed, as argparse is not called
        self.cli_jardiff_wrap(1, os.path.join("test_jardiff", "generic1.jar"),
            os.path.join("test_jardiff", "generic2.jar"),
            "Change in generic file is not detected")

    def test_json_binary_diff(self):
        left = get_data_fn(os.path.join("test_jardiff", "ec.jar"))
        right = get_data_fn(os.path.join("test_jardiff", "ec-tampered.jar"))

# Path: javatools/jardiff.py
# def cli_jars_diff(options, left, right):
#     from .report import quick_report, Reporter
#     from .report import JSONReportFormat, TextReportFormat
# 
#     reports = getattr(options, "reports", tuple())
#     if reports:
#         rdir = options.report_dir or "./"
# 
#         rpt = Reporter(rdir, JarReport.report_name, options)
#         rpt.add_formats_by_name(reports)
# 
#         delta = JarReport(left, right, rpt)
# 
#     else:
#         delta = JarChange(left, right)
# 
#     delta.check()
# 
#     if not options.silent:
#         if options.json:
#             quick_report(JSONReportFormat, delta, options)
#         else:
#             quick_report(TextReportFormat, delta, options)
# 
#     if (not delta.is_change()) or delta.is_ignored(options):
#         return 0
#     else:
#         return 1
# 
# def main(args=sys.argv):
#     """
#     main entry point for the jardiff CLI
#     """
# 
#     parser = create_optparser(args[0])
#     return cli(parser.parse_args(args[1:]))


# Path: tests/jardiff.py
import os
from unittest import TestCase
from . import get_data_fn
from javatools.jardiff import cli_jars_diff, main


    options.silent = True
    options.ignore_jar_signature = False

    # Two identical JARs (in different files, just in case)
    def test_identical_jars(self):
        self.cli_jardiff_wrap(0, "test_jardiff/ec.jar", "test_jardiff/ec-copied.jar",
            "Identical JARs reported as different")

    def test_sig_block_file_tampered(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-tampered.jar",
            "Change in signature block file is not detected")

    def test_sig_block_file_removed(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-sig-block-removed.jar",
            "Removal of signature block file is not detected")

    def test_sig_manifest_tampered(self):
        self.cli_jardiff_wrap(1, "test_jardiff/ec.jar", "test_jardiff/ec-sig-mf-tampered.jar",
            "Change in manifest signature file is not detected")

    def test_generic_file_change(self):
        self.options.ignore_jar_entry = []  # Needed, as argparse is not called
        self.cli_jardiff_wrap(1, os.path.join("test_jardiff", "generic1.jar"),
            os.path.join("test_jardiff", "generic2.jar"),
            "Change in generic file is not detected")

    def test_json_binary_diff(self):
        left = get_data_fn(os.path.join("test_jardiff", "ec.jar"))
        right = get_data_fn(os.path.join("test_jardiff", "ec-tampered.jar"))

        self.assertEqual(1, main(["argv0", "--json", left, right]))