*/
static ProjectDefinition convert(MavenProject pom) {
String key = new StringBuilder().append(pom.getGroupId()).append(":").append(pom.getArtifactId()).toString();
- ProjectDefinition definition = ProjectDefinition.create();
- definition.setProperties(pom.getModel().getProperties())
- .setKey(key)
+ ProjectDefinition definition = ProjectDefinition.create(pom.getModel().getProperties());
+ definition.setKey(key)
.setVersion(pom.getVersion())
.setName(pom.getName())
.setDescription(pom.getDescription())
* @param properties project properties
*/
public ProjectDefinition(File baseDir, File workDir, Properties properties) {
- target = org.sonar.api.batch.bootstrap.ProjectDefinition.create()
+ target = org.sonar.api.batch.bootstrap.ProjectDefinition.create(properties)
.setBaseDir(baseDir)
- .setWorkDir(workDir)
- .setProperties(properties);
+ .setWorkDir(workDir);
}
public File getBaseDir() {
private List<ProjectDefinition> subProjects = Lists.newArrayList();
private List<Object> containerExtensions = Lists.newArrayList();
- private ProjectDefinition() {
- }
-
- public static ProjectDefinition create() {
- return new ProjectDefinition();
+ private ProjectDefinition(Properties p) {
+ this.properties = p;
}
- public ProjectDefinition setProperties(Properties p) {
- this.properties = p;
- return this;
+ public static ProjectDefinition create(Properties properties) {
+ return new ProjectDefinition(properties);
}
- public File getBaseDir() {
- return baseDir;
+ public static ProjectDefinition create() {
+ return new ProjectDefinition(new Properties());
}
public ProjectDefinition setBaseDir(File baseDir) {
return this;
}
+ public File getBaseDir() {
+ return baseDir;
+ }
public ProjectDefinition setWorkDir(File workDir) {
this.workDir = workDir;
return this;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.matchers.JUnitMatchers.hasItem;
public class ProjectDefinitionTest {
def.setKey("myKey");
assertThat(def.getName(), is("Unnamed - myKey"));
}
+
@Test
public void shouldGetKeyFromProperties() {
Properties props = new Properties();
props.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");
- ProjectDefinition def = ProjectDefinition.create();
- def.setProperties(props);
+ ProjectDefinition def = ProjectDefinition.create(props);
assertThat(def.getKey(), is("foo"));
}