Skip to content

Commit

Permalink
SCANMAVEN-233 check that sonar.java.jdkHome has default value even …
Browse files Browse the repository at this point in the history
…without configuration from user (#249)
  • Loading branch information
erwan-serandour authored Oct 30, 2024
1 parent 993000d commit 69c0e1a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
8 changes: 8 additions & 0 deletions its/projects/jdkHome/defaultValue/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sonarsource.it.samples</groupId>
<artifactId>extract-jre</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Sonar :: Integration Tests :: Extract Jre</name>

</project>
12 changes: 12 additions & 0 deletions its/projects/jdkHome/defaultValue/src/main/java/sample/Sample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sample;

public class Sample {

public Sample(int i) {
int j = i++;
}

public String myMethod() {
return "hello";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package sample;

import org.junit.Test;

public class SampleTest {

@Test
public void test() {
new Sample(1).myMethod();
}

}
20 changes: 20 additions & 0 deletions its/src/test/java/com/sonar/maven/it/suite/JavaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ void setJavaVersionProperties() throws IOException {
entry("sonar.java.target", "1.8"));
}

@Test
void when_java_home_exists_it_is_used_as_default_sonar_java_jdkHome_value() throws IOException {
//fix value, the plugin should not modify them
String javaHomeSystem = System.getProperty("java.home");

File outputProps = temp.resolve("out.properties").toFile();
outputProps.createNewFile();
File pom = ItUtils.locateProjectPom("jdkHome/defaultValue");

MavenBuild build = MavenBuild.create(pom)
.setGoals(sonarGoal())
.setProperty("sonar.scanner.internal.dumpToFile", outputProps.getAbsolutePath());
executeBuildAndValidateWithoutCE(build);

Properties props = getProps(outputProps);
String jdkHome = props.getProperty("sonar.java.jdkHome");
//the jdk is not configured in the project, so default value should be used
assertThat(jdkHome).isEqualTo(javaHomeSystem);
}

@Test
void setJdkHomeFromCompilerExecutableConfiguration() throws IOException {
File outputProps = temp.resolve("out.properties").toFile();
Expand Down

0 comments on commit 69c0e1a

Please sign in to comment.