aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-07-25 16:31:45 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-07-30 18:03:36 +0200
commit6074164392edd3db2dfdfd21d05cd56c19e2b0e6 (patch)
treeb9314796d68c4c396dcf45a1ab689b06490fd4a2 /sonar-plugin-api
parent12f243728f42a5eb1e714ff15f0240109193f1d8 (diff)
downloadsonarqube-6074164392edd3db2dfdfd21d05cd56c19e2b0e6.tar.gz
sonarqube-6074164392edd3db2dfdfd21d05cd56c19e2b0e6.zip
SONAR-5389 New duplication API
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java4
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java17
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationBuilder.java38
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/TokenBuilder.java40
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java21
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java1
7 files changed, 121 insertions, 3 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
index aad1de5ea03..b73e0a0ecee 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
@@ -344,10 +344,10 @@ public interface CoreProperties {
/**
* @since 2.11
*/
- String CPD_CROSS_RPOJECT = "sonar.cpd.cross_project";
+ String CPD_CROSS_PROJECT = "sonar.cpd.cross_project";
/**
- * @see #CPD_CROSS_RPOJECT
+ * @see #CPD_CROSS_PROJECT
* @since 2.11
*/
boolean CPD_CROSS_RPOJECT_DEFAULT_VALUE = false;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
index 156e140fa57..7c82aa501d0 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/internal/DeprecatedDefaultInputFile.java
@@ -50,8 +50,9 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org.
return new File(basedir);
}
- public void setBasedir(File basedir) {
+ public DeprecatedDefaultInputFile setBasedir(File basedir) {
this.basedir = PathUtils.sanitize(basedir.getAbsolutePath());
+ return this;
}
/**
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
index 787d2fddb3d..647cab3f3f9 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
@@ -24,6 +24,8 @@ import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.rule.ActiveRules;
+import org.sonar.api.batch.sensor.duplication.DuplicationBuilder;
+import org.sonar.api.batch.sensor.duplication.TokenBuilder;
import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.issue.IssueBuilder;
@@ -126,4 +128,19 @@ public interface SensorContext {
*/
SymbolTableBuilder symbolTableBuilder(InputFile inputFile);
+ // ------------ DUPLICATIONS ------------
+
+ /**
+ * Builder to define tokens in a file. Tokens are used to compute duplication by the core.
+ * @since 4.5
+ */
+ TokenBuilder tokenBuilder(InputFile inputFile);
+
+ /**
+ * Builder to manually define duplications in a file. When duplication are manually computed then
+ * no need to use {@link #tokenBuilder(InputFile)}.
+ * @since 4.5
+ */
+ DuplicationBuilder duplicationBuilder(InputFile inputFile);
+
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationBuilder.java
new file mode 100644
index 00000000000..2f37220b1a3
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/DuplicationBuilder.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.sonar.api.batch.sensor.duplication;
+
+import org.sonar.api.batch.fs.InputFile;
+
+/**
+ * This builder is used to declare duplications on files of the project.
+ * @since 4.5
+ */
+public interface DuplicationBuilder {
+
+ DuplicationBuilder originBlock(int startLine, int endLine);
+
+ DuplicationBuilder isDuplicatedBy(InputFile sameOrOtherFile, int startLine, int endLine);
+
+ /**
+ * Call this method only once when your are done with defining all duplicates of origin block.
+ */
+ void done();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/TokenBuilder.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/TokenBuilder.java
new file mode 100644
index 00000000000..f4de9fffc8c
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/TokenBuilder.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.sonar.api.batch.sensor.duplication;
+
+/**
+ * This builder is used to define token on files. Tokens are later used to compute duplication.
+ * Tokens should be declared in sequential order.
+ * @since 4.5
+ */
+public interface TokenBuilder {
+
+ /**
+ * Call this method to register a new token.
+ * @param line Line number of the token. Line starts at 1.
+ * @param image Text of the token.
+ */
+ TokenBuilder addToken(int line, String image);
+
+ /**
+ * Call this method only once when your are done with defining tokens of the file.
+ */
+ void done();
+}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java
new file mode 100644
index 00000000000..4973316830a
--- /dev/null
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/duplication/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package org.sonar.api.batch.sensor.duplication;
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
index 7a86f7b145c..870a8519271 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Measure.java
@@ -343,6 +343,7 @@ public class Measure<G extends Serializable> implements Serializable {
/**
* @return the data field of the measure
*/
+ @CheckForNull
public String getData() {
return data;
}