Skip to content

Commit ae144ab

Browse files
committed
Added XML Coverage reporter for Sonar.
Added JSON Coverage reporter for Coveralls. Added grants and synonyms for coverage API objects. Changed RunAll to use XML coverage reporter for publishing to sonar. Added sonar scanner script to the Travis build - so the sonar stats get updated and coverage gets pulled to sonar after each build. Updated deletes from coverage table to run in autonomous transaction. Fixed bug in ut_output_buffer, where lat line was displayed 2 times.
1 parent f2da43b commit ae144ab

14 files changed

Lines changed: 711 additions & 215 deletions

.travis.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
sudo: required
22
language: python
33

4+
addons:
5+
apt:
6+
packages:
7+
#packages required for oracle
8+
- bc
9+
- rpm
10+
- unzip
11+
#Java8 required for sonar
12+
- oracle-java8-installer
13+
- oracle-java8-set-default
14+
sonarqube:
15+
token:
16+
secure: AmQdR1Fm0tvA9Ees1wz1RqnUl49lZrGdhWCkx7SnIzz+/1Lm2L9aH/e4bL60wIqkJ+AK8tJ1YX4L2B+i7/t5dBSH9Nj8JgbJFwHMqHdMCmaqKpvT5eJRzhbgr0kccm8ECHWTWBL+mIyXXYUm4f/tuRnnngfZS/bxtUpFUDvotcEybuuGUvKSbmc6ew5tfBuX79G/lXbFBceO6EQStoi8SeIHDkgeX/BoQQin0BFVMcsuWKPuQ5P5B19KfxubEk6tiHLZffoaF1q+RbsFcwpr4nyXHiusTRdtLmHb5DvlSQsy15qaakJP6AA073sGjnKxcGiGvP48HbC07tQmtBiZY2Ybkqj9i4aRq0hzX/VXRuZOV/rQARjItS4MKTmD9gET9XkYzc/P8VxSGRFT97guF3f6qtPzcGCu3TbFQpgeP+mgcePLvDl5j/AL+tZAAwSj3mPhEGncr5j+QkcLhl+mM5TymNeJn828qb8I7+mSdqbmPwytc//hwJLeqFJDX2GGnXZD4VkMZDvUO6gq2bQXy0hLgdI7uIQpIzIUlAGoYG6MK4SuHxnx+ZNwsW/nrMGVCJrK67Ii/R++Fg4et5QshTaTbkcQ3Deroady/pnGwlD5FR59LYpjqOVQ+4ey2bf92eGx0j0NWCz+CfirKSXd3o1hESSqamyi8KtOqkqiLEg=
17+
418
env:
519
global:
620
- ORACLE_COOKIE=sqldev
@@ -10,6 +24,7 @@ env:
1024
- ORACLE_BASE=/u01/app/oracle
1125
- LD_LIBRARY_PATH=$ORACLE_HOME/lib
1226
- PATH=$PATH:$ORACLE_HOME/jdbc/lib:$ORACLE_HOME/bin
27+
- JAVA_HOME=/usr/lib/jvm/java-8-oracle/jre
1328
- DATABASE_VERSION=11.2.0.2
1429
- ORACLE_SID=XE
1530
- DATABASE_NAME=XE
@@ -25,17 +40,6 @@ env:
2540
- PAGES_TARGET_BRANCH="gh-pages"
2641
- PAGES_VERSION_BASE="version3"
2742

28-
addons:
29-
apt:
30-
packages:
31-
#packages required for oracle
32-
- bc
33-
- rpm
34-
- unzip
35-
sonarqube:
36-
token:
37-
secure: AmQdR1Fm0tvA9Ees1wz1RqnUl49lZrGdhWCkx7SnIzz+/1Lm2L9aH/e4bL60wIqkJ+AK8tJ1YX4L2B+i7/t5dBSH9Nj8JgbJFwHMqHdMCmaqKpvT5eJRzhbgr0kccm8ECHWTWBL+mIyXXYUm4f/tuRnnngfZS/bxtUpFUDvotcEybuuGUvKSbmc6ew5tfBuX79G/lXbFBceO6EQStoi8SeIHDkgeX/BoQQin0BFVMcsuWKPuQ5P5B19KfxubEk6tiHLZffoaF1q+RbsFcwpr4nyXHiusTRdtLmHb5DvlSQsy15qaakJP6AA073sGjnKxcGiGvP48HbC07tQmtBiZY2Ybkqj9i4aRq0hzX/VXRuZOV/rQARjItS4MKTmD9gET9XkYzc/P8VxSGRFT97guF3f6qtPzcGCu3TbFQpgeP+mgcePLvDl5j/AL+tZAAwSj3mPhEGncr5j+QkcLhl+mM5TymNeJn828qb8I7+mSdqbmPwytc//hwJLeqFJDX2GGnXZD4VkMZDvUO6gq2bQXy0hLgdI7uIQpIzIUlAGoYG6MK4SuHxnx+ZNwsW/nrMGVCJrK67Ii/R++Fg4et5QshTaTbkcQ3Deroady/pnGwlD5FR59LYpjqOVQ+4ey2bf92eGx0j0NWCz+CfirKSXd3o1hESSqamyi8KtOqkqiLEg=
38-
3943
cache:
4044
directories:
4145
- .cache
@@ -64,6 +68,7 @@ script:
6468
# - bash .travis/run_test_as_user.sh
6569
# - bash .travis/build_docs.sh
6670
# - bash .travis/push_docs_to_gh_pages.sh
71+
- sonar-scanner
6772

6873
deploy:
6974
provider: releases

sonar-project.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sonar.projectVersion=3.0.0.Alpha
99
# If not set, SonarQube starts looking for source code from the directory containing
1010
# the sonar-project.properties file.
1111
sonar.sources=./source
12+
sonar.coverageReportPaths=./tests/coverage.xml
1213

1314
# Encoding of the source code. Default is default system encoding
1415
#sonar.sourceEncoding=UTF-8

source/core/coverage/ut_coverage.pks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ create or replace package ut_coverage authid current_user is
2222
gc_regex_type_subexpression constant positive := 5;
2323

2424
-- total run coverage information
25-
subtype t_full_name is varchar2(500);
25+
subtype t_full_name is varchar2(4000);
2626
subtype t_object_name is varchar2(250);
2727

2828
subtype t_line_executions is binary_integer;

source/core/coverage/ut_coverage_helper.pkb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ create or replace package body ut_coverage_helper is
3030
end;
3131

3232
function coverage_start(a_run_comment varchar2) return integer is
33+
pragma autonomous_transaction;
3334
begin
3435
--those are Global Temporary tables for profiler usage only
3536
delete from plsql_profiler_data;
3637
delete from plsql_profiler_units;
3738
delete from plsql_profiler_runs;
3839
dbms_profiler.start_profiler(run_comment => a_run_comment, run_number => g_coverage_id);
3940
coverage_pause();
41+
commit;
4042
return g_coverage_id;
4143
end;
4244

source/create_synonyms_and_grants_for_public.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,19 @@ grant execute on ut_teamcity_reporter to public;
4646
grant execute on ut_xunit_reporter to public;
4747
grant execute on ut_documentation_reporter to public;
4848
grant execute on ut_coverage_html_reporter to public;
49+
grant execute on ut_coverage_xml_reporter to public;
50+
grant execute on ut_coverage_json_reporter to public;
4951
grant execute on ut_reporters to public;
5052
grant execute on ut_varchar2_list to public;
5153
grant execute on ut_reporter_base to public;
5254
grant execute on ut_coverage to public;
5355
grant execute on ut_coverage_helper to public;
5456
grant insert, delete, select on ut_coverage_sources_tmp to public;
5557
grant execute on ut_output_buffer to public;
58+
grant execute on ut_coverage_file_mappings to public;
59+
grant execute on ut_coverage_file_mapping to public;
60+
grant execute on ut_key_value_pairs to public;
61+
grant execute on ut_key_value_pair to public;
5662

5763
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to PUBLIC
5864

@@ -75,10 +81,16 @@ create public synonym ut_teamcity_reporter for ut_teamcity_reporter;
7581
create public synonym ut_xunit_reporter for ut_xunit_reporter;
7682
create public synonym ut_documentation_reporter for ut_documentation_reporter;
7783
create public synonym ut_coverage_html_reporter for ut_coverage_html_reporter;
84+
create public synonym ut_coverage_xml_reporter for ut_coverage_xml_reporter;
85+
create public synonym ut_coverage_json_reporter for ut_coverage_json_reporter;
7886
create public synonym ut_reporters for ut_reporters;
7987
create public synonym ut_varchar2_list for ut_varchar2_list;
8088
create public synonym ut_reporter_base for ut_reporter_base;
8189
create public synonym ut_coverage for ut_coverage;
8290
create public synonym ut_coverage_helper for ut_coverage_helper;
8391
create public synonym ut_coverage_sources_tmp for ut_coverage_sources_tmp;
8492
create public synonym ut_output_buffer for ut_output_buffer;
93+
create public synonym ut_coverage_file_mappings for ut_coverage_file_mappings;
94+
create public synonym ut_coverage_file_mapping for ut_coverage_file_mapping;
95+
create public synonym ut_key_value_pairs for ut_key_value_pairs;
96+
create public synonym ut_key_value_pair for ut_key_value_pair;

source/create_synonyms_and_grants_for_user.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ grant execute on ut_teamcity_reporter to &ut3_user;
4747
grant execute on ut_xunit_reporter to &ut3_user;
4848
grant execute on ut_documentation_reporter to &ut3_user;
4949
grant execute on ut_coverage_html_reporter to &ut3_user;
50+
grant execute on ut_coverage_xml_reporter to &ut3_user;
51+
grant execute on ut_coverage_json_reporter to &ut3_user;
5052
grant execute on ut_reporters to &ut3_user;
5153
grant execute on ut_varchar2_list to &ut3_user;
5254
grant execute on ut_reporter_base to &ut3_user;
5355
grant execute on ut_coverage to &ut3_user;
5456
grant execute on ut_coverage_helper to &ut3_user;
5557
grant insert, delete, select on ut_coverage_sources_tmp to &ut3_user;
5658
grant execute on ut_output_buffer to &ut3_user;
59+
grant execute on ut_coverage_file_mappings to &ut3_user;
60+
grant execute on ut_coverage_file_mapping to &ut3_user;
61+
grant execute on ut_key_value_pairs to &ut3_user;
62+
grant execute on ut_key_value_pair to &ut3_user;
5763

5864
prompt Creating synonyms for UTPLSQL objects in &&ut3_owner schema to user &&ut3_user
5965

@@ -76,10 +82,16 @@ create or replace synonym &ut3_user .ut_teamcity_reporter for ut_teamcity_report
7682
create or replace synonym &ut3_user .ut_xunit_reporter for ut_xunit_reporter;
7783
create or replace synonym &ut3_user .ut_documentation_reporter for ut_documentation_reporter;
7884
create or replace synonym &ut3_user .ut_coverage_html_reporter for ut_coverage_html_reporter;
85+
create or replace synonym &ut3_user .ut_coverage_xml_reporter for ut_coverage_xml_reporter;
86+
create or replace synonym &ut3_user .ut_coverage_json_reporter for ut_coverage_json_reporter;
7987
create or replace synonym &ut3_user .ut_reporters for ut_reporters;
8088
create or replace synonym &ut3_user .ut_varchar2_list for ut_varchar2_list;
8189
create or replace synonym &ut3_user .ut_reporter_base for ut_reporter_base;
8290
create or replace synonym &ut3_user .ut_coverage for ut_coverage;
8391
create or replace synonym &ut3_user .ut_coverage_helper for ut_coverage_helper;
8492
create or replace synonym &ut3_user .ut_coverage_sources_tmp for ut_coverage_sources_tmp;
8593
create or replace synonym &ut3_user .ut_output_buffer for ut_output_buffer;
94+
create or replace synonym &ut3_user .ut_coverage_file_mappings for ut_coverage_file_mappings;
95+
create or replace synonym &ut3_user .ut_coverage_file_mapping for ut_coverage_file_mapping;
96+
create or replace synonym &ut3_user .ut_key_value_pairs for ut_key_value_pairs;
97+
create or replace synonym &ut3_user .ut_key_value_pair for ut_key_value_pair;

source/install.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ whenever oserror exit failure rollback
218218
@@reporters/ut_coverage_report_html_helper.pks
219219
@@reporters/ut_coverage_report_html_helper.pkb
220220
@@reporters/ut_coverage_html_reporter.tpb
221+
@@reporters/ut_coverage_xml_reporter.tps
222+
@@reporters/ut_coverage_xml_reporter.tpb
223+
@@reporters/ut_coverage_json_reporter.tps
224+
@@reporters/ut_coverage_json_reporter.tpb
221225

222226
@@api/be_between.syn
223227
@@api/be_empty.syn
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
create or replace type body ut_coverage_json_reporter is
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
constructor function ut_coverage_json_reporter(
20+
self in out nocopy ut_coverage_json_reporter,
21+
a_schema_names ut_varchar2_list := null,
22+
a_include_object_list ut_varchar2_list := null,
23+
a_exclude_object_list ut_varchar2_list := null
24+
) return self as result is
25+
begin
26+
self.init($$plsql_unit);
27+
ut_coverage.init(a_schema_names, a_include_object_list, a_exclude_object_list);
28+
return;
29+
end;
30+
31+
constructor function ut_coverage_json_reporter(
32+
self in out nocopy ut_coverage_json_reporter,
33+
a_object_owner varchar2 := null,
34+
a_file_paths ut_varchar2_list,
35+
a_regex_pattern varchar2,
36+
a_object_owner_subexpression positive,
37+
a_object_name_subexpression positive,
38+
a_object_type_subexpression positive,
39+
a_file_to_object_type_mapping ut_key_value_pairs,
40+
a_include_object_list ut_varchar2_list := null,
41+
a_exclude_object_list ut_varchar2_list := null
42+
) return self as result is
43+
l_mappings ut_coverage_file_mappings;
44+
begin
45+
l_mappings := ut_coverage.build_file_mappings(
46+
a_object_owner, a_file_paths, a_file_to_object_type_mapping, a_regex_pattern,
47+
a_object_owner_subexpression, a_object_name_subexpression, a_object_type_subexpression
48+
);
49+
self.init($$plsql_unit);
50+
ut_coverage.init(l_mappings, a_include_object_list, a_exclude_object_list);
51+
return;
52+
end;
53+
54+
constructor function ut_coverage_json_reporter(
55+
self in out nocopy ut_coverage_json_reporter,
56+
a_object_owner varchar2 := null,
57+
a_file_paths ut_varchar2_list,
58+
a_include_object_list ut_varchar2_list := null,
59+
a_exclude_object_list ut_varchar2_list := null
60+
) return self as result is
61+
l_mappings ut_coverage_file_mappings;
62+
begin
63+
l_mappings := ut_coverage.build_file_mappings( a_object_owner, a_file_paths );
64+
self.init($$plsql_unit);
65+
ut_coverage.init(l_mappings, a_include_object_list, a_exclude_object_list);
66+
return;
67+
end;
68+
69+
constructor function ut_coverage_json_reporter(
70+
self in out nocopy ut_coverage_json_reporter,
71+
a_file_mappings ut_coverage_file_mappings,
72+
a_include_object_list ut_varchar2_list := null,
73+
a_exclude_object_list ut_varchar2_list := null
74+
) return self as result is
75+
begin
76+
self.init($$plsql_unit);
77+
ut_coverage.init(a_file_mappings, a_include_object_list, a_exclude_object_list);
78+
return;
79+
end;
80+
81+
overriding member procedure after_calling_run(self in out nocopy ut_coverage_json_reporter, a_run in ut_run) as
82+
l_report_lines ut_varchar2_list;
83+
l_coverage_data ut_coverage.t_coverage;
84+
85+
function get_lines_json(a_unit_coverage ut_coverage.t_unit_coverage) return clob is
86+
l_file_part varchar2(32767);
87+
l_result clob;
88+
l_last_line_no binary_integer;
89+
c_coverage_header constant varchar2(30) := '"coverage": [';
90+
c_null constant varchar2(4) := 'null';
91+
begin
92+
dbms_lob.createtemporary(l_result, true);
93+
dbms_lob.writeappend(l_result, length(c_coverage_header), c_coverage_header);
94+
95+
l_last_line_no := a_unit_coverage.lines.last;
96+
if l_last_line_no is not null then
97+
for line_no in 1 .. l_last_line_no loop
98+
l_file_part :=
99+
case
100+
when a_unit_coverage.lines.exists(line_no) then
101+
to_char(a_unit_coverage.lines(line_no))
102+
else
103+
c_null
104+
end
105+
||
106+
case
107+
when line_no < l_last_line_no then
108+
','
109+
end;
110+
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
111+
end loop;
112+
end if;
113+
dbms_lob.writeappend(l_result, 1, ']');
114+
return l_result;
115+
end;
116+
117+
function get_coverage_json(
118+
a_coverage_data ut_coverage.t_coverage
119+
) return clob is
120+
l_file_part varchar2(32767);
121+
l_result clob;
122+
l_unit ut_coverage.t_full_name;
123+
c_coverage_header constant varchar2(30) := '{"source_files":['||chr(10);
124+
c_coverage_footer constant varchar2(30) := ']}'||chr(10)||chr(10)||chr(10)||chr(10)||' ';
125+
begin
126+
dbms_lob.createtemporary(l_result,true);
127+
128+
dbms_lob.writeappend(l_result, length(c_coverage_header), c_coverage_header);
129+
l_unit := a_coverage_data.objects.first;
130+
while l_unit is not null loop
131+
l_file_part := '{ "name": "'||l_unit||'",'||chr(10);
132+
dbms_lob.writeappend(l_result, length(l_file_part), l_file_part);
133+
134+
dbms_lob.append(l_result,get_lines_json(a_coverage_data.objects(l_unit)));
135+
136+
dbms_lob.writeappend(l_result, 1, '}');
137+
138+
l_unit := a_coverage_data.objects.next(l_unit);
139+
if l_unit is not null then
140+
dbms_lob.writeappend(l_result, 2, ','||chr(10));
141+
end if;
142+
end loop;
143+
dbms_lob.writeappend(l_result, length(c_coverage_footer), c_coverage_footer);
144+
return l_result;
145+
end;
146+
begin
147+
ut_coverage.coverage_stop();
148+
149+
l_coverage_data := ut_coverage.get_coverage_data();
150+
151+
l_report_lines := ut_utils.clob_to_table(get_coverage_json( l_coverage_data ));
152+
for i in 1 .. l_report_lines.count loop
153+
self.print_text( l_report_lines(i) );
154+
end loop;
155+
156+
(self as ut_reporter_base).after_calling_run(a_run);
157+
end;
158+
159+
end;
160+
/
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
create or replace type ut_coverage_json_reporter force under ut_coverage_reporter_base(
2+
/*
3+
utPLSQL - Version X.X.X.X
4+
Copyright 2016 - 2017 utPLSQL Project
5+
6+
Licensed under the Apache License, Version 2.0 (the "License"):
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
/**
20+
* Builds a coverage XML report that follows rules described in
21+
* https://docs.sonarqube.org/display/SONAR/Generic+Test+Data
22+
*/
23+
constructor function ut_coverage_json_reporter(
24+
self in out nocopy ut_coverage_json_reporter,
25+
a_schema_names ut_varchar2_list := null,
26+
a_include_object_list ut_varchar2_list := null,
27+
a_exclude_object_list ut_varchar2_list := null
28+
) return self as result,
29+
30+
constructor function ut_coverage_json_reporter(
31+
self in out nocopy ut_coverage_json_reporter,
32+
a_object_owner varchar2 := null,
33+
a_file_paths ut_varchar2_list,
34+
a_regex_pattern varchar2,
35+
a_object_owner_subexpression positive,
36+
a_object_name_subexpression positive,
37+
a_object_type_subexpression positive,
38+
a_file_to_object_type_mapping ut_key_value_pairs,
39+
a_include_object_list ut_varchar2_list := null,
40+
a_exclude_object_list ut_varchar2_list := null
41+
) return self as result,
42+
43+
constructor function ut_coverage_json_reporter(
44+
self in out nocopy ut_coverage_json_reporter,
45+
a_object_owner varchar2 := null,
46+
a_file_paths ut_varchar2_list,
47+
a_include_object_list ut_varchar2_list := null,
48+
a_exclude_object_list ut_varchar2_list := null
49+
) return self as result,
50+
51+
constructor function ut_coverage_json_reporter(
52+
self in out nocopy ut_coverage_json_reporter,
53+
a_file_mappings ut_coverage_file_mappings,
54+
a_include_object_list ut_varchar2_list := null,
55+
a_exclude_object_list ut_varchar2_list := null
56+
) return self as result,
57+
58+
overriding member procedure after_calling_run(self in out nocopy ut_coverage_json_reporter, a_run in ut_run)
59+
)
60+
/

0 commit comments

Comments
 (0)