aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-18 14:07:18 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2014-04-18 14:07:18 +0200
commitf9f85043a17edeb69f3ea5a93e56b4d60e3a22ae (patch)
treeb0d03b8352f156e560229309601e22103fedde49 /sonar-batch
parent6334cb7d7397e1455099611b3b1259ad050706e6 (diff)
downloadsonarqube-f9f85043a17edeb69f3ea5a93e56b4d60e3a22ae.tar.gz
sonarqube-f9f85043a17edeb69f3ea5a93e56b4d60e3a22ae.zip
Revert "SONAR-5218 Once a module has been turned into a project, its issues are no more visible in the UI"
This reverts commit 6334cb7d7397e1455099611b3b1259ad050706e6.
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java1
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java21
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java6
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java46
8 files changed, 47 insertions, 49 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
index 578bb2bb49e..62b44e7d69e 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java
@@ -24,7 +24,6 @@ import org.sonar.api.component.Component;
import org.sonar.api.issue.Issuable;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.api.resources.Project;
import org.sonar.core.issue.DefaultIssueBuilder;
import java.util.List;
@@ -37,18 +36,16 @@ public class DefaultIssuable implements Issuable {
private final ModuleIssues moduleIssues;
private final IssueCache cache;
private final Component component;
- private final Project project;
- DefaultIssuable(Component component, Project project, ModuleIssues moduleIssues, IssueCache cache) {
+ DefaultIssuable(Component component, ModuleIssues moduleIssues, IssueCache cache) {
this.component = component;
- this.project = project;
this.moduleIssues = moduleIssues;
this.cache = cache;
}
@Override
public IssueBuilder newIssueBuilder() {
- return new DefaultIssueBuilder().componentKey(component.key()).projectKey(project.getKey());
+ return new DefaultIssueBuilder().componentKey(component.key());
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
index 7491bbb7814..147ab7c7c15 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssuableFactory.java
@@ -22,7 +22,6 @@ package org.sonar.batch.issue;
import org.sonar.api.component.Component;
import org.sonar.api.issue.Issuable;
import org.sonar.api.resources.Scopes;
-import org.sonar.batch.ProjectTree;
import org.sonar.core.component.PerspectiveBuilder;
import org.sonar.core.component.ResourceComponent;
@@ -36,13 +35,11 @@ public class IssuableFactory extends PerspectiveBuilder<Issuable> {
private final ModuleIssues moduleIssues;
private final IssueCache cache;
- private final ProjectTree projectTree;
- public IssuableFactory(ModuleIssues moduleIssues, IssueCache cache, ProjectTree projectTree) {
+ public IssuableFactory(ModuleIssues moduleIssues, IssueCache cache) {
super(Issuable.class);
this.moduleIssues = moduleIssues;
this.cache = cache;
- this.projectTree = projectTree;
}
@CheckForNull
@@ -52,6 +49,6 @@ public class IssuableFactory extends PerspectiveBuilder<Issuable> {
if (component instanceof ResourceComponent) {
supported = Scopes.isHigherThanOrEquals(((ResourceComponent) component).scope(), Scopes.FILE);
}
- return supported ? new DefaultIssuable(component, projectTree.getRootProject(), moduleIssues, cache) : null;
+ return supported ? new DefaultIssuable(component, moduleIssues, cache) : null;
}
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
index 6f46e2cc7a9..c0a49d68671 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java
@@ -67,7 +67,6 @@ public class ModuleIssues {
private DefaultIssue newIssue(Violation violation) {
return (DefaultIssue) new DefaultIssueBuilder()
.componentKey(violation.getResource().getEffectiveKey())
- .projectKey(project.getRoot().getEffectiveKey())
.ruleKey(RuleKey.of(violation.getRule().getRepositoryKey(), violation.getRule().getKey()))
.effortToFix(violation.getCost())
.line(violation.getLineId())
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java
index 723082eb335..23dab80cde1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ScanIssueStorage.java
@@ -23,7 +23,6 @@ import org.sonar.api.BatchComponent;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.rules.RuleFinder;
-import org.sonar.batch.ProjectTree;
import org.sonar.batch.index.SnapshotCache;
import org.sonar.core.issue.db.IssueStorage;
import org.sonar.core.persistence.MyBatis;
@@ -35,18 +34,16 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent {
private final SnapshotCache snapshotCache;
private final ResourceDao resourceDao;
- private final ProjectTree projectTree;
- public ScanIssueStorage(MyBatis mybatis, RuleFinder ruleFinder, SnapshotCache snapshotCache, ResourceDao resourceDao, ProjectTree projectTree) {
+ public ScanIssueStorage(MyBatis mybatis, RuleFinder ruleFinder, SnapshotCache snapshotCache, ResourceDao resourceDao) {
super(mybatis, ruleFinder);
this.snapshotCache = snapshotCache;
this.resourceDao = resourceDao;
- this.projectTree = projectTree;
}
@Override
protected long componentId(DefaultIssue issue) {
- Snapshot snapshot = snapshotCache.get(issue.componentKey());
+ Snapshot snapshot = getSnapshot(issue);
if (snapshot != null) {
return snapshot.getResourceId();
}
@@ -61,7 +58,19 @@ public class ScanIssueStorage extends IssueStorage implements BatchComponent {
@Override
protected long projectId(DefaultIssue issue) {
- return projectTree.getRootProject().getId();
+ Snapshot snapshot = getSnapshot(issue);
+ if (snapshot != null) {
+ return snapshot.getRootProjectId();
+ }
+ throw new IllegalStateException("Project id not found for: " + issue.componentKey());
+ }
+
+ private Snapshot getSnapshot(DefaultIssue issue) {
+ Snapshot snapshot = snapshotCache.get(issue.componentKey());
+ if (snapshot != null) {
+ return snapshot;
+ }
+ return null;
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
index 90721058222..1f557c64ad1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DefaultIssuableTest.java
@@ -23,7 +23,6 @@ import org.junit.Test;
import org.sonar.api.component.Component;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.api.resources.Project;
import java.util.Arrays;
import java.util.List;
@@ -36,7 +35,6 @@ public class DefaultIssuableTest {
ModuleIssues moduleIssues = mock(ModuleIssues.class);
IssueCache cache = mock(IssueCache.class);
- Project project = mock(Project.class);
Component component = mock(Component.class);
@Test
@@ -46,7 +44,7 @@ public class DefaultIssuableTest {
DefaultIssue unresolved = new DefaultIssue();
when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved));
- DefaultIssuable perspective = new DefaultIssuable(component, project, moduleIssues, cache);
+ DefaultIssuable perspective = new DefaultIssuable(component, moduleIssues, cache);
List<Issue> issues = perspective.issues();
assertThat(issues).containsOnly(unresolved);
@@ -59,7 +57,7 @@ public class DefaultIssuableTest {
DefaultIssue unresolved = new DefaultIssue();
when(cache.byComponent("struts:org.apache.Action")).thenReturn(Arrays.asList(resolved, unresolved));
- DefaultIssuable perspective = new DefaultIssuable(component, project, moduleIssues, cache);
+ DefaultIssuable perspective = new DefaultIssuable(component, moduleIssues, cache);
List<Issue> issues = perspective.resolvedIssues();
assertThat(issues).containsOnly(resolved);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
index 4753023ccbc..d11d0a72111 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/IssuableFactoryTest.java
@@ -25,7 +25,6 @@ import org.sonar.api.component.Component;
import org.sonar.api.issue.Issuable;
import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
-import org.sonar.batch.ProjectTree;
import org.sonar.core.component.ResourceComponent;
import static org.fest.assertions.Assertions.assertThat;
@@ -35,11 +34,10 @@ public class IssuableFactoryTest {
ModuleIssues moduleIssues = mock(ModuleIssues.class);
IssueCache cache = mock(IssueCache.class, Mockito.RETURNS_MOCKS);
- ProjectTree projectTree = mock(ProjectTree.class);
@Test
public void file_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree);
+ IssuableFactory factory = new IssuableFactory(moduleIssues, cache);
Component component = new ResourceComponent(new File("foo/bar.c").setEffectiveKey("foo/bar.c"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
@@ -50,7 +48,7 @@ public class IssuableFactoryTest {
@Test
public void project_should_be_issuable() throws Exception {
- IssuableFactory factory = new IssuableFactory(moduleIssues, cache, projectTree);
+ IssuableFactory factory = new IssuableFactory(moduleIssues, cache);
Component component = new ResourceComponent(new Project("Foo").setEffectiveKey("foo"));
Issuable issuable = factory.loadPerspective(Issuable.class, component);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
index bacfe55be16..3df87485b74 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ModuleIssuesTest.java
@@ -73,7 +73,6 @@ public class ModuleIssuesTest {
public void setUp() {
when(project.getAnalysisDate()).thenReturn(new Date());
when(project.getEffectiveKey()).thenReturn("org.apache:struts-core");
- when(project.getRoot()).thenReturn(project);
}
@Test
@@ -226,7 +225,6 @@ public class ModuleIssuesTest {
assertThat(issue.key()).isNotEmpty();
assertThat(issue.ruleKey().toString()).isEqualTo("squid:AvoidCycle");
assertThat(issue.componentKey()).isEqualTo("struts:src/org/struts/Action.java");
- assertThat(issue.projectKey()).isEqualTo("org.apache:struts-core");
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java
index 8866851b3da..7875ae97f25 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/ScanIssueStorageTest.java
@@ -19,19 +19,13 @@
*/
package org.sonar.batch.issue;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.issue.internal.DefaultIssue;
-import org.sonar.api.resources.Project;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.Rule;
import org.sonar.api.rules.RuleFinder;
import org.sonar.api.rules.RuleQuery;
-import org.sonar.batch.ProjectTree;
import org.sonar.batch.index.SnapshotCache;
import org.sonar.core.persistence.AbstractDaoTestCase;
import org.sonar.core.resource.ResourceDao;
@@ -40,28 +34,16 @@ import java.util.Collection;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
public class ScanIssueStorageTest extends AbstractDaoTestCase {
-
- @Mock
- SnapshotCache snapshotCache;
-
- @Mock
- ProjectTree projectTree;
-
- ScanIssueStorage storage;
-
- @Before
- public void setUp() throws Exception {
- storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()), projectTree);
- }
-
@Test
public void should_load_component_id_from_cache() throws Exception {
+ SnapshotCache snapshotCache = mock(SnapshotCache.class);
when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123));
+ ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(componentId).isEqualTo(123);
@@ -70,8 +52,10 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase {
@Test
public void should_load_component_id_from_db() throws Exception {
setupData("should_load_component_id_from_db");
+ SnapshotCache snapshotCache = mock(SnapshotCache.class);
when(snapshotCache.get("struts:Action.java")).thenReturn(null);
+ ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
long componentId = storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(componentId).isEqualTo(123);
@@ -80,8 +64,10 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase {
@Test
public void should_fail_to_load_component_id_if_unknown_component() throws Exception {
setupData("should_fail_to_load_component_id_if_unknown_component");
+ SnapshotCache snapshotCache = mock(SnapshotCache.class);
when(snapshotCache.get("struts:Action.java")).thenReturn(null);
+ ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
try {
storage.componentId(new DefaultIssue().setComponentKey("struts:Action.java"));
fail();
@@ -92,13 +78,29 @@ public class ScanIssueStorageTest extends AbstractDaoTestCase {
@Test
public void should_load_project_id() throws Exception {
- when(projectTree.getRootProject()).thenReturn((Project) new Project("struts").setId(100));
+ SnapshotCache snapshotCache = mock(SnapshotCache.class);
+ when(snapshotCache.get("struts:Action.java")).thenReturn(new Snapshot().setResourceId(123).setRootProjectId(100));
+ ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
long projectId = storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
assertThat(projectId).isEqualTo(100);
}
+ @Test
+ public void should_fail_to_load_project_id_if_unknown_component() throws Exception {
+ SnapshotCache snapshotCache = mock(SnapshotCache.class);
+ when(snapshotCache.get("struts:Action.java")).thenReturn(null);
+
+ ScanIssueStorage storage = new ScanIssueStorage(getMyBatis(), new FakeRuleFinder(), snapshotCache, new ResourceDao(getMyBatis()));
+ try {
+ storage.projectId(new DefaultIssue().setComponentKey("struts:Action.java"));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).hasMessage("Project id not found for: struts:Action.java");
+ }
+ }
+
static class FakeRuleFinder implements RuleFinder {
@Override