aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-08-22 10:00:59 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-08-22 10:01:35 +0200
commit9369c4fc6230b858596594473513f9b350d8e284 (patch)
treee9921d9f21d71b49c4edf2b24a4a5019ca527caf /sonar-core
parent90864dacb4972d0251c5659d4cb962fbd919b032 (diff)
downloadsonarqube-9369c4fc6230b858596594473513f9b350d8e284.tar.gz
sonarqube-9369c4fc6230b858596594473513f9b350d8e284.zip
fix quality flaws
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueDto.java9
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/db/IssueKey.java121
2 files changed, 126 insertions, 4 deletions
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 858a1b7c8ff..ddb98282cdc 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
@@ -37,7 +37,7 @@ import java.util.Date;
/**
* @since 3.6
*/
-public final class IssueDto extends Dto<String> implements Serializable {
+public final class IssueDto extends Dto<IssueKey> implements Serializable {
private Long id;
@@ -76,16 +76,17 @@ public final class IssueDto extends Dto<String> implements Serializable {
private String componentKey;
private String rootComponentKey;
-
@Override
- public String getKey() {
- return kee;
+ public IssueKey getKey() {
+ return IssueKey.of(ruleKey, ruleRepo, rootComponentKey, componentKey);
}
+ @Deprecated
public Long getId() {
return id;
}
+ @Deprecated
public IssueDto setId(@Nullable Long id) {
this.id = id;
return this;
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueKey.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueKey.java
new file mode 100644
index 00000000000..b9345a11731
--- /dev/null
+++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueKey.java
@@ -0,0 +1,121 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.issue.db;
+
+import com.google.common.base.Preconditions;
+import org.sonar.api.rule.RuleKey;
+
+import java.io.Serializable;
+
+public class IssueKey implements Serializable {
+
+ private final RuleKey ruleKey;
+ private final String projectKey, componentKey;
+
+ protected IssueKey(RuleKey ruleKey, String projectKey, String componentKey) {
+ Preconditions.checkNotNull(ruleKey, "RuleKey is missing");
+ Preconditions.checkNotNull(projectKey, "Project is missing");
+ this.ruleKey = ruleKey;
+ this.projectKey = projectKey;
+ this.componentKey = componentKey;
+ }
+
+
+ /**
+ * Create a key. Parameters are NOT null.
+ */
+ public static IssueKey of(String ruleKey, String ruleRepo, String rootComponentKey, String componentKey) {
+ return new IssueKey(RuleKey.of(ruleRepo, ruleKey), rootComponentKey, componentKey);
+ }
+
+ /**
+ * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised
+ * if the format is not valid.
+ */
+ public static IssueKey parse(String s) {
+ Preconditions.checkArgument(s.split(":").length >= 4, "Bad format of issueKey key: " + s);
+// int semiColonPos = s.indexOf(":");
+// String key = s.substring(0, semiColonPos);
+// String ruleKey = s.substring(semiColonPos + 1);
+// return IssueKey.of(key, RuleKey.parse(ruleKey));
+ return null;
+ }
+
+ /**
+ * Never null
+ */
+ public RuleKey ruleKey() {
+ return ruleKey;
+ }
+
+ /**
+ * Never null
+ */
+ public String projectKey() {
+ return projectKey;
+ }
+
+ /**
+ * Never null
+ */
+ public String componentKey() {
+ return componentKey;
+ }
+
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ IssueKey key = (IssueKey) o;
+ if (!ruleKey.equals(key.ruleKey)) {
+ return false;
+ }
+ if (!projectKey.equals(key.projectKey)) {
+ return false;
+ }
+ if (!componentKey.equals(key.componentKey)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = ruleKey.hashCode();
+ result = 31 * result + projectKey.hashCode();
+ result = 31 * result + componentKey.hashCode();
+ return result;
+ }
+
+
+ /**
+ * Format is "qprofile:rule:project:component", for example "12345:squid:AvoidCycle"
+ */
+ @Override
+ public String toString() {
+ return String.format("%s:%s:%s", ruleKey.toString(), projectKey(), componentKey());
+ }
+
+}