StevenLooman / sw5-jacoco-reporter

Smallworld5 JaCoCo Reporter
GNU Lesser General Public License v3.0
1 stars 1 forks source link

Duplicate method definitions causes JaCoCo to fail #6

Open sebastiaanspeck opened 1 year ago

sebastiaanspeck commented 1 year ago

When having the next exemplar in Magik:

_package user

_pragma(classify_level=basic, topic={duplicate})
def_slotted_exemplar(:simple_exemplar, {})
$

_pragma(classify_level=basic, topic={duplicate})
_method simple_exemplar.duplicated_method()
    _return _unset
_endmethod
$

_pragma(classify_level=basic, topic={duplicate})
_method simple_exemplar.duplicated_method()
    _return _unset
_endmethod
$

Creating the next jacoco.xml:

   <package name="magik/simple_test_product/duplicated_method_module">
      <class name="magik/simple_test_product/duplicated_method_module/simple_exemplar_55" sourcefilename="simple_test_product\modules\duplicated_method_module\source\simple_exemplar.magik">
         <method name="simple_exemplar.duplicated_method()" desc="" line="10">
            <counter type="INSTRUCTION" missed="2" covered="0" />
            <counter type="LINE" missed="1" covered="0" />
            <counter type="COMPLEXITY" missed="1" covered="0" />
            <counter type="METHOD" missed="1" covered="0" />
         </method>
         <method name="simple_exemplar.duplicated_method()" desc="" line="16">
            <counter type="INSTRUCTION" missed="0" covered="2" />
            <counter type="LINE" missed="0" covered="1" />
            <counter type="COMPLEXITY" missed="0" covered="1" />
            <counter type="METHOD" missed="0" covered="1" />
         </method>
         <counter type="INSTRUCTION" missed="2" covered="2" />
         <counter type="LINE" missed="1" covered="1" />
         <counter type="COMPLEXITY" missed="1" covered="1" />
         <counter type="METHOD" missed="1" covered="1" />
         <counter type="CLASS" missed="0" covered="1" />
      </class>
      <sourcefile name="simple_test_product\modules\duplicated_method_module\source\simple_exemplar.magik">
         <line nr="10" mi="2" ci="0" mb="0" cb="0" />
         <line nr="16" mi="0" ci="2" mb="0" cb="0" />
         <counter type="INSTRUCTION" missed="2" covered="2" />
         <counter type="LINE" missed="1" covered="1" />
      </sourcefile>
      <counter type="INSTRUCTION" missed="38" covered="4" />
      <counter type="LINE" missed="6" covered="2" />
      <counter type="COMPLEXITY" missed="4" covered="1" />
      <counter type="METHOD" missed="4" covered="1" />
      <counter type="CLASS" missed="1" covered="1" />
   </package>

The double method definition with name simple_exemplar.duplicated_method() causes the next error when pushing this to the JaCoCo-plugin in Jenkins:

java.lang.IllegalArgumentException: There is already a child [METHOD] simple_exemplar.duplicated_method() with the name simple_exemplar.duplicated_method() in [CLASS] magik/simple_test_product/duplicated_method_module/simple_exemplar_55>
StevenLooman commented 1 year ago

Thank you for this issue @sebastiaanspeck. Is this a problem with sw5-jacoco-reporter, or a problem witch the JaCoCo-plugin in Jenkins?

Though, I do think sw5-jacoco-reporter can do something here. The question is what however... In the same file I would say, ignore all duplicate methods except for the last (with the same name of course).

But what about duplicate methods in different files? I do think Smallworld appends a unique (incrementing) number to each method in the Java Byte Code and from that the last defined (compiled) method can be found.

At least a warning can be shown during the conversion.

sebastiaanspeck commented 1 year ago

The issue raises as soon as you use the JaCoCo-plugin in Jenkins, but it originates from the sw5-jacoco-reporter (actually the Magik-code ofcourse).

I think a warning during conversion seems enough for me I think, you need to resolve duplicated methods in the Magik-code.

I will take a look how the XML will look when having the duplicated method in a different file and will append it here.