2 * SonarQube, open source software quality management tool.
3 * Copyright (C) 2008-2014 SonarSource
4 * mailto:contact AT sonarsource DOT com
6 * SonarQube is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * SonarQube is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.computation.duplication;
23 import org.junit.rules.ExternalResource;
24 import org.sonar.server.computation.batch.TreeRootHolderRule;
25 import org.sonar.server.computation.component.Component;
26 import org.sonar.server.computation.component.ComponentProvider;
27 import org.sonar.server.computation.component.TreeRootHolder;
28 import org.sonar.server.computation.component.TreeRootHolderComponentProvider;
30 public class DuplicationRepositoryRule extends ExternalResource implements DuplicationRepository {
31 private final TreeRootHolder treeRootHolder;
32 private final ComponentProvider componentProvider;
33 private DuplicationRepositoryImpl delegate;
35 private DuplicationRepositoryRule(TreeRootHolder treeRootHolder) {
36 this.treeRootHolder = treeRootHolder;
37 this.componentProvider = new TreeRootHolderComponentProvider(treeRootHolder);
40 public static DuplicationRepositoryRule create(TreeRootHolderRule treeRootHolder) {
41 return new DuplicationRepositoryRule(treeRootHolder);
45 protected void before() throws Throwable {
46 this.delegate = new DuplicationRepositoryImpl(treeRootHolder);
50 protected void after() {
51 this.componentProvider.reset();
55 public Set<Duplication> getDuplications(int fileRef) {
56 componentProvider.ensureInitialized();
58 return delegate.getDuplications(componentProvider.getByRef(fileRef));
61 public DuplicationRepositoryRule addDuplication(int fileRef, TextBlock original, TextBlock duplicate) {
62 componentProvider.ensureInitialized();
64 delegate.addDuplication(componentProvider.getByRef(fileRef), original, duplicate);
69 public DuplicationRepositoryRule addDuplication(int fileRef, TextBlock original, int otherFileRef, TextBlock duplicate) {
70 componentProvider.ensureInitialized();
72 delegate.addDuplication(componentProvider.getByRef(fileRef), original, componentProvider.getByRef(otherFileRef), duplicate);
77 public DuplicationRepositoryRule addDuplication(int fileRef, TextBlock original, String otherFileKey, TextBlock duplicate) {
78 componentProvider.ensureInitialized();
80 delegate.addDuplication(componentProvider.getByRef(fileRef), original, otherFileKey, duplicate);
86 public Set<Duplication> getDuplications(Component file) {
87 return delegate.getDuplications(file);
91 public void addDuplication(Component file, TextBlock original, TextBlock duplicate) {
92 delegate.addDuplication(file, original, duplicate);
96 public void addDuplication(Component file, TextBlock original, Component otherFile, TextBlock duplicate) {
97 delegate.addDuplication(file, original, otherFile, duplicate);
101 public void addDuplication(Component file, TextBlock original, String otherFileKey, TextBlock duplicate) {
102 delegate.addDuplication(file, original, otherFileKey, duplicate);