aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core/src
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2014-11-21 10:58:48 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2014-11-21 11:08:41 +0100
commit4498173ba720d9ab3d10982894ad76d08c321802 (patch)
tree74e5e2e5048182b0a06eb6fbe4bf0809e22cf8f7 /sonar-core/src
parent50050c7ea204110ee4ac3bf59e8f42f510622f12 (diff)
downloadsonarqube-4498173ba720d9ab3d10982894ad76d08c321802.tar.gz
sonarqube-4498173ba720d9ab3d10982894ad76d08c321802.zip
Centralize algorithm of UUID generation
Diffstat (limited to 'sonar-core/src')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultActionPlan.java5
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java7
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java3
-rw-r--r--sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java3
6 files changed, 12 insertions, 15 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java b/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java
index 2e4ae57f118..517f0e998a7 100644
--- a/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/activity/db/ActivityDto.java
@@ -22,12 +22,11 @@ package org.sonar.core.activity.db;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.api.utils.internal.Uuids;
import org.sonar.core.activity.Activity;
import org.sonar.core.activity.ActivityLog;
import org.sonar.core.persistence.Dto;
-import java.util.UUID;
-
/**
* @since 4.4
*/
@@ -42,7 +41,7 @@ public final class ActivityDto extends Dto<String> {
private String data;
protected ActivityDto() {
- this.key = UUID.randomUUID().toString();
+ this.key = Uuids.create();
}
@Override
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java
index bafd57fbf6d..cc4eba49a18 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java
@@ -21,9 +21,9 @@
package org.sonar.core.issue;
import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.utils.internal.Uuids;
import java.util.Date;
-import java.util.UUID;
public class ActionPlanStats extends DefaultActionPlan {
@@ -36,7 +36,7 @@ public class ActionPlanStats extends DefaultActionPlan {
public static ActionPlanStats create(String name) {
ActionPlanStats actionPlan = new ActionPlanStats();
- actionPlan.setKey(UUID.randomUUID().toString());
+ actionPlan.setKey(Uuids.create());
Date now = new Date();
actionPlan.setName(name);
actionPlan.setStatus(ActionPlan.STATUS_OPEN);
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultActionPlan.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultActionPlan.java
index 6106fd7a9ff..0fe3fd96aeb 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultActionPlan.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultActionPlan.java
@@ -21,12 +21,11 @@
package org.sonar.core.issue;
import org.sonar.api.issue.ActionPlan;
+import org.sonar.api.utils.internal.Uuids;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Date;
-import java.util.UUID;
public class DefaultActionPlan implements ActionPlan {
@@ -46,7 +45,7 @@ public class DefaultActionPlan implements ActionPlan {
public static DefaultActionPlan create(String name) {
DefaultActionPlan actionPlan = new DefaultActionPlan();
- actionPlan.setKey(UUID.randomUUID().toString());
+ actionPlan.setKey(Uuids.create());
Date now = new Date();
actionPlan.setName(name);
actionPlan.setStatus(ActionPlan.STATUS_OPEN);
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
index 3d1eaea3383..e81ae5448b6 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
@@ -20,17 +20,15 @@
package org.sonar.core.issue;
import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.internal.Uuids;
import javax.annotation.Nullable;
-
import java.util.Map;
-import java.util.UUID;
public class DefaultIssueBuilder implements Issuable.IssueBuilder {
@@ -110,8 +108,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder {
Preconditions.checkNotNull(ruleKey, "Rule key must be set");
DefaultIssue issue = new DefaultIssue();
- String key = UUID.randomUUID().toString();
- Preconditions.checkState(!Strings.isNullOrEmpty(key), "Fail to generate issue key");
+ String key = Uuids.create();
issue.setKey(key);
issue.setComponentKey(componentKey);
issue.setProjectKey(projectKey);
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java
index 378c2fca6b2..387d36efa6f 100644
--- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java
@@ -28,6 +28,7 @@ import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.Duration;
import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.api.utils.internal.Uuids;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.persistence.Dto;
import org.sonar.core.rule.RuleDto;
@@ -633,6 +634,6 @@ public final class IssueDto extends Dto<String> implements Serializable {
return new IssueDto()
.setProjectId(Long.valueOf(project.getId()))
.setRuleId(rule.getId())
- .setKee(UUID.randomUUID().toString());
+ .setKee(Uuids.create());
}
}
diff --git a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
index aa2a82606a5..538ff9cbb7f 100644
--- a/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
+++ b/sonar-core/src/main/java/org/sonar/core/resource/ResourceDao.java
@@ -25,6 +25,7 @@ import org.apache.ibatis.session.SqlSession;
import org.sonar.api.component.Component;
import org.sonar.api.resources.Scopes;
import org.sonar.api.utils.System2;
+import org.sonar.api.utils.internal.Uuids;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.component.SnapshotDto;
import org.sonar.core.persistence.DaoComponent;
@@ -151,7 +152,7 @@ public class ResourceDao implements DaoComponent {
if (resource.getId() == null) {
// Fix for Views
if (resource.getUuid() == null && Scopes.PROJECT.equals(resource.getScope())) {
- String uuid = UUID.randomUUID().toString();
+ String uuid = Uuids.create();
resource.setUuid(uuid);
resource.setProjectUuid(uuid);
}