diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-25 13:48:35 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-10-02 17:52:23 +0200 |
commit | cb639f864815f8dfd7dbbd0f21fd4ad08b7db8cc (patch) | |
tree | 89798ee35e415d2a024e320e6369636654780520 /sonar-plugin-api | |
parent | a1cb900c90178390776c987462a4f2501b1e4e2c (diff) | |
download | sonarqube-cb639f864815f8dfd7dbbd0f21fd4ad08b7db8cc.tar.gz sonarqube-cb639f864815f8dfd7dbbd0f21fd4ad08b7db8cc.zip |
SONAR-5644 Rework SCM API
Diffstat (limited to 'sonar-plugin-api')
5 files changed, 104 insertions, 23 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameCommand.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameCommand.java new file mode 100644 index 00000000000..385b3528e54 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameCommand.java @@ -0,0 +1,47 @@ +/* + * 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.scm; + +import org.sonar.api.batch.fs.FileSystem; +import org.sonar.api.batch.fs.InputFile; + +import java.util.List; + +/** + * @since 5.0 + */ +public interface BlameCommand { + + /** + * Compute blame of the provided files. Computation can be done in parallel. + * If there is an error that prevent to blame a file then an exception should be raised. + */ + void blame(FileSystem fs, Iterable<InputFile> files, BlameResult result); + + /** + * Callback for the provider to report results of blame per file. + */ + public static interface BlameResult { + + void add(InputFile file, List<BlameLine> lines); + + } + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java index 2303b90f794..c4362f05a9b 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java @@ -19,6 +19,11 @@ */ package org.sonar.api.batch.scm; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import org.apache.commons.lang.builder.ToStringStyle; + import java.util.Date; /** @@ -99,4 +104,41 @@ public class BlameLine { this.date = null; } } + + // For testing purpose + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this) { + return true; + } + if (obj.getClass() != getClass()) { + return false; + } + BlameLine rhs = (BlameLine) obj; + return new EqualsBuilder() + .append(date, rhs.date) + .append(revision, rhs.revision) + .append(author, rhs.author) + .append(committer, rhs.committer) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(27, 45). + append(date) + .append(revision) + .append(author) + .append(committer) + .toHashCode(); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java index 2630f95b5e6..a32bec98538 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java @@ -21,42 +21,31 @@ package org.sonar.api.batch.scm; import org.sonar.api.BatchExtension; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.batch.fs.FileSystem; -import org.sonar.api.batch.fs.InputFile; import java.io.File; -import java.util.List; /** * @since 5.0 */ @InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public interface ScmProvider extends BatchExtension { +public abstract class ScmProvider implements BatchExtension { /** * Unique identifier of the provider. Can be used in SCM URL to define the provider to use. */ - String key(); + public abstract String key(); /** * Does this provider able to manage files located in this directory. - * Used by autodetection. + * Used by autodetection. Not considered if user has forced the provider key. + * @return false by default */ - boolean supports(File baseDir); - - /** - * Compute blame of the provided files. Computation can be done in parallel. - * If there is an error that prevent to blame a file then an exception should be raised. - */ - void blame(FileSystem fs, Iterable<InputFile> files, BlameResult result); - - /** - * Callback for the provider to save results of blame per file. - */ - public static interface BlameResult { - - void add(InputFile file, List<BlameLine> lines); + public boolean supports(File baseDir) { + return false; + } + public BlameCommand blameCommand() { + throw new UnsupportedOperationException("Blame command is not supported by " + key() + " provider"); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java index 23148378f35..42637fdd4cb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/internal/DefaultIssue.java @@ -52,10 +52,12 @@ public class DefaultIssue implements Issue { private final SensorStorage storage; public DefaultIssue() { + this.key = UUID.randomUUID().toString(); this.storage = null; } public DefaultIssue(SensorStorage storage) { + this.key = UUID.randomUUID().toString(); this.storage = storage; } @@ -155,9 +157,6 @@ public class DefaultIssue implements Issue { public void save() { Preconditions.checkNotNull(this.storage, "No persister on this object"); Preconditions.checkNotNull(this.ruleKey, "ruleKey is mandatory on issue"); - if (this.key == null) { - this.key = UUID.randomUUID().toString(); - } Preconditions.checkState(!Strings.isNullOrEmpty(key), "Fail to generate issue key"); storage.store(this); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java index 7d05c23f259..023adec8106 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/test/internal/DefaultTestCase.java @@ -43,6 +43,10 @@ public class DefaultTestCase implements TestCase { private TestCase.Type type = Type.UNIT; private String stackTrace; + public DefaultTestCase() { + this.storage = null; + } + public DefaultTestCase(SensorStorage storage) { this.storage = storage; } |