Add configuration for Sonar

This commit introduces configuration for Sonar in the parent pom
and the pom of the updatesite project. With this, the Jacoco agent
for test coverage is set up and exclusions to ignore generated
files are defined.

Change-Id: I1822b8d739f66f5bb4f69325e5d9f62b02d79557
diff --git a/pom.xml b/pom.xml
index 6512262..31e0d4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -89,6 +89,18 @@
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 		<tycho-version>2.1.0</tycho-version>
 		<org.jboss.tools.tycho-plugins.version>1.6.0</org.jboss.tools.tycho-plugins.version>
+		<jacoco.version>0.8.6</jacoco.version>
+
+		<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../../releng/org.eclipse.capra.releng.p2/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
+		<sonar.surefire.reportsPath>**/surefire-reports/</sonar.surefire.reportsPath>
+		<sonar.exclusions>**/src-gen/**/*,**/xtend-gen/**/*,**/xcore-gen/**/*</sonar.exclusions>
+		<sonar.issue.ignore.allfile>generated</sonar.issue.ignore.allfile>
+		<sonar.issue.ignore.allfile.generated.fileRegexp>@generated</sonar.issue.ignore.allfile.generated.fileRegexp>
+		<sonar.java.source>11</sonar.java.source>
+		<!-- coverage exclusions -->
+		<sonar.coverage.exclusions>**/*.tests/**/*.java,**/*.testsuite/**/*.java</sonar.coverage.exclusions>
+		<!-- duplication exclusion -->
+		<sonar.cpd.exclusions>**/*.tests/**/*.java,**/*.testsuite/**/*.java</sonar.cpd.exclusions>
 	</properties>
 
 	<profiles>
@@ -100,9 +112,38 @@
 				</os>
 			</activation>
 			<properties>
-				<os-jvm-flags>-XstartOnFirstThread</os-jvm-flags>
+				<!-- The property tycho.testArgLine is used by Jacoco to inject
+				     the agent when preparing data for Sonar. By using the same
+				     property, we don't need any extra work for Tycho to pick up
+				     the right argument. Since Jenkins uses Linux, this profiles
+				     is not active when building for Sonar. -->
+				<tycho.testArgLine>-XstartOnFirstThread</tycho.testArgLine>
 			</properties>
 		</profile>
+
+		<profile>
+			<id>sonar</id>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.jacoco</groupId>
+						<artifactId>jacoco-maven-plugin</artifactId>
+
+						<configuration>
+							<sessionId>${project.artifactId}</sessionId>
+						</configuration>
+
+						<executions>
+							<execution>
+								<goals>
+									<goal>prepare-agent</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
 	</profiles>
 
 	<repositories>
@@ -122,9 +163,18 @@
        <connection>scm:git:https://git.eclipse.org/r/capra/org.eclipse.capra.git</connection>
        <developerConnection>scm:git:https://git.eclipse.org/r/capra/org.eclipse.capra.git</developerConnection>
        <tag>0.7.0</tag>
-   </scm>
+	</scm>
 
 	<build>
+		<pluginManagement>
+			<plugins>
+				<plugin>
+					<groupId>org.jacoco</groupId>
+					<artifactId>jacoco-maven-plugin</artifactId>
+					<version>${jacoco.version}</version>
+				</plugin>
+			</plugins>
+		</pluginManagement>
 		<plugins>
 			<plugin>
 				<groupId>org.eclipse.tycho</groupId>
@@ -141,7 +191,7 @@
 				<configuration>
 					<useUIHarness>true</useUIHarness>
 					<useUIThread>true</useUIThread>
-					<argLine>${os-jvm-flags}</argLine>
+					<argLine>${tycho.testArgLine}</argLine>
 					<dependencies>
 						<dependency>
 							<type>eclipse-plugin</type>
@@ -198,4 +248,5 @@
 			</plugin>
 		</plugins>
 	</build>
+
 </project>
diff --git a/releng/org.eclipse.capra.releng.p2/pom.xml b/releng/org.eclipse.capra.releng.p2/pom.xml
index 90816f6..90326de 100644
--- a/releng/org.eclipse.capra.releng.p2/pom.xml
+++ b/releng/org.eclipse.capra.releng.p2/pom.xml
@@ -1,10 +1,10 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- Copyright (c) 
-	2016, 2019 Chalmers | University of Gothenburg, rt-labs and others. All rights 
-	reserved. This program and the accompanying materials are made available 
-	under the terms of the Eclipse Public License v2.0 which accompanies this 
-	distribution, and is available at http://www.eclipse.org/legal/epl-v20.html 
-	SPDX-License-Identifier: EPL-2.0 Contributors: Chalmers | University of Gothenburg 
-	and rt-labs - initial API and implementation and/or initial documentation 
+<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- Copyright (c)
+	2016, 2019 Chalmers | University of Gothenburg, rt-labs and others. All rights
+	reserved. This program and the accompanying materials are made available
+	under the terms of the Eclipse Public License v2.0 which accompanies this
+	distribution, and is available at http://www.eclipse.org/legal/epl-v20.html
+	SPDX-License-Identifier: EPL-2.0 Contributors: Chalmers | University of Gothenburg
+	and rt-labs - initial API and implementation and/or initial documentation
 	Chalmers | University of Gothenburg - additional features, updated API --><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/xsd/maven-4.0.0.xsd">
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
@@ -42,7 +42,7 @@
 			</plugin>
 
 			<!-- Generate HTML version of update site -->
-			<!-- Also add additional repositories. Note that this information could 
+			<!-- Also add additional repositories. Note that this information could
 				be entered in category.xml but Tycho ignores it currently. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=453708 -->
 			<plugin>
 				<groupId>org.jboss.tools.tycho-plugins</groupId>
@@ -79,4 +79,62 @@
 			</plugin>
 		</plugins>
 	</build>
+
+	<profiles>
+		<profile>
+			<id>sonar</id>
+
+			<dependencies>
+				<dependency>
+					<groupId>${project.groupId}</groupId>
+					<artifactId>org.eclipse.capra.testsuite</artifactId>
+					<version>${project.version}</version>
+				</dependency>
+				<dependency>
+					<groupId>${project.groupId}</groupId>
+					<artifactId>org.eclipse.capra.handler.cdt.tests</artifactId>
+					<version>${project.version}</version>
+				</dependency>
+				<dependency>
+					<groupId>${project.groupId}</groupId>
+					<artifactId>org.eclipse.capra.handler.jdt.tests</artifactId>
+					<version>${project.version}</version>
+				</dependency>
+				<dependency>
+					<groupId>${project.groupId}</groupId>
+					<artifactId>org.eclipse.capra.handler.uml.tests</artifactId>
+					<version>${project.version}</version>
+				</dependency>
+				<dependency>
+					<groupId>${project.groupId}</groupId>
+					<artifactId>org.eclipse.capra.handler.featureide.tests</artifactId>
+					<version>${project.version}</version>
+				</dependency>
+
+			</dependencies>
+
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.jacoco</groupId>
+						<artifactId>jacoco-maven-plugin</artifactId>
+
+						<executions>
+							<execution>
+								<id>report-aggregate</id>
+								<phase>prepare-package</phase>
+								<goals>
+									<goal>report-aggregate</goal>
+								</goals>
+								<configuration>
+									<title>Eclipse Capra</title>
+									<footer>Code Coverage Report for Eclipse Capra ${project.version}</footer>
+								</configuration>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
 </project>