import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
+import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.issue.Issue.Severity;
import org.sonar.api.batch.sensor.measure.Measure;
jsonWriter.beginObject()
.prop("repository", issue.ruleKey().repository())
.prop("rule", issue.ruleKey().rule());
- if (issue.inputPath() != null) {
- jsonWriter.prop("path", issue.inputPath().relativePath());
+ InputPath inputPath = issue.inputPath();
+ if (inputPath != null) {
+ jsonWriter.prop("path", inputPath.relativePath());
}
jsonWriter.prop("message", issue.message())
.prop("effortToFix", issue.effortToFix())
@Override
public Object get(Value value, Class clazz, CoderContext context) {
- DefaultIssue newIssue = new DefaultIssue(null);
+ DefaultIssue newIssue = new DefaultIssue();
newIssue.withKey(value.getString());
if (value.isNull(true)) {
newIssue.onProject();
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Type;
+import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.rule.internal.DefaultActiveRule;
@Override
public void store(Issue issue) {
String resourceKey;
- if (issue.inputPath() != null) {
- resourceKey = ComponentKeys.createEffectiveKey(def.getKey(), issue.inputPath());
+ InputPath inputPath = issue.inputPath();
+ if (inputPath != null) {
+ resourceKey = ComponentKeys.createEffectiveKey(def.getKey(), inputPath);
} else {
resourceKey = def.getKey();
}
autodetection();
if (this.provider == null) {
considerOldScmUrl();
+ }
+ if (this.provider == null) {
LOG.warn("SCM provider autodetection failed. No SCM provider claims to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY
+ " to define SCM of your project.");
}
}
private void autodetection() {
- for (ScmProvider provider : providerPerKey.values()) {
- if (provider.supports(projectReactor.getRoot().getBaseDir())) {
+ for (ScmProvider installedProvider : providerPerKey.values()) {
+ if (installedProvider.supports(projectReactor.getRoot().getBaseDir())) {
if (this.provider == null) {
- this.provider = provider;
+ this.provider = installedProvider;
} else {
- throw new IllegalStateException("SCM provider autodetection failed. Both " + this.provider.key() + " and " + provider.key()
+ throw new IllegalStateException("SCM provider autodetection failed. Both " + this.provider.key() + " and " + installedProvider.key()
+ " claim to support this project. Please use " + CoreProperties.SCM_PROVIDER_KEY + " to define SCM of your project.");
}
}
@Override
public void stop() {
-
+ // Nothing to do
}
}
List<InputFile> filesToBlame = new LinkedList<InputFile>();
for (InputFile f : fs.inputFiles(fs.predicates().all())) {
- FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
- if (f.status() == Status.SAME
- && fileData != null
- && fileData.scmAuthorsByLine() != null
- && fileData.scmLastCommitDatetimesByLine() != null
- && fileData.scmRevisionsByLine() != null) {
- saveMeasures(context, f, fileData.scmAuthorsByLine(), fileData.scmLastCommitDatetimesByLine(), fileData.scmRevisionsByLine());
- } else {
- filesToBlame.add(f);
- }
+ copyPreviousMeasuresForUnmodifiedFiles(context, filesToBlame, f);
}
if (!filesToBlame.isEmpty()) {
LOG.info("SCM provider for this project is: " + configuration.provider().key());
}
}
+ private void copyPreviousMeasuresForUnmodifiedFiles(final SensorContext context, List<InputFile> filesToBlame, InputFile f) {
+ FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
+
+ if (f.status() == Status.SAME && fileData != null) {
+ String scmAuthorsByLine = fileData.scmAuthorsByLine();
+ String scmLastCommitDatetimesByLine = fileData.scmLastCommitDatetimesByLine();
+ String scmRevisionsByLine = fileData.scmRevisionsByLine();
+ if (scmAuthorsByLine != null
+ && scmLastCommitDatetimesByLine != null
+ && scmRevisionsByLine != null) {
+ saveMeasures(context, f, scmAuthorsByLine, scmLastCommitDatetimesByLine, scmRevisionsByLine);
+ } else {
+ filesToBlame.add(f);
+ }
+ } else {
+ filesToBlame.add(f);
+ }
+ }
+
/**
* This method is synchronized since it is allowed for plugins to compute blame in parallel.
*/
long duration = value.getLong();
TestCase.Type type = TestCase.Type.values()[value.getInt()];
TestCase.Status status = TestCase.Status.values()[value.getInt()];
- return new DefaultTestCase(null)
+ return new DefaultTestCase()
.inTestFile(testFile)
.ofType(type)
.name(name)