diff --git a/src/jgo/jgo.py b/src/jgo/jgo.py index bd2b328..934d3ed 100644 --- a/src/jgo/jgo.py +++ b/src/jgo/jgo.py @@ -821,12 +821,18 @@ def _run( pass if not primary_endpoint.main_class: - _logger.info("Inferring main class from jar manifest") - jar_path = glob.glob( - os.path.join(workspace, primary_endpoint.jar_name()) + glob_pattern = ( + primary_endpoint.jar_name() .replace(Endpoint.VERSION_RELEASE, "*") .replace(Endpoint.VERSION_LATEST, "*") - )[0] + ) + _logger.info( + f"Inferring main class from manifest of {primary_endpoint.jar_name()}" + f" using glob '{glob_pattern}'" + ) + jar_paths = sorted(glob.glob(os.path.join(workspace, glob_pattern))) + _logger.debug(f"Using first jar from matching jars {jar_paths}") + jar_path = jar_paths[0] with zipfile.ZipFile(jar_path) as jar_file: with jar_file.open("META-INF/MANIFEST.MF") as manifest: main_class_pattern = re.compile(".*Main-Class: *") diff --git a/tests/test_run.py b/tests/test_run.py index f14d7d1..945fe2e 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -476,6 +476,29 @@ def test_explicit_main_class(self, launch_java_mock): self.assertIsNone(stderr) self.assertFalse(check) + @patch("jgo.jgo.launch_java") + def test_infer_main_class(self, launch_java_mock): + parser = jgo_parser() + argv = ["com.pinterest.ktlint:ktlint-cli"] + + run(parser, argv) + self.assertTrue(launch_java_mock.called) + args, kwargs = _call_args(launch_java_mock) + workspace = args[0] + jvm_args = args[1] + program_args = args[2:] + additional_jars = kwargs["additional_jars"] + stdout = kwargs["stdout"] + stderr = kwargs["stderr"] + check = kwargs["check"] + self.assertIsInstance(workspace, str) + self.assertEqual(jvm_args, []) + self.assertEqual(program_args, ("com.pinterest.ktlint.Main",)) + self.assertEqual(additional_jars, []) + self.assertIsNone(stdout) + self.assertIsNone(stderr) + self.assertFalse(check) + class TestUtil(unittest.TestCase): @patch("jgo.jgo._run")