import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.*;
+import org.sonar.api.resources.Language;
+import org.sonar.api.resources.Library;
+import org.sonar.api.resources.Project;
+import org.sonar.api.resources.Qualifiers;
+import org.sonar.api.resources.Resource;
+import org.sonar.api.resources.ResourceUtils;
+import org.sonar.api.resources.Scopes;
import org.sonar.api.security.ResourcePermissions;
import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.internal.Uuids;
}
if (parentResource != null) {
ResourceModel parentModel = session.getSingleResult(ResourceModel.class, "id", parentResource.getId());
- // FIXME ProjectUUid should never be null but empty (or now ".")
- if (parentModel.getProjectUuid() != null) {
- model.setProjectUuid(parentModel.getProjectUuid());
- } else {
- model.setProjectUuid(parentModel.getUuid());
- }
+ model.setProjectUuid(parentModel.getProjectUuid());
if (Scopes.isProject(parentResource)) {
model.setModuleUuid(parentResource.getUuid());
String parentModuleUuidPath = parentModel.getModuleUuidPath();
- model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath + "." + parentModel.getUuid() : parentModel.getUuid());
+ model.setModuleUuidPath(parentModuleUuidPath + parentModel.getUuid() + ".");
} else {
model.setModuleUuid(parentModel.getModuleUuid());
String parentModuleUuidPath = parentModel.getModuleUuidPath();
- model.setModuleUuidPath(StringUtils.isNotBlank(parentModuleUuidPath) ? parentModuleUuidPath : parentModel.getUuid());
+ model.setModuleUuidPath(parentModuleUuidPath);
}
} else {
// Root module && libraries
model.setProjectUuid(model.getUuid());
- model.setModuleUuidPath("");
+ model.setModuleUuidPath(".");
}
}
assertThat(newProject.uuid()).isNotNull();
assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
assertThat(newProject.moduleUuid()).isNull();
- assertThat(newProject.moduleUuidPath()).isEmpty();
+ assertThat(newProject.moduleUuidPath()).isEqualTo(".");
// SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
assertThat(newProject.getCreatedAt()).isNotNull();
}
assertThat(newProject.uuid()).isNotNull();
assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
assertThat(newProject.moduleUuid()).isNull();
- assertThat(newProject.moduleUuidPath()).isEmpty();
+ assertThat(newProject.moduleUuidPath()).isEqualTo(".");
}
}
assertThat(root.uuid()).isNotNull();
assertThat(root.projectUuid()).isEqualTo(root.uuid());
assertThat(root.moduleUuid()).isNull();
- assertThat(root.moduleUuidPath()).isEmpty();
+ assertThat(root.moduleUuidPath()).isEqualTo(".");
ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
assertThat(a.uuid()).isNotNull();
assertThat(a.projectUuid()).isEqualTo(root.uuid());
assertThat(a.moduleUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuidPath()).isEqualTo(root.uuid());
+ assertThat(a.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
assertThat(b.uuid()).isNotNull();
assertThat(b.projectUuid()).isEqualTo(root.uuid());
assertThat(b.moduleUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuidPath()).isEqualTo(root.uuid());
+ assertThat(b.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
assertThat(b1.uuid()).isNotNull();
assertThat(b1.projectUuid()).isEqualTo(root.uuid());
assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
- assertThat(b1.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid());
+ assertThat(b1.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + ".");
ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
assertThat(dir.uuid()).isNotNull();
assertThat(dir.projectUuid()).isEqualTo(root.uuid());
assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(dir.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+ assertThat(dir.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
assertThat(fileComp.uuid()).isNotNull();
assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(fileComp.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+ assertThat(fileComp.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
}
}
assertThat(root.uuid()).isNotNull();
assertThat(root.projectUuid()).isEqualTo(root.uuid());
assertThat(root.moduleUuid()).isNull();
- assertThat(root.moduleUuidPath()).isEmpty();
+ assertThat(root.moduleUuidPath()).isEqualTo(".");
ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
System.out.println("A: " + a.uuid());
assertThat(a.uuid()).isNotNull();
assertThat(a.projectUuid()).isEqualTo(root.uuid());
assertThat(a.moduleUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuidPath()).isEqualTo(root.uuid());
+ assertThat(a.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
System.out.println("B: " + b.uuid());
assertThat(b.uuid()).isNotNull();
assertThat(b.projectUuid()).isEqualTo(root.uuid());
assertThat(b.moduleUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuidPath()).isEqualTo(root.uuid());
+ assertThat(b.moduleUuidPath()).isEqualTo("." + root.uuid() + ".");
ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
System.out.println("B1: " + b1.uuid());
assertThat(b1.uuid()).isNotNull();
assertThat(b1.projectUuid()).isEqualTo(root.uuid());
assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
- assertThat(b1.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid());
+ assertThat(b1.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + ".");
ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
assertThat(dir.uuid()).isNotNull();
assertThat(dir.projectUuid()).isEqualTo(root.uuid());
assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(dir.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+ assertThat(dir.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
assertThat(fileComp.uuid()).isNotNull();
assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(fileComp.moduleUuidPath()).isEqualTo(root.uuid() + "." + b.uuid() + "." + b1.uuid());
+ assertThat(fileComp.moduleUuidPath()).isEqualTo("." + root.uuid() + "." + b.uuid() + "." + b1.uuid() + ".");
}
}
assertThat(newDir.uuid()).isNotNull();
assertThat(newDir.projectUuid()).isEqualTo(newProject.uuid());
assertThat(newDir.moduleUuid()).isEqualTo(newProject.uuid());
- assertThat(newDir.moduleUuidPath()).isEqualTo(newProject.uuid());
+ assertThat(newDir.moduleUuidPath()).isEqualTo("." + newProject.uuid() + ".");
}
}
assertThat(newLib.uuid()).isNotNull();
assertThat(newLib.projectUuid()).isEqualTo(newLib.uuid());
assertThat(newLib.moduleUuid()).isNull();
- assertThat(newLib.moduleUuidPath()).isEmpty();
+ assertThat(newLib.moduleUuidPath()).isEqualTo(".");
}
}