@@ -31,7 +31,7 @@ | |||
<dependency> | |||
<groupId>org.sonarsource.orchestrator</groupId> | |||
<artifactId>sonar-orchestrator</artifactId> | |||
<version>3.13</version> | |||
<version>3.15.0.974</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
@@ -115,6 +115,7 @@ | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-dependency-plugin</artifactId> | |||
@@ -130,6 +131,36 @@ | |||
<artifact>org.sonarsource.scanner.cli:sonar-scanner-cli:${scanner.version}:zip</artifact> | |||
</configuration> | |||
</execution> | |||
<execution> | |||
<id>get-linux-scanner</id> | |||
<phase>initialize</phase> | |||
<goals> | |||
<goal>get</goal> | |||
</goals> | |||
<configuration> | |||
<artifact>org.sonarsource.scanner.cli:sonar-scanner-cli:${scanner.version}:zip:linux</artifact> | |||
</configuration> | |||
</execution> | |||
<execution> | |||
<id>get-windows-scanner</id> | |||
<phase>initialize</phase> | |||
<goals> | |||
<goal>get</goal> | |||
</goals> | |||
<configuration> | |||
<artifact>org.sonarsource.scanner.cli:sonar-scanner-cli:${scanner.version}:zip:windows</artifact> | |||
</configuration> | |||
</execution> | |||
<execution> | |||
<id>get-macosx-scanner</id> | |||
<phase>initialize</phase> | |||
<goals> | |||
<goal>get</goal> | |||
</goals> | |||
<configuration> | |||
<artifact>org.sonarsource.scanner.cli:sonar-scanner-cli:${scanner.version}:zip:macosx</artifact> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> |
@@ -0,0 +1,72 @@ | |||
/* | |||
* SonarSource :: IT :: SonarQube Scanner | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package com.sonar.runner.it; | |||
import com.sonar.orchestrator.build.BuildFailureException; | |||
import com.sonar.orchestrator.build.SonarScanner; | |||
import com.sonar.orchestrator.locator.ResourceLocation; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import java.util.Map; | |||
import org.junit.After; | |||
import org.junit.Test; | |||
import org.sonarqube.ws.WsMeasures.Measure; | |||
import static java.lang.Integer.parseInt; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class DistributionTest extends ScannerTestCase { | |||
@After | |||
public void cleanup() { | |||
orchestrator.resetData(); | |||
} | |||
@Test | |||
public void should_succeed_with_self_contained_jre_despite_rubbish_java_home() throws IOException, InterruptedException { | |||
String projectKey = "java:basedir-with-source"; | |||
orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); | |||
orchestrator.getServer().provisionProject(projectKey, "Basedir with source"); | |||
orchestrator.getServer().associateProjectToQualityProfile(projectKey, "java", "sonar-way"); | |||
File projectDir = new File("projects/basedir-with-source"); | |||
SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey) | |||
.setEnvironmentVariable("JAVA_HOME", "nonexistent") | |||
.useNative(); | |||
orchestrator.executeBuild(build, true); | |||
Map<String, Measure> projectMeasures = getMeasures(projectKey, "files", "ncloc"); | |||
assertThat(parseInt(projectMeasures.get("files").getValue())).isEqualTo(1); | |||
assertThat(parseInt(projectMeasures.get("ncloc").getValue())).isGreaterThan(1); | |||
} | |||
@Test(expected = BuildFailureException.class) | |||
public void should_fail_without_self_contained_jre_when_rubbish_java_home() throws IOException, InterruptedException { | |||
String projectKey = "java:basedir-with-source"; | |||
orchestrator.getServer().restoreProfile(ResourceLocation.create("/sonar-way-profile.xml")); | |||
orchestrator.getServer().provisionProject(projectKey, "Basedir with source"); | |||
orchestrator.getServer().associateProjectToQualityProfile(projectKey, "java", "sonar-way"); | |||
File projectDir = new File("projects/basedir-with-source"); | |||
SonarScanner build = newScanner(projectDir, "sonar.projectKey", projectKey) | |||
.setEnvironmentVariable("JAVA_HOME", "nonexistent"); | |||
orchestrator.executeBuild(build, true); | |||
} | |||
} |
@@ -26,7 +26,7 @@ import org.junit.runners.Suite; | |||
import org.junit.runners.Suite.SuiteClasses; | |||
@RunWith(Suite.class) | |||
@SuiteClasses({JavaTest.class, MultimoduleTest.class}) | |||
@SuiteClasses({JavaTest.class, MultimoduleTest.class, DistributionTest.class}) | |||
public class SonarScannerTestSuite { | |||
@ClassRule |
@@ -44,6 +44,14 @@ | |||
<!-- used for deployment to SonarSource Artifactory --> | |||
<gitRepositoryName>sonar-scanner-cli</gitRepositoryName> | |||
<!-- configuration for assembly of distributions --> | |||
<unpack.dir>${project.build.directory}/unpack</unpack.dir> | |||
<scanner.jar>${project.build.finalName}.jar</scanner.jar> | |||
<jre.version>8u121</jre.version> | |||
<jre.dirname.linux>jre1.8.0_121</jre.dirname.linux> | |||
<jre.dirname.windows>jre1.8.0_121</jre.dirname.windows> | |||
<jre.dirname.macosx>jre1.8.0_121.jre/Contents/Home</jre.dirname.macosx> | |||
</properties> | |||
<dependencies> | |||
@@ -129,6 +137,7 @@ | |||
<artifactId>maven-assembly-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>cli</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>single</goal> | |||
@@ -138,8 +147,11 @@ | |||
<appendAssemblyId>false</appendAssemblyId> | |||
<escapeString>\</escapeString> | |||
<descriptors> | |||
<descriptor>${project.basedir}/assembly.xml</descriptor> | |||
<descriptor>src/main/assembly/noarch.xml</descriptor> | |||
</descriptors> | |||
<filters> | |||
<filter>src/main/assembly/filter-noarch.properties</filter> | |||
</filters> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
@@ -179,5 +191,180 @@ | |||
<module>it</module> | |||
</modules> | |||
</profile> | |||
<profile> | |||
<id>dist-linux</id> | |||
<build> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-dependency-plugin</artifactId> | |||
<version>3.0.0</version> | |||
<executions> | |||
<execution> | |||
<id>unpack-linux</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>unpack</goal> | |||
</goals> | |||
<configuration> | |||
<artifactItems> | |||
<artifactItem> | |||
<groupId>com.oracle</groupId> | |||
<artifactId>jre</artifactId> | |||
<version>${jre.version}</version> | |||
<classifier>linux-x64</classifier> | |||
<type>tar.gz</type> | |||
<overWrite>true</overWrite> | |||
</artifactItem> | |||
</artifactItems> | |||
<outputDirectory>${unpack.dir}/linux</outputDirectory> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<plugin> | |||
<artifactId>maven-assembly-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>assemble-linux</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>single</goal> | |||
</goals> | |||
<configuration> | |||
<finalName>sonar-scanner-${project.version}</finalName> | |||
<escapeString>\</escapeString> | |||
<descriptors> | |||
<descriptor>src/main/assembly/dist-linux.xml</descriptor> | |||
</descriptors> | |||
<filters> | |||
<filter>src/main/assembly/filter-dist.properties</filter> | |||
</filters> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</profile> | |||
<profile> | |||
<id>dist-windows</id> | |||
<build> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-dependency-plugin</artifactId> | |||
<version>3.0.0</version> | |||
<executions> | |||
<execution> | |||
<id>unpack-windows</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>unpack</goal> | |||
</goals> | |||
<configuration> | |||
<artifactItems> | |||
<artifactItem> | |||
<groupId>com.oracle</groupId> | |||
<artifactId>jre</artifactId> | |||
<version>${jre.version}</version> | |||
<classifier>windows-x64</classifier> | |||
<type>tar.gz</type> | |||
<overWrite>true</overWrite> | |||
</artifactItem> | |||
</artifactItems> | |||
<outputDirectory>${unpack.dir}/windows</outputDirectory> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
<plugin> | |||
<artifactId>maven-assembly-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>assemble-windows</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>single</goal> | |||
</goals> | |||
<configuration> | |||
<finalName>sonar-scanner-${project.version}</finalName> | |||
<escapeString>\</escapeString> | |||
<descriptors> | |||
<descriptor>src/main/assembly/dist-windows.xml</descriptor> | |||
</descriptors> | |||
<filters> | |||
<filter>src/main/assembly/filter-dist.properties</filter> | |||
</filters> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</profile> | |||
<profile> | |||
<id>dist-macosx</id> | |||
<build> | |||
<plugins> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-dependency-plugin</artifactId> | |||
<version>3.0.0</version> | |||
<executions> | |||
<execution> | |||
<id>unpack-macosx</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>unpack</goal> | |||
</goals> | |||
</execution> | |||
</executions> | |||
<configuration> | |||
<artifactItems> | |||
<artifactItem> | |||
<groupId>com.oracle</groupId> | |||
<artifactId>jre</artifactId> | |||
<version>${jre.version}</version> | |||
<classifier>macosx-x64</classifier> | |||
<type>tar.gz</type> | |||
<overWrite>true</overWrite> | |||
</artifactItem> | |||
</artifactItems> | |||
<outputDirectory>${unpack.dir}/macosx</outputDirectory> | |||
</configuration> | |||
</plugin> | |||
<plugin> | |||
<artifactId>maven-assembly-plugin</artifactId> | |||
<executions> | |||
<execution> | |||
<id>assemble-macosx</id> | |||
<phase>package</phase> | |||
<goals> | |||
<goal>single</goal> | |||
</goals> | |||
<configuration> | |||
<finalName>sonar-scanner-${project.version}</finalName> | |||
<escapeString>\</escapeString> | |||
<descriptors> | |||
<descriptor>src/main/assembly/dist-macosx.xml</descriptor> | |||
</descriptors> | |||
<filters> | |||
<filter>src/main/assembly/filter-dist.properties</filter> | |||
</filters> | |||
</configuration> | |||
</execution> | |||
</executions> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</profile> | |||
</profiles> | |||
</project> |
@@ -36,9 +36,12 @@ sonar_runner_home=$(dirname "$script_path")/.. | |||
# make it fully qualified | |||
sonar_runner_home=$(cd "$sonar_runner_home" && pwd) | |||
# check that the sonar_runner_home has been correctly set | |||
if [ ! -f "$sonar_runner_home/lib/sonar-scanner-cli-${project.version}.jar" ] ; then | |||
echo '$sonar_runner_home' does not point to a valid installation directory: $sonar_runner_home | |||
jar_file=$sonar_runner_home/lib/sonar-scanner-cli-${project.version}.jar | |||
# check that sonar_runner_home has been correctly set | |||
if [ ! -f "$jar_file" ] ; then | |||
echo "File does not exist: $jar_file" | |||
echo "'$sonar_runner_home' does not point to a valid installation directory: $sonar_runner_home" | |||
exit 1 | |||
fi | |||
@@ -57,7 +60,6 @@ then | |||
fi | |||
fi | |||
jar_file=${sonar_runner_home}/lib/sonar-scanner-cli-${project.version}.jar | |||
project_home=$(pwd) | |||
#echo "Info: Using sonar-runner at $sonar_runner_home" |
@@ -35,12 +35,20 @@ sonar_scanner_home=$(dirname "$script_path")/.. | |||
# make it fully qualified | |||
sonar_scanner_home=$(cd "$sonar_scanner_home" && pwd -P) | |||
jar_file=$sonar_scanner_home/lib/sonar-scanner-cli-${project.version}.jar | |||
# check that sonar_scanner_home has been correctly set | |||
if [ ! -f "$sonar_scanner_home/lib/sonar-scanner-cli-${project.version}.jar" ] ; then | |||
echo '$sonar_scanner_home' does not point to a valid installation directory: $sonar_scanner_home | |||
if [ ! -f "$jar_file" ] ; then | |||
echo "File does not exist: $jar_file" | |||
echo "'$sonar_scanner_home' does not point to a valid installation directory: $sonar_scanner_home" | |||
exit 1 | |||
fi | |||
use_embedded_jre=${use_embedded_jre} | |||
if [ "$use_embedded_jre" = true ]; then | |||
export JAVA_HOME=$sonar_scanner_home/lib/jre | |||
fi | |||
if [ -n "$JAVA_HOME" ] | |||
then | |||
java_cmd="$JAVA_HOME/bin/java" | |||
@@ -48,7 +56,6 @@ else | |||
java_cmd="$(which java)" | |||
fi | |||
jar_file=${sonar_scanner_home}/lib/sonar-scanner-cli-${project.version}.jar | |||
project_home=$(pwd) | |||
#echo "Info: Using sonar-scanner at $sonar_scanner_home" |
@@ -13,8 +13,16 @@ set ERROR_CODE=0 | |||
@REM set local scope for the variables with windows NT shell | |||
@setlocal | |||
set SONAR_SCANNER_HOME=%~dp0.. | |||
@REM ==== START VALIDATION ==== | |||
@REM *** JAVA EXEC VALIDATION *** | |||
set use_embedded_jre=${use_embedded_jre} | |||
if "%use_embedded_jre%" == "true" ( | |||
set JAVA_HOME=%SONAR_SCANNER_HOME%\lib\jre | |||
) | |||
if not "%JAVA_HOME%" == "" goto foundJavaHome | |||
for %%i in (java.exe) do set JAVA_EXEC=%%~$PATH:i | |||
@@ -47,7 +55,6 @@ goto error | |||
set JAVA_EXEC="%JAVA_HOME%\bin\java.exe" | |||
:OkJava | |||
set SONAR_SCANNER_HOME=%~dp0.. | |||
goto run | |||
@@ -0,0 +1,58 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<assembly> | |||
<id>linux</id> | |||
<formats> | |||
<format>zip</format> | |||
</formats> | |||
<includeBaseDirectory>true</includeBaseDirectory> | |||
<fileSets> | |||
<!-- jre basic, except bin/ --> | |||
<fileSet> | |||
<directory>${unpack.dir}/linux/${jre.dirname.linux}</directory> | |||
<outputDirectory>lib/jre</outputDirectory> | |||
<excludes> | |||
<exclude>bin/**</exclude> | |||
<exclude>man/**</exclude> | |||
<exclude>plugin/**</exclude> | |||
</excludes> | |||
</fileSet> | |||
<!-- jre bin/java --> | |||
<fileSet> | |||
<directory>${unpack.dir}/linux/${jre.dirname.linux}/bin</directory> | |||
<outputDirectory>lib/jre/bin</outputDirectory> | |||
<includes> | |||
<include>java</include> | |||
</includes> | |||
<fileMode>0755</fileMode> | |||
</fileSet> | |||
<!-- scanner files --> | |||
<fileSet> | |||
<directory>${project.build.directory}</directory> | |||
<outputDirectory>lib</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<includes> | |||
<include>${scanner.jar}</include> | |||
</includes> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/conf</directory> | |||
<outputDirectory>conf</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<lineEnding>unix</lineEnding> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/bin</directory> | |||
<outputDirectory>bin</outputDirectory> | |||
<fileMode>0755</fileMode> | |||
<lineEnding>unix</lineEnding> | |||
<filtered>true</filtered> | |||
<includes> | |||
<include>sonar-scanner</include> | |||
<include>sonar-scanner-debug</include> | |||
</includes> | |||
</fileSet> | |||
</fileSets> | |||
</assembly> |
@@ -0,0 +1,57 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<assembly> | |||
<id>macosx</id> | |||
<formats> | |||
<format>zip</format> | |||
</formats> | |||
<includeBaseDirectory>true</includeBaseDirectory> | |||
<fileSets> | |||
<!-- jre basic, except bin/ --> | |||
<fileSet> | |||
<directory>${unpack.dir}/macosx/${jre.dirname.macosx}</directory> | |||
<outputDirectory>lib/jre</outputDirectory> | |||
<excludes> | |||
<exclude>bin/**</exclude> | |||
<exclude>man/**</exclude> | |||
</excludes> | |||
</fileSet> | |||
<!-- jre bin/java --> | |||
<fileSet> | |||
<directory>${unpack.dir}/macosx/${jre.dirname.macosx}/bin</directory> | |||
<outputDirectory>lib/jre/bin</outputDirectory> | |||
<includes> | |||
<include>java</include> | |||
</includes> | |||
<fileMode>0755</fileMode> | |||
</fileSet> | |||
<!-- scanner files --> | |||
<fileSet> | |||
<directory>${project.build.directory}</directory> | |||
<outputDirectory>lib</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<includes> | |||
<include>${scanner.jar}</include> | |||
</includes> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/conf</directory> | |||
<outputDirectory>conf</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<lineEnding>unix</lineEnding> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/bin</directory> | |||
<outputDirectory>bin</outputDirectory> | |||
<fileMode>0755</fileMode> | |||
<lineEnding>unix</lineEnding> | |||
<filtered>true</filtered> | |||
<includes> | |||
<include>sonar-scanner</include> | |||
<include>sonar-scanner-debug</include> | |||
</includes> | |||
</fileSet> | |||
</fileSets> | |||
</assembly> |
@@ -0,0 +1,55 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<assembly> | |||
<id>windows</id> | |||
<formats> | |||
<format>zip</format> | |||
</formats> | |||
<includeBaseDirectory>true</includeBaseDirectory> | |||
<fileSets> | |||
<!-- jre basic, except bin/ --> | |||
<fileSet> | |||
<directory>${unpack.dir}/windows/${jre.dirname.windows}</directory> | |||
<outputDirectory>lib/jre</outputDirectory> | |||
<excludes> | |||
<exclude>bin/**</exclude> | |||
<exclude>man/**</exclude> | |||
<exclude>plugin/**</exclude> | |||
</excludes> | |||
</fileSet> | |||
<!-- jre bin --> | |||
<fileSet> | |||
<directory>${unpack.dir}/windows/${jre.dirname.windows}/bin</directory> | |||
<outputDirectory>lib/jre/bin</outputDirectory> | |||
<fileMode>0755</fileMode> | |||
</fileSet> | |||
<!-- scanner files --> | |||
<fileSet> | |||
<directory>${project.build.directory}</directory> | |||
<outputDirectory>lib</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<includes> | |||
<include>${scanner.jar}</include> | |||
</includes> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/conf</directory> | |||
<outputDirectory>conf</outputDirectory> | |||
<fileMode>0644</fileMode> | |||
<lineEnding>unix</lineEnding> | |||
</fileSet> | |||
<fileSet> | |||
<directory>src/main/assembly/bin</directory> | |||
<outputDirectory>bin</outputDirectory> | |||
<fileMode>0755</fileMode> | |||
<lineEnding>dos</lineEnding> | |||
<filtered>true</filtered> | |||
<includes> | |||
<include>sonar-scanner.bat</include> | |||
<include>sonar-scanner-debug.bat</include> | |||
</includes> | |||
</fileSet> | |||
</fileSets> | |||
</assembly> |
@@ -0,0 +1 @@ | |||
use_embedded_jre=true |
@@ -0,0 +1 @@ | |||
use_embedded_jre=false |
@@ -11,5 +11,5 @@ configureTravis | |||
export DEPLOY_PULL_REQUEST=true | |||
regular_mvn_build_deploy_analyze | |||
regular_mvn_build_deploy_analyze -Pdist-linux,dist-windows,dist-macosx | |||