]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3526 no need to populate field authorLogin
authorJulien HENRY <julien.henry@sonarsource.com>
Mon, 15 Jul 2013 10:19:29 +0000 (12:19 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Mon, 15 Jul 2013 11:53:13 +0000 (13:53 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTracking.java
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/IssueTrackingDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingDecoratorTest.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb

index b10d53a67504465def3c76effab6e672cd0798dd..b433614c6300ccff32b77beb818969278e77ed38 100644 (file)
@@ -33,22 +33,11 @@ import org.sonar.api.resources.Resource;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.batch.scan.LastSnapshots;
 import org.sonar.core.issue.db.IssueDto;
-import org.sonar.plugins.core.issue.tracking.HashedSequence;
-import org.sonar.plugins.core.issue.tracking.HashedSequenceComparator;
-import org.sonar.plugins.core.issue.tracking.RollingHashSequence;
-import org.sonar.plugins.core.issue.tracking.RollingHashSequenceComparator;
-import org.sonar.plugins.core.issue.tracking.SourceChecksum;
-import org.sonar.plugins.core.issue.tracking.StringText;
-import org.sonar.plugins.core.issue.tracking.StringTextComparator;
-import org.sonar.plugins.core.issue.tracking.ViolationTrackingBlocksRecognizer;
+import org.sonar.plugins.core.issue.tracking.*;
 
 import javax.annotation.Nullable;
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 public class IssueTracking implements BatchExtension {
 
@@ -113,9 +102,9 @@ public class IssueTracking implements BatchExtension {
     for (DefaultIssue newIssue : newIssues) {
       if (isNotAlreadyMapped(newIssue, result)) {
         mapIssue(
-            newIssue,
-            findLastIssueWithSameLineAndChecksum(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
-            result);
+          newIssue,
+          findLastIssueWithSameLineAndChecksum(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
+          result);
       }
     }
   }
@@ -190,9 +179,9 @@ public class IssueTracking implements BatchExtension {
     for (DefaultIssue newIssue : newIssues) {
       if (isNotAlreadyMapped(newIssue, result)) {
         mapIssue(
-            newIssue,
-            findLastIssueWithSameChecksumAndMessage(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
-            result);
+          newIssue,
+          findLastIssueWithSameChecksumAndMessage(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
+          result);
       }
     }
 
@@ -200,9 +189,9 @@ public class IssueTracking implements BatchExtension {
     for (DefaultIssue newIssue : newIssues) {
       if (isNotAlreadyMapped(newIssue, result)) {
         mapIssue(
-            newIssue,
-            findLastIssueWithSameLineAndMessage(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
-            result);
+          newIssue,
+          findLastIssueWithSameLineAndMessage(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
+          result);
       }
     }
 
@@ -211,9 +200,9 @@ public class IssueTracking implements BatchExtension {
     for (DefaultIssue newIssue : newIssues) {
       if (isNotAlreadyMapped(newIssue, result)) {
         mapIssue(
-            newIssue,
-            findLastIssueWithSameChecksum(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
-            result);
+          newIssue,
+          findLastIssueWithSameChecksum(newIssue, result.unmatchedForRule(newIssue.ruleKey())),
+          result);
       }
     }
   }
index b6b8a2fb2aaf54ce3f89c74df9807bcd521013d9..7b1a97aba85f3c50fc648d6e4263aa27211c2c91 100644 (file)
@@ -64,23 +64,20 @@ public class IssueTrackingDecorator implements Decorator {
   private final ResourcePerspectives perspectives;
   private final RulesProfile rulesProfile;
   private final RuleFinder ruleFinder;
-  private FileLinesContextFactory fileLineContextFactory;
 
   public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking,
-      IssueHandlers handlers, IssueWorkflow workflow,
-      IssueUpdater updater,
-      Project project,
-      ResourcePerspectives perspectives,
-      RulesProfile rulesProfile,
-      RuleFinder ruleFinder,
-      FileLinesContextFactory fileLineContextFactory) {
+                                IssueHandlers handlers, IssueWorkflow workflow,
+                                IssueUpdater updater,
+                                Project project,
+                                ResourcePerspectives perspectives,
+                                RulesProfile rulesProfile,
+                                RuleFinder ruleFinder) {
     this.issueCache = issueCache;
     this.initialOpenIssues = initialOpenIssues;
     this.tracking = tracking;
     this.handlers = handlers;
     this.workflow = workflow;
     this.updater = updater;
-    this.fileLineContextFactory = fileLineContextFactory;
     this.changeContext = IssueChangeContext.createScan(project.getAnalysisDate());
     this.perspectives = perspectives;
     this.rulesProfile = rulesProfile;
@@ -110,8 +107,6 @@ public class IssueTrackingDecorator implements Decorator {
     // all the issues that are not closed in db before starting this module scan, including manual issues
     Collection<IssueDto> dbOpenIssues = initialOpenIssues.selectAndRemove(resource.getEffectiveKey());
 
-    setScmAuthorOnNewIssues(resource, issues);
-
     IssueTrackingResult trackingResult = tracking.track(resource, dbOpenIssues, issues);
 
     // unmatched = issues that have been resolved + issues on disabled/removed rules + manual issues
@@ -131,23 +126,6 @@ public class IssueTrackingDecorator implements Decorator {
     }
   }
 
-  @VisibleForTesting
-  void setScmAuthorOnNewIssues(Resource resource, Collection<DefaultIssue> newIssues) {
-    if (ResourceUtils.isFile(resource)) {
-      FileLinesContext fileLineContext = fileLineContextFactory.createFor(resource);
-      for (DefaultIssue issue : newIssues) {
-        Integer line = issue.line();
-        if (line != null) {
-          // TODO When issue is on line 0 then who is the author?
-          String scmAuthorLogin = fileLineContext.getStringValue(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY, line);
-          if (scmAuthorLogin != null) {
-            issue.setAuthorLogin(scmAuthorLogin);
-          }
-        }
-      }
-    }
-  }
-
   private void mergeMatched(IssueTrackingResult result) {
     for (DefaultIssue issue : result.matched()) {
       IssueDto ref = result.matching(issue);
index 9e8d0e9dbd46cfae7a733d0cd2f1971d4c67d8e1..54d54bc6b658e733a13f5b747e201deee26fe266 100644 (file)
@@ -27,13 +27,10 @@ import org.sonar.api.batch.DecoratorContext;
 import org.sonar.api.component.ResourcePerspectives;
 import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.issue.internal.IssueChangeContext;
-import org.sonar.api.measures.FileLinesContext;
-import org.sonar.api.measures.FileLinesContextFactory;
 import org.sonar.api.profiles.RulesProfile;
 import org.sonar.api.resources.File;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.Scopes;
 import org.sonar.api.rule.RuleKey;
 import org.sonar.api.rules.Rule;
 import org.sonar.api.rules.RuleFinder;
@@ -50,18 +47,7 @@ import java.util.Collections;
 import java.util.List;
 
 import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyCollection;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.RETURNS_MOCKS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
 public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
 
@@ -75,23 +61,20 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
   ResourcePerspectives perspectives = mock(ResourcePerspectives.class);
   RulesProfile profile = mock(RulesProfile.class);
   RuleFinder ruleFinder = mock(RuleFinder.class);
-  private FileLinesContextFactory fileLineContextFactory;
 
   @Before
   public void init() {
-    fileLineContextFactory = mock(FileLinesContextFactory.class);
     decorator = new IssueTrackingDecorator(
-        issueCache,
-        initialOpenIssues,
-        tracking,
-        handlers,
-        workflow,
-        updater,
-        mock(Project.class),
-        perspectives,
-        profile,
-        ruleFinder,
-        fileLineContextFactory);
+      issueCache,
+      initialOpenIssues,
+      tracking,
+      handlers,
+      workflow,
+      updater,
+      mock(Project.class),
+      perspectives,
+      profile,
+      ruleFinder);
   }
 
   @Test
@@ -240,65 +223,4 @@ public class IssueTrackingDecoratorTest extends AbstractDaoTestCase {
       }
     }));
   }
-
-  @Test
-  public void should_update_scm_author_on_new_issues() {
-    Resource resource = mock(Resource.class);
-    FileLinesContext context = mock(FileLinesContext.class);
-    when(context.getStringValue("authors_by_line", 1)).thenReturn("julien");
-    when(fileLineContextFactory.createFor(resource)).thenReturn(context);
-
-    DefaultIssue newIssue = mock(DefaultIssue.class);
-    when(newIssue.line()).thenReturn(1);
-
-    when(resource.getScope()).thenReturn(Scopes.FILE);
-    decorator.setScmAuthorOnNewIssues(resource, Arrays.asList(newIssue));
-
-    verify(newIssue).setAuthorLogin("julien");
-  }
-
-  @Test
-  public void should_not_update_scm_author_when_resource_is_not_a_file() {
-    Resource resource = mock(Resource.class);
-
-    DefaultIssue newIssue = mock(DefaultIssue.class);
-    when(newIssue.line()).thenReturn(1);
-
-    when(resource.getScope()).thenReturn(Scopes.PROJECT);
-    decorator.setScmAuthorOnNewIssues(resource, Arrays.asList(newIssue));
-
-    verify(newIssue, never()).setAuthorLogin(anyString());
-  }
-
-  @Test
-  public void should_not_update_scm_author_when_issue_is_on_line_0() {
-    Resource resource = mock(Resource.class);
-    FileLinesContext context = mock(FileLinesContext.class);
-    when(context.getStringValue("authors_by_line", 1)).thenReturn("julien");
-    when(fileLineContextFactory.createFor(resource)).thenReturn(context);
-
-    DefaultIssue newIssue = mock(DefaultIssue.class);
-    when(newIssue.line()).thenReturn(null);
-
-    when(resource.getScope()).thenReturn(Scopes.FILE);
-    decorator.setScmAuthorOnNewIssues(resource, Arrays.asList(newIssue));
-
-    verify(newIssue, never()).setAuthorLogin(anyString());
-  }
-
-  @Test
-  public void should_not_update_scm_author_when_unknow_scm_author() {
-    Resource resource = mock(Resource.class);
-    FileLinesContext context = mock(FileLinesContext.class);
-    when(context.getStringValue("authors_by_line", 1)).thenReturn(null);
-    when(fileLineContextFactory.createFor(resource)).thenReturn(context);
-
-    DefaultIssue newIssue = mock(DefaultIssue.class);
-    when(newIssue.line()).thenReturn(1);
-
-    when(resource.getScope()).thenReturn(Scopes.FILE);
-    decorator.setScmAuthorOnNewIssues(resource, Arrays.asList(newIssue));
-
-    verify(newIssue, never()).setAuthorLogin(anyString());
-  }
 }
index 72d70638ab55878863ae46cd07ad6568138794c0..cd2867c0d2f62a0580353190ef15edebf5ea2db3 100644 (file)
@@ -52,7 +52,6 @@ public class IssueTrackingTest {
     lastSnapshots = mock(LastSnapshots.class);
 
     project = mock(Project.class);
-
     tracking = new IssueTracking(lastSnapshots, null);
   }
 
@@ -268,9 +267,9 @@ public class IssueTrackingTest {
 
     IssueTrackingResult result = new IssueTrackingResult();
     tracking.mapIssues(
-        Arrays.asList(newIssue1, newIssue2, newIssue3),
-        Arrays.asList(referenceIssue1),
-        source, project, result);
+      Arrays.asList(newIssue1, newIssue2, newIssue3),
+      Arrays.asList(referenceIssue1),
+      source, project, result);
 
     assertThat(result.matching(newIssue1)).isNull();
     assertThat(result.matching(newIssue2)).isSameAs(referenceIssue1);
@@ -284,27 +283,24 @@ public class IssueTrackingTest {
 
     IssueDto referenceIssue1 = newReferenceIssue("Avoid unused local variables such as 'j'.", 6, "squid", "AvoidCycle", "63c11570fc0a76434156be5f8138fa03");
     IssueDto referenceIssue2 = newReferenceIssue("Avoid unused private methods such as 'myMethod()'.", 13, "squid", "NullDeref", "ef23288705d1ef1e512448ace287586e");
-    IssueDto referenceIssue3 = newReferenceIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, "pmd",
-        "UnusedLocalVariable", "ed5cdd046fda82727d6fedd1d8e3a310");
+    IssueDto referenceIssue3 = newReferenceIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, "pmd", "UnusedLocalVariable", "ed5cdd046fda82727d6fedd1d8e3a310");
 
     // New issue
     DefaultIssue newIssue1 = newDefaultIssue("Avoid unused local variables such as 'msg'.", 18, RuleKey.of("squid", "AvoidCycle"), "a24254126be2bf1a9b9a8db43f633733");
     // Same as referenceIssue2
     DefaultIssue newIssue2 = newDefaultIssue("Avoid unused private methods such as 'myMethod()'.", 13, RuleKey.of("squid", "NullDeref"), "ef23288705d1ef1e512448ace287586e");
     // Same as referenceIssue3
-    DefaultIssue newIssue3 = newDefaultIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9,
-        RuleKey.of("pmd", "UnusedLocalVariable"), "ed5cdd046fda82727d6fedd1d8e3a310");
+    DefaultIssue newIssue3 = newDefaultIssue("Method 'avoidUtilityClass' is not designed for extension - needs to be abstract, final or empty.", 9, RuleKey.of("pmd", "UnusedLocalVariable"), "ed5cdd046fda82727d6fedd1d8e3a310");
     // New issue
-    DefaultIssue newIssue4 = newDefaultIssue("Method 'newViolation' is not designed for extension - needs to be abstract, final or empty.", 17,
-        RuleKey.of("pmd", "UnusedLocalVariable"), "7d58ac9040c27e4ca2f11a0269e251e2");
+    DefaultIssue newIssue4 = newDefaultIssue("Method 'newViolation' is not designed for extension - needs to be abstract, final or empty.", 17, RuleKey.of("pmd", "UnusedLocalVariable"), "7d58ac9040c27e4ca2f11a0269e251e2");
     // Same as referenceIssue1
     DefaultIssue newIssue5 = newDefaultIssue("Avoid unused local variables such as 'j'.", 6, RuleKey.of("squid", "AvoidCycle"), "4432a2675ec3e1620daefe38386b51ef");
 
     IssueTrackingResult result = new IssueTrackingResult();
     tracking.mapIssues(
-        Arrays.asList(newIssue1, newIssue2, newIssue3, newIssue4, newIssue5),
-        Arrays.asList(referenceIssue1, referenceIssue2, referenceIssue3),
-        source, project, result);
+      Arrays.asList(newIssue1, newIssue2, newIssue3, newIssue4, newIssue5),
+      Arrays.asList(referenceIssue1, referenceIssue2, referenceIssue3),
+      source, project, result);
 
     assertThat(result.matching(newIssue1)).isNull();
     assertThat(result.matching(newIssue2)).isSameAs(referenceIssue2);
index ff010384541d99f3f25628cb53317b73fe7be70a..56e8e7dcc892924e05294b7901a939364d621d63 100644 (file)
@@ -32,7 +32,7 @@
     <% if issue.authorLogin %>
       <img src="<%= ApplicationController.root_context -%>/images/sep12.png"/>
       &nbsp;
-      <span><%= message('issue.authorLogin') -%> <%= issue.authorLogin -%></span>
+     <span><%= message('issue.authorLogin') -%> <%= issue.authorLogin -%></span>
       &nbsp;
     <% end %>
   </div>