2 This module provides utlilities related to creating Jenkins' warnings-ng-plugin-compatible reports from codeanalysis 11 This class provides a set of methods to create reports that are compatible with Jenkins' warnings-ng plugin 18 Initialize the ReportBuilder 21 self.
issues_all = {
"_class":
"io.jenkins.plugins.analysis.core.restapi.ReportApi",
"issues": [],
"size": 0}
23 raise ValueError(
"Could not initialize the ReportBuilder, because its 'issues_all' property was not None.")
27 Extracts basename of a given path (only files). Should Work with any OS Path on any OS 29 @param path path to get base folder path of 30 @returns base folder path 32 basename = re.search(
r"[^\\/]+(?![\\/])$", path)
34 return basename.group(0)
36 def addIssue(self, path, severity, message, lineStart=-1, lineEnd=-1, columnStart=-1, columnEnd=-1, category=None, type=None, description=None, packageName=None, moduleName=None, additionalProperties=None):
38 Adds a new issue to the report 40 @warning This function will not add duplicate issue to the report 42 @param path path to the file in which the issue happens 43 @param severity severity level for the issue, allowed options are LOW, NORMAL, HIGH, CRITICAL or ERROR 44 @param message issue message (brief description of the problem) 45 @param lineStart line at which issue happens or starting line of a block in which it happens 46 @param lineEnd ending line of a block in which issue hapens 47 @param columnStart column at which issue happens or starting column of a block in which it happens 48 @param columnEnd ending column of a block in which issue happens 49 @param category issue category to show in jenkins 50 @param type issue type to show in jenkins 51 @param description issue description (longer and more precise than message) 52 @param packageName fully qualified name of the package in which the issue happens 53 @param moduleName fully qualifies name of the module in which the issue happens 54 @param additionalProperties additional parameters to pass to Jenkins' warnings-ng plugin 56 lineStart = int(lineStart)
57 lineEnd = int(lineEnd)
58 columnStart = int(columnStart)
59 columnEnd = int(columnEnd)
62 severity = severity.upper()
63 if filename
is None or filename ==
"":
64 raise Exception(
"Path is not a file path!")
65 if severity
not in [
"LOW",
"NORMAL",
"HIGH",
"CRITICAL",
"ERROR"]:
66 raise Exception(
"Path is not a file path!")
67 if message
is None or message ==
"":
68 raise Exception(
"Message must not be empty!")
69 dirname = path.replace(filename,
"")
71 issue = {
"fileName": path,
"directory": dirname,
"severity": severity,
"message": message}
74 issue.update({
"lineStart": lineStart})
76 if lineStart > -1
and lineEnd > -1:
77 issue.update({
"lineEnd": lineEnd})
80 issue.update({
"columnStart": columnStart})
82 if columnStart > -1
and columnEnd > -1:
83 issue.update({
"columnEnd": columnEnd})
85 if category
is not None:
86 issue.update({
"category": category})
89 issue.update({
"type": type})
91 if description
is not None:
92 issue.update({
"description": description})
94 if packageName
is not None:
95 issue.update({
"packageName": packageName})
97 if moduleName
is not None:
98 issue.update({
"moduleName": moduleName})
100 if additionalProperties
is not None:
101 issue.update({
"additionalProperties": additionalProperties})
108 Generates the report in json format 110 @returns json-formatted dictionary containing all issues and _class header def addIssue(self, path, severity, message, lineStart=-1, lineEnd=-1, columnStart=-1, columnEnd=-1, category=None, type=None, description=None, packageName=None, moduleName=None, additionalProperties=None)
Adds a new issue to the report.
This class provides a set of methods to create reports that are compatible with Jenkins' warnings-ng ...
def generateReport(self)
Generates the report in json format.
def extract_basename_file(self, path)
Extracts basename of a given path (only files).
def __init__(self)
Initialize the ReportBuilder.