aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java12
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java8
2 files changed, 18 insertions, 2 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
index 858c302e093..3b487e3b208 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java
@@ -60,7 +60,6 @@ public class ProjectReactorBuilder {
private static final String INVALID_VALUE_OF_X_FOR_Y = "Invalid value of {0} for {1}";
-
private static final Logger LOG = Loggers.get(ProjectReactorBuilder.class);
@VisibleForTesting
@@ -125,7 +124,9 @@ public class ProjectReactorBuilder {
Profiler profiler = Profiler.create(LOG).startInfo("Process project properties");
Map<String, Map<String, String>> propertiesByModuleIdPath = new HashMap<>();
extractPropertiesByModule(propertiesByModuleIdPath, "", "", new HashMap<>(scannerProps.properties()));
- ProjectDefinition rootProject = createModuleDefinition(propertiesByModuleIdPath.get(""), null);
+ var rootModuleProperties = propertiesByModuleIdPath.get("");
+ setBaseDirIfNeeded(rootModuleProperties);
+ ProjectDefinition rootProject = createModuleDefinition(rootModuleProperties, null);
rootProjectWorkDir = rootProject.getWorkDir();
defineChildren(rootProject, propertiesByModuleIdPath, "");
cleanAndCheckProjectDefinitions(rootProject);
@@ -133,6 +134,13 @@ public class ProjectReactorBuilder {
return new ProjectReactor(rootProject);
}
+ private static void setBaseDirIfNeeded(Map<String, String> rootModuleProperties) {
+ var baseDir = rootModuleProperties.get(PROPERTY_PROJECT_BASEDIR);
+ if (StringUtils.isBlank(baseDir)) {
+ rootModuleProperties.put(PROPERTY_PROJECT_BASEDIR, Paths.get("").toAbsolutePath().toString());
+ }
+ }
+
private static void extractPropertiesByModule(Map<String, Map<String, String>> propertiesByModuleIdPath, String currentModuleId, String currentModuleIdPath,
Map<String, String> parentProperties) {
if (propertiesByModuleIdPath.containsKey(currentModuleIdPath)) {
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
index 7ed5fc9e084..4092d2f7e0f 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java
@@ -51,6 +51,14 @@ public class ProjectReactorBuilderTest {
public LogTester logTester = new LogTester();
@Test
+ public void projectBaseDirDefaultToCurrentDirectory() {
+ ScannerProperties bootstrapProps = new ScannerProperties(Map.of("sonar.projectKey", "foo"));
+ ProjectReactor projectReactor = new ProjectReactorBuilder(bootstrapProps, mock(AnalysisWarnings.class)).execute();
+ var def = projectReactor.getRoot();
+ assertThat(def.getBaseDir()).isEqualTo(new File("").getAbsoluteFile());
+ }
+
+ @Test
public void shouldDefineSimpleProject() {
ProjectDefinition projectDefinition = loadProjectDefinition("simple-project");