aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-duplications
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2018-07-19 11:42:54 +0200
committerSonarTech <sonartech@sonarsource.com>2018-07-19 20:21:26 +0200
commite51cb49945d4f3a1d39f74234de49be8ca925fff (patch)
tree6dc4181f26a0f4895874e1c6fb1f83669a213839 /sonar-duplications
parent35428013060d9fb81e7119426e9bfe9858521d4a (diff)
downloadsonarqube-e51cb49945d4f3a1d39f74234de49be8ca925fff.tar.gz
sonarqube-e51cb49945d4f3a1d39f74234de49be8ca925fff.zip
Revert "SONAR-10541, SONAR-10331 Drop compatibility mode and clean plugin classloader"
This reverts commit 4dcb5245f1147048d122ff2d335a6b5b7364c565.
Diffstat (limited to 'sonar-duplications')
-rw-r--r--sonar-duplications/build.gradle1
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/CodeFragment.java44
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java6
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java6
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java3
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java1
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java79
-rw-r--r--sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java5
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java6
-rw-r--r--sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java1
10 files changed, 142 insertions, 10 deletions
diff --git a/sonar-duplications/build.gradle b/sonar-duplications/build.gradle
index 79e4b224640..a45feb6dca7 100644
--- a/sonar-duplications/build.gradle
+++ b/sonar-duplications/build.gradle
@@ -8,7 +8,6 @@ dependencies {
// please keep list ordered
compile 'org.codehaus.sonar:sonar-channel'
- compile project(':sonar-plugin-api')
compileOnly 'com.google.code.findbugs:jsr305'
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/CodeFragment.java b/sonar-duplications/src/main/java/org/sonar/duplications/CodeFragment.java
new file mode 100644
index 00000000000..450259c72e6
--- /dev/null
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/CodeFragment.java
@@ -0,0 +1,44 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.duplications;
+
+
+/**
+ * TODO Enforce contracts of this interface in concrete classes by using preconditions, currently this leads to failures of tests.
+ *
+ * <p>This interface is not intended to be implemented by clients.</p>
+ *
+ * @since 2.14
+ */
+public interface CodeFragment {
+
+ /**
+ * Number of line where fragment starts.
+ * Numbering starts from 1.
+ */
+ int getStartLine();
+
+ /**
+ * Number of line where fragment ends.
+ * Numbering starts from 1.
+ */
+ int getEndLine();
+
+}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
index 76b8bbc4b36..7b2e5fe3dce 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/block/Block.java
@@ -19,11 +19,13 @@
*/
package org.sonar.duplications.block;
+import org.sonar.duplications.CodeFragment;
+
/**
* Represents part of source code between two lines.
* If two blocks have the same {@link #getBlockHash() hash}, then we assume that there is a duplication in a code, which they represent.
*/
-public final class Block {
+public final class Block implements CodeFragment {
private final String resourceId;
private final ByteArray blockHash;
@@ -125,10 +127,12 @@ public final class Block {
return indexInFile;
}
+ @Override
public int getStartLine() {
return startLine;
}
+ @Override
public int getEndLine() {
return endLine;
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
index 5b62937268a..da8cd64c543 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/index/ClonePart.java
@@ -19,7 +19,9 @@
*/
package org.sonar.duplications.index;
-public class ClonePart {
+import org.sonar.duplications.CodeFragment;
+
+public class ClonePart implements CodeFragment {
private final String resourceId;
private final int startUnit;
@@ -46,10 +48,12 @@ public class ClonePart {
return startUnit;
}
+ @Override
public int getStartLine() {
return startLine;
}
+ @Override
public int getEndLine() {
return endLine;
}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java
index 1e11b40dc9c..50a32621f0a 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/PmdBlockChunker.java
@@ -21,8 +21,9 @@ package org.sonar.duplications.internal.pmd;
import java.util.ArrayList;
import java.util.List;
+
import javax.annotation.concurrent.Immutable;
-import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
+
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
index e98f30e9e00..44f1576dc75 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokenizerBridge.java
@@ -26,7 +26,6 @@ import net.sourceforge.pmd.cpd.SourceCode;
import net.sourceforge.pmd.cpd.TokenEntry;
import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.cpd.Tokens;
-import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.cpd.FileCodeLoaderWithoutCache;
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java
new file mode 100644
index 00000000000..62f3059b01d
--- /dev/null
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/internal/pmd/TokensLine.java
@@ -0,0 +1,79 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.duplications.internal.pmd;
+
+import org.sonar.duplications.CodeFragment;
+
+/**
+ * Immutable code fragment, which formed from tokens of one line.
+ */
+public class TokensLine implements CodeFragment {
+
+ private final String value;
+
+ private final int startLine;
+ private final int hashCode;
+
+ private final int startUnit;
+ private final int endUnit;
+
+ public TokensLine(int startUnit, int endUnit, int startLine, String value) {
+ if (startLine <= 0) {
+ throw new IllegalArgumentException("Start line should be strictly positive");
+ }
+ // TODO do we have requirements for length and hashcode ?
+ this.startLine = startLine;
+ this.value = value;
+ this.hashCode = value.hashCode();
+
+ this.startUnit = startUnit;
+ this.endUnit = endUnit;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public int getStartLine() {
+ return startLine;
+ }
+
+ /**
+ * Same as {@link #getStartLine()}
+ */
+ @Override
+ public int getEndLine() {
+ return startLine;
+ }
+
+ public int getHashCode() {
+ return hashCode;
+ }
+
+ public int getStartUnit() {
+ return startUnit;
+ }
+
+ public int getEndUnit() {
+ return endUnit;
+ }
+
+}
diff --git a/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java b/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java
index c6a84d59a7b..a18c6635381 100644
--- a/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java
+++ b/sonar-duplications/src/main/java/org/sonar/duplications/statement/Statement.java
@@ -21,9 +21,10 @@ package org.sonar.duplications.statement;
import java.util.List;
import javax.annotation.Nullable;
+import org.sonar.duplications.CodeFragment;
import org.sonar.duplications.token.Token;
-public class Statement {
+public class Statement implements CodeFragment {
private final int startLine;
private final int endLine;
@@ -53,10 +54,12 @@ public class Statement {
this.endLine = tokens.get(tokens.size() - 1).getLine();
}
+ @Override
public int getStartLine() {
return startLine;
}
+ @Override
public int getEndLine() {
return endLine;
}
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java
index 99d895c0b9b..4335be00567 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/PmdBlockChunkerTest.java
@@ -19,13 +19,13 @@
*/
package org.sonar.duplications.internal.pmd;
-import java.util.Arrays;
-import java.util.List;
import org.junit.Test;
-import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
import org.sonar.duplications.block.Block;
import org.sonar.duplications.block.ByteArray;
+import java.util.Arrays;
+import java.util.List;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
diff --git a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
index 12f58bd8c9a..7ff5dbe30d4 100644
--- a/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
+++ b/sonar-duplications/src/test/java/org/sonar/duplications/internal/pmd/TokenizerBridgeTest.java
@@ -30,7 +30,6 @@ import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.cpd.Tokens;
import org.junit.Before;
import org.junit.Test;
-import org.sonar.api.batch.sensor.cpd.internal.TokensLine;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;