From 6731981ba7c471289a3049d879b0cc6210bd2ede Mon Sep 17 00:00:00 2001 From: Nitish Ramakrishnan <69108657+niccolopaganini@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:31:14 -0600 Subject: [PATCH] Python Script that extracts methods in java files --- .../Methods in Java Files.ipynb | 384 ++++++++++++++++++ 1 file changed, 384 insertions(+) create mode 100644 bin/API_Migration_scripts_readme/Methods in Java Files.ipynb diff --git a/bin/API_Migration_scripts_readme/Methods in Java Files.ipynb b/bin/API_Migration_scripts_readme/Methods in Java Files.ipynb new file mode 100644 index 000000000..ba7c969b2 --- /dev/null +++ b/bin/API_Migration_scripts_readme/Methods in Java Files.ipynb @@ -0,0 +1,384 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "99e81d0e", + "metadata": {}, + "source": [ + "# Methods in Plugins" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab88f421", + "metadata": {}, + "outputs": [], + "source": [ + "#imports\n", + "import os\n", + "import csv\n", + "import requests" + ] + }, + { + "cell_type": "markdown", + "id": "6694d43d", + "metadata": {}, + "source": [ + "## Python Script to check methods" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e2dcb10e", + "metadata": {}, + "outputs": [], + "source": [ + "def find_matches(csv_file,java_directory): #custom method\n", + " \n", + " methods = []\n", + " with open(csv_file,\"r\") as csvfile: #reading the CSV\n", + " reader = csv.reader(csvfile, delimiter=\",\")\n", + " for row in reader:\n", + " method_name = row[0]\n", + " methods.append(method_name)\n", + " \n", + " matching_methods = [] #reading the java file\n", + " for file in os.listdir(java_directory):\n", + " if file.endswith(\".java\"):\n", + " with open(os.path.join(java_directory, file), \"r\") as f:\n", + " for line in f:\n", + " for method in methods:\n", + " if method in line:\n", + " matching_methods.append((file, line))\n", + " \n", + " return matching_methods" + ] + }, + { + "cell_type": "markdown", + "id": "ab5108dd", + "metadata": {}, + "source": [ + "### 1. Data Collection" + ] + }, + { + "cell_type": "markdown", + "id": "d129d6d5", + "metadata": {}, + "source": [ + "#### Main Folder" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "148c0e2b", + "metadata": {}, + "outputs": [], + "source": [ + "#Absolute PATH" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ebbbc031", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\") #to print which method is in which file" + ] + }, + { + "cell_type": "markdown", + "id": "82813869", + "metadata": {}, + "source": [ + "#### Location" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a842f54c", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "7eb3310b", + "metadata": {}, + "source": [ + "#### Location -> actions" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2373580e", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "866689b9", + "metadata": {}, + "source": [ + "#### Sensors" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "146f6762", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "20c4f963", + "metadata": {}, + "source": [ + "#### Verification" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf5829b4", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "99fb5147", + "metadata": {}, + "source": [ + "#### Wrapper" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "114a36ae", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "40fc40a6", + "metadata": {}, + "source": [ + "### 2. OPCodeAuth" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6b46a72e", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "2fc6202d", + "metadata": {}, + "source": [ + "### 3. server communication" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "369ca081", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "35c33aaa", + "metadata": {}, + "source": [ + "### 4. serversync" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7964e49", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "3fff1e87", + "metadata": {}, + "source": [ + "### 5. settings" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "696c8679", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "f4c1ae20", + "metadata": {}, + "source": [ + "### 6. unified logger" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "088c73b6", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "markdown", + "id": "b6279463", + "metadata": {}, + "source": [ + "### 7. usercache" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "41f9ee95", + "metadata": {}, + "outputs": [], + "source": [ + "if __name__ == \"__main__\":\n", + " csv_file = \"/tmp\"\n", + " java_directory = \"/tmp\"\n", + " matching_methods = find_matches(csv_file, java_directory)\n", + " for file, line in matching_methods:\n", + " print(f\"{file} has {line}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7153299b", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}