import java.util.List;
public class PmdPlugin extends SonarPlugin {
- @SuppressWarnings("unchecked")
public List<Class<? extends Extension>> getExtensions() {
return ImmutableList.of(
PmdSensor.class,
return new ClonePart(resourceId, unitStart, unitStart, unitStart + cloneUnitLength + LINES_PER_BLOCK - 1);
}
- protected abstract List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks);
+ protected abstract List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks);
/**
* Given:
CloneIndex index = createIndex(
newBlocks("y", "2 3 4 5"),
newBlocks("z", "3 4"));
- List<Block> fileBlocks = newBlocks("x", "1 2 3 4 5 6");
+ Block[] fileBlocks = newBlocks("x", "1 2 3 4 5 6");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
CloneIndex cloneIndex = createIndex(
newBlocks("a", "2 3 4 5"),
newBlocks("b", "3 4"));
- List<Block> fileBlocks = newBlocks("c", "1 2 3 4 5 6");
+ Block[] fileBlocks = newBlocks("c", "1 2 3 4 5 6");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
CloneIndex index = createIndex(
newBlocks("b", "3 4 5 6"),
newBlocks("c", "5 6 7"));
- List<Block> fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 4 5 6 7 8 9");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
CloneIndex index = createIndex(
newBlocks("b", "1 2 3 4 1 2 3 4 1 2 3 4"),
newBlocks("c", "1 2 3 4"));
- List<Block> fileBlocks = newBlocks("a", "1 2 3 5");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 5");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@Test
public void clonesInFileItself() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("a", "1 2 3 1 2 4");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 1 2 4");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
public void covered() {
CloneIndex index = createIndex(
newBlocks("b", "1 2 1 2"));
- List<Block> fileBlocks = newBlocks("a", "1 2 1");
+ Block[] fileBlocks = newBlocks("a", "1 2 1");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
public void problemWithNestedCloneGroups() {
CloneIndex index = createIndex(
newBlocks("b", "1 2 1 2 1 2 1"));
- List<Block> fileBlocks = newBlocks("a", "1 2 1 2 1 2");
+ Block[] fileBlocks = newBlocks("a", "1 2 1 2 1 2");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
newBlocks("a", "1 2 3"),
newBlocks("b", "1 2 4"));
// Note about blocks with hashes "3", "4" and "5": those blocks here in order to not face another problem - with EOF (see separate test)
- List<Block> fileBlocks = newBlocks("a", "1 2 5");
+ Block[] fileBlocks = newBlocks("a", "1 2 5");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@Test
public void only_one_query_of_index_for_each_unique_hash() {
CloneIndex index = spy(createIndex());
- List<Block> fileBlocks = newBlocks("a", "1 2 1 2");
+ Block[] fileBlocks = newBlocks("a", "1 2 1 2");
detect(index, fileBlocks);
verify(index).getBySequenceHash(new ByteArray("01"));
*/
@Test
public void shouldReturnEmptyListWhenNoBlocksForFile() {
- List<CloneGroup> result = detect(null, new ArrayList<Block>());
+ List<CloneGroup> result = detect(null, new Block[0]);
assertThat(result, sameInstance(Collections.EMPTY_LIST));
}
public void problemWithEndOfFile() {
CloneIndex cloneIndex = createIndex(
newBlocks("b", "1 2 3 4"));
- List<Block> fileBlocks =
+ Block[] fileBlocks =
newBlocks("a", "1 2 3");
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
Block.Builder block = Block.builder()
.setResourceId("a")
.setLines(0, 1);
- List<Block> fileBlocks = Arrays.asList(
- block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
- block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
- block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build());
+ Block[] fileBlocks = new Block[] {
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(0).build(),
+ block.setBlockHash(new ByteArray("2".getBytes())).setIndexInFile(1).build(),
+ block.setBlockHash(new ByteArray("1".getBytes())).setIndexInFile(2).build()
+ };
List<CloneGroup> clones = detect(cloneIndex, fileBlocks);
print(clones);
System.out.println();
}
- protected static List<Block> newBlocks(String resourceId, String hashes) {
+ protected static Block[] newBlocks(String resourceId, String hashes) {
List<Block> result = Lists.newArrayList();
int indexInFile = 0;
for (int i = 0; i < hashes.length(); i += 2) {
result.add(block);
indexInFile++;
}
- return result;
+ return result.toArray(new Block[result.size()]);
}
- protected static CloneIndex createIndex(List<Block>... blocks) {
+ protected static CloneIndex createIndex(Block[]... blocks) {
CloneIndex cloneIndex = new MemoryCloneIndex();
- for (List<Block> b : blocks) {
+ for (Block[] b : blocks) {
for (Block block : b) {
cloneIndex.insert(block);
}
*/
package org.sonar.duplications.detector.original;
+import java.util.Arrays;
import java.util.List;
import org.sonar.duplications.block.Block;
public class OriginalCloneDetectionAlgorithmTest extends DetectorTestCase {
@Override
- protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) {
- return OriginalCloneDetectionAlgorithm.detect(index, fileBlocks);
+ protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) {
+ return OriginalCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks));
}
}
*/
package org.sonar.duplications.detector.suffixtree;
-import static org.hamcrest.Matchers.sameInstance;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
-
-import java.util.Collections;
-import java.util.List;
-
import org.junit.Test;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
import org.sonar.duplications.index.CloneGroup;
import org.sonar.duplications.index.CloneIndex;
-import com.google.common.collect.Lists;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.sonar.duplications.detector.CloneGroupMatcher.hasCloneGroup;
public class SuffixTreeCloneDetectionAlgorithmTest extends DetectorTestCase {
@Test
public void noDuplications() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("a", "1 2 3");
+ Block[] fileBlocks = newBlocks("a", "1 2 3");
List<CloneGroup> result = detect(index, fileBlocks);
assertThat(result, sameInstance(Collections.EMPTY_LIST));
}
@Test
public void huge() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = Lists.newArrayList();
- int indexInFile = 0;
+ Block[] fileBlocks = new Block[5000];
for (int i = 0; i < 5000; i++) {
- Block block = newBlock("x", new ByteArray("01"), indexInFile);
- fileBlocks.add(block);
- indexInFile++;
+ fileBlocks[i] = newBlock("x", new ByteArray("01"), i);
}
List<CloneGroup> result = detect(index, fileBlocks);
@Test
public void myTest() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2");
+ Block[] fileBlocks = newBlocks("x", "a 2 b 2 c 2 2 2");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
@Test
public void myTest2() {
CloneIndex index = createIndex();
- List<Block> fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3");
+ Block[] fileBlocks = newBlocks("x", "a 2 3 b 2 3 c 2 3 d 2 3 2 3 2 3");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
newBlocks("b", "4 3 2"),
newBlocks("c", "4 3 1")
);
- List<Block> fileBlocks = newBlocks("a", "1 2 3 4");
+ Block[] fileBlocks = newBlocks("a", "1 2 3 4");
List<CloneGroup> result = detect(index, fileBlocks);
print(result);
}
@Override
- protected List<CloneGroup> detect(CloneIndex index, List<Block> fileBlocks) {
- return SuffixTreeCloneDetectionAlgorithm.detect(index, fileBlocks);
+ protected List<CloneGroup> detect(CloneIndex index, Block[] fileBlocks) {
+ return SuffixTreeCloneDetectionAlgorithm.detect(index, Arrays.asList(fileBlocks));
}
}
*/
package org.sonar.maven3;
+import com.google.common.collect.Maps;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.batch.bootstrapper.LoggingConfiguration;
-import java.util.Map;
-
/**
* @goal sonar
* @aggregator
}
private void configureLogging(LoggingConfiguration logging) {
- logging.setProperties((Map) session.getSystemProperties());
+ logging.setProperties(Maps.fromProperties(session.getSystemProperties()));
logging.setFormat(LoggingConfiguration.FORMAT_MAVEN);
if (getLog().isDebugEnabled()) {
logging.setVerbose(true);
return Phase.Name.DEFAULT;
}
- private void evaluateMethod(Object extension, Method method, List results) {
+ private void evaluateMethod(Object extension, Method method, List<Object> results) {
try {
Object result = method.invoke(extension);
if (result != null) {
if (result instanceof Class) {
results.addAll(componentContainer.getComponentsByType((Class) result));
- } else if (result instanceof Collection) {
- results.addAll((Collection) result);
+ } else if (result instanceof Collection<?>) {
+ results.addAll((Collection<?>) result);
} else {
results.add(result);
*/
package org.sonar.api.batch;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
import org.junit.Test;
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Mockito.*;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.Metric;
import java.util.Arrays;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class DefaultFormulaDataTest {
@Test
DecoratorContext context = mock(DecoratorContext.class);
DefaultFormulaData data = new DefaultFormulaData(context);
- data.getChildrenMeasures((MeasuresFilter) anyObject());
- verify(context).getChildrenMeasures((MeasuresFilter) anyObject());
+ data.getChildrenMeasures(any(MeasuresFilter.class));
+ verify(context).getChildrenMeasures(any(MeasuresFilter.class));
- data.getChildrenMeasures((Metric) anyObject());
- verify(context).getChildrenMeasures((Metric) anyObject());
+ data.getChildrenMeasures(any(Metric.class));
+ verify(context).getChildrenMeasures(any(Metric.class));
- data.getMeasures((MeasuresFilter) anyObject());
- verify(context).getMeasures((MeasuresFilter) anyObject());
+ data.getMeasures(any(MeasuresFilter.class));
+ verify(context).getMeasures(any(MeasuresFilter.class));
- data.getMeasure((Metric) anyObject());
- verify(context).getMeasure((Metric) anyObject());
+ data.getMeasure(any(Metric.class));
+ verify(context).getMeasure(any(Metric.class));
}
@Test
}
private void register(View view) {
- ViewProxy proxy = new ViewProxy(view);
if (view instanceof Widget) {
+ ViewProxy<Widget> proxy = new ViewProxy<Widget>((Widget) view);
widgets.add(proxy);
widgetsPerId.put(proxy.getId(), proxy);
} else if (view instanceof Page) {
+ ViewProxy<Page> proxy = new ViewProxy<Page>((Page) view);
pagesPerId.put(proxy.getId(), proxy);
pages.add(proxy);
}
}
-
public ViewProxy<Page> getPage(String id) {
return pagesPerId.get(id);
}