Skip to content

Commit

Permalink
Merge pull request #42 from tahiat/cf-691-field
Browse files Browse the repository at this point in the history
set up cf-691 to use --targetField
  • Loading branch information
kelloggm authored Apr 12, 2024
2 parents 7daed0b + cb428bd commit 618628b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions Keyvalue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
22 changes: 16 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.get(JsonKeys.FIELD_NAME.value)
file_name = target[JsonKeys.FILE_NAME.value]
package_name = target[JsonKeys.PACKAGE.value]

Expand All @@ -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

Expand All @@ -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 = ""
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions resources/test_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,11 @@
"root_dir": "",
"targets": [
{
"method": "sort(List<T>)",
"method": "",
"field": "EMPTY_NAVIGABLE_SET",
"file": "Collections.java",
"package": "com.example"
"package": "com.example",
"inner_class": "UnmodifiableNavigableSet"
}
],
"cf_version": "1.9.13",
Expand Down

0 comments on commit 618628b

Please sign in to comment.