<?xml version="1.0" encoding="UTF-8"?>
<!---->
<project name="sonar-jacoco-module" basedir="." xmlns:jacoco="antlib:org.jacoco.ant" xmlns:sonar="antlib:org.sonar.ant">
<description>Builds the module suite otherSuite.</description><property name="jacoco.dir" location="${nbplatform.default.harness.dir}/jacoco-0.7.1"/>
<property name="result.exec.file" location="${jacoco.dir}/jacoco.exec"/>
<property name="build.test.results.dir" location="build/test/unit/results"/><property file="nbproject/project.properties"/><!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${jacoco.dir}/jacocoant.jar"/>
</taskdef><!-- Target at the level of modules -->
<target name="-do-junit" depends="test-init">
<echo message="Doing testing for jacoco" />
<macrodef name="junit-impl">
<attribute name="test.type"/>
<attribute name="disable.apple.ui" default="false"/>
<sequential>
<jacoco:coverage destfile="${build.test.results.dir}/${code.name.base}_jacoco.exec">
<junit showoutput="true" fork="true" failureproperty="tests.failed" errorproperty="tests.failed"
filtertrace="${test.filter.trace}" tempdir="${build.test.@{test.type}.results.dir}" timeout="${test.timeout}">
<batchtest todir="${build.test.@{test.type}.results.dir}">
<fileset dir="${build.test.@{test.type}.classes.dir}" includes="${test.includes}" excludes="${test.excludes}"/>
</batchtest>
<classpath refid="test.@{test.type}.run.cp"/>
<syspropertyset refid="test.@{test.type}.properties"/>
<jvmarg value="${test.bootclasspath.prepend.args}"/>
<jvmarg line="${test.run.args}"/>
<!--needed to have tests NOT to steal focus when running, works in latest apple jdk update only.-->
<sysproperty key="apple.awt.UIElement" value="@{disable.apple.ui}"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
</junit>
</jacoco:coverage>
<copy file="${build.test.results.dir}/${code.name.base}_jacoco.exec" todir="${suite.dir}/build/coverage"/>
<!--
Copy the result of all the unit tests of all the modules into one common
folder at the level of the suite, so that sonar could find those files to
generate associated reports
-->
<copy todir="${suite.dir}/build/test-results">
<fileset dir="${build.test.results.dir}">
<include name="**/TEST*.xml"/>
</fileset>
</copy>
<fail if="tests.failed" unless="continue.after.failing.tests">Some tests failed; see details above.</fail>
</sequential>
</macrodef>
<junit-impl test.type="${run.test.type}" disable.apple.ui="${disable.apple.ui}"/>
</target></project>
<?xml version="1.0" encoding="UTF-8"?>
<project name="sonar-jacoco-suite" basedir="." xmlns:jacoco="antlib:org.jacoco.ant" xmlns:sonar="antlib:org.sonar.ant">
<description>Builds the module suite otherSuite.</description><property name="jacoco.dir" location="${nbplatform.default.harness.dir}/jacoco-0.7.1"/>
<property name="result.exec.file" location="build/coverage"/> ? ?<!-- Define the SonarQube global properties (the most usual way is to pass these properties via the command line) -->
<property name="sonar.jdbc.url" value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" />
<property name="sonar.jdbc.username" value="sonar" />
<property name="sonar.jdbc.password" value="sonar" />
<!-- Define the SonarQube project properties -->
<property name="sonar.projectKey" value="org.codehaus.sonar:example-java-ant" />
<property name="sonar.projectName" value="Simple Java Project analyzed with the SonarQube Ant Task" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<!-- Load the project properties file for retrieving the modules of the suite -->
<property file="nbproject/project.properties"/><!-- Using Javascript functions to build the paths of the data source for sonar configuration -->
<script language="javascript">?
<![CDATA[// getting the value
modulesName = project.getProperty("modules");
modulesName = modulesName.replace(":",",");
res = modulesName.split(",");
srcModules = "";
binariesModules = "";
testModules = "";
//Build the paths ?
for (var i=0; i<res.length; i++)
{
srcModules += res[i]+"/src,";
binariesModules += res[i]+"/build/classes,";
testModules += res[i]+"/test,";
}
//Remove the last comma
srcModules = srcModules.substring(0, srcModules.length - 1);
binariesModules = binariesModules.substring(0, binariesModules.length - 1);
testModules = testModules.substring(0, testModules.length - 1);
// store the result in a new properties
project.setProperty("srcModulesPath",srcModules);
project.setProperty("binariesModulesPath",binariesModules);
project.setProperty("testModulesPath",testModules);
]]>
</script> ?
<!-- Display the values -->? ? ? ?
<property name="sonar.sources" value="${srcModulesPath}"/>
<property name="sonar.binaries" value="${binariesModulesPath}" />
<property name="sonar.tests" value="${testModulesPath}" />
<!-- Define where the coverage reports are located -->
<!-- Tells SonarQube to reuse existing reports for unit tests execution and coverage reports -->
<property name="sonar.dynamicAnalysis" value="reuseReports" />
<!-- Tells SonarQube where the unit tests execution reports are -->
<property name="sonar.junit.reportsPath" value="build/test-results" />
<!-- Tells SonarQube that the code coverage tool by unit tests is JaCoCo -->
<property name="sonar.java.coveragePlugin" value="jacoco" />
<!-- Tells SonarQube where the unit tests code coverage report is -->
<property name="sonar.jacoco.reportPath" value="${result.exec.file}/merged.exec" />
<!-- ?Step 1: Import JaCoCo Ant tasks ?-->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${jacoco.dir}/jacocoant.jar"/>
</taskdef> ? ?
<target name="merge-coverage"> ? ? ? ?
<jacoco:merge destfile="${result.exec.file}/merged.exec">
<fileset dir="${result.exec.file}" includes="*.exec"/>
</jacoco:merge>
</target><target name="sonar">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="${harness.dir}/sonar-ant-task-2.1/sonar-ant-task-2.1.jar" />
</taskdef><!-- Execute the SonarQube analysis -->
<sonar:sonar />
</target></project>
# Permissions to create tables, indices and triggers
# must be granted to JDBC user.
# The schema must be created first.
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar#----- MySQL 5.x
# Comment the embedded database and uncomment the following
# line to use MySQL
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true