Skip to content

Commit

Permalink
vscode-plugin fix for refreshing list of issues after applying patche…
Browse files Browse the repository at this point in the history
…s. (#106)

* Applied new 'grouped' json config layout to vscode-plugin.

#59

* Update issues TreeView to show the number of subelements.

* vscode-plugin issues bugfix (1.0.11)

#60
#73
#78
#79
#80

* Bugfix for #90.

-Selection and cursor are now set to the warning's position whenever an issue is opened up in the editor.

* vscode-plugin bugfix for #73.

-The config.properties file are now generated into the folder set up as the "Executable Path".

* Update version of vscode-plugin.

* Vscode-Plugin update 1.0.13.

- #94: Fixed bug where declining a warning patch candidate would result the removal of the entire warning from the analysis output window.
- #73: Changed format of generated config.property file.

* Update patch.ts to fix refreshing the list of the detected vulnerabilities issue.

- Referenced issue: #105

* Update plugin version.

* Remove unnecessary settings from plugin config.

Reducing the users' responsibility #109

* Update README.md

* Update plugin README.md

* Started reworking analysis call to only run on current cu.

* Minor fixes for windows with using OpenStaticAnalyzer.

* Minor fix for multiple analysis failure in plugin.

* Update plugin with new analyzer executable as parameter

-Reworked treeview generation with merging multiple json input as one json.

* Update saving previous state after patching in case of redo.

* Update status bar to support analysis on currently opened file.

* Starting multiple simultaneous analysis are no longer possible when status bar command is pressed repeatedly.

* Create custom output channel for the extensions logging.

* Remove old issue config updates.

* Minor fixes with patch view mode.

* Update treeview builder.

* Analysis output treeView build bugfix.

-Incorrect number of issues would show up in the treeview after analysis.

* Simplified configuration handling.

- use of -config flag is no longer needed in executableParameters, the plugin now uses it automatically.
- Only one config file are used for both the executable and the plugin.

* Update analyzer logic with new config handling and treeview refresh.

* Fixed Testview command already exists unhandled errors issue.

* Revert "Fixed Testview command already exists unhandled errors issue."

This reverts commit f3756e8.

* (Re) Fixed Testview command already exists unhandled errors issue.

* After manual save of a file, a file analysis now starts to refresh the results.

* Fixed unhandled 'webview is disposed' error.

* Analysis no longer runs on unsupported documents.

* Fix bug where code actions no longer appeared at other files but the file that was lastly analyzed.

* Analysis will no longer be started after declining a patch.

* Fixed some treeview refreshing issues after editing and analyzing a file.

* Add new try-catch scopes for previously unhandled errors.

* update treeView refresh after applying or declining patches.

* fixed bug at issue tree where after a patch was applied the issue tree had many duplicate issues pointing to the same location.

* Sorting patches by score.

* sorter wrapper

* add sorter

---------

Co-authored-by: Ákos <[email protected]>
Co-authored-by: Péter Mészáros <[email protected]>
  • Loading branch information
3 people authored May 9, 2023
1 parent 967848c commit 97a04b4
Show file tree
Hide file tree
Showing 97 changed files with 73,925 additions and 54 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
<mainClass>eu.assuremoss.VulnRepairDriver</mainClass>
<mainClass>eu.assuremoss.VulnerabilityRepairDriver</mainClass>
</manifest>
</archive>
</configuration>
Expand Down
137 changes: 137 additions & 0 deletions sorter/JSONHandler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import json
from numpy import dtype


# Data classes to encode the json into objects
class Patch:
def __init__(self, path, score, explanation):
self.path, self.score, self.explanation = path, score, explanation


class TextRange:
def __init__(self, endLine, endColumn, startColumn, startLine):
self.endLine, self.endColumn = endLine, endColumn
self.startColumn, self.startLine = startColumn, startLine


class PatchesArray:
def __init__(self, patches, textRange):
self.patches = [
Patch(patch["path"], patch["score"], patch["explanation"])
for patch in patches
]
self.textRange = TextRange(
textRange["endLine"],
textRange["endColumn"],
textRange["startColumn"],
textRange["startLine"],
)


class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, dtype):
return obj.val()
try:
return vars(obj)
except Exception as e:
return str(obj)


class Issue:
def __init__(self, name, patchList):
self.name = name

if isinstance(patchList, list):
self.patchesArray = [
PatchesArray(patchesArray["patches"], patchesArray["textRange"])
for patchesArray in patchList
]
elif isinstance(patchList, dict):
self.patchesArray = [
PatchesArray(patchList["patches"], patchList["textRange"])
]
else:
raise TypeError("patchList should be list or dict")


class JSONHandler:
def __init__(self):
self.issues = []
self.initialScores = []

def parseJSON(self, issuesPath):
"""Parses the json file which contains the issues into objects
Parameters
----------
issuesPath : str
The path to the json file
Returns
-------
list[str]
A list containing all the paths to the patches extracted from the json file
"""
with open(issuesPath, "rt") as file:
parsedjsondict = json.load(file)
self.issues = [Issue(key, parsedjsondict[key]) for key in parsedjsondict.keys()]

patchPaths = []
for issue in self.issues:
for patchesArray in issue.patchesArray:
for patch in patchesArray.patches:
patchPaths.append(patch)
self.initialScores.append(patch.score)
return patchPaths

def extractPatchesArrays(self) -> list[PatchesArray]:
"""Gets the patches arrays (textrange and a list of candidate patches) from the previously read json file
Returns
-------
list[PatchesArray]
A list of all the patchesArrays in the json file
"""
patchesArrays = []
for issue in self.issues:
patchesArrays.extend(issue.patchesArray)
return patchesArrays

def updateJSON(self, issuesPath, scores):
"""Updates the scores for the patches in the json file
Parameters
----------
issuesPath :
The path to the json file
scores : list[float]
A list of the scores, the scores should be in the same order as
previously read from the json file (e. g. with parseJSON method)
"""
i = 0
for issue in self.issues:
for patchlocation in issue.patchesArray:
for patch in patchlocation.patches:
patch.score = scores[i]
i += 1

completejson = dict()
for issue in self.issues:
completejson[issue.name] = issue.patchesArray
with open(issuesPath, "w") as file:
json.dump(completejson, file, indent=2, cls=JSONEncoder)

def extract_patches(self):
"""Gets the patches from the previously read json file
Returns
-------
list(Patch)
A list of all the patches
"""
patches = []
for issue in self.issues:
for patchlocation in issue.patchesArray:
patches.extend(patchlocation.patches)
return patches
Loading

0 comments on commit 97a04b4

Please sign in to comment.