2 Replies Latest reply on Mar 1, 2017 9:25 AM by avoigtma

    Windup rules: excluding files / logical operators in when condition

    avoigtma

      Trying to match some patterns in e.g. xml files and exclude certain files.

      The <when> condition supports logical operators, but how do they work?

      Example below does not work as expected.

      As well, removing the <and>/<not> from the when part and attempting to

      handle this using the regexp for the filenamepattern, I did not succeed.

       

      Any ideas?

      Thanks.

       

      <rule id="myRule">

          <when>

              <and>

                  <filecontent pattern="myPattern" filename="{namepattern}.xml" />

                  <not>

                      <file filename="pom.xml" />

                  </not>

              </and>

          </when>

          <perform>

              <hint title="myRule: title" effort="1" category-id="mandatory">

                  <message>...</message>

              </hint>

          </perform>

          <where param="namepattern">

              <!-- <matches pattern="((?!pom)(.*))"/> -->

              <matches pattern="(.*)"/>

          </where>

      </rule>

        • 1. Re: Windup rules: excluding files / logical operators in when condition
          manarh

          Andreas Voigtmann wrote:

           

          Trying to match some patterns in e.g. xml files and exclude certain files.

          The <when> condition supports logical operators, but how do they work?

          Example below does not work as expected.

          As well, removing the <and>/<not> from the when part and attempting to

          handle this using the regexp for the filenamepattern, I did not succeed.

           

          Any ideas?

          Thanks.

           

          <rule id="myRule">

          <when>

          <and>

          <filecontent pattern="myPattern" filename="{namepattern}.xml" />

          <not>

          <file filename="pom.xml" />

          </not>

          </and>

          </when>

          <perform>

          <hint title="myRule: title" effort="1" category-id="mandatory">

          <message>...</message>

          </hint>

          </perform>

          <where param="namepattern">

          <!-- <matches pattern="((?!pom)(.*))"/> -->

          <matches pattern="(.*)"/>

          </where>

          </rule>

          Generally all when conditions have implicitly <and> by default so not required to have it there. And using <not> is negating not a condition but just that one, I would omit it and I think this should work for you

                <rule id="myRule">
                      <when>
                          <filecontent pattern="pathToRoot" filename="{pattern}.xml"/>
                      </when>
                      <perform>
                          <hint title="myRule: title" effort="1" category-id="mandatory">
                              <message>Something was caught</message>
                          </hint>
                      </perform>
                      <where param="pattern">
                          <matches pattern="([^pom]*)"/>
                      </where> 
                  </rule>
          
          1 of 1 people found this helpful
          • 2. Re: Windup rules: excluding files / logical operators in when condition
            avoigtma

            manarh thanks for the hint !

            your suggested pattern will not do it as it would filter our too much from the target filename (e.g. omit 'config.xml') but  the following seems to solve it.

            <matches pattern="([^p]{1}.*|p[^o].*|po[^m].*)" />