From 376a242a620899cad52b780b65ce16389fa8bb81 Mon Sep 17 00:00:00 2001 From: Martin Kellogg Date: Thu, 11 Apr 2024 23:10:02 -0400 Subject: [PATCH 1/2] set up cf-691 to use --targetField. Sadly, it crashes --- Keyvalue.py | 1 + main.py | 22 ++++++++++++++++------ resources/test_data.json | 6 ++++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Keyvalue.py b/Keyvalue.py index 8b9f2ed..aba87bc 100644 --- a/Keyvalue.py +++ b/Keyvalue.py @@ -11,6 +11,7 @@ class JsonKeys(Enum): PACKAGE = 'package' TARGETS = 'targets' METHOD_NAME = 'method' + FIELD_NAME = 'field' FILE_NAME = 'file' CF_Version = 'cf_version' JAVA_VERSION = 'java_version' diff --git a/main.py b/main.py index 6ff69be..79e5a75 100644 --- a/main.py +++ b/main.py @@ -272,7 +272,7 @@ def build_specimin_command(project_name: str, project_name (str): Name of the target project. Example: daikon target_base_dir (str): path of the target project directory. Ex: ISSUES/cf-1291 root_dir (str): A directory path relative to the project base directory where java package stored. - targets ({'method': '', 'file': '', 'package': ''}) : target java file and method name data + targets ({'method': '' or 'field': '', 'file': '', 'package': ''}) : target java file and method/field name data Retruns: command (str): The gradle command of SPECIMIN for the issue. @@ -294,10 +294,12 @@ def build_specimin_command(project_name: str, target_file_list = [] target_method_list = [] + target_field_list = [] for target in targets: method_name = target[JsonKeys.METHOD_NAME.value] + field_name = target[JsonKeys.FIELD_NAME.value] file_name = target[JsonKeys.FILE_NAME.value] package_name = target[JsonKeys.PACKAGE.value] @@ -307,10 +309,11 @@ def build_specimin_command(project_name: str, qualified_file_name = os.path.join(dot_replaced_package_name, file_name) target_file_list.append(qualified_file_name) + inner_class_name = "" + if JsonKeys.INNER_CLASS.value in target and target[JsonKeys.INNER_CLASS.value] : + inner_class_name = f".{target[JsonKeys.INNER_CLASS.value]}" + if method_name: - inner_class_name = "" - if JsonKeys.INNER_CLASS.value in target and target[JsonKeys.INNER_CLASS.value] : - inner_class_name = f".{target[JsonKeys.INNER_CLASS.value]}" #if non-primary class exists, file name will not be included in target-method # Look for PR #177: https://github.com/kelloggm/specimin/pull/177 @@ -320,6 +323,9 @@ def build_specimin_command(project_name: str, qualified_method_name = package_name + "." + os.path.splitext(file_name)[0]+ inner_class_name + "#" + method_name target_method_list.append(qualified_method_name) + if field_name: + target_field_list.append(package_name + "." + os.path.splitext(file_name)[0]+ inner_class_name + "#" + field_name) + output_dir_subcommand = "--outputDirectory" + " " + f"\"{output_dir}\"" root_dir_subcommand = "--root" + " " + f"\"{root_dir}\"" target_file_subcommand = "" @@ -329,12 +335,16 @@ def build_specimin_command(project_name: str, target_method_subcommand = "" for method in target_method_list: target_method_subcommand += "--targetMethod" + " " + f"\"{method}\"" - + + target_field_subcommand = "" + for field in target_field_list: + target_field_subcommand += "--targetField" + " " + f"\"{field}\"" + jar_path_subcommand = "" if jar_path: jar_path_subcommand = " --jarPath" + " " + f"\"{jar_path}\"" - command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + jar_path_subcommand + command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + " " + target_field_subcommand + jar_path_subcommand command = "./gradlew" + " " + "run" + " " + "--args=" + f"\'{command_args}\'" return command diff --git a/resources/test_data.json b/resources/test_data.json index 6f0aaec..1e8bd90 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -386,9 +386,11 @@ "root_dir": "", "targets": [ { - "method": "sort(List)", + "method": "", + "field": "EMPTY_NAVIGABLE_SET", "file": "Collections.java", - "package": "com.example" + "package": "com.example", + "inner_class": "UnmodifiableNavigableSet" } ], "cf_version": "1.9.13", From cb428bd60f26d73570d9787ebd2ad62c586faf6d Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Apr 2024 01:30:03 -0400 Subject: [PATCH 2/2] test break fix --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 79e5a75..ee2778f 100644 --- a/main.py +++ b/main.py @@ -299,7 +299,7 @@ def build_specimin_command(project_name: str, for target in targets: method_name = target[JsonKeys.METHOD_NAME.value] - field_name = target[JsonKeys.FIELD_NAME.value] + field_name = target.get(JsonKeys.FIELD_NAME.value) file_name = target[JsonKeys.FILE_NAME.value] package_name = target[JsonKeys.PACKAGE.value] @@ -338,13 +338,13 @@ def build_specimin_command(project_name: str, target_field_subcommand = "" for field in target_field_list: - target_field_subcommand += "--targetField" + " " + f"\"{field}\"" + target_field_subcommand += " --targetField" + " " + f"\"{field}\"" jar_path_subcommand = "" if jar_path: jar_path_subcommand = " --jarPath" + " " + f"\"{jar_path}\"" - command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + " " + target_field_subcommand + jar_path_subcommand + command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + target_field_subcommand + jar_path_subcommand command = "./gradlew" + " " + "run" + " " + "--args=" + f"\'{command_args}\'" return command