aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-11-13 17:41:30 +0100
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-11-16 08:44:16 +0100
commit2b676da5ab6265e66534b735e82fcdfc7f32bb10 (patch)
tree4704c3dde7c088b04826350120df055f62691741 /it
parent1757a06de3e2196b15cf0656b3aa844ea729d6e3 (diff)
downloadsonarqube-2b676da5ab6265e66534b735e82fcdfc7f32bb10.tar.gz
sonarqube-2b676da5ab6265e66534b735e82fcdfc7f32bb10.zip
SONAR-6323 Replace java project by xoo project in DuplicationsTest
Diffstat (limited to 'it')
-rw-r--r--it/it-projects/duplications/file-duplications/pom.xml8
-rw-r--r--it/it-projects/duplications/file-duplications/sonar-project.properties5
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java60
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java60
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo41
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo41
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage1.java)35
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage2.java)33
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_same_class/DuplicatedLinesInSameClass.java)31
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class1.java)27
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class2.java)27
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo.measures1
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo (renamed from it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class3.java)29
-rw-r--r--it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo.measures1
-rw-r--r--it/it-tests/src/test/java/it/Category4Suite.java1
-rw-r--r--it/it-tests/src/test/java/it/duplication/DuplicationsTest.java237
-rw-r--r--it/it-tests/src/test/resources/duplication/DuplicationsTest/duplications_show-expected.json26
-rw-r--r--it/it-tests/src/test/resources/duplication/DuplicationsTest/sources_lines_duplication-expected.json359
24 files changed, 631 insertions, 397 deletions
diff --git a/it/it-projects/duplications/file-duplications/pom.xml b/it/it-projects/duplications/file-duplications/pom.xml
deleted file mode 100644
index dd73385ea96..00000000000
--- a/it/it-projects/duplications/file-duplications/pom.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>com.sonarsource.it.samples</groupId>
- <artifactId>duplications</artifactId>
- <version>1.0-SNAPSHOT</version>
-
-</project>
diff --git a/it/it-projects/duplications/file-duplications/sonar-project.properties b/it/it-projects/duplications/file-duplications/sonar-project.properties
new file mode 100644
index 00000000000..ae173196ce4
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/sonar-project.properties
@@ -0,0 +1,5 @@
+sonar.projectKey=file-duplications
+sonar.projectName=File duplications
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.sources=src/main/xoo
+sonar.language=xoo
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java b/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java
deleted file mode 100644
index cb27ed9455a..00000000000
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Sonar, entreprise quality control tool.
- * Copyright (C) 2007-2008 Hortis-GRC SA
- * mailto:be_agile HAT hortis DOT ch
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_lines_with_other_package1;
-
-public class DuplicatedLinesWithOtherPackage {
-
- public DuplicatedLinesWithOtherPackage() {
- }
-
- public void duplicatedMethodWithOtherPackage() {
- char[] charList = new char[30];
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- }
-} \ No newline at end of file
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java b/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java
deleted file mode 100644
index f49127f3a06..00000000000
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Sonar, entreprise quality control tool.
- * Copyright (C) 2007-2008 Hortis-GRC SA
- * mailto:be_agile HAT hortis DOT ch
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_lines_with_other_package2;
-
-public class DuplicatedLinesWithOtherPackage {
-
- public DuplicatedLinesWithOtherPackage() {
- }
-
- public void duplicatedMethodWithOtherPackage() {
- char[] charList = new char[30];
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- for (int i = 0; i < 10; i++) {
- charList[i] = 'a';
- }
- }
-} \ No newline at end of file
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo
new file mode 100644
index 00000000000..88e610b4a74
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo
@@ -0,0 +1,41 @@
+package duplicated_lines_with_other_dir1;
+
+public class DuplicatedLinesWithOtherDirectory {
+
+ public DuplicatedLinesWithOtherDirectory() {
+ }
+
+ public void duplicatedMethodWithOtherDirectory() {
+ char[] charList = new char[30];
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ }
+}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo.measures
new file mode 100644
index 00000000000..03005736cf7
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo.measures
@@ -0,0 +1 @@
+ncloc:42
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo
new file mode 100644
index 00000000000..bb3cc734be4
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo
@@ -0,0 +1,41 @@
+package duplicated_lines_with_other_dir2;
+
+public class DuplicatedLinesWithOtherDirectory {
+
+ public DuplicatedLinesWithOtherDirectory() {
+ }
+
+ public void duplicatedMethodWithOtherDirectory() {
+ char[] charList = new char[30];
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ for (int i = 0; i < 10; i++) {
+ charList[i] = 'a';
+ }
+ }
+}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo.measures
new file mode 100644
index 00000000000..03005736cf7
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo.measures
@@ -0,0 +1 @@
+ncloc:42
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage1.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo
index 7316bdebbcf..5f23377bed4 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage1.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo
@@ -1,33 +1,14 @@
-/*
- * Sonar, entreprise quality control tool.
- * Copyright (C) 2007-2008 Hortis-GRC SA
- * mailto:be_agile HAT hortis DOT ch
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_lines_within_package;
+package duplicated_lines_within_dir;
-public class DuplicatedLinesInSamePackage1 {
+public class DuplicatedLinesInSameDirectory1 {
- public DuplicatedLinesInSamePackage1() {
+ public DuplicatedLinesInSameDirectory1() {
}
/*
* sddfgdfgfg
*/
- public void duplicatedMethodInSameClass1() {
+ public void duplicatedMethodInSameFile1() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
intergerToBeIncremented++;
@@ -60,7 +41,7 @@ public class DuplicatedLinesInSamePackage1 {
}
- public void duplicatedMethodInSameClass3() {
+ public void duplicatedMethodInSameFile3() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
intergerToBeIncremented++;
@@ -92,8 +73,8 @@ public class DuplicatedLinesInSamePackage1 {
intergerToBeIncremented70++;
}
}
-
- public void duplicated2MethodInSameClass3() {
+
+ public void duplicated2MethodInSameFile3() {
System.out.print("copy test start");
int intergerToBeIncremented1 = 0;
while (intergerToBeIncremented1 < 100) {
@@ -121,4 +102,4 @@ public class DuplicatedLinesInSamePackage1 {
}
System.out.print("copy test end");
}
-} \ No newline at end of file
+}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo.measures
new file mode 100644
index 00000000000..c71c98ec52e
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo.measures
@@ -0,0 +1 @@
+ncloc:106
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage2.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo
index d338c25b369..b565bfd75a2 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage2.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo
@@ -1,30 +1,11 @@
-/*
- * Sonar, entreprise quality control tool.
- * Copyright (C) 2007-2008 Hortis-GRC SA
- * mailto:be_agile HAT hortis DOT ch
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_lines_within_package;
+package duplicated_lines_within_dir;
-public class DuplicatedLinesInSamePackage2 {
+public class DuplicatedLinesInSameDirectory2 {
- public DuplicatedLinesInSamePackage2() {
+ public DuplicatedLinesInSameDirectory2() {
}
-
- public void duplicated2MethodInSameClass3() {
+
+ public void duplicated2MethodInSameFile3() {
System.out.print("copy test start");
int intergerToBeIncremented1 = 0;
while (intergerToBeIncremented1 < 100) {
@@ -53,7 +34,7 @@ public class DuplicatedLinesInSamePackage2 {
System.out.print("copy test end");
}
- public void duplicatedMethodInSameClass1() {
+ public void duplicatedMethodInSameFile1() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
intergerToBeIncremented++;
@@ -87,4 +68,4 @@ public class DuplicatedLinesInSamePackage2 {
}
}
-} \ No newline at end of file
+}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo.measures
new file mode 100644
index 00000000000..f175998c7cc
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo.measures
@@ -0,0 +1 @@
+ncloc:72
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_same_class/DuplicatedLinesInSameClass.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo
index 3bf33bbbaa2..6a0d3345eb7 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_lines_within_same_class/DuplicatedLinesInSameClass.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo
@@ -1,30 +1,11 @@
-/*
- * Sonar, entreprise quality control tool.
- * Copyright (C) 2007-2008 Hortis-GRC SA
- * mailto:be_agile HAT hortis DOT ch
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_lines_within_same_class;
+package duplicated_lines_within_same_file;
-public class DuplicatedLinesInSameClass {
+public class DuplicatedLinesInSameFile {
- public DuplicatedLinesInSameClass() {
+ public DuplicatedLinesInSameFile() {
}
- public void duplicatedMethodInSameClass1() {
+ public void duplicatedMethodInSameFile1() {
String temp = "";
for (int i=0; i<10; i++){
temp += "say something"+i;
@@ -55,7 +36,7 @@ public class DuplicatedLinesInSameClass {
}
}
- public void duplicatedMethodInSameClass2() {
+ public void duplicatedMethodInSameFile2() {
String temp = "";
for (int i=0; i<10; i++){
temp += "say something"+i;
@@ -83,7 +64,7 @@ public class DuplicatedLinesInSameClass {
}
for (int i=0; i<90; i++){
temp += "bye"+i;
- }
+ }
}
}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo.measures
new file mode 100644
index 00000000000..5e818e5e054
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo.measures
@@ -0,0 +1 @@
+ncloc:71
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class1.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo
index 250c3d6228d..8083fdec9d6 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class1.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo
@@ -1,30 +1,11 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_same_lines_within_3_classes;
+package duplicated_same_lines_within_3_files;
-public class Class1 {
+public class File1 {
public void someMethod() {
System.out.println("Test");
}
-
+
public void duplicatedMethod() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
@@ -56,5 +37,5 @@ public class Class1 {
intergerToBeIncremented7++;
}
}
-
+
}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo.measures
new file mode 100644
index 00000000000..03005736cf7
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo.measures
@@ -0,0 +1 @@
+ncloc:42
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class2.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo
index 494cbb9d43d..b76919dbd67 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class2.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo
@@ -1,26 +1,7 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_same_lines_within_3_classes;
+package duplicated_same_lines_within_3_files;
+
+public class File2 {
-public class Class2 {
-
public void duplicatedMethod() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
@@ -52,7 +33,7 @@ public class Class2 {
intergerToBeIncremented7++;
}
}
-
+
public void someOtherMethod() {
System.out.println("Test2");
}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo.measures
new file mode 100644
index 00000000000..076450c97b0
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo.measures
@@ -0,0 +1 @@
+ncloc:41
diff --git a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class3.java b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo
index a785723c3bc..5db9d2fd221 100644
--- a/it/it-projects/duplications/file-duplications/src/main/java/duplicated_same_lines_within_3_classes/Class3.java
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo
@@ -1,28 +1,9 @@
-/*
- * Sonar, open source software quality management tool.
- * Copyright (C) 2008-2011 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * Sonar 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.
- *
- * Sonar 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 Sonar; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
- */
-package duplicated_same_lines_within_3_classes;
+package duplicated_same_lines_within_3_files;
-public class Class3 {
+public class File3 {
private String test;
-
+
public void duplicatedMethod() {
int intergerToBeIncremented = 0;
while (intergerToBeIncremented < 100) {
@@ -54,9 +35,9 @@ public class Class3 {
intergerToBeIncremented7++;
}
}
-
+
public String getTest() {
return test;
}
-
+
}
diff --git a/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo.measures b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo.measures
new file mode 100644
index 00000000000..9fd62445ebd
--- /dev/null
+++ b/it/it-projects/duplications/file-duplications/src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo.measures
@@ -0,0 +1 @@
+ncloc:44
diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java
index 9a566c5741c..c1460fc9218 100644
--- a/it/it-tests/src/test/java/it/Category4Suite.java
+++ b/it/it-tests/src/test/java/it/Category4Suite.java
@@ -69,6 +69,5 @@ public class Category4Suite {
@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.addPlugin(xooPlugin())
- .setOrchestratorProperty("javaVersion", "LATEST_RELEASE").addPlugin("java")
.build();
}
diff --git a/it/it-tests/src/test/java/it/duplication/DuplicationsTest.java b/it/it-tests/src/test/java/it/duplication/DuplicationsTest.java
index a800174764a..729bc564e00 100644
--- a/it/it-tests/src/test/java/it/duplication/DuplicationsTest.java
+++ b/it/it-tests/src/test/java/it/duplication/DuplicationsTest.java
@@ -1,155 +1,107 @@
/*
- * Copyright (C) 2009-2014 SonarSource SA
- * All rights reserved
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
* mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube 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.
+ *
+ * SonarQube 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 it.duplication;
import com.sonar.orchestrator.Orchestrator;
-import com.sonar.orchestrator.build.MavenBuild;
+import com.sonar.orchestrator.locator.FileLocation;
import it.Category4Suite;
+import java.util.List;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.ArrayUtils;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
+import org.sonar.wsclient.issue.Issue;
+import org.sonar.wsclient.issue.IssueQuery;
import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.ResourceQuery;
-import util.ItUtils;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.core.IsNot.not;
-import static org.hamcrest.core.IsNull.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.skyscreamer.jsonassert.JSONAssert.assertEquals;
+import static util.ItUtils.runProjectAnalysis;
+import static util.ItUtils.setServerProperty;
public class DuplicationsTest {
- private static final String DUPLICATIONS = "com.sonarsource.it.samples:duplications";
- private static final String DUPLICATIONS_WITH_EXCLUSIONS = "com.sonarsource.it.samples:duplications-with-exclusions";
+ static final String DUPLICATIONS = "file-duplications";
+ static final String DUPLICATIONS_WITH_EXCLUSIONS = "file-duplications-with-exclusions";
+ static final String WITHOUT_ENOUGH_TOKENS = "project_without_enough_tokens";
@ClassRule
public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR;
@BeforeClass
- public static void init() {
+ public static void analyzeProjects() {
orchestrator.resetData();
- MavenBuild build = MavenBuild.create(ItUtils.projectPom("duplications/file-duplications"))
- .setCleanPackageSonarGoals();
- orchestrator.executeBuild(build);
-
- // Use a new project key to avoid conflict with other tests
- String projectKey = DUPLICATIONS_WITH_EXCLUSIONS;
- build = MavenBuild.create(ItUtils.projectPom("duplications/file-duplications"))
- .setCleanPackageSonarGoals()
- .setProperties("sonar.projectKey", projectKey,
- "sonar.cpd.exclusions", "**/Class*");
- orchestrator.executeBuild(build);
+ orchestrator.getServer().restoreProfile(FileLocation.ofClasspath("/duplication/xoo-duplication-profile.xml"));
+ analyzeProject(DUPLICATIONS);
+ analyzeProject(DUPLICATIONS_WITH_EXCLUSIONS, "sonar.cpd.exclusions", "**/File*");
+ // Set minimum tokens to a big value in order to not get duplications
+ setServerProperty(orchestrator, "sonar.cpd.xoo.minimumTokens", "1000");
+ analyzeProject(WITHOUT_ENOUGH_TOKENS);
}
@Test
- public void duplicated_lines_within_same_class() {
- Resource file = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_within_same_class/DuplicatedLinesInSameClass.java");
- assertThat(file, not(nullValue()));
- assertThat(file.getMeasureValue("duplicated_blocks"), is(2.0));
- assertThat(file.getMeasureValue("duplicated_lines"), is(27.0 * 2)); // 2 blocks with 27 lines
- assertThat(file.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file.getMeasureValue("duplicated_lines_density"), is(60.0));
+ public void duplicated_lines_within_same_file() {
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo",
+ 2,
+ 30 * 2, // 2 blocks with 30 lines
+ 1,
+ 84.5);
}
@Test
public void duplicated_same_lines_within_3_classes() {
- Resource file1 = getResource(DUPLICATIONS + ":src/main/java/duplicated_same_lines_within_3_classes/Class1.java");
- assertThat(file1, not(nullValue()));
- assertThat(file1.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(file1.getMeasureValue("duplicated_lines"), is(29.0));
- assertThat(file1.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file1.getMeasureValue("duplicated_lines_density"), is(47.5));
-
- Resource file2 = getResource(DUPLICATIONS + ":src/main/java/duplicated_same_lines_within_3_classes/Class2.java");
- assertThat(file2, not(nullValue()));
- assertThat(file2.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(file2.getMeasureValue("duplicated_lines"), is(29.0));
- assertThat(file2.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file2.getMeasureValue("duplicated_lines_density"), is(48.3));
-
- Resource file3 = getResource(DUPLICATIONS + ":src/main/java/duplicated_same_lines_within_3_classes/Class3.java");
- assertThat(file3, not(nullValue()));
- assertThat(file3.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(file3.getMeasureValue("duplicated_lines"), is(29.0));
- assertThat(file3.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file3.getMeasureValue("duplicated_lines_density"), is(46.0));
-
- Resource pkg = getResource(DUPLICATIONS + ":src/main/java/duplicated_same_lines_within_3_classes");
- assertThat(pkg, not(nullValue()));
- assertThat(pkg.getMeasureValue("duplicated_blocks"), is(3.0));
- assertThat(pkg.getMeasureValue("duplicated_lines"), is(29.0 * 3)); // 3 blocks with 29 lines
- assertThat(pkg.getMeasureValue("duplicated_files"), is(3.0));
- assertThat(pkg.getMeasureValue("duplicated_lines_density"), is(47.3));
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_same_lines_within_3_files/File1.xoo", 1, 33, 1, 78.6);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_same_lines_within_3_files/File2.xoo", 1, 31, 1, 75.6);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_same_lines_within_3_files/File3.xoo", 1, 31, 1, 70.5);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_same_lines_within_3_files", 3, 95, 3, 74.8);
+ }
+
+ @Test
+ public void duplicated_lines_within_directory() {
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory1.xoo", 1, 30, 1, 28.3);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_dir/DuplicatedLinesInSameDirectory2.xoo", 1, 30, 1, 41.7);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_dir", 2, 60, 2, 33.7);
}
@Test
- public void duplicated_lines_within_package() {
- Resource file1 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage1.java");
- assertThat(file1, not(nullValue()));
- assertThat(file1.getMeasureValue("duplicated_blocks"), is(4.0));
- assertThat(file1.getMeasureValue("duplicated_lines"), is(72.0));
- assertThat(file1.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file1.getMeasureValue("duplicated_lines_density"), is(58.1));
-
- Resource file2 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_within_package/DuplicatedLinesInSamePackage2.java");
- assertThat(file2, not(nullValue()));
- assertThat(file2.getMeasureValue("duplicated_blocks"), is(3.0));
- assertThat(file2.getMeasureValue("duplicated_lines"), is(58.0));
- assertThat(file2.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file2.getMeasureValue("duplicated_lines_density"), is(64.4));
-
- Resource pkg = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_within_package");
- assertThat(pkg, not(nullValue()));
- assertThat(pkg.getMeasureValue("duplicated_blocks"), is(4.0 + 3.0));
- assertThat(pkg.getMeasureValue("duplicated_lines"), is(72.0 + 58.0));
- assertThat(pkg.getMeasureValue("duplicated_files"), is(2.0));
- assertThat(pkg.getMeasureValue("duplicated_lines_density"), is(60.7));
+ public void duplicated_lines_with_other_directory() {
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_with_other_dir1/DuplicatedLinesWithOtherDirectory.xoo", 1, 39, 1, 92.9);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_with_other_dir1", 1, 39, 1, 92.9);
+
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_with_other_dir2/DuplicatedLinesWithOtherDirectory.xoo", 1, 39, 1, 92.9);
+ verifyDuplicationMeasures(DUPLICATIONS + ":src/main/xoo/duplicated_lines_with_other_dir2", 1, 39, 1, 92.9);
}
@Test
- public void duplicated_lines_with_other_package() {
- Resource file1 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_with_other_package1/DuplicatedLinesWithOtherPackage.java");
- assertThat(file1, not(nullValue()));
- assertThat(file1.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(file1.getMeasureValue("duplicated_lines"), is(36.0));
- assertThat(file1.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file1.getMeasureValue("duplicated_lines_density"), is(60.0));
-
- Resource pkg1 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_with_other_package1");
- assertThat(pkg1, not(nullValue()));
- assertThat(pkg1.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(pkg1.getMeasureValue("duplicated_lines"), is(36.0));
- assertThat(pkg1.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(pkg1.getMeasureValue("duplicated_lines_density"), is(60.0));
-
- Resource file2 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_with_other_package2/DuplicatedLinesWithOtherPackage.java");
- assertThat(file2, not(nullValue()));
- assertThat(file2.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(file2.getMeasureValue("duplicated_lines"), is(36.0));
- assertThat(file2.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(file2.getMeasureValue("duplicated_lines_density"), is(60.0));
-
- Resource pkg2 = getResource(DUPLICATIONS + ":src/main/java/duplicated_lines_with_other_package2");
- assertThat(pkg2, not(nullValue()));
- assertThat(pkg2.getMeasureValue("duplicated_blocks"), is(1.0));
- assertThat(pkg2.getMeasureValue("duplicated_lines"), is(36.0));
- assertThat(pkg2.getMeasureValue("duplicated_files"), is(1.0));
- assertThat(pkg2.getMeasureValue("duplicated_lines_density"), is(60.0));
+ public void duplication_measures_on_project() {
+ verifyDuplicationMeasures(DUPLICATIONS, 9, 293, 8, 63.7);
}
@Test
- public void consolidation() {
- Resource project = getResource(DUPLICATIONS);
- assertThat(project, not(nullValue()));
- assertThat(project.getMeasureValue("duplicated_blocks"), is(14.0));
- assertThat(project.getMeasureValue("duplicated_lines"), is(343.0));
- assertThat(project.getMeasureValue("duplicated_files"), is(8.0));
- assertThat(project.getMeasureValue("duplicated_lines_density"), is(56.4));
+ public void project_without_enough_tokens_has_duplication() {
+ verifyDuplicationMeasures(WITHOUT_ENOUGH_TOKENS, 0, 0, 0, 0d);
}
/**
@@ -157,17 +109,62 @@ public class DuplicationsTest {
*/
@Test
public void use_duplication_exclusions() {
- Resource project = getResource(DUPLICATIONS_WITH_EXCLUSIONS);
- assertThat(project, not(nullValue()));
- assertThat(project.getMeasureValue("duplicated_blocks"), is(11.0));
- assertThat(project.getMeasureValue("duplicated_lines"), is(256.0));
- assertThat(project.getMeasureValue("duplicated_files"), is(5.0));
- assertThat(project.getMeasureValue("duplicated_lines_density"), is(42.1));
+ verifyDuplicationMeasures(DUPLICATIONS_WITH_EXCLUSIONS, 6, 198, 5, 43d);
}
- private Resource getResource(String key) {
- return orchestrator.getServer().getWsClient()
+ @Test
+ public void issues_on_duplicated_blocks_are_generated_on_each_file() throws Exception {
+ List<Issue> issues = orchestrator.getServer().wsClient().issueClient()
+ .find(IssueQuery.create()
+ .rules("common-xoo:DuplicatedBlocks"))
+ .list();
+ assertThat(issues).hasSize(13);
+ }
+
+ @Test
+ public void verify_sources_lines_ws_duplication_information() throws Exception {
+ verifyWsResultOnDuplicateFile(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo",
+ "api/sources/lines", "sources_lines_duplication-expected.json");
+ }
+
+ @Test
+ public void verify_duplications_show_ws() throws Exception {
+ verifyWsResultOnDuplicateFile(DUPLICATIONS + ":src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo",
+ "api/duplications/show", "duplications_show-expected.json");
+ }
+
+ private static Resource getComponent(String key) {
+ Resource component = orchestrator.getServer().getWsClient()
.find(ResourceQuery.createForMetrics(key, "duplicated_lines", "duplicated_blocks", "duplicated_files", "duplicated_lines_density"));
+ assertThat(component).isNotNull();
+ return component;
+ }
+
+ private static void verifyDuplicationMeasures(String componentKey, int duplicatedBlocks, int duplicatedLines, int duplicatedFiles, double duplicatedLinesDensity) {
+ Resource file = getComponent(componentKey);
+ assertThat(file.getMeasureValue("duplicated_blocks").intValue()).isEqualTo(duplicatedBlocks);
+ assertThat(file.getMeasureValue("duplicated_lines").intValue()).isEqualTo(duplicatedLines);
+ assertThat(file.getMeasureValue("duplicated_files").intValue()).isEqualTo(duplicatedFiles);
+ assertThat(file.getMeasureValue("duplicated_lines_density")).isEqualTo(duplicatedLinesDensity);
+ }
+
+ private static void analyzeProject(String projectKey, String... additionalProperties) {
+ orchestrator.getServer().provisionProject(projectKey, projectKey);
+ orchestrator.getServer().associateProjectToQualityProfile(projectKey, "xoo", "xoo-duplication-profile");
+
+ runProjectAnalysis(orchestrator, "duplications/file-duplications",
+ ArrayUtils.addAll(
+ new String[] {
+ "sonar.projectKey", projectKey,
+ "sonar.projectName", projectKey
+ },
+ additionalProperties));
+ }
+
+ private static void verifyWsResultOnDuplicateFile(String fileKey, String ws, String expectedFilePath) throws Exception {
+ String duplication = orchestrator.getServer().adminWsClient().get(ws, "key", fileKey);
+ assertEquals(IOUtils.toString(CrossProjectDuplicationsTest.class.getResourceAsStream("/duplication/DuplicationsTest/" + expectedFilePath), "UTF-8"), duplication,
+ false);
}
}
diff --git a/it/it-tests/src/test/resources/duplication/DuplicationsTest/duplications_show-expected.json b/it/it-tests/src/test/resources/duplication/DuplicationsTest/duplications_show-expected.json
new file mode 100644
index 00000000000..83b69f2be1d
--- /dev/null
+++ b/it/it-tests/src/test/resources/duplication/DuplicationsTest/duplications_show-expected.json
@@ -0,0 +1,26 @@
+{
+ "duplications": [
+ {
+ "blocks": [
+ {
+ "from": 9,
+ "size": 29,
+ "_ref": "1"
+ },
+ {
+ "from": 40,
+ "size": 31,
+ "_ref": "1"
+ }
+ ]
+ }
+ ],
+ "files": {
+ "1": {
+ "key": "file-duplications:src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo",
+ "name": "src/main/xoo/duplicated_lines_within_same_file/DuplicatedLinesInSameFile.xoo",
+ "project": "file-duplications",
+ "projectName": "file-duplications"
+ }
+ }
+}
diff --git a/it/it-tests/src/test/resources/duplication/DuplicationsTest/sources_lines_duplication-expected.json b/it/it-tests/src/test/resources/duplication/DuplicationsTest/sources_lines_duplication-expected.json
new file mode 100644
index 00000000000..f6ccc926f29
--- /dev/null
+++ b/it/it-tests/src/test/resources/duplication/DuplicationsTest/sources_lines_duplication-expected.json
@@ -0,0 +1,359 @@
+{
+ "sources": [
+ {
+ "line": 1,
+ "code": "package duplicated_lines_within_same_file;",
+ "duplicated": false
+ },
+ {
+ "line": 2,
+ "code": "",
+ "duplicated": false
+ },
+ {
+ "line": 3,
+ "code": "public class DuplicatedLinesInSameFile {",
+ "duplicated": false
+ },
+ {
+ "line": 4,
+ "code": "",
+ "duplicated": false
+ },
+ {
+ "line": 5,
+ "code": " public DuplicatedLinesInSameFile() {",
+ "duplicated": false
+ },
+ {
+ "line": 6,
+ "code": " }",
+ "duplicated": false
+ },
+ {
+ "line": 7,
+ "code": "",
+ "duplicated": false
+ },
+ {
+ "line": 8,
+ "code": " public void duplicatedMethodInSameFile1() {",
+ "duplicated": false
+ },
+ {
+ "line": 9,
+ "code": " String temp = \"\";",
+ "duplicated": true
+ },
+ {
+ "line": 10,
+ "code": " for (int i=0; i&lt;10; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 11,
+ "code": " temp += \"say something\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 12,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 13,
+ "code": " for (int i=0; i&lt;20; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 14,
+ "code": " temp += \"say nothing\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 15,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 16,
+ "code": " for (int i=0; i&lt;30; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 17,
+ "code": " temp += \"always say nothing\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 18,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 19,
+ "code": " for (int i=0; i&lt;40; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 20,
+ "code": " temp += \"really nothing to say \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 21,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 22,
+ "code": " for (int i=0; i&lt;50; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 23,
+ "code": " temp += \"really really nothing to say \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 24,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 25,
+ "code": " for (int i=0; i&lt;60; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 26,
+ "code": " temp += \".. \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 27,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 28,
+ "code": " for (int i=0; i&lt;70; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 29,
+ "code": " temp += \"you say something? \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 30,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 31,
+ "code": " for (int i=0; i&lt;80; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 32,
+ "code": " temp += \"ah no...\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 33,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 34,
+ "code": " for (int i=0; i&lt;90; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 35,
+ "code": " temp += \"bye\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 36,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 37,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 38,
+ "code": "",
+ "duplicated": false
+ },
+ {
+ "line": 39,
+ "code": " public void duplicatedMethodInSameFile2() {",
+ "duplicated": false
+ },
+ {
+ "line": 40,
+ "code": " String temp = \"\";",
+ "duplicated": true
+ },
+ {
+ "line": 41,
+ "code": " for (int i=0; i&lt;10; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 42,
+ "code": " temp += \"say something\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 43,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 44,
+ "code": " for (int i=0; i&lt;20; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 45,
+ "code": " temp += \"say nothing\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 46,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 47,
+ "code": " for (int i=0; i&lt;30; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 48,
+ "code": " temp += \"always say nothing\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 49,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 50,
+ "code": " for (int i=0; i&lt;40; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 51,
+ "code": " temp += \"really nothing to say \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 52,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 53,
+ "code": " for (int i=0; i&lt;50; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 54,
+ "code": " temp += \"really really nothing to say \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 55,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 56,
+ "code": " for (int i=0; i&lt;60; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 57,
+ "code": " temp += \".. \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 58,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 59,
+ "code": " for (int i=0; i&lt;70; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 60,
+ "code": " temp += \"you say something? \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 61,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 62,
+ "code": " for (int i=0; i&lt;80; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 63,
+ "code": " temp += \"ah no...\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 64,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 65,
+ "code": " for (int i=0; i&lt;90; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 66,
+ "code": " temp += \"bye\"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 67,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 68,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 69,
+ "code": "",
+ "duplicated": true
+ },
+ {
+ "line": 70,
+ "code": "}",
+ "duplicated": true
+ },
+ {
+ "line": 71,
+ "code": "",
+ "duplicated": false
+ }
+ ]
+}