Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCANMAVEN-233 check that sonar.java.jdkHome has default value even without configuration from user #249

Merged
merged 7 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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