}
private ProjectDefinition defineProject(Properties properties) {
- checkMandatoryProperties("root project", properties, MANDATORY_PROPERTIES_FOR_PROJECT);
+ checkMandatoryProperties(properties, MANDATORY_PROPERTIES_FOR_PROJECT);
File baseDir = new File(properties.getProperty(PROPERTY_PROJECT_BASEDIR));
ProjectDefinition definition = ProjectDefinition.create((Properties) properties.clone())
.setBaseDir(baseDir)
}
private ProjectDefinition loadChildProject(ProjectDefinition parentProject, Properties moduleProps, String moduleId) {
- setProjectKeyIfNotDefined(moduleProps, moduleId);
+ setProjectKeyAndNameIfNotDefined(moduleProps, moduleId);
if (moduleProps.containsKey(PROPERTY_PROJECT_BASEDIR)) {
File baseDir = getFileFromPath(moduleProps.getProperty(PROPERTY_PROJECT_BASEDIR), parentProject.getBaseDir());
}
// and finish
- checkMandatoryProperties(moduleId, moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
+ checkMandatoryProperties(moduleProps, MANDATORY_PROPERTIES_FOR_CHILD);
mergeParentProperties(moduleProps, parentProject.getProperties());
prefixProjectKeyWithParentKey(moduleProps, parentProject.getKey());
}
@VisibleForTesting
- protected static void setProjectKeyIfNotDefined(Properties childProps, String moduleId) {
+ protected static void setProjectKeyAndNameIfNotDefined(Properties childProps, String moduleId) {
if (!childProps.containsKey(PROPERTY_PROJECT_KEY)) {
childProps.put(PROPERTY_PROJECT_KEY, moduleId);
}
+ if (!childProps.containsKey(PROPERTY_PROJECT_NAME)) {
+ childProps.put(PROPERTY_PROJECT_NAME, moduleId);
+ }
}
@VisibleForTesting
}
@VisibleForTesting
- protected static void checkMandatoryProperties(String moduleId, Properties props, String[] mandatoryProps) {
+ protected static void checkMandatoryProperties(Properties props, String[] mandatoryProps) {
replaceDeprecatedProperties(props);
StringBuilder missing = new StringBuilder();
for (String mandatoryProperty : mandatoryProps) {
}
if (missing.length() != 0) {
String projectKey = props.getProperty(PROPERTY_PROJECT_KEY);
- throw new RunnerException("You must define the following mandatory properties for '" + (projectKey == null ? moduleId : projectKey) + "': " + missing);
+ throw new RunnerException("You must define the following mandatory properties for '" + (projectKey == null ? "Unknown" : projectKey) + "': " + missing);
}
}
// Module 1
ProjectDefinition module1 = modules.get(0);
assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-all-in-root/module1"));
- assertThat(module1.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- assertThat(module1.getName()).isEqualTo("Foo Module 1");
+ assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
+ assertThat(module1.getName()).isEqualTo("module1");
assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
// Description should not be inherited from parent if not set
assertThat(module1.getDescription()).isNull();
// Module 1
ProjectDefinition module1 = modules.get(0);
assertThat(module1.getBaseDir().getCanonicalFile()).isEqualTo(TestUtils.getResource(this.getClass(), "multi-module-definitions-in-each-module/module1"));
- assertThat(module1.getKey()).isEqualTo("com.foo.project:com.foo.project.module1");
- assertThat(module1.getName()).isEqualTo("Foo Module 1");
+ assertThat(module1.getKey()).isEqualTo("com.foo.project:module1");
+ assertThat(module1.getName()).isEqualTo("module1");
assertThat(module1.getVersion()).isEqualTo("1.0-SNAPSHOT");
// Description should not be inherited from parent if not set
assertThat(module1.getDescription()).isNull();
props.setProperty("foo4", "bla");
thrown.expect(RunnerException.class);
- thrown.expectMessage("You must define the following mandatory properties for 'foo': foo2, foo3");
+ thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3");
- SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1", "foo2", "foo3"});
+ SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
+ }
+
+ @Test
+ public void shouldFailIfMandatoryPropertiesAreNotPresentButWithProjectKey() {
+ Properties props = new Properties();
+ props.setProperty("foo1", "bla");
+ props.setProperty("sonar.projectKey", "my-project");
+
+ thrown.expect(RunnerException.class);
+ thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3");
+
+ SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"});
}
@Test
props.setProperty("foo1", "bla");
props.setProperty("foo4", "bla");
- SonarProjectBuilder.checkMandatoryProperties("foo", props, new String[] {"foo1"});
+ SonarProjectBuilder.checkMandatoryProperties(props, new String[] {"foo1"});
// No exception should be thrown
}
props.put("sonar.projectVersion", "1.0");
// should be set
- SonarProjectBuilder.setProjectKeyIfNotDefined(props, "foo");
+ SonarProjectBuilder.setProjectKeyAndNameIfNotDefined(props, "foo");
assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+ assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
// but not this 2nd time
- SonarProjectBuilder.setProjectKeyIfNotDefined(props, "bar");
+ SonarProjectBuilder.setProjectKeyAndNameIfNotDefined(props, "bar");
assertThat(props.getProperty("sonar.projectKey")).isEqualTo("foo");
+ assertThat(props.getProperty("sonar.projectName")).isEqualTo("foo");
}
@Test