+++ /dev/null
-<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>
--- /dev/null
+sonar.projectKey=file-duplications
+sonar.projectName=File duplications
+sonar.projectVersion=1.0-SNAPSHOT
+sonar.sources=src/main/xoo
+sonar.language=xoo
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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;
-
-public class DuplicatedLinesInSamePackage1 {
-
- public DuplicatedLinesInSamePackage1() {
- }
-
- /*
- * sddfgdfgfg
- */
- public void duplicatedMethodInSameClass1() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- int intergerToBeIncremented2 = 0;
- while (intergerToBeIncremented2 < 100) {
- intergerToBeIncremented2++;
- }
- // first
- int intergerToBeIncremented3 = 0;
- while (intergerToBeIncremented3 < 100) {
- intergerToBeIncremented3++;
- }
- int intergerToBeIncremented4 = 0;
- while (intergerToBeIncremented4 < 100) {
- intergerToBeIncremented4++;
- }
- int intergerToBeIncremented5 = 0;
- while (intergerToBeIncremented5 < 100) {
- intergerToBeIncremented5++;
- }
- int intergerToBeIncremented6 = 0;
- while (intergerToBeIncremented6 < 100) {
- intergerToBeIncremented6++;
- }
- int intergerToBeIncremented7 = 0;
- while (intergerToBeIncremented7 < 100) {
- intergerToBeIncremented7++;
- }
- }
-
-
- public void duplicatedMethodInSameClass3() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- // test2
- int intergerToBeIncremented2 = 0;
- while (intergerToBeIncremented2 < 100) {
- intergerToBeIncremented2++;
- }
- int intergerToBeIncremented8 = 0;
- while (intergerToBeIncremented8 < 100) {
- intergerToBeIncremented8++;
- }
- int intergerToBeIncremented9 = 0;
- while (intergerToBeIncremented9 < 100) {
- intergerToBeIncremented9++;
- }
- // test 1
- int intergerToBeIncremented10 = 0;
- while (intergerToBeIncremented10 < 100) {
- intergerToBeIncremented10++;
- }
- int intergerToBeIncremented60 = 0;
- while (intergerToBeIncremented60 < 100) {
- intergerToBeIncremented60++;
- }
- int intergerToBeIncremented70 = 0;
- while (intergerToBeIncremented70 < 100) {
- intergerToBeIncremented70++;
- }
- }
-
- public void duplicated2MethodInSameClass3() {
- System.out.print("copy test start");
- int intergerToBeIncremented1 = 0;
- while (intergerToBeIncremented1 < 100) {
- intergerToBeIncremented1++;
- }
- int intergerToBeIncremented20 = 0;
- while (intergerToBeIncremented20 < 100) {
- intergerToBeIncremented20++;
- }
- int intergerToBeIncremented8 = 0;
- while (intergerToBeIncremented8 < 100) {
- intergerToBeIncremented8++;
- }
- int intergerToBeIncremented9 = 0;
- while (intergerToBeIncremented9 < 100) {
- intergerToBeIncremented9++;
- }
- int intergerToBeIncremented10 = 0;
- while (intergerToBeIncremented10 < 100) {
- intergerToBeIncremented10++;
- }
- int intergerToBeIncremented60 = 0;
- while (intergerToBeIncremented60 < 100) {
- intergerToBeIncremented60++;
- }
- System.out.print("copy test end");
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * 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;
-
-public class DuplicatedLinesInSamePackage2 {
-
- public DuplicatedLinesInSamePackage2() {
- }
-
- public void duplicated2MethodInSameClass3() {
- System.out.print("copy test start");
- int intergerToBeIncremented1 = 0;
- while (intergerToBeIncremented1 < 100) {
- intergerToBeIncremented1++;
- }
- int intergerToBeIncremented20 = 0;
- while (intergerToBeIncremented20 < 100) {
- intergerToBeIncremented20++;
- }
- int intergerToBeIncremented8 = 0;
- while (intergerToBeIncremented8 < 100) {
- intergerToBeIncremented8++;
- }
- int intergerToBeIncremented9 = 0;
- while (intergerToBeIncremented9 < 100) {
- intergerToBeIncremented9++;
- }
- int intergerToBeIncremented10 = 0;
- while (intergerToBeIncremented10 < 100) {
- intergerToBeIncremented10++;
- }
- int intergerToBeIncremented60 = 0;
- while (intergerToBeIncremented60 < 100) {
- intergerToBeIncremented60++;
- }
- System.out.print("copy test end");
- }
-
- public void duplicatedMethodInSameClass1() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- int intergerToBeIncremented2 = 0;
- while (intergerToBeIncremented2 < 100) {
- intergerToBeIncremented2++;
- }
- // second
- int intergerToBeIncremented3 = 0;
- while (intergerToBeIncremented3 < 100) {
- intergerToBeIncremented3++;
- }
- int intergerToBeIncremented4 = 0;
- while (intergerToBeIncremented4 < 100) {
- intergerToBeIncremented4++;
- }
- int intergerToBeIncremented5 = 0;
- while (intergerToBeIncremented5 < 100) {
- intergerToBeIncremented5++;
- }
- // vghgvhz
- // bhjjh
- int intergerToBeIncremented6 = 0;
- while (intergerToBeIncremented6 < 100) {
- intergerToBeIncremented6++;
- }
- int intergerToBeIncremented7 = 0;
- while (intergerToBeIncremented7 < 100) {
- intergerToBeIncremented7++;
- }
- }
-
-}
\ No newline at end of file
+++ /dev/null
-/*
- * 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;
-
-public class DuplicatedLinesInSameClass {
-
- public DuplicatedLinesInSameClass() {
- }
-
- public void duplicatedMethodInSameClass1() {
- String temp = "";
- for (int i=0; i<10; i++){
- temp += "say something"+i;
- }
- for (int i=0; i<20; i++){
- temp += "say nothing"+i;
- }
- for (int i=0; i<30; i++){
- temp += "always say nothing"+i;
- }
- for (int i=0; i<40; i++){
- temp += "really nothing to say "+i;
- }
- for (int i=0; i<50; i++){
- temp += "really really nothing to say "+i;
- }
- for (int i=0; i<60; i++){
- temp += ".. "+i;
- }
- for (int i=0; i<70; i++){
- temp += "you say something? "+i;
- }
- for (int i=0; i<80; i++){
- temp += "ah no..."+i;
- }
- for (int i=0; i<90; i++){
- temp += "bye"+i;
- }
- }
-
- public void duplicatedMethodInSameClass2() {
- String temp = "";
- for (int i=0; i<10; i++){
- temp += "say something"+i;
- }
- for (int i=0; i<20; i++){
- temp += "say nothing"+i;
- }
- for (int i=0; i<30; i++){
- temp += "always say nothing"+i;
- }
- for (int i=0; i<40; i++){
- temp += "really nothing to say "+i;
- }
- for (int i=0; i<50; i++){
- temp += "really really nothing to say "+i;
- }
- for (int i=0; i<60; i++){
- temp += ".. "+i;
- }
- for (int i=0; i<70; i++){
- temp += "you say something? "+i;
- }
- for (int i=0; i<80; i++){
- temp += "ah no..."+i;
- }
- for (int i=0; i<90; i++){
- temp += "bye"+i;
- }
- }
-
-}
+++ /dev/null
-/*
- * 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;
-
-public class Class1 {
-
- public void someMethod() {
- System.out.println("Test");
- }
-
- public void duplicatedMethod() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- System.out.println("test");
- int intergerToBeIncremented3 = 0;
- while (intergerToBeIncremented3 < 100) {
- intergerToBeIncremented3++;
- }
- System.out.println("test");
- int intergerToBeIncremented4 = 0;
- while (intergerToBeIncremented4 < 100) {
- intergerToBeIncremented4++;
- }
- System.out.println("test");
- int intergerToBeIncremented5 = 0;
- while (intergerToBeIncremented5 < 100) {
- intergerToBeIncremented5++;
- }
- System.out.println("test");
- int intergerToBeIncremented6 = 0;
- while (intergerToBeIncremented6 < 100) {
- intergerToBeIncremented6++;
- }
- System.out.println("test");
- int intergerToBeIncremented7 = 0;
- while (intergerToBeIncremented7 < 100) {
- intergerToBeIncremented7++;
- }
- }
-
-}
+++ /dev/null
-/*
- * 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;
-
-public class Class2 {
-
- public void duplicatedMethod() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- System.out.println("test");
- int intergerToBeIncremented3 = 0;
- while (intergerToBeIncremented3 < 100) {
- intergerToBeIncremented3++;
- }
- System.out.println("test");
- int intergerToBeIncremented4 = 0;
- while (intergerToBeIncremented4 < 100) {
- intergerToBeIncremented4++;
- }
- System.out.println("test");
- int intergerToBeIncremented5 = 0;
- while (intergerToBeIncremented5 < 100) {
- intergerToBeIncremented5++;
- }
- System.out.println("test");
- int intergerToBeIncremented6 = 0;
- while (intergerToBeIncremented6 < 100) {
- intergerToBeIncremented6++;
- }
- System.out.println("test");
- int intergerToBeIncremented7 = 0;
- while (intergerToBeIncremented7 < 100) {
- intergerToBeIncremented7++;
- }
- }
-
- public void someOtherMethod() {
- System.out.println("Test2");
- }
-}
+++ /dev/null
-/*
- * 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;
-
-public class Class3 {
-
- private String test;
-
- public void duplicatedMethod() {
- int intergerToBeIncremented = 0;
- while (intergerToBeIncremented < 100) {
- intergerToBeIncremented++;
- }
- System.out.println("test");
- int intergerToBeIncremented3 = 0;
- while (intergerToBeIncremented3 < 100) {
- intergerToBeIncremented3++;
- }
- System.out.println("test");
- int intergerToBeIncremented4 = 0;
- while (intergerToBeIncremented4 < 100) {
- intergerToBeIncremented4++;
- }
- System.out.println("test");
- int intergerToBeIncremented5 = 0;
- while (intergerToBeIncremented5 < 100) {
- intergerToBeIncremented5++;
- }
- System.out.println("test");
- int intergerToBeIncremented6 = 0;
- while (intergerToBeIncremented6 < 100) {
- intergerToBeIncremented6++;
- }
- System.out.println("test");
- int intergerToBeIncremented7 = 0;
- while (intergerToBeIncremented7 < 100) {
- intergerToBeIncremented7++;
- }
- }
-
- public String getTest() {
- return test;
- }
-
-}
--- /dev/null
+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';
+ }
+ }
+}
--- /dev/null
+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';
+ }
+ }
+}
--- /dev/null
+package duplicated_lines_within_dir;
+
+public class DuplicatedLinesInSameDirectory1 {
+
+ public DuplicatedLinesInSameDirectory1() {
+ }
+
+ /*
+ * sddfgdfgfg
+ */
+ public void duplicatedMethodInSameFile1() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ int intergerToBeIncremented2 = 0;
+ while (intergerToBeIncremented2 < 100) {
+ intergerToBeIncremented2++;
+ }
+ // first
+ int intergerToBeIncremented3 = 0;
+ while (intergerToBeIncremented3 < 100) {
+ intergerToBeIncremented3++;
+ }
+ int intergerToBeIncremented4 = 0;
+ while (intergerToBeIncremented4 < 100) {
+ intergerToBeIncremented4++;
+ }
+ int intergerToBeIncremented5 = 0;
+ while (intergerToBeIncremented5 < 100) {
+ intergerToBeIncremented5++;
+ }
+ int intergerToBeIncremented6 = 0;
+ while (intergerToBeIncremented6 < 100) {
+ intergerToBeIncremented6++;
+ }
+ int intergerToBeIncremented7 = 0;
+ while (intergerToBeIncremented7 < 100) {
+ intergerToBeIncremented7++;
+ }
+ }
+
+
+ public void duplicatedMethodInSameFile3() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ // test2
+ int intergerToBeIncremented2 = 0;
+ while (intergerToBeIncremented2 < 100) {
+ intergerToBeIncremented2++;
+ }
+ int intergerToBeIncremented8 = 0;
+ while (intergerToBeIncremented8 < 100) {
+ intergerToBeIncremented8++;
+ }
+ int intergerToBeIncremented9 = 0;
+ while (intergerToBeIncremented9 < 100) {
+ intergerToBeIncremented9++;
+ }
+ // test 1
+ int intergerToBeIncremented10 = 0;
+ while (intergerToBeIncremented10 < 100) {
+ intergerToBeIncremented10++;
+ }
+ int intergerToBeIncremented60 = 0;
+ while (intergerToBeIncremented60 < 100) {
+ intergerToBeIncremented60++;
+ }
+ int intergerToBeIncremented70 = 0;
+ while (intergerToBeIncremented70 < 100) {
+ intergerToBeIncremented70++;
+ }
+ }
+
+ public void duplicated2MethodInSameFile3() {
+ System.out.print("copy test start");
+ int intergerToBeIncremented1 = 0;
+ while (intergerToBeIncremented1 < 100) {
+ intergerToBeIncremented1++;
+ }
+ int intergerToBeIncremented20 = 0;
+ while (intergerToBeIncremented20 < 100) {
+ intergerToBeIncremented20++;
+ }
+ int intergerToBeIncremented8 = 0;
+ while (intergerToBeIncremented8 < 100) {
+ intergerToBeIncremented8++;
+ }
+ int intergerToBeIncremented9 = 0;
+ while (intergerToBeIncremented9 < 100) {
+ intergerToBeIncremented9++;
+ }
+ int intergerToBeIncremented10 = 0;
+ while (intergerToBeIncremented10 < 100) {
+ intergerToBeIncremented10++;
+ }
+ int intergerToBeIncremented60 = 0;
+ while (intergerToBeIncremented60 < 100) {
+ intergerToBeIncremented60++;
+ }
+ System.out.print("copy test end");
+ }
+}
--- /dev/null
+package duplicated_lines_within_dir;
+
+public class DuplicatedLinesInSameDirectory2 {
+
+ public DuplicatedLinesInSameDirectory2() {
+ }
+
+ public void duplicated2MethodInSameFile3() {
+ System.out.print("copy test start");
+ int intergerToBeIncremented1 = 0;
+ while (intergerToBeIncremented1 < 100) {
+ intergerToBeIncremented1++;
+ }
+ int intergerToBeIncremented20 = 0;
+ while (intergerToBeIncremented20 < 100) {
+ intergerToBeIncremented20++;
+ }
+ int intergerToBeIncremented8 = 0;
+ while (intergerToBeIncremented8 < 100) {
+ intergerToBeIncremented8++;
+ }
+ int intergerToBeIncremented9 = 0;
+ while (intergerToBeIncremented9 < 100) {
+ intergerToBeIncremented9++;
+ }
+ int intergerToBeIncremented10 = 0;
+ while (intergerToBeIncremented10 < 100) {
+ intergerToBeIncremented10++;
+ }
+ int intergerToBeIncremented60 = 0;
+ while (intergerToBeIncremented60 < 100) {
+ intergerToBeIncremented60++;
+ }
+ System.out.print("copy test end");
+ }
+
+ public void duplicatedMethodInSameFile1() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ int intergerToBeIncremented2 = 0;
+ while (intergerToBeIncremented2 < 100) {
+ intergerToBeIncremented2++;
+ }
+ // second
+ int intergerToBeIncremented3 = 0;
+ while (intergerToBeIncremented3 < 100) {
+ intergerToBeIncremented3++;
+ }
+ int intergerToBeIncremented4 = 0;
+ while (intergerToBeIncremented4 < 100) {
+ intergerToBeIncremented4++;
+ }
+ int intergerToBeIncremented5 = 0;
+ while (intergerToBeIncremented5 < 100) {
+ intergerToBeIncremented5++;
+ }
+ // vghgvhz
+ // bhjjh
+ int intergerToBeIncremented6 = 0;
+ while (intergerToBeIncremented6 < 100) {
+ intergerToBeIncremented6++;
+ }
+ int intergerToBeIncremented7 = 0;
+ while (intergerToBeIncremented7 < 100) {
+ intergerToBeIncremented7++;
+ }
+ }
+
+}
--- /dev/null
+package duplicated_lines_within_same_file;
+
+public class DuplicatedLinesInSameFile {
+
+ public DuplicatedLinesInSameFile() {
+ }
+
+ public void duplicatedMethodInSameFile1() {
+ String temp = "";
+ for (int i=0; i<10; i++){
+ temp += "say something"+i;
+ }
+ for (int i=0; i<20; i++){
+ temp += "say nothing"+i;
+ }
+ for (int i=0; i<30; i++){
+ temp += "always say nothing"+i;
+ }
+ for (int i=0; i<40; i++){
+ temp += "really nothing to say "+i;
+ }
+ for (int i=0; i<50; i++){
+ temp += "really really nothing to say "+i;
+ }
+ for (int i=0; i<60; i++){
+ temp += ".. "+i;
+ }
+ for (int i=0; i<70; i++){
+ temp += "you say something? "+i;
+ }
+ for (int i=0; i<80; i++){
+ temp += "ah no..."+i;
+ }
+ for (int i=0; i<90; i++){
+ temp += "bye"+i;
+ }
+ }
+
+ public void duplicatedMethodInSameFile2() {
+ String temp = "";
+ for (int i=0; i<10; i++){
+ temp += "say something"+i;
+ }
+ for (int i=0; i<20; i++){
+ temp += "say nothing"+i;
+ }
+ for (int i=0; i<30; i++){
+ temp += "always say nothing"+i;
+ }
+ for (int i=0; i<40; i++){
+ temp += "really nothing to say "+i;
+ }
+ for (int i=0; i<50; i++){
+ temp += "really really nothing to say "+i;
+ }
+ for (int i=0; i<60; i++){
+ temp += ".. "+i;
+ }
+ for (int i=0; i<70; i++){
+ temp += "you say something? "+i;
+ }
+ for (int i=0; i<80; i++){
+ temp += "ah no..."+i;
+ }
+ for (int i=0; i<90; i++){
+ temp += "bye"+i;
+ }
+ }
+
+}
--- /dev/null
+package duplicated_same_lines_within_3_files;
+
+public class File1 {
+
+ public void someMethod() {
+ System.out.println("Test");
+ }
+
+ public void duplicatedMethod() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented3 = 0;
+ while (intergerToBeIncremented3 < 100) {
+ intergerToBeIncremented3++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented4 = 0;
+ while (intergerToBeIncremented4 < 100) {
+ intergerToBeIncremented4++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented5 = 0;
+ while (intergerToBeIncremented5 < 100) {
+ intergerToBeIncremented5++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented6 = 0;
+ while (intergerToBeIncremented6 < 100) {
+ intergerToBeIncremented6++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented7 = 0;
+ while (intergerToBeIncremented7 < 100) {
+ intergerToBeIncremented7++;
+ }
+ }
+
+}
--- /dev/null
+package duplicated_same_lines_within_3_files;
+
+public class File2 {
+
+ public void duplicatedMethod() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented3 = 0;
+ while (intergerToBeIncremented3 < 100) {
+ intergerToBeIncremented3++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented4 = 0;
+ while (intergerToBeIncremented4 < 100) {
+ intergerToBeIncremented4++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented5 = 0;
+ while (intergerToBeIncremented5 < 100) {
+ intergerToBeIncremented5++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented6 = 0;
+ while (intergerToBeIncremented6 < 100) {
+ intergerToBeIncremented6++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented7 = 0;
+ while (intergerToBeIncremented7 < 100) {
+ intergerToBeIncremented7++;
+ }
+ }
+
+ public void someOtherMethod() {
+ System.out.println("Test2");
+ }
+}
--- /dev/null
+package duplicated_same_lines_within_3_files;
+
+public class File3 {
+
+ private String test;
+
+ public void duplicatedMethod() {
+ int intergerToBeIncremented = 0;
+ while (intergerToBeIncremented < 100) {
+ intergerToBeIncremented++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented3 = 0;
+ while (intergerToBeIncremented3 < 100) {
+ intergerToBeIncremented3++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented4 = 0;
+ while (intergerToBeIncremented4 < 100) {
+ intergerToBeIncremented4++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented5 = 0;
+ while (intergerToBeIncremented5 < 100) {
+ intergerToBeIncremented5++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented6 = 0;
+ while (intergerToBeIncremented6 < 100) {
+ intergerToBeIncremented6++;
+ }
+ System.out.println("test");
+ int intergerToBeIncremented7 = 0;
+ while (intergerToBeIncremented7 < 100) {
+ intergerToBeIncremented7++;
+ }
+ }
+
+ public String getTest() {
+ return test;
+ }
+
+}
@ClassRule
public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
.addPlugin(xooPlugin())
- .setOrchestratorProperty("javaVersion", "LATEST_RELEASE").addPlugin("java")
.build();
}
/*
- * 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);
}
/**
*/
@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);
}
}
--- /dev/null
+{
+ "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"
+ }
+ }
+}
--- /dev/null
+{
+ "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<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<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<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<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<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<60; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 26,
+ "code": " temp += \".. \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 27,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 28,
+ "code": " for (int i=0; i<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<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<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<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<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<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<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<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<60; i++){",
+ "duplicated": true
+ },
+ {
+ "line": 57,
+ "code": " temp += \".. \"+i;",
+ "duplicated": true
+ },
+ {
+ "line": 58,
+ "code": " }",
+ "duplicated": true
+ },
+ {
+ "line": 59,
+ "code": " for (int i=0; i<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<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<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
+ }
+ ]
+}