Commit 9ec7aad2 authored by Chris Lamb's avatar Chris Lamb 👀
Browse files

Ensure that Java class files are named .class on the filesystem before passing them to javap(1).

parent 8ea42a68
Loading
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@
import re
import os.path
import logging
import shutil

from diffoscope.tools import tool_required
from diffoscope.difference import Difference
from diffoscope.exc import RequiredToolNotFound
from diffoscope.tempfiles import get_named_temporary_file
from diffoscope.tools import tool_required

from .utils.file import File
from .utils.command import Command, strip_ansi_escapes
@@ -49,9 +51,19 @@ class ProcyonDecompiler(Command):

class Javap(Command):
    def __init__(self, path, *args, **kwargs):
        super().__init__(path, *args, **kwargs)
        # Ensure that class files are named .class on the filesystem as javap
        # will not accept files with other extensions.
        if not path.endswith(".class"):
            self.tempfile = get_named_temporary_file(suffix=".class")
            logger.debug(f"Copying {path} to {self.tempfile.name}")
            shutil.copy(path, self.tempfile.name)
            path = self.tempfile.name

        # Save the realpath for filter()
        self.real_path = os.path.realpath(path)

        super().__init__(path, *args, **kwargs)

    @tool_required("javap")
    def cmdline(self):
        return [