diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2024-04-11 16:40:43 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-04-15 20:02:44 +0000 |
commit | 60fee355ef174e184b5c3a477a3c81e95302c754 (patch) | |
tree | 8121df42008f1b20468f45fcae8a2508708b3e69 /sonar-scanner-engine | |
parent | 6d0efcc7475fbf341c25f0ad747bb1edd3addb84 (diff) | |
download | sonarqube-60fee355ef174e184b5c3a477a3c81e95302c754.tar.gz sonarqube-60fee355ef174e184b5c3a477a3c81e95302c754.zip |
SONAR-22054 Make property sonar.projectBaseDir optional
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r-- | sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorBuilder.java | 12 | ||||
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java | 8 |
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"); |