Skip to content
This repository has been archived by the owner on Jul 8, 2019. It is now read-only.

Commit

Permalink
Merge branch 'SoftwareBuildService-bugfix/canonical-path', fix #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Mar 11, 2017
2 parents 1f09a13 + 58a2f0b commit 37de552
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/main/java/com/pablissimo/sonar/TsLintSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.pablissimo.sonar.model.TsLintIssue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.rule.ActiveRule;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
Expand All @@ -14,6 +15,7 @@
import org.sonar.api.rule.RuleKey;

import java.io.File;
import java.io.IOException;
import java.util.*;

public class TsLintSensor implements Sensor {
Expand Down Expand Up @@ -67,9 +69,10 @@ public void execute(SensorContext ctx) {
ruleNames.add(rule.ruleKey().rule());
}

FileSystem fs = ctx.fileSystem();
List<String> paths = new ArrayList<>();

for (InputFile file : ctx.fileSystem().inputFiles(ctx.fileSystem().predicates().hasLanguage(TypeScriptLanguage.LANGUAGE_KEY))) {
for (InputFile file : fs.inputFiles(fs.predicates().hasLanguage(TypeScriptLanguage.LANGUAGE_KEY))) {
if (shouldSkipFile(file.file(), skipTypeDefFiles)) {
continue;
}
Expand All @@ -87,6 +90,15 @@ public void execute(SensorContext ctx) {
return;
}

File baseDir = fs.baseDir();
String baseDirPath = baseDir.getPath();
String baseDirCanonicalPath = null;
try {
baseDirCanonicalPath = baseDir.getCanonicalPath();
} catch (IOException e) {
LOG.error("Failed to canonicalize " + baseDirPath, e);
}

// Each issue bucket will contain info about a single file
for (Map.Entry<String, List<TsLintIssue>> kvp : issues.entrySet()) {
String filePath = kvp.getKey();
Expand All @@ -96,7 +108,10 @@ public void execute(SensorContext ctx) {
continue;
}

File matchingFile = ctx.fileSystem().resolvePath(filePath);
if (baseDirCanonicalPath != null) {
filePath = filePath.replace(baseDirCanonicalPath, baseDirPath);
}
File matchingFile = fs.resolvePath(filePath);
InputFile inputFile = null;

if (shouldSkipFile(matchingFile, skipTypeDefFiles)) {
Expand All @@ -105,7 +120,7 @@ public void execute(SensorContext ctx) {

if (matchingFile != null) {
try {
inputFile = ctx.fileSystem().inputFile(ctx.fileSystem().predicates().is(matchingFile));
inputFile = fs.inputFile(fs.predicates().is(matchingFile));
}
catch (IllegalArgumentException e) {
LOG.error("Failed to resolve " + filePath + " to a single path", e);
Expand Down

0 comments on commit 37de552

Please sign in to comment.