]> source.dussan.org Git - sonarqube.git/commitdiff
Fix some quality flaws
authorSimon Brandhof <simon.brandhof@gmail.com>
Sun, 2 Jun 2013 22:46:58 +0000 (00:46 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Sun, 2 Jun 2013 22:46:58 +0000 (00:46 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplate.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/notification/NewIssuesEmailTemplateTest.java
sonar-core/src/main/java/org/sonar/core/issue/ActionPlanStats.java
sonar-core/src/main/java/org/sonar/core/issue/DefaultIssueBuilder.java
sonar-server/src/main/java/org/sonar/server/issue/IssueChangeService.java

index b3e883b273e5cfc8dd44270ec8d21eeec786d52f..c07e6adaa29a317f8f265f80470d4ce99d8d3973 100644 (file)
@@ -65,10 +65,12 @@ public class NewIssuesEmailTemplate extends EmailTemplate {
   private void appendFooter(StringBuilder sb, Notification notification) {
     String projectKey = notification.getFieldValue("projectKey");
     String dateString = notification.getFieldValue("projectDate");
-    Date date = DateUtils.parseDateTime(dateString);
-    String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s",
-      settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date));
-    sb.append("\n").append("See it in SonarQube: ").append(url).append("\n");
+    if (projectKey != null && dateString != null) {
+      Date date = DateUtils.parseDateTime(dateString);
+      String url = String.format("%s/issues/search?componentRoots=%s&createdAfter=%s",
+        settings.getServerBaseURL(), URLEncoder.encode(projectKey), DateUtils.formatDate(date));
+      sb.append("\n").append("See it in SonarQube: ").append(url).append("\n");
+    }
   }
 
 }
index 238b68109014958e56e0af9688a18091d89471dc..f3f8b1cf42cff3360a03d9eb6d8c70dfea92588a 100644 (file)
@@ -75,4 +75,14 @@ public class NewIssuesEmailTemplateTest {
       "\n" +
       "See it in SonarQube: http://nemo.sonarsource.org/issues/search?componentRoots=org.apache%3Astruts&createdAfter=2010-05-18\n");
   }
+
+  @Test
+  public void shouldNotAddFooterIfMissingProperties() {
+    Notification notification = new Notification("new-issues")
+      .setFieldValue("count", "32")
+      .setFieldValue("projectName", "Struts");
+
+    EmailMessage message = template.format(notification);
+    assertThat(message.getMessage()).doesNotContain("See it");
+  }
 }
index 371125642c57c61e42b4fe45e1f7f2cc1f4e83fa..30f7c66c072a1de6b8074ffc88401695b5e1bf5d 100644 (file)
@@ -71,6 +71,7 @@ public class ActionPlanStats extends DefaultActionPlan {
   }
 
   public boolean overDue(){
-    return isOpen() && deadLine() != null && new Date().after(deadLine());
+    Date deadline = deadLine();
+    return isOpen() && deadline != null && new Date().after(deadline);
   }
 }
index be3bb84b722111bf780cf8e9b81cea9ee7bd0ed2..a8a8c303c2f6bcdd4123f15d4e1e9f72b69b5cc1 100644 (file)
@@ -71,7 +71,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder {
   }
 
   @Override
-  public Issuable.IssueBuilder severity(String severity) {
+  public Issuable.IssueBuilder severity(@Nullable String severity) {
     this.severity = severity;
     return this;
   }
@@ -89,7 +89,7 @@ public class DefaultIssueBuilder implements Issuable.IssueBuilder {
   }
 
   @Override
-  public Issuable.IssueBuilder attribute(String key, String value) {
+  public Issuable.IssueBuilder attribute(String key, @Nullable String value) {
     if (attributes == null) {
       attributes = Maps.newLinkedHashMap();
     }
index 450f35c44d0fe475f6cc05bbb635361390cf52da..3d73cbdea8c28f53f506986fcb1efec1cb678c35 100644 (file)
@@ -125,8 +125,13 @@ public class IssueChangeService implements ServerComponent {
     }
   }
 
+  // TODO remove this duplication from IssueService
   public IssueQueryResult loadIssue(String issueKey) {
     IssueQuery query = IssueQuery.builder().issueKeys(Arrays.asList(issueKey)).requiredRole(UserRole.USER).build();
-    return finder.find(query);
+    IssueQueryResult result = finder.find(query);
+    if (result.issues().size()!=1) {
+      throw new IllegalStateException("Issue not found: " + issueKey);
+    }
+    return result;
   }
 }