Skip to content

Commit 4bbff8f

Browse files
committed
Updates from 0.79
1 parent 88c70b8 commit 4bbff8f

16 files changed

+246
-184
lines changed

src/main/java/com/vectorcast/plugins/vectorcastexecution/VectorCASTJobPipeline.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
import hudson.model.AutoCompletionCandidates;
4848
import org.kohsuke.stapler.QueryParameter;
49-
49+
import org.kohsuke.stapler.DataBoundSetter;
5050

5151
/**
5252
* Create pipeline job.
@@ -115,7 +115,7 @@ public ExternalResultsFileException getResException() {
115115
public String getUrlName() {
116116
return "pipeline-job";
117117
}
118-
118+
119119
/**
120120
* Get node label.
121121
* @return node label
@@ -129,7 +129,7 @@ public String getNodeLabel() {
129129
* @param inputNL - input nodel label
130130
*/
131131
@DataBoundSetter
132-
public void setNodeLabel(String inputNL) {
132+
public void setNodeLabel(final String inputNL) {
133133
this.nodeLabel = inputNL;
134134
}
135135

src/main/resources/scripts/cobertura.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
fileList = []
4646

47-
from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding
47+
from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding, checkProjectResults
4848

4949
encFmt = getVectorCASTEncoding()
5050

@@ -347,11 +347,13 @@ def procesCoverage(coverXML, coverApi, extended = False, source_root = ""):
347347

348348
if extended:
349349
for func in coverApi.functions:
350-
350+
351+
if isinstance(func.instrumented_functions[0].parameterized_name, bool):
352+
continue
353+
351354
method = etree.SubElement(methods, "method")
352-
353355
method.attrib['name'] = func.name
354-
method.attrib['signature'] = func.instrumented_functions[0].parameterized_name.replace(func.name,"",1)
356+
method.attrib['signature'] = func.instrumented_functions[0].parameterized_name.replace(func.name,"",1)
355357
method.attrib['line-rate'] = str(func.metrics.max_covered_statements_pct/100.0)
356358

357359
statementPercentStr = "{:.2f}".format(func.metrics.max_covered_statements_pct) + "% (" + str(func.metrics.max_covered_statements) + "/" + str(func.metrics.statements) + ")"
@@ -387,11 +389,26 @@ def procesCoverage(coverXML, coverApi, extended = False, source_root = ""):
387389
return processStatementBranchMCDC(coverApi, lines, extended)
388390

389391
def runCoverageResultsMP(packages, mpFile, verbose = False, extended=False, source_root = ""):
392+
393+
with VCProjectApi(mpFile) as vcproj:
390394

391-
vcproj = VCProjectApi(mpFile)
392-
api = vcproj.project.cover_api
395+
anyLocalResults, anyImportedResults = checkProjectResults(vcproj)
396+
397+
if anyImportedResults:
398+
importedResultsError = " ** Cobertura results does not processing imported results at this time\n\n"
399+
print(importedResultsError)
400+
return [-1] * 19
401+
402+
if not anyLocalResults:
403+
localResultsError = " ** No local results in project to process\n\n"
404+
print(localResultsError)
405+
return [-1] * 19
406+
407+
api = vcproj.project.cover_api
408+
409+
results = runCoberturaResults(packages, api, verbose = False, extended = extended, source_root = source_root)
393410

394-
return runCoberturaResults(packages, api, verbose = False, extended = extended, source_root = source_root)
411+
return results
395412

396413
def runCoberturaResults(packages, api, verbose = False, extended = False, source_root = ""):
397414

@@ -449,8 +466,7 @@ def runCoberturaResults(packages, api, verbose = False, extended = False, source
449466
except:
450467
prj_dir = os.getcwd().replace("\\","/") + "/"
451468

452-
# get a sorted listed of all the files with the proj directory stripped off
453-
469+
# get a sorted listed of all the files with the proj directory stripped off
454470
for file in api.SourceFile.all():
455471
if file.display_name == "":
456472
continue
@@ -752,7 +768,7 @@ def generateCoverageResults(inFile, azure = False, xml_data_dir = "xml_data", ve
752768
if MCDC_rate != -1.0: print ("mcdc pairs: {:.2f}% ({:d} out of {:d})".format(MCDC_rate*100.0, cov_mcdc, total_mcdc))
753769

754770
if statement_rate != -1.0: print ("coverage: {:.2f}% of statements".format(statement_rate*100.0))
755-
print ("complexity: {:d}".format(complexity))
771+
if complexity != -1.0: print ("complexity: {:d}".format(complexity))
756772
source = etree.SubElement(sources, "source")
757773
source.text = "./"
758774

src/main/resources/scripts/copy_build_dir.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,8 @@ def run(ManageProjectName, Level, BaseName, Env, workspace, vCastProjectWorkspac
237237

238238
def getVcastProjectWorkspace(args):
239239

240-
vc_api = VCProjectApi(args.ManageProject)
241-
vCastProjectWorkspace = vc_api.project.workspace
242-
vc_api.close()
240+
with VCProjectApi(args.ManageProject) as vcproj:
241+
vCastProjectWorkspace = vcproj.project.workspace
243242

244243
return vCastProjectWorkspace
245244

src/main/resources/scripts/create_index_html.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,24 @@ def create_index_html(mpName, isGitLab = False, output_dir = ""):
104104
global baseOutputDir
105105
baseOutputDir = output_dir
106106

107-
api = VCProjectApi(mpName)
108-
# Set custom report directory to the where this script was
109-
# found. Must contain sections/index_section.py
110-
rep_path = pathlib.Path(__file__).parent.resolve()
107+
with VCProjectApi(mpName) as vcproj:
108+
# Set custom report directory to the where this script was
109+
# found. Must contain sections/index_section.py
110+
rep_path = pathlib.Path(__file__).parent.resolve()
111111

112-
if usingGitLabCI:
113-
output_file=os.path.join(baseOutputDir,"index.html")
114-
else:
115-
output_file=os.path.join(baseOutputDir,"index.html")
116-
117-
CustomReport.report_from_api(
118-
api=api,
119-
title="HTML Reports",
120-
report_type="INDEX_FILE",
121-
formats=["HTML"],
122-
output_file=output_file,
123-
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
124-
customization_dir=rep_path)
125-
126-
api.close()
112+
if usingGitLabCI:
113+
output_file=os.path.join(baseOutputDir,"index.html")
114+
else:
115+
output_file=os.path.join(baseOutputDir,"index.html")
116+
117+
CustomReport.report_from_api(
118+
api=vcproj,
119+
title="HTML Reports",
120+
report_type="INDEX_FILE",
121+
formats=["HTML"],
122+
output_file=output_file,
123+
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','INDEX_SECTION', 'CUSTOM_FOOTER'],
124+
customization_dir=rep_path)
127125

128126
def create_index_html_body ():
129127

src/main/resources/scripts/full_report_no_toc.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,6 @@ def generate_full_status(manageProject):
3636
mpName = os.path.splitext(os.path.basename(manageProject))[0]
3737
full_report_name = mpName + "_full_report.html"
3838
metrics_report_name = mpName + "_metrics_report.html"
39-
40-
# try:
41-
# from vector.apps.DataAPI.vcproject_api import VCProjectApi
42-
# api = VCProjectApi(manageProject)
43-
44-
# api.report(report_type="MANAGE_STATUS_FULL_REPORT", formats=["HTML"], output_file=full_report_name , environments=api.Environment.all(), levels = [])
45-
# api.report(report_type="MANAGE_METRICS_REPORT" , formats=["HTML"], output_file=metrics_report_name, environments=api.Environment.all(), levels = [])
46-
47-
# shutil.copy(full_report_name,full_report_name + "_tmp")
48-
# fixup_reports.fixup_2020_reports(full_report_name + "_tmp")
49-
50-
# shutil.copy(metrics_report_name,metrics_report_name + "_tmp")
51-
# fixup_reports.fixup_2020_reports(metrics_report_name + "_tmp")
52-
53-
# api.close()
54-
55-
# except:
5639

5740
from managewait import ManageWait
5841

src/main/resources/scripts/generate-results.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,13 @@ def buildReports(FullManageProjectName = None,
556556
print("Cleanup: " + str(time.time()))
557557
if useNewReport and not legacy:
558558
try:
559-
api = VCProjectApi(FullManageProjectName)
560-
tool_version = api.tool_version
561-
if tool_version.startswith("20"):
562-
use_manage_api = False
563-
else:
564-
use_manage_api = True
565-
api.close()
559+
with VCProjectApi(FullManageProjectName) as vcproj:
560+
tool_version = vcproj.tool_version
561+
if tool_version.startswith("20"):
562+
use_manage_api = False
563+
else:
564+
use_manage_api = True
566565
except:
567-
##teePrint.teePrint(" *INFO: Issue getting tool version from: " + FullManageProjectName)
568566
use_manage_api = False
569567

570568
if use_manage_api:
@@ -582,17 +580,17 @@ def buildReports(FullManageProjectName = None,
582580
manageEnvs, level, envName, cbtDict, generate_individual_reports,
583581
use_archive_extract, report_only_failures, no_full_report,
584582
useStartLine, teePrint, use_cte)
585-
586-
with open("unit_test_fail_count.txt", "wb") as fd:
587-
fd.write(str(failed_count).encode(encFmt, "replace"))
588-
589-
with open("unit_test_passfail_count.txt", "wb") as fd:
590-
text = "{} {}".format(passed_count, failed_count)
591-
fd.write(text.encode(encFmt, "replace"))
592-
583+
593584
if timing:
594585
print("XML and Individual reports: " + str(time.time()))
595586

587+
with open("unit_test_fail_count.txt", "wb") as fd:
588+
fd.write(str(failed_count).encode(encFmt, "replace"))
589+
590+
with open("unit_test_passfail_count.txt", "wb") as fd:
591+
text = "{} {}".format(passed_count, failed_count)
592+
fd.write(text.encode(encFmt, "replace"))
593+
596594
### NOT Using new data API
597595
else:
598596

@@ -761,17 +759,18 @@ def buildReports(FullManageProjectName = None,
761759
failed_count += int(line.split("\"")[5])
762760
passed_count += int(line.split("\"")[3]) - failed_count
763761
break
764-
except:
765-
teePrint.teePrint (" *INFO: Problem parsing test results file for unit testcase failure count: " + file)
766-
if print_exc: traceback.print_exc()
767-
762+
768763
with open("unit_test_fail_count.txt", "wb") as fd:
769764
fd.write(str(failed_count).encode(encFmt, "replace"))
770765

771766
with open("unit_test_passfail_count.txt", "wb") as fd:
772767
text = "{} {}".format(passed_count, failed_count)
773768
fd.write(text.encode(encFmt, "replace"))
774769

770+
except:
771+
teePrint.teePrint (" *INFO: Problem parsing test results file for unit testcase failure count: " + file)
772+
if print_exc: traceback.print_exc()
773+
775774
for file in copyList:
776775

777776
if verbose:

src/main/resources/scripts/generate_lcov.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@
4040
import subprocess
4141
import argparse
4242

43-
from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding
43+
from vcast_utils import dump, checkVectorCASTVersion, getVectorCASTEncoding, checkProjectResults
4444
try:
4545
from safe_open import open
4646
except:
4747
pass
4848

49+
try:
50+
import math
51+
INF = math.inf
52+
except Exception:
53+
INF = float("inf") # Py2-compatible
4954
encFmt = getVectorCASTEncoding()
5055

5156
fileList = []
@@ -116,30 +121,46 @@ def has_branches_covered(line):
116121

117122
def get_function_name_line_number(file_path, function, initial_guess):
118123

119-
with open(file_path,"rb") as fd:
124+
with open(file_path, "rb") as fd:
120125
lines = [line.decode(encFmt, "replace") for line in fd.readlines()]
121-
122-
line_number_closest_so_far = initial_guess;
123-
delta = 9999999999;
124126

125-
# print(function, line_number_closest_so_far, delta, initial_guess)
126-
for count, line in enumerate(reversed(lines[:initial_guess+1])):
127-
if function in line.replace(" ",""):
127+
if initial_guess is None or initial_guess >= len(lines):
128+
initial_guess = len(lines) - 1
129+
130+
line_number_closest_so_far = initial_guess
131+
delta = INF
132+
133+
for count, line in enumerate(reversed(lines[:initial_guess + 1])):
134+
if function in line.replace(" ", ""):
128135
line_num = initial_guess - count
129136
if abs(line_num - initial_guess) < delta:
130137
line_number_closest_so_far = line_num
131138
delta = abs(line_num - initial_guess)
132-
# print(function, line_number_closest_so_far, delta, initial_guess)
133-
134-
# print(line_number_closest_so_far + 1,function)
135-
return line_number_closest_so_far + 1 ## add one since python starts from 0
139+
140+
return line_number_closest_so_far + 1 # convert 0-based to 1-based
141+
136142

137143
def runCoverageResultsMP(mpFile, verbose = False, testName = "", source_root = ""):
138144

139-
vcproj = VCProjectApi(mpFile)
140-
api = vcproj.project.cover_api
145+
with VCProjectApi(mpFile) as vcproj:
146+
147+
anyLocalResults, anyImportedResults = checkProjectResults(vcproj)
148+
149+
if anyImportedResults:
150+
importedResultsError = " ** LCOV results does not processing imported results at this time\n\n"
151+
print(importedResultsError)
152+
return importedResultsError
153+
154+
if not anyLocalResults:
155+
localResultsError = " ** No local results in project to process\n\n"
156+
print(localResultsError)
157+
return localResultsError
158+
159+
api = vcproj.project.cover_api
160+
161+
results = runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root)
141162

142-
return runGcovResults(api, verbose = verbose, testName = vcproj.project.name, source_root=source_root)
163+
return results
143164

144165
def runGcovResults(api, verbose = False, testName = "", source_root = "") :
145166

@@ -152,7 +173,7 @@ def runGcovResults(api, verbose = False, testName = "", source_root = "") :
152173
except:
153174
prj_dir = os.getcwd().replace("\\","/") + "/"
154175

155-
# get a sorted listed of all the files with the proj directory stripped off
176+
# get a sorted listed of all the files with the proj directory stripped off
156177
for file in api.SourceFile.all():
157178
if file.display_name == "":
158179
continue

src/main/resources/scripts/generate_pclp_reports.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -324,21 +324,19 @@ def generate_html_report(mpName, input_xml, output_html):
324324
if output_html is None:
325325
output_html = "pclp_findings.html"
326326

327-
api = VCProjectApi(mpName)
328-
329-
# Set custom report directory to the where this script was
330-
# found. Must contain sections/index_section.py
331-
rep_path = pathlib.Path(__file__).parent.resolve()
332-
CustomReport.report_from_api(
333-
api=api,
334-
title="PC-Lint Plus Results",
335-
report_type="INDEX_FILE",
336-
formats=["HTML"],
337-
output_file=output_html,
338-
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','PCLP_SUMMARY_SECTION','PCLP_DETAILS_SECTION','PCLP_SOURCE_SECTION', 'CUSTOM_FOOTER'],
339-
customization_dir=rep_path)
340-
341-
api.close()
327+
with VCProjectApi(mpName) as vcproj:
328+
329+
# Set custom report directory to the where this script was
330+
# found. Must contain sections/index_section.py
331+
rep_path = pathlib.Path(__file__).parent.resolve()
332+
CustomReport.report_from_api(
333+
api=vcproj,
334+
title="PC-Lint Plus Results",
335+
report_type="INDEX_FILE",
336+
formats=["HTML"],
337+
output_file=output_html,
338+
sections=['CUSTOM_HEADER', 'REPORT_TITLE', 'TABLE_OF_CONTENTS','PCLP_SUMMARY_SECTION','PCLP_DETAILS_SECTION','PCLP_SOURCE_SECTION', 'CUSTOM_FOOTER'],
339+
customization_dir=rep_path)
342340

343341
def has_any_coverage(line):
344342

0 commit comments

Comments
 (0)