8000 Updating a regex to treat object as annotated only if it contains val… · utPLSQL/utPLSQL@b8e9c31 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8e9c31

Browse files
committed
Updating a regex to treat object as annotated only if it contains valid annotations.
1 parent ed6307b commit b8e9c31

File tree

6 files changed

+56
-15
lines changed

6 files changed

+56
-15
lines changed

source/core/annotations/ut_annotation_manager.pkb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,32 +99,22 @@ create or replace package body ut_annotation_manager as
9999
return l_result;
100100
end;
101101

102-
function get_annotations_list return ut_varchar2_list pipelined is
103-
begin
104-
for i in 1 .. ut_utils.gc_supported_annotations.count loop
105-
pipe row( ut_utils.gc_supported_annotations(i) );
106-
end loop;
107-
end get_annotations_list;
102+
108103

109104
function get_sources_to_annotate(a_object_owner varchar2, a_object_type varchar2, a_objects_to_refresh ut_annotation_objs_cache_info) return sys_refcursor is
110105
l_result sys_refcursor;
111106
l_sources_view varchar2(200) := ut_metadata.get_source_view_name();
112107
l_card natural;
113-
l_allowed_annotations varchar2(32767) := 'suite';
108+
l_allowed_annotations varchar2(32767) := ut_utils.get_annotations_list_regex;
114109
begin
115110

116-
select listagg(column_value,'|') within group (order by column_value)
117-
into l_allowed_annotations
118-
from table(get_annotations_list);
119-
120-
121111
l_card := ut_utils.scale_cardinality(cardinality(a_objects_to_refresh));
122112
open l_result for
123113
q'[select /*+ no_parallel */ x.name, x.text
124114
from (select /*+ cardinality( r ]'||l_card||q'[ )*/
125115
s.name, s.text, s.line,
126116
max(case when s.text like '%--%\%%' escape '\'
127-
and regexp_like(s.text,'^\s*--\s*]'||l_allowed_annotations||q'[%')
117+
and regexp_like(s.text,'^\s*--\s*%(]'||l_allowed_annotations||q'[)')
128118
then 'Y' else 'N' end
129119
)
130120
over(partition by s.name) is_annotated

source/core/annotations/ut_annotation_manager.pks

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ create or replace package ut_annotation_manager authid current_user as
2020
* Builds annotations out of database source code by reading it from cache
2121
*/
2222

23-
function get_annotations_list return ut_varchar2_list pipelined;
24-
2523
/**
2624
* Gets annotations for all objects of a specified type for database schema.
2725
* Annotations that are stale or missing are parsed and placed in persistent cache.

source/core/ut_utils.pkb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,5 +1024,17 @@ create or replace package body ut_utils is
10241024
return l_result;
10251025
end;
10261026

1027+
function get_annotations_list_regex return varchar2 is
1028+
cursor c_get_annotation_regex is
1029+
select listagg(column_value,'|') within group (order by column_value)
1030+
from table(gc_supported_annotations);
1031+
l_result varchar2(4000);
1032+
begin
1033+
open c_get_annotation_regex;
1034+
fetch c_get_annotation_regex into l_result;
1035+
close c_get_annotation_regex;
1036+
return l_result;
1037+
end get_annotations_list_regex;
1038+
10271039
end ut_utils;
10281040
/

source/core/ut_utils.pks

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,5 +517,6 @@ create or replace package ut_utils authid definer is
517517
*/
518518
function lengthb_clob( a_clob clob) return integer;
519519

520+
function get_annotations_list_regex return varchar2;
520521
end ut_utils;
521522
/

test/ut3_tester/core/annotations/test_annotation_manager.pkb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ create or replace package body test_annotation_manager is
5858
end;]');
5959
end;
6060

61+
procedure add_badly_annotated_pck is
62+
begin
63+
exec_autonomous(q'[
64+
create or replace package badly_annot_pkg as
65+
--%sparameter(no parameter)
66+
--%returns(no return)
67+
--%usage(no usage)
68+
procedure some_dummy_test_procedure;
69+
end;]');
70+
end;
71+
6172
procedure drop_dummy_test_package is
6273
begin
6374
exec_autonomous(q'[drop package dummy_test_package]');
@@ -66,6 +77,14 @@ create or replace package body test_annotation_manager is
6677
null;
6778
end;
6879

80+
procedure drop_badly_ann_pkg is
81+
begin
82+
exec_autonomous(q'[drop package badly_annot_pkg]');
83+
exception
84+
when others then
85+
null;
86+
end;
87+
6988
procedure recompile_dummy_test_package is
7089
begin
7190
exec_autonomous(q'[alter package dummy_test_package compile]');
@@ -462,5 +481,23 @@ create or replace package body test_annotation_manager is
462481
assert_dummy_test_package(l_start_date);
463482
end;
464483

484+
procedure issue_1278_correct_annotation is
485+
l_actual sys_refcursor;
486+
begin
487+
--Arrange
488+
add_badly_annotated_pck();
489+
--Act
490+
ut3_develop.ut_annotation_manager.rebuild_annotation_cache(sys_context('USERENV', 'CURRENT_USER'),'PACKAGE');
491+
--Assert
492+
open l_actual for
493+
select *
494+
from ut3_develop.ut_suite_cache_package
495+
where object_owner = sys_context('USERENV', 'CURRENT_USER') and object_name = 'BADLY_ANNOT_PKG';
496+
497+
drop_badly_ann_pkg;
498+
ut.expect(l_actual).to_be_empty;
499+
end;
500+
501+
465502
end test_annotation_manager;
466503
/

test/ut3_tester/core/annotations/test_annotation_manager.pks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,8 @@ create or replace package test_annotation_manager is
100100

101101
--%endcontext
102102

103+
--%test(Issue #1278 of marking object as annotated when it is not)
104+
procedure issue_1278_correct_annotation;
105+
103106
end test_annotation_manager;
104107
/

0 commit comments

Comments
 (0)
0