assertThat(logs).containsPattern("Too small (initial|maximum) heap");
}
+ // SQSCANNER-24
+ @Test
+ public void should_override_project_settings_path() {
+ File projectHome = new File("projects/override-project-settings-path");
+ SonarScanner build = newScanner(projectHome)
+ .setProperty("project.settings", new File(projectHome, "conf/sq-project.properties").getAbsolutePath());
+ orchestrator.executeBuild(build);
+
+ assertThat(getComponent("sample-with-custom-settings-path").getName()).isEqualTo("Test with custom settings location");
+ }
+
}
import java.util.List;
import java.util.Map;
import java.util.Properties;
-
import javax.annotation.Nullable;
-
import org.sonarsource.scanner.api.Utils;
class Conf {
result.putAll(loadEnvironmentProperties());
result.putAll(cli.properties());
result = resolve(result);
-
+
// root project base directory must be present and be absolute
result.setProperty(PROPERTY_PROJECT_BASEDIR, getRootProjectBaseDir(result).toString());
result.remove(PROJECT_HOME);
return moduleProps;
}
- private static Path locatePropertiesFile(Properties props, String homeKey, String relativePathFromHome,
- String settingsKey) {
+ private static Path locatePropertiesFile(Properties props, String homeKey, String relativePathFromHome, String settingsKey) {
Path settingsFile = null;
String scannerHome = props.getProperty(homeKey, "");
if (!"".equals(scannerHome)) {
}
private static Path locatePropertiesFile(@Nullable Path defaultPath, Properties props, String settingsKey) {
- Path settingsFile = defaultPath;
- if (settingsFile == null || !Files.exists(settingsFile)) {
- String settingsPath = props.getProperty(settingsKey, "");
- if (!"".equals(settingsPath)) {
- settingsFile = Paths.get(settingsPath);
- }
+ Path settingsFile;
+ String settingsPath = props.getProperty(settingsKey, "");
+ if (!"".equals(settingsPath)) {
+ settingsFile = Paths.get(settingsPath);
+ } else {
+ settingsFile = defaultPath;
}
if (settingsFile != null) {
Files.delete(linkProjectHome);
}
}
+
+ // SQSCANNER-24
+ @Test
+ public void should_load_project_settings_using_property() throws Exception {
+ Path home = Paths.get(getClass().getResource("ConfTest/shouldOverrideProjectSettingsPath/").toURI());
+ args.setProperty("project.home", home.toAbsolutePath().toString());
+
+ Properties properties = conf.properties();
+ assertThat(properties.get("sonar.prop")).isEqualTo("default");
+
+ args.setProperty("project.settings", home.resolve("conf/sq-project.properties").toAbsolutePath().toString());
+
+ properties = conf.properties();
+ assertThat(properties.get("sonar.prop")).isEqualTo("expected");
+ }
}