Skip to content

Commit 69c0e1a

Browse files
SCANMAVEN-233 check that sonar.java.jdkHome has default value even without configuration from user (#249)
1 parent 993000d commit 69c0e1a

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.sonarsource.it.samples</groupId>
4+
<artifactId>extract-jre</artifactId>
5+
<version>1.0-SNAPSHOT</version>
6+
<name>Sonar :: Integration Tests :: Extract Jre</name>
7+
8+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package sample;
2+
3+
public class Sample {
4+
5+
public Sample(int i) {
6+
int j = i++;
7+
}
8+
9+
public String myMethod() {
10+
return "hello";
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package sample;
2+
3+
import org.junit.Test;
4+
5+
public class SampleTest {
6+
7+
@Test
8+
public void test() {
9+
new Sample(1).myMethod();
10+
}
11+
12+
}

its/src/test/java/com/sonar/maven/it/suite/JavaTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ void setJavaVersionProperties() throws IOException {
120120
entry("sonar.java.target", "1.8"));
121121
}
122122

123+
@Test
124+
void when_java_home_exists_it_is_used_as_default_sonar_java_jdkHome_value() throws IOException {
125+
//fix value, the plugin should not modify them
126+
String javaHomeSystem = System.getProperty("java.home");
127+
128+
File outputProps = temp.resolve("out.properties").toFile();
129+
outputProps.createNewFile();
130+
File pom = ItUtils.locateProjectPom("jdkHome/defaultValue");
131+
132+
MavenBuild build = MavenBuild.create(pom)
133+
.setGoals(sonarGoal())
134+
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
135+
executeBuildAndValidateWithoutCE(build);
136+
137+
Properties props = getProps(outputProps);
138+
String jdkHome = props.getProperty("sonar.java.jdkHome");
139+
//the jdk is not configured in the project, so default value should be used
140+
assertThat(jdkHome).isEqualTo(javaHomeSystem);
141+
}
142+
123143
@Test
124144
void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
125145
File outputProps = temp.resolve("out.properties").toFile();

0 commit comments

Comments
 (0)