Custom rule for XML does not work as expected

  • using SonarQube 8.8
  • trigger analysis as mvn sonar:sonar in Docker container

I want to check if there exist a line <skipMunitTests>true</skipMunitTests> in pom.xml and if it exists whether it contains a value = true. If so throw an error.

I followed Adding Coding Rules | SonarQube Docs

I extended a default template for XML and Mule languages and created custom rules, activated extended quality profiles for a project:


XPath that I used:
boolean(//skipMunitTests) and contains(//skipMunitTests, 'true')

I verified the expression here: http://xpather.com against pom.xml (attached at the very bottom)

But after execution I got no errors whereas mentioned above line exists in pom.xml
Please advise

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
		<artifactId>vfgl-mule-pom</artifactId>
		<version>2.0.0</version>
    </parent>
	
	<groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
	<artifactId>vfgl-cart-eapi-app</artifactId>
	<version>1.4.2</version>
	<packaging>mule-application</packaging>
	<name>vfgl-cart-eapi</name>
	
	<properties>
		<mule.maven.plugin.version>3.4.1</mule.maven.plugin.version>
		<app.runtime>4.3.0</app.runtime>

    </properties>
	
	<profiles>
		<profile>
			<id>default</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<properties>
				<packaging.type>mule-application</packaging.type>
				<package.release>-d</package.release>
			</properties>
		</profile>
		<profile>
			<id>prod</id>
			<properties>
				<package.release>-p</package.release>
			</properties>
		</profile>
	</profiles>
	
	<build>
		<finalName>${project.artifactId}-${project.version}${package.release}</finalName>
		<plugins>
			<plugin>
				<groupId>org.mule.tools.maven</groupId>
				<artifactId>mule-maven-plugin</artifactId>
				<version>${mule.maven.plugin.version}</version>
				<extensions>true</extensions>
				<configuration>
					<classifier>mule-application</classifier>
					<cloudHubDeployment>
						<skipDeploymentVerification>${skipVerification}</skipDeploymentVerification>
						<uri>https://anypoint.mulesoft.com</uri>
						<muleVersion>${app.runtime}</muleVersion>
						<server>VFExchange</server>
						<applicationName>${project.name}${APP_SUFFIX}</applicationName>
						<environment>${CLOUDHUB_ENVIRONMENT}</environment>
						<region>${CLOUDHUB_REGION}</region>
						<workers>${CLOUDHUB_WORKERS}</workers>
						<workerType>${CLOUDHUB_WORKER_TYPE}</workerType>
						<businessGroupId>test</businessGroupId>
						<properties>
							<build.commit_id>${build.commit_id}</build.commit_id>
							<build.version>${project.version}</build.version>
							<build.deploy_date>${build.deploy_date}</build.deploy_date>
							<app.name>${project.name}</app.name>
							<mule.env>${mule.env}</mule.env>
							<mule.key>${mule.key}</mule.key>
                            <anypoint.platform.config.analytics.agent.enabled>true</anypoint.platform.config.analytics.agent.enabled>
                            <anypoint.platform.visualizer.layer>Experience</anypoint.platform.visualizer.layer>
                            <anypoint.platform.visualizer.displayName>${project.name}</anypoint.platform.visualizer.displayName>
							<anypoint.platform.client_id>${client_id}</anypoint.platform.client_id>
                            <anypoint.platform.client_secret>${client_secret}</anypoint.platform.client_secret>
							<elk.auth>${elk.auth}</elk.auth>
							<elk.host>${elk.host}</elk.host>
							<mule.flowTrace>${flowTrace}</mule.flowTrace>
						</properties>
					</cloudHubDeployment> 
				</configuration>
			</plugin>
		<plugin>
                <groupId>com.mulesoft.munit.tools</groupId>
                <artifactId>munit-maven-plugin</artifactId>
                <version>${munit.version}</version>
                <executions>
                    <execution>
                        <id>test</id>
                        <phase>test</phase>
                        <goals>
                            <goal>test</goal>
                            <goal>coverage-report</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
					<systemPropertyVariables>
        				<mule.env>dev</mule.env>
						<mule.key>key</mule.key>
        	
      				</systemPropertyVariables>
                    <coverage>
                        <runCoverage>true</runCoverage>
                        <formats>
                            <format>html</format>
                        </formats>
                    </coverage>
                    <skipMunitTests>true</skipMunitTests>
					<runtimeVersion>${app.runtime}</runtimeVersion>
                </configuration>
            </plugin>
        </plugins>
	</build>
	
	<dependencies>
		<dependency>
			<groupId>org.mule.connectors</groupId>
			<artifactId>mule-http-connector</artifactId>
			<classifier>mule-plugin</classifier>
		</dependency>
		<dependency>
			<groupId>org.mule.connectors</groupId>
			<artifactId>mule-sockets-connector</artifactId>
			<classifier>mule-plugin</classifier>
		</dependency>
		<dependency>
			<groupId>org.mule.modules</groupId>
			<artifactId>mule-apikit-module</artifactId>
			<classifier>mule-plugin</classifier>
		</dependency>
		<dependency>
			<groupId>com.mulesoft.munit</groupId>
			<artifactId>munit-runner</artifactId>
			<classifier>mule-plugin</classifier>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.mulesoft.munit</groupId>
			<artifactId>munit-tools</artifactId>
			<classifier>mule-plugin</classifier>
			<scope>test</scope>
		</dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>common-error-handler</artifactId>
            <version>3.0.2</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-sfcc-shopping-baskets-sapi</artifactId>
            <version>0.0.46</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-oms-inventory-sapi</artifactId>
            <version>0.0.10</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-presource-papi</artifactId>
            <version>1.0.11</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-cybersource-sapi</artifactId>
            <version>1.0.20</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-sfcc-orders-papi</artifactId>
            <version>0.0.16</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    	<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>vgfl-cart-eapi</artifactId>
            <version>0.3.18</version>
            <classifier>raml</classifier>
            <type>zip</type>
        </dependency>
    	<dependency>
            <groupId>com.mulesoft.modules</groupId>
            <artifactId>mule-cryptography-module</artifactId>
            <version>1.3.6</version>
            <classifier>mule-plugin</classifier>
        </dependency>
		<dependency>
            <groupId>cd609ea1-1c8a-4d06-9d4d-230aca5955d4</groupId>
            <artifactId>mule-plugin-vfgl-utilities-papi</artifactId>
            <version>0.1.11</version>
            <classifier>mule-plugin</classifier>
        </dependency>
    </dependencies>
	
	<repositories>
		
		<repository>
            <id>VFExchange</id>
            <name>VFGL Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v2/organizations/cd609ea1-1c8a-4d06-9d4d-230aca5955d4/maven</url>
            <layout>default</layout>
        </repository>
		<repository>
            <id>anypoint-exchange-v2</id>
            <name>Anypoint Exchange</name>
            <url>https://maven.anypoint.mulesoft.com/api/v2/maven</url>
            <layout>default</layout>
        </repository>
        <repository>
            <id>mulesoft-releases</id>
            <name>MuleSoft Releases Repository</name>
            <url>https://repository.mulesoft.org/releases/</url>
            <layout>default</layout>
        </repository>
         <repository>
	       <id>central</id>
	       <name>Maven Repository Switchboard</name>
	       <url>https://repo1.maven.org/maven2</url>
     </repository>
    </repositories>
</project>

The issue was in filePattern. Somehow value pom.xml treated incorrectly. To fix an issue I just made it empty. Have no idea how to specify that only one exact file should be analysed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.