From 7ee16c23a260bc9cb38e680b400af389d18e0d76 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Tue, 9 Jan 2024 15:41:09 -0500 Subject: [PATCH 01/18] cloning the specimin project and pulling latest if exists already --- main.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 599716a..21a4935 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import subprocess issue_directory = 'ISSUES' +specimin_input = 'input' +specimin_output = 'ouput' def read_json_from_file(file_path): try: @@ -20,8 +22,8 @@ def create_directory(issue_container_dir, issue_id): issue_directory_name = os.path.join(issue_container_dir, issue_id) os.makedirs(issue_directory_name, exist_ok=True) - specimin_input_dir = os.path.join(issue_directory_name, "input") - specimin_output_dir = os.path.join(issue_directory_name, "output") + specimin_input_dir = os.path.join(issue_directory_name, specimin_input) + specimin_output_dir = os.path.join(issue_directory_name, specimin_output) os.makedirs(specimin_input_dir, exist_ok=True) os.makedirs(specimin_output_dir, exist_ok=True) From ce081825ba8acc786c8d2501a7a86ac5bdb3d13f Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Wed, 10 Jan 2024 22:19:39 -0500 Subject: [PATCH 02/18] restructuring json data and building specimin command --- main.py | 56 +++++++++++++++++++++++++++++++++++----- resources/test_data.json | 15 ++++++++--- 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 21a4935..7da2c2a 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,8 @@ issue_directory = 'ISSUES' specimin_input = 'input' specimin_output = 'ouput' +specimin_project_name = 'specimin' +specimin_source_url = 'git@github.com:kelloggm/specimin.git' def read_json_from_file(file_path): try: @@ -29,7 +31,7 @@ def create_directory(issue_container_dir, issue_id): os.makedirs(specimin_output_dir, exist_ok=True) return specimin_input_dir -def clone_repository(url, directory): #TODO: parallel cloning task +def clone_repository(url, directory): subprocess.run(["git", "clone", url, directory]) def change_branch(branch, directory): @@ -46,8 +48,37 @@ def checkout_commit(commit_hash, directory): print(f"Failed to checkout commit {commit_hash} in {directory}") -def run_specimin(build_command): - pass +def run_specimin(issue_id, root_dir, package_name, targets): + command = ["./gradlew", "run", "-"] + + + output_dir = os.path.join(issue_directory, issue_id, specimin_output) + root_dir = os.path.join(issue_directory, issue_id, specimin_input, root_dir) + os.sep + + + dot_replaced_package_name = package_name.replace('.', '/') + + target_file_list = [] + target_method_list = [] + + for target in targets: + method_name = target["method"] + file_name = target["file"] + + if file_name: + qualified_file_name = os.path.join(dot_replaced_package_name, file_name) + target_file_list.append(qualified_file_name) + + if method_name: + qualified_method_name = package_name + "." + os.path.splitext(file_name)[0]+ "#" + method_name + target_method_list.append(qualified_method_name) + + + + + + + def performEvaluation(issue): issue_id = issue['issue_id'] @@ -65,22 +96,35 @@ def performEvaluation(issue): if commit_hash: checkout_commit(commit_hash, input_dir) - success = run_specimin(specimin_command) + success = run_specimin(issue_id, issue['rootDir'], issue['package'], issue['targets']) if success: print(f"Test {issue_id} successfully completed.") else: print(f"Test {issue_id} failed.") + +def perform_git_pull (directory): + command=["git", "pull", "origin", "--rebase"] + subprocess.run(command, cwd=directory) + +def clone_specimin(): + spcimin_source_path = os.path.join(issue_directory, specimin_project_name) + if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): + perform_git_pull(spcimin_source_path) + else: + clone_repository(specimin_source_url, spcimin_source_path) + def main(): - - json_file_path = 'resources/test_data.json' + clone_specimin() + json_file_path = 'resources/test_data.json' parsed_data = read_json_from_file(json_file_path) if parsed_data: for issue in parsed_data: performEvaluation(issue) + if __name__ == "__main__": main() \ No newline at end of file diff --git a/resources/test_data.json b/resources/test_data.json index ba2e609..68b094e 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -3,12 +3,19 @@ "issue_id" : "cf-1291", "url": "git@github.com:codespecs/daikon.git", "branch": "", - "commitHash":"15d7c2d84", + "commitHash": "15d7c2d84", "project_name": "daikon", "build_command": "this can be cf command or java", - "specimin_command": "command to run specimin", - "note": "", + "rootDir": "java", + "package": "daikon.chicory", + "targets": [ + { + "method": "executePureMethod(Method, Object, Object[])", + "file": "PureMethodInfo.java" + } + ], "cf_version": "2.1.10", - "java_version":"" + "java_version": "", + "note": "" } ] \ No newline at end of file From 3698235209b50b756c2d00dc5aac5cd5e1aa0bb1 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Thu, 11 Jan 2024 02:33:17 -0500 Subject: [PATCH 03/18] enum for json key values, running specimin command --- Keyvalue.py | 17 ++++++++++++++++ main.py | 57 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 Keyvalue.py diff --git a/Keyvalue.py b/Keyvalue.py new file mode 100644 index 0000000..475705a --- /dev/null +++ b/Keyvalue.py @@ -0,0 +1,17 @@ +from enum import Enum + +class JsonKeys(Enum): + ISSUE_ID = 'issue_id' + URL = 'url' + BRANCH = 'branch' + COMMIT_HASH = 'commit_hash' + PROJECT_NAME = 'project_name' + BUILD_COMMAND = 'build_command' + ROOT_DIR = 'root_dir' + package = 'package' + TARGETS = 'targets' + METHOD_NAME = 'method' + FILE_NAME = 'file' + CF_Version = 'cf_version' + JAVA_VERSION = 'java_version' + NOTE = 'note' diff --git a/main.py b/main.py index 7da2c2a..e107357 100644 --- a/main.py +++ b/main.py @@ -1,8 +1,10 @@ import json import os import subprocess +from Keyvalue import JsonKeys -issue_directory = 'ISSUES' + +issue_folder_dir = 'ISSUES' specimin_input = 'input' specimin_output = 'ouput' specimin_project_name = 'specimin' @@ -48,13 +50,9 @@ def checkout_commit(commit_hash, directory): print(f"Failed to checkout commit {commit_hash} in {directory}") -def run_specimin(issue_id, root_dir, package_name, targets): - command = ["./gradlew", "run", "-"] - - - output_dir = os.path.join(issue_directory, issue_id, specimin_output) - root_dir = os.path.join(issue_directory, issue_id, specimin_input, root_dir) + os.sep - +def build_specimin_command(issue_id, root_dir, package_name, targets): + output_dir = os.path.join("..", issue_id, specimin_output) + root_dir = os.path.join("..", issue_id, specimin_input, root_dir) + os.sep dot_replaced_package_name = package_name.replace('.', '/') @@ -62,8 +60,8 @@ def run_specimin(issue_id, root_dir, package_name, targets): target_method_list = [] for target in targets: - method_name = target["method"] - file_name = target["file"] + method_name = target[JsonKeys.METHOD_NAME.value] + file_name = target[JsonKeys.FILE_NAME.value] if file_name: qualified_file_name = os.path.join(dot_replaced_package_name, file_name) @@ -73,21 +71,37 @@ def run_specimin(issue_id, root_dir, package_name, targets): qualified_method_name = package_name + "." + os.path.splitext(file_name)[0]+ "#" + method_name target_method_list.append(qualified_method_name) + output_dir_subcommand = "--outputDirectory" + " " + f"\"{output_dir}\"" + root_dir_subcommand = "--root" + " " + f"\"{root_dir}\"" + target_file_subcommand = "" + for file in target_file_list: + target_file_subcommand += "--targetFile" + " " + f"\"{file}\"" + target_method_subcommand = "" + for method in target_method_list: + target_method_subcommand += "--targetMethod" + " " + f"\"{method}\"" + command_args = root_dir_subcommand + " " + output_dir_subcommand + " " + target_file_subcommand + " " + target_method_subcommand + command = "./gradlew" + " " + "run" + " " + "--args=" + f"\'{command_args}\'" + + return command - - +def run_specimin(command, directory): + result = subprocess.run(command, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # TODO: + if result.returncode == 0: + return True + else: + return False + def performEvaluation(issue): - issue_id = issue['issue_id'] - url = issue['url'] - branch = issue['branch'] - commit_hash = issue['commitHash'] - specimin_command = issue['specimin_command'] + issue_id = issue[JsonKeys.ISSUE_ID.value] + url = issue[JsonKeys.URL.value] + branch = issue[JsonKeys.BRANCH.value] + commit_hash = issue[JsonKeys.COMMIT_HASH.value] - input_dir = create_directory(issue_directory, issue_id) + input_dir = create_directory(issue_folder_dir, issue_id) clone_repository(url, input_dir) # TODO: check if clonning is successful. if branch: @@ -96,7 +110,9 @@ def performEvaluation(issue): if commit_hash: checkout_commit(commit_hash, input_dir) - success = run_specimin(issue_id, issue['rootDir'], issue['package'], issue['targets']) + specimin_command = build_specimin_command(issue_id, issue[JsonKeys.ROOT_DIR.value], issue[JsonKeys.PACKAGE.value], issue[JsonKeys.TARGETS.value]) + + success = run_specimin(specimin_command, os.path.join(issue_folder_dir, specimin_project_name)) if success: print(f"Test {issue_id} successfully completed.") @@ -109,12 +125,13 @@ def perform_git_pull (directory): subprocess.run(command, cwd=directory) def clone_specimin(): - spcimin_source_path = os.path.join(issue_directory, specimin_project_name) + spcimin_source_path = os.path.join(issue_folder_dir, specimin_project_name) if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): perform_git_pull(spcimin_source_path) else: clone_repository(specimin_source_url, spcimin_source_path) + def main(): clone_specimin() From e186ff841e00b64773f96fd676a5bbdb4ab9fed0 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Thu, 11 Jan 2024 02:43:17 -0500 Subject: [PATCH 04/18] adding cache folder in gitignore, fixing json key values in enum --- .gitignore | 4 +++- Keyvalue.py | 2 +- resources/test_data.json | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4d2eed5..e63e05c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ ISSUES # macOS specific file -.DS_Store \ No newline at end of file +.DS_Store + +__pycache__/ \ No newline at end of file diff --git a/Keyvalue.py b/Keyvalue.py index 475705a..b8a5dc9 100644 --- a/Keyvalue.py +++ b/Keyvalue.py @@ -8,7 +8,7 @@ class JsonKeys(Enum): PROJECT_NAME = 'project_name' BUILD_COMMAND = 'build_command' ROOT_DIR = 'root_dir' - package = 'package' + PACKAGE = 'package' TARGETS = 'targets' METHOD_NAME = 'method' FILE_NAME = 'file' diff --git a/resources/test_data.json b/resources/test_data.json index 68b094e..ecef4f6 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -3,10 +3,10 @@ "issue_id" : "cf-1291", "url": "git@github.com:codespecs/daikon.git", "branch": "", - "commitHash": "15d7c2d84", + "commit_hash": "15d7c2d84", "project_name": "daikon", "build_command": "this can be cf command or java", - "rootDir": "java", + "root_dir": "java", "package": "daikon.chicory", "targets": [ { From 4682554d20a4d67b30173bad29962170d58a67d1 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Thu, 11 Jan 2024 16:45:01 -0500 Subject: [PATCH 05/18] adding Docstrings for functions --- main.py | 149 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index e107357..d527c1f 100644 --- a/main.py +++ b/main.py @@ -11,6 +11,15 @@ specimin_source_url = 'git@github.com:kelloggm/specimin.git' def read_json_from_file(file_path): + ''' + Parse a json file. + + Parameters: + file_path (path): Path to the json file + + Retruns: + { }: Parsed json data + ''' try: with open(file_path, 'r') as file: json_data = json.load(file) @@ -22,7 +31,26 @@ def read_json_from_file(file_path): print(f"File not found: {file_path}") return None -def create_directory(issue_container_dir, issue_id): +def create_issue_directory(issue_container_dir, issue_id): + ''' + Creates a directory to store a SPECIMIN target project. Example: issue_id of cf-111 will create + a cf-111 directory inside 'issue_container_dir'. Two other directory (input and output inside) will + be created inside 'issue_container_dir/issue_id' directory. Target project is cloned inside + 'issue_container_dir/issue_id/input' directory. SPECIMIN output is stored inside 'issue_container_dir/issue_id/output' + directory + + issue_container_dir + |--- issue_id + | |--- input + | |--- output + + Parameters: + issue_container_dir (str): The directory where new directory is created + issue_id (str): Name of the directory to be created + + Returns: + specimin_input_dir (str): A target directory of SPECIMIN. + ''' issue_directory_name = os.path.join(issue_container_dir, issue_id) os.makedirs(issue_directory_name, exist_ok=True) @@ -34,23 +62,88 @@ def create_directory(issue_container_dir, issue_id): return specimin_input_dir def clone_repository(url, directory): + ''' + Clone a repository from 'url' in 'directory' + + Parameters: + url (str): repository url + directory (str): directory to clone in + ''' subprocess.run(["git", "clone", url, directory]) def change_branch(branch, directory): - pass + ''' + Checkout a branch of a git repository + + Parameters: + branch (str): branch name + directory (str): local directory of the git repository + ''' + command = ["git", "checkout", f"{branch}"] + subprocess.run(command, cwd=directory) def checkout_commit(commit_hash, directory): + ''' + Checkout a commit of a git repository + + Parameters: + commit_hash (str): commit hash + directory (str): local directory of the git repository + ''' command = ["git", "checkout", commit_hash] result = subprocess.run(command, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # Check if the command was successful if result.returncode == 0: print(f"Successfully checked-out commit {commit_hash} in {directory}") else: print(f"Failed to checkout commit {commit_hash} in {directory}") - + +def perform_git_pull (directory): + ''' + Pull latest of a git repository + + Parameters: + directory (str): local directory of the git repository + ''' + command=["git", "pull", "origin", "--rebase"] + subprocess.run(command, cwd=directory) + +def clone_specimin(): + ''' + Checkout a commit of a git repository + + Parameters: + commit_hash (str): commit hash + directory (str): local directory of the git repository + ''' + spcimin_source_path = os.path.join(issue_folder_dir, specimin_project_name) + if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): + perform_git_pull(spcimin_source_path) + else: + clone_repository(specimin_source_url, spcimin_source_path) + def build_specimin_command(issue_id, root_dir, package_name, targets): + ''' + Checkout a commit of a git repository + + issue_container_dir(ISSUES) + |--- issue_id(cf-1291) + | |--- input ---> it contains the git repository of a target project + | | |----nomulus/core/src/main/java/ ---> this is the root directory of a package + | | |---package_path/file.java (daikon/chicory/PureMethodInfo.java) --> a target file + | |--- output --> Contains minimization result of Specimin + + + Parameters: + issue_id (str): Name of the directory/folder that contains a SPECIMINS' target project. Ex: cf-1291 + root_dir (str): A directory path relative to the project base directory where java package stored. + package_name (str): A valid Java package + targets ({'method': '', 'file': ''}) : targetted java file and method name data + + Retruns: + command (str): The gradle command of SPECIMIN for the issue. + ''' output_dir = os.path.join("..", issue_id, specimin_output) root_dir = os.path.join("..", issue_id, specimin_input, root_dir) + os.sep @@ -88,6 +181,16 @@ def build_specimin_command(issue_id, root_dir, package_name, targets): return command def run_specimin(command, directory): + ''' + Execute SPECIMIN on a target project + + Parameters: + command (str): The gradle command to run specimin + directory (str): The base directory of the specimin repository + + Returns: + boolean: True/False based on successful execution of SPECIMIN + ''' result = subprocess.run(command, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # TODO: if result.returncode == 0: return True @@ -95,13 +198,20 @@ def run_specimin(command, directory): return False -def performEvaluation(issue): - issue_id = issue[JsonKeys.ISSUE_ID.value] - url = issue[JsonKeys.URL.value] - branch = issue[JsonKeys.BRANCH.value] - commit_hash = issue[JsonKeys.COMMIT_HASH.value] +def performEvaluation(issue_data): + ''' + For each issue dataExecute SPECIMIN on a target project. + + Parameters: + issue ({}): json data associated with an issue + ''' - input_dir = create_directory(issue_folder_dir, issue_id) + issue_id = issue_data[JsonKeys.ISSUE_ID.value] + url = issue_data[JsonKeys.URL.value] + branch = issue_data[JsonKeys.BRANCH.value] + commit_hash = issue_data[JsonKeys.COMMIT_HASH.value] + + input_dir = create_issue_directory(issue_folder_dir, issue_id) clone_repository(url, input_dir) # TODO: check if clonning is successful. if branch: @@ -110,7 +220,7 @@ def performEvaluation(issue): if commit_hash: checkout_commit(commit_hash, input_dir) - specimin_command = build_specimin_command(issue_id, issue[JsonKeys.ROOT_DIR.value], issue[JsonKeys.PACKAGE.value], issue[JsonKeys.TARGETS.value]) + specimin_command = build_specimin_command(issue_id, issue_data[JsonKeys.ROOT_DIR.value], issue_data[JsonKeys.PACKAGE.value], issue_data[JsonKeys.TARGETS.value]) success = run_specimin(specimin_command, os.path.join(issue_folder_dir, specimin_project_name)) @@ -120,21 +230,12 @@ def performEvaluation(issue): print(f"Test {issue_id} failed.") -def perform_git_pull (directory): - command=["git", "pull", "origin", "--rebase"] - subprocess.run(command, cwd=directory) - -def clone_specimin(): - spcimin_source_path = os.path.join(issue_folder_dir, specimin_project_name) - if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): - perform_git_pull(spcimin_source_path) - else: - clone_repository(specimin_source_url, spcimin_source_path) - - def main(): - clone_specimin() + ''' + Main method of the script. It iterates over the json data and perform minimization for each cases. + ''' + clone_specimin() json_file_path = 'resources/test_data.json' parsed_data = read_json_from_file(json_file_path) From c5b99abb2c1aba8a05ad259e73fb6a80b766ee94 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Thu, 11 Jan 2024 21:01:02 -0500 Subject: [PATCH 06/18] adding a test class --- TestMain.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 TestMain.py diff --git a/TestMain.py b/TestMain.py new file mode 100644 index 0000000..c043ce8 --- /dev/null +++ b/TestMain.py @@ -0,0 +1,11 @@ +import unittest +import main + +class TestMain(unittest.TestCase): + + def test_build_specimin_command(): + pass + + + if __name__ == '__main__': + unittest.main() \ No newline at end of file From d79ecd27594d886495e7696866fc4f85ab382d67 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 04:25:52 -0500 Subject: [PATCH 07/18] adding test cases and resource for testing --- TestMain.py | 58 ++++++++++++- main.py | 80 +++++++++++++----- .../expected/com/example/Simple.java | 13 +++ .../input/com/example/Simple.class | Bin 0 -> 409 bytes .../input/com/example/Simple.java | 13 +++ resources/specimin_command_cf-6019.txt | 1 + resources/specimin_command_cf-6077.txt | 1 + 7 files changed, 144 insertions(+), 22 deletions(-) create mode 100644 resources/onefilesimple/expected/com/example/Simple.java create mode 100644 resources/onefilesimple/input/com/example/Simple.class create mode 100644 resources/onefilesimple/input/com/example/Simple.java create mode 100644 resources/specimin_command_cf-6019.txt create mode 100644 resources/specimin_command_cf-6077.txt diff --git a/TestMain.py b/TestMain.py index c043ce8..1229598 100644 --- a/TestMain.py +++ b/TestMain.py @@ -1,11 +1,63 @@ import unittest import main + class TestMain(unittest.TestCase): - def test_build_specimin_command(): + def setUp(self): + pass + + def tearDown(self): pass + def test_get_repository_name(self): + url = 'git@github.com:codespecs/daikon.git' + self.assertEqual(main.get_repository_name(url), 'daikon') + + url = 'git@github.com:kelloggm/specimin.git' + self.assertEqual(main.get_repository_name(url), 'specimin') + + url = 'git@github.com:typetools/checker-framework.git' + self.assertEqual(main.get_repository_name(url), 'checker-framework') + + url = 'git@github.com:awslabs/aws-kms-compliance-checker.git' + self.assertEqual(main.get_repository_name(url), 'aws-kms-compliance-checker') + + url = 'git@github.com:awslabs/aws-kms-compliance-checker.git' + self.assertNotEqual(main.get_repository_name(url), 'aws-km-compliance-checker') + + def test_build_specimin_command(self): + proj_name = 'cassandra' + root = 'src/java' + package = 'org.apache.cassandra.index.sasi.conf' + targets = [{ + "method": "getMode(ColumnMetadata, Map)", + "file": "IndexMode.java" + }] + specimin_dir = 'user/specimin' + target_dir = 'user/ISSUES/cf-6077' + command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, targets) + target_command = '' + with open('resources/specimin_command_cf-6077.txt','r') as file: + target_command = file.read() + self.assertEqual(command, target_command) + + proj_name = 'kafka-sensors' + root = 'src/main/java/' + package = 'com.fillmore_labs.kafka.sensors.serde.confluent.interop' + targets = [{ + "method": "transform(String, byte[])", + "file": "Avro2Confluent.java" + }] + specimin_dir = 'user/specimin' + target_dir = 'user/ISSUES/cf-6019' + command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, targets) + with open('resources/specimin_command_cf-6019.txt','r') as file: + target_command = file.read() + self.assertEqual(command, target_command) + + + - if __name__ == '__main__': - unittest.main() \ No newline at end of file +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/main.py b/main.py index d527c1f..9ea521c 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,7 @@ issue_folder_dir = 'ISSUES' specimin_input = 'input' -specimin_output = 'ouput' +specimin_output = 'output' specimin_project_name = 'specimin' specimin_source_url = 'git@github.com:kelloggm/specimin.git' @@ -31,6 +31,18 @@ def read_json_from_file(file_path): print(f"File not found: {file_path}") return None + +def get_repository_name(github_ssh: str): + ''' + Extract the repository name from github ssh + Parameters: + github_ssh (str): A valid github ssh + + Returns: repository name + ''' + repository_name = os.path.splitext(os.path.basename(github_ssh))[0] + return repository_name + def create_issue_directory(issue_container_dir, issue_id): ''' Creates a directory to store a SPECIMIN target project. Example: issue_id of cf-111 will create @@ -61,6 +73,18 @@ def create_issue_directory(issue_container_dir, issue_id): os.makedirs(specimin_output_dir, exist_ok=True) return specimin_input_dir + +def is_git_directory(dir): + ''' + Check whether a directory is a git directory + Parameters: + dir: path of the directory + Returns: + booleans + ''' + git_dir_path = os.path.join(dir, '.git') + return os.path.exists(git_dir_path) and os.path.isdir(git_dir_path) + def clone_repository(url, directory): ''' Clone a repository from 'url' in 'directory' @@ -69,7 +93,7 @@ def clone_repository(url, directory): url (str): repository url directory (str): directory to clone in ''' - subprocess.run(["git", "clone", url, directory]) + subprocess.run(["git", "clone", url], cwd=directory) def change_branch(branch, directory): ''' @@ -79,6 +103,8 @@ def change_branch(branch, directory): branch (str): branch name directory (str): local directory of the git repository ''' + if not is_git_directory(directory): + raise ValueError(f"{directory} is not a valid git directory") command = ["git", "checkout", f"{branch}"] subprocess.run(command, cwd=directory) @@ -90,6 +116,9 @@ def checkout_commit(commit_hash, directory): commit_hash (str): commit hash directory (str): local directory of the git repository ''' + if not is_git_directory(directory): + raise ValueError(f"{directory} is not a valid git directory") + command = ["git", "checkout", commit_hash] result = subprocess.run(command, cwd=directory, stdout=subprocess.PIPE, stderr=subprocess.PIPE) @@ -108,24 +137,29 @@ def perform_git_pull (directory): command=["git", "pull", "origin", "--rebase"] subprocess.run(command, cwd=directory) -def clone_specimin(): +def clone_specimin(path_to_clone, url): ''' - Checkout a commit of a git repository + Clone the latest Speimin project from github Parameters: - commit_hash (str): commit hash - directory (str): local directory of the git repository + path_to_clone (str): Path where Specimin is to be clonned + url (str): url of specimin ''' spcimin_source_path = os.path.join(issue_folder_dir, specimin_project_name) if (os.path.exists(spcimin_source_path)) and os.path.isdir(spcimin_source_path): perform_git_pull(spcimin_source_path) else: - clone_repository(specimin_source_url, spcimin_source_path) + clone_repository(url, path_to_clone) -def build_specimin_command(issue_id, root_dir, package_name, targets): +def build_specimin_command(project_name: str, + issue_input_dir: str, + specimin_dir: str, + root_dir: str, + package_name: str, + targets: list): ''' - Checkout a commit of a git repository + Build the gradle command to execute Specimin on target project issue_container_dir(ISSUES) |--- issue_id(cf-1291) @@ -136,16 +170,22 @@ def build_specimin_command(issue_id, root_dir, package_name, targets): Parameters: - issue_id (str): Name of the directory/folder that contains a SPECIMINS' target project. Ex: cf-1291 + project_name (str): Name of the target project. Example: daikon + issue_input_dir (str): path of the target project directory. Ex: ISSUES/cf-1291 + specimin_dir (str): Specimin directory path root_dir (str): A directory path relative to the project base directory where java package stored. package_name (str): A valid Java package - targets ({'method': '', 'file': ''}) : targetted java file and method name data + targets ({'method': '', 'file': ''}) : target java file and method name data Retruns: command (str): The gradle command of SPECIMIN for the issue. ''' - output_dir = os.path.join("..", issue_id, specimin_output) - root_dir = os.path.join("..", issue_id, specimin_input, root_dir) + os.sep + + relative_path_of_target_dir = os.path.relpath(issue_input_dir, specimin_dir) + + output_dir = os.path.join(relative_path_of_target_dir, specimin_output) + root_dir = os.path.join(relative_path_of_target_dir, specimin_input, project_name, root_dir) + root_dir = root_dir.rstrip('/') + os.sep dot_replaced_package_name = package_name.replace('.', '/') @@ -200,7 +240,7 @@ def run_specimin(command, directory): def performEvaluation(issue_data): ''' - For each issue dataExecute SPECIMIN on a target project. + For each issue data, execute SPECIMIN on a target project. Parameters: issue ({}): json data associated with an issue @@ -211,16 +251,17 @@ def performEvaluation(issue_data): branch = issue_data[JsonKeys.BRANCH.value] commit_hash = issue_data[JsonKeys.COMMIT_HASH.value] - input_dir = create_issue_directory(issue_folder_dir, issue_id) + input_dir = create_issue_directory(issue_folder_dir, issue_id) # ../cf-12/input clone_repository(url, input_dir) # TODO: check if clonning is successful. + repo_name = get_repository_name(url) if branch: - change_branch(input_dir, branch) + change_branch(branch, f"{input_dir}/{repo_name}") if commit_hash: - checkout_commit(commit_hash, input_dir) + checkout_commit(commit_hash, f"{input_dir}/{repo_name}") - specimin_command = build_specimin_command(issue_id, issue_data[JsonKeys.ROOT_DIR.value], issue_data[JsonKeys.PACKAGE.value], issue_data[JsonKeys.TARGETS.value]) + specimin_command = build_specimin_command(repo_name, os.path.join(issue_folder_dir, issue_id), os.path.join(issue_folder_dir, specimin_project_name), issue_data[JsonKeys.ROOT_DIR.value], issue_data[JsonKeys.PACKAGE.value], issue_data[JsonKeys.TARGETS.value]) success = run_specimin(specimin_command, os.path.join(issue_folder_dir, specimin_project_name)) @@ -234,8 +275,9 @@ def main(): ''' Main method of the script. It iterates over the json data and perform minimization for each cases. ''' + os.makedirs(issue_folder_dir, exist_ok=True) # create the issue holder directory + clone_specimin(issue_folder_dir, specimin_source_url) - clone_specimin() json_file_path = 'resources/test_data.json' parsed_data = read_json_from_file(json_file_path) diff --git a/resources/onefilesimple/expected/com/example/Simple.java b/resources/onefilesimple/expected/com/example/Simple.java new file mode 100644 index 0000000..3a35e62 --- /dev/null +++ b/resources/onefilesimple/expected/com/example/Simple.java @@ -0,0 +1,13 @@ +package com.example; + +class Simple { + + void bar() { + Object obj = new Object(); + obj = baz(obj); + } + + Object baz(Object obj) { + throw new Error(); + } +} diff --git a/resources/onefilesimple/input/com/example/Simple.class b/resources/onefilesimple/input/com/example/Simple.class new file mode 100644 index 0000000000000000000000000000000000000000..a338fe364efad8d2b7e22c5b3457bc1884608911 GIT binary patch literal 409 zcmZWlO-sW-5Pg%hNlju>wR#ggNm{}E0aY)8r=W+3;Bga|vZYBRq$2(*y(n1d5Aa8c zv&N62hn<;y`{uoweS3dh0yxHw2Me}~PJk{PLVqgnq?pNaA}+G2${T`nq)XkL5bSt( z<)Mc)7hV7#0bw(*3Zd?0aXV8Y)h017lMjUbIQgqJ9{z`ne;6P_pU`Wnw5fGDAq?VG zZi|iyozv=u9il{+>U>^gs=k!jmuF4z(rRAk>P#ERZ|6BQQ(%whws>Q}=EJLku))1@y!P@5IqOx74j4s$c;l5iMX{Gdmd_Ji|?Xo5D|Rhn-x69AW;5g}!}EbC-M8 PAGuid@%c7j%)<5uI=4rU literal 0 HcmV?d00001 diff --git a/resources/onefilesimple/input/com/example/Simple.java b/resources/onefilesimple/input/com/example/Simple.java new file mode 100644 index 0000000..a6d461d --- /dev/null +++ b/resources/onefilesimple/input/com/example/Simple.java @@ -0,0 +1,13 @@ +package com.example; + +class Simple { + // Target method. + void bar() { + Object obj = new Object(); + obj = baz(obj); + } + + Object baz(Object obj) { + return obj.toString(); + } +} diff --git a/resources/specimin_command_cf-6019.txt b/resources/specimin_command_cf-6019.txt new file mode 100644 index 0000000..125f64e --- /dev/null +++ b/resources/specimin_command_cf-6019.txt @@ -0,0 +1 @@ +./gradlew run --args='--root "../ISSUES/cf-6019/input/kafka-sensors/src/main/java/" --outputDirectory "../ISSUES/cf-6019/output" --targetFile "com/fillmore_labs/kafka/sensors/serde/confluent/interop/Avro2Confluent.java" --targetMethod "com.fillmore_labs.kafka.sensors.serde.confluent.interop.Avro2Confluent#transform(String, byte[])"' \ No newline at end of file diff --git a/resources/specimin_command_cf-6077.txt b/resources/specimin_command_cf-6077.txt new file mode 100644 index 0000000..5ee2143 --- /dev/null +++ b/resources/specimin_command_cf-6077.txt @@ -0,0 +1 @@ +./gradlew run --args='--root "../ISSUES/cf-6077/input/cassandra/src/java/" --outputDirectory "../ISSUES/cf-6077/output" --targetFile "org/apache/cassandra/index/sasi/conf/IndexMode.java" --targetMethod "org.apache.cassandra.index.sasi.conf.IndexMode#getMode(ColumnMetadata, Map)"' \ No newline at end of file From 8169725dd5b563997ce86109855b6ec12d791e45 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 04:59:40 -0500 Subject: [PATCH 08/18] test case for specimin execution --- TestMain.py | 32 +++++++++++++++--- .../expected/com/example/Simple.java | 13 ------- .../{ => test_proj}/com/example/Simple.class | Bin .../{ => test_proj}/com/example/Simple.java | 0 4 files changed, 27 insertions(+), 18 deletions(-) delete mode 100644 resources/onefilesimple/expected/com/example/Simple.java rename resources/onefilesimple/input/{ => test_proj}/com/example/Simple.class (100%) rename resources/onefilesimple/input/{ => test_proj}/com/example/Simple.java (100%) diff --git a/TestMain.py b/TestMain.py index 1229598..b54b14c 100644 --- a/TestMain.py +++ b/TestMain.py @@ -1,14 +1,21 @@ import unittest import main - +import shutil class TestMain(unittest.TestCase): - def setUp(self): - pass + @classmethod + def setUpClass(cls): + # cloning the specimin + main.clone_repository('git@github.com:kelloggm/specimin.git', 'resources') - def tearDown(self): - pass + @classmethod + def tearDownClass(cls): + # deleting specimin from resources + try: + shutil.rmtree('resources/specimin') + except Exception as e: + print(f"Error occurred {e}") def test_get_repository_name(self): url = 'git@github.com:codespecs/daikon.git' @@ -55,6 +62,21 @@ def test_build_specimin_command(self): with open('resources/specimin_command_cf-6019.txt','r') as file: target_command = file.read() self.assertEqual(command, target_command) + + def test_run_specimin(self): + proj_name = 'test_proj' + root = '' + package = 'com.example' + targets = [{ + "method": "bar()", + "file": "Simple.java" + }] + specimin_dir = 'resources/specimin' + target_dir = 'resources/onefilesimple' + + command = main.build_specimin_command(proj_name, target_dir, specimin_dir, root, package, targets) + result = main.run_specimin(command, 'resources/specimin') + self.assertTrue(result) diff --git a/resources/onefilesimple/expected/com/example/Simple.java b/resources/onefilesimple/expected/com/example/Simple.java deleted file mode 100644 index 3a35e62..0000000 --- a/resources/onefilesimple/expected/com/example/Simple.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example; - -class Simple { - - void bar() { - Object obj = new Object(); - obj = baz(obj); - } - - Object baz(Object obj) { - throw new Error(); - } -} diff --git a/resources/onefilesimple/input/com/example/Simple.class b/resources/onefilesimple/input/test_proj/com/example/Simple.class similarity index 100% rename from resources/onefilesimple/input/com/example/Simple.class rename to resources/onefilesimple/input/test_proj/com/example/Simple.class diff --git a/resources/onefilesimple/input/com/example/Simple.java b/resources/onefilesimple/input/test_proj/com/example/Simple.java similarity index 100% rename from resources/onefilesimple/input/com/example/Simple.java rename to resources/onefilesimple/input/test_proj/com/example/Simple.java From e368f2dc79aa25c81fa6ba43bde617178f2401c7 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 11:17:32 -0500 Subject: [PATCH 09/18] ignore .class file and removing existing .class file from PR --- .gitignore | 5 ++++- .../input/test_proj/com/example/Simple.class | Bin 409 -> 0 bytes 2 files changed, 4 insertions(+), 1 deletion(-) delete mode 100644 resources/onefilesimple/input/test_proj/com/example/Simple.class diff --git a/.gitignore b/.gitignore index e63e05c..0afcf54 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ ISSUES # macOS specific file .DS_Store -__pycache__/ \ No newline at end of file +__pycache__/ + +#Ignore compiled class file +*.class \ No newline at end of file diff --git a/resources/onefilesimple/input/test_proj/com/example/Simple.class b/resources/onefilesimple/input/test_proj/com/example/Simple.class deleted file mode 100644 index a338fe364efad8d2b7e22c5b3457bc1884608911..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 409 zcmZWlO-sW-5Pg%hNlju>wR#ggNm{}E0aY)8r=W+3;Bga|vZYBRq$2(*y(n1d5Aa8c zv&N62hn<;y`{uoweS3dh0yxHw2Me}~PJk{PLVqgnq?pNaA}+G2${T`nq)XkL5bSt( z<)Mc)7hV7#0bw(*3Zd?0aXV8Y)h017lMjUbIQgqJ9{z`ne;6P_pU`Wnw5fGDAq?VG zZi|iyozv=u9il{+>U>^gs=k!jmuF4z(rRAk>P#ERZ|6BQQ(%whws>Q}=EJLku))1@y!P@5IqOx74j4s$c;l5iMX{Gdmd_Ji|?Xo5D|Rhn-x69AW;5g}!}EbC-M8 PAGuid@%c7j%)<5uI=4rU From 0c63f12a312dba8907f553b39dd8c3e2601fec3a Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 11:54:16 -0500 Subject: [PATCH 10/18] adding github action to run test --- .github/workflows/main.yml | 21 +++++++++++++++++++++ main.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..2ca91e4 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ +name: Python Test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + python-script-test: + runs-on: ubuntu-latest + steps: + - name: Checkout project sources + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Run tests + run: python TestMain.py diff --git a/main.py b/main.py index 9ea521c..58fd03a 100644 --- a/main.py +++ b/main.py @@ -139,7 +139,7 @@ def perform_git_pull (directory): def clone_specimin(path_to_clone, url): ''' - Clone the latest Speimin project from github + Clone the latest Specimin project from github Parameters: path_to_clone (str): Path where Specimin is to be clonned From 242a0ca368ffe12ff277c1315d929a6092fcd4e6 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 12:03:41 -0500 Subject: [PATCH 11/18] setup gradle in actions --- .github/workflows/main.yml | 5 ++++- .../onefilesimple/output/com/example/Simple.java | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 resources/onefilesimple/output/com/example/Simple.java diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2ca91e4..40a9f8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -12,10 +12,13 @@ jobs: steps: - name: Checkout project sources uses: actions/checkout@v3 - + with: + fetch-depth: 0 # so that spotless can ratchet; see https://github.com/diffplug/spotless/issues/710 - name: Setup Python uses: actions/setup-python@v2 with: python-version: 3.8 + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 - name: Run tests run: python TestMain.py diff --git a/resources/onefilesimple/output/com/example/Simple.java b/resources/onefilesimple/output/com/example/Simple.java new file mode 100644 index 0000000..3a35e62 --- /dev/null +++ b/resources/onefilesimple/output/com/example/Simple.java @@ -0,0 +1,13 @@ +package com.example; + +class Simple { + + void bar() { + Object obj = new Object(); + obj = baz(obj); + } + + Object baz(Object obj) { + throw new Error(); + } +} From 149a78471816eee53090384d093cbec1f8be0a63 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 12:17:02 -0500 Subject: [PATCH 12/18] adding secrets for clon --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40a9f8c..3082f7c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,6 +14,7 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 # so that spotless can ratchet; see https://github.com/diffplug/spotless/issues/710 + ssh-key: ${{ secrets.GH_ACTIONS_SSH_KEY }} - name: Setup Python uses: actions/setup-python@v2 with: From 69e55c00b27b7e63153e64fe3b6a06e884435c7d Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 12:23:07 -0500 Subject: [PATCH 13/18] remove secrets and changing ssh of specimin to my remote rep --- .github/workflows/main.yml | 1 - main.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3082f7c..40a9f8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,7 +14,6 @@ jobs: uses: actions/checkout@v3 with: fetch-depth: 0 # so that spotless can ratchet; see https://github.com/diffplug/spotless/issues/710 - ssh-key: ${{ secrets.GH_ACTIONS_SSH_KEY }} - name: Setup Python uses: actions/setup-python@v2 with: diff --git a/main.py b/main.py index 58fd03a..d657514 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ specimin_input = 'input' specimin_output = 'output' specimin_project_name = 'specimin' -specimin_source_url = 'git@github.com:kelloggm/specimin.git' +specimin_source_url = 'git@github.com:tahiat/specimin.git' def read_json_from_file(file_path): ''' From 9d85533bf646bf076277805a382f80cbebb7d3d8 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 12:42:31 -0500 Subject: [PATCH 14/18] update repo url to https one --- TestMain.py | 3 +++ main.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/TestMain.py b/TestMain.py index b54b14c..afe0f47 100644 --- a/TestMain.py +++ b/TestMain.py @@ -30,6 +30,9 @@ def test_get_repository_name(self): url = 'git@github.com:awslabs/aws-kms-compliance-checker.git' self.assertEqual(main.get_repository_name(url), 'aws-kms-compliance-checker') + url = 'https://github.com/tahiat/specimin.git' + self.assertEqual(main.get_repository_name(url), 'specimin') + url = 'git@github.com:awslabs/aws-kms-compliance-checker.git' self.assertNotEqual(main.get_repository_name(url), 'aws-km-compliance-checker') diff --git a/main.py b/main.py index d657514..ec89553 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,7 @@ specimin_input = 'input' specimin_output = 'output' specimin_project_name = 'specimin' -specimin_source_url = 'git@github.com:tahiat/specimin.git' +specimin_source_url = 'https://github.com/kelloggm/specimin.git' def read_json_from_file(file_path): ''' From 18cf93c284765649f8757be2142864ca3efbf694 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 12:45:16 -0500 Subject: [PATCH 15/18] cloning specimin repository using the https url instead of ssh to avoid permission denial --- TestMain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TestMain.py b/TestMain.py index afe0f47..d2cd1b0 100644 --- a/TestMain.py +++ b/TestMain.py @@ -7,7 +7,7 @@ class TestMain(unittest.TestCase): @classmethod def setUpClass(cls): # cloning the specimin - main.clone_repository('git@github.com:kelloggm/specimin.git', 'resources') + main.clone_repository('https://github.com/kelloggm/specimin.git', 'resources') @classmethod def tearDownClass(cls): From 45a0d078bdb64fc64addca158e8e29632486f85d Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 15:18:20 -0500 Subject: [PATCH 16/18] specimin execution test for issue cf-1291 where specimin succesfully exit execution --- Keyvalue.py | 1 + TestMain.py | 32 ++++++++++++++++++- main.py | 6 +++- .../output/com/example/Simple.java | 13 -------- 4 files changed, 37 insertions(+), 15 deletions(-) delete mode 100644 resources/onefilesimple/output/com/example/Simple.java diff --git a/Keyvalue.py b/Keyvalue.py index b8a5dc9..86f0d19 100644 --- a/Keyvalue.py +++ b/Keyvalue.py @@ -15,3 +15,4 @@ class JsonKeys(Enum): CF_Version = 'cf_version' JAVA_VERSION = 'java_version' NOTE = 'note' + SKIP = 'skip' diff --git a/TestMain.py b/TestMain.py index d2cd1b0..f61c243 100644 --- a/TestMain.py +++ b/TestMain.py @@ -1,6 +1,8 @@ import unittest import main import shutil +import os +from Keyvalue import JsonKeys class TestMain(unittest.TestCase): @@ -8,6 +10,9 @@ class TestMain(unittest.TestCase): def setUpClass(cls): # cloning the specimin main.clone_repository('https://github.com/kelloggm/specimin.git', 'resources') + cls.json_data = main.read_json_from_file('resources/test_data.json')[0] + cls.specimin_dir = "resources/specimin" + @classmethod def tearDownClass(cls): @@ -16,6 +21,14 @@ def tearDownClass(cls): shutil.rmtree('resources/specimin') except Exception as e: print(f"Error occurred {e}") + # removing any issue project cloned in resources + for root, dirs, files in os.walk('resources', topdown=False): + for dir_name in dirs: + if 'cf-' in dir_name: + dir_path = os.path.join(root, dir_name) + shutil.rmtree(dir_path) + print(f"Removed directory: {dir_path}") + def test_get_repository_name(self): url = 'git@github.com:codespecs/daikon.git' @@ -51,7 +64,7 @@ def test_build_specimin_command(self): with open('resources/specimin_command_cf-6077.txt','r') as file: target_command = file.read() self.assertEqual(command, target_command) - + # not executing since this crashes specimin proj_name = 'kafka-sensors' root = 'src/main/java/' package = 'com.fillmore_labs.kafka.sensors.serde.confluent.interop' @@ -65,6 +78,23 @@ def test_build_specimin_command(self): with open('resources/specimin_command_cf-6019.txt','r') as file: target_command = file.read() self.assertEqual(command, target_command) + #not executing since it crashes specimin. + + # make + issue_name = self.json_data[JsonKeys.ISSUE_ID.value] + main.create_issue_directory('resources', issue_name) + self.assertTrue(os.path.exists('resources/cf-1291/input')) + main.clone_repository(self.json_data[JsonKeys.URL.value], f"resources/{issue_name}/input") + + project_name = main.get_repository_name(self.json_data[JsonKeys.URL.value]) + + self.assertTrue(main.checkout_commit(self.json_data[JsonKeys.COMMIT_HASH.value],f"resources/{issue_name}/input/{project_name}")) + self.assertTrue(main.is_git_directory(f"resources/{issue_name}/input/{project_name}")) + + command = main.build_specimin_command(project_name, f"resources/{issue_name}", self.specimin_dir, self.json_data[JsonKeys.ROOT_DIR.value], self.json_data[JsonKeys.PACKAGE.value], self.json_data[JsonKeys.TARGETS.value]) + print(command) + result = main.run_specimin(command, self.specimin_dir) + self.assertTrue(result) def test_run_specimin(self): proj_name = 'test_proj' diff --git a/main.py b/main.py index ec89553..233f437 100644 --- a/main.py +++ b/main.py @@ -61,7 +61,7 @@ def create_issue_directory(issue_container_dir, issue_id): issue_id (str): Name of the directory to be created Returns: - specimin_input_dir (str): A target directory of SPECIMIN. + specimin_input_dir (str): A target directory of SPECIMIN. (issue_container_dir/issue_id/input) ''' issue_directory_name = os.path.join(issue_container_dir, issue_id) os.makedirs(issue_directory_name, exist_ok=True) @@ -93,6 +93,9 @@ def clone_repository(url, directory): url (str): repository url directory (str): directory to clone in ''' + project_name = get_repository_name(url) + if (os.path.exists(f"{directory}/{project_name}")): + print(f"{project_name} repository already exists. Aborting cloning") subprocess.run(["git", "clone", url], cwd=directory) def change_branch(branch, directory): @@ -126,6 +129,7 @@ def checkout_commit(commit_hash, directory): print(f"Successfully checked-out commit {commit_hash} in {directory}") else: print(f"Failed to checkout commit {commit_hash} in {directory}") + return result.returncode == 0 if True else False def perform_git_pull (directory): ''' diff --git a/resources/onefilesimple/output/com/example/Simple.java b/resources/onefilesimple/output/com/example/Simple.java deleted file mode 100644 index 3a35e62..0000000 --- a/resources/onefilesimple/output/com/example/Simple.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.example; - -class Simple { - - void bar() { - Object obj = new Object(); - obj = baz(obj); - } - - Object baz(Object obj) { - throw new Error(); - } -} From c0784a219ab830f658a02bd5cc611761ea0db243 Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 15:20:59 -0500 Subject: [PATCH 17/18] use http clone url instead of SSH --- resources/test_data.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/test_data.json b/resources/test_data.json index ecef4f6..472f6fd 100644 --- a/resources/test_data.json +++ b/resources/test_data.json @@ -1,7 +1,7 @@ [ { "issue_id" : "cf-1291", - "url": "git@github.com:codespecs/daikon.git", + "url": "https://github.com/codespecs/daikon.git", "branch": "", "commit_hash": "15d7c2d84", "project_name": "daikon", From 8adc121c6403e3287a0f5af01aad011c96bb8c3d Mon Sep 17 00:00:00 2001 From: Tahiatul Islam Date: Fri, 12 Jan 2024 16:22:48 -0500 Subject: [PATCH 18/18] removing spotless command, use the github url of main specimin fork --- .github/workflows/main.yml | 2 +- TestMain.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 40a9f8c..f521262 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -13,7 +13,7 @@ jobs: - name: Checkout project sources uses: actions/checkout@v3 with: - fetch-depth: 0 # so that spotless can ratchet; see https://github.com/diffplug/spotless/issues/710 + fetch-depth: 0 - name: Setup Python uses: actions/setup-python@v2 with: diff --git a/TestMain.py b/TestMain.py index f61c243..f0c7023 100644 --- a/TestMain.py +++ b/TestMain.py @@ -13,7 +13,6 @@ def setUpClass(cls): cls.json_data = main.read_json_from_file('resources/test_data.json')[0] cls.specimin_dir = "resources/specimin" - @classmethod def tearDownClass(cls): # deleting specimin from resources @@ -43,7 +42,7 @@ def test_get_repository_name(self): url = 'git@github.com:awslabs/aws-kms-compliance-checker.git' self.assertEqual(main.get_repository_name(url), 'aws-kms-compliance-checker') - url = 'https://github.com/tahiat/specimin.git' + url = 'https://github.com/kelloggm/specimin.git' self.assertEqual(main.get_repository_name(url), 'specimin') url = 'git@github.com:awslabs/aws-kms-compliance-checker.git'