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

Commit

Permalink
Merge branch 'master' of github.com:Pablissimo/SonarTsPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablissimo committed Feb 4, 2017
2 parents 3032987 + 42e821c commit 99b61e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.pablissimo.sonar</groupId>
<artifactId>sonar-typescript-plugin</artifactId>
<packaging>sonar-plugin</packaging>
<version>0.99-SNAPSHOT</version>
<version>0.99.1-SNAPSHOT</version>

<name>TypeScript</name>
<description>Analyse TypeScript projects</description>
Expand Down
18 changes: 16 additions & 2 deletions src/main/java/com/pablissimo/sonar/LCOVParserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -148,14 +150,25 @@ private static void logWrongDataWarning(String dataType, String lineNumber, Ille
private FileData loadCurrentFileData(final Map<InputFile, FileData> files, String line) {
String filePath = line.substring(SF.length());
FileData fileData = null;
// some tools (like Istanbul, Karma) provide relative paths, so let's consider them relative to project directory
InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));

// some tools (like Istanbul, Karma) provide relative paths, so let's consider them relative to project directory
InputFile inputFile = null;
try {
Paths.get(filePath);
inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(filePath));
}
catch (InvalidPathException ex) {
LOG.debug("LCOV file referred to path that appears invalid (not just not on disk): " + filePath);
}

// Try to accommodate Angular projects that, when the angular template loader's used
// by checking for a ! in the filepath if the path isn't found - have a bash at seeking
// everything after the ! as a second fallback pass
if (inputFile == null && filePath.contains("!") && (filePath.indexOf("!") + 1) < filePath.length()) {
String amendedPath = filePath.substring(filePath.indexOf("!") + 1);

LOG.debug("Failed to resolve " + filePath + " as a valid source file, so attempting " + amendedPath + " instead");

inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(amendedPath));
}

Expand All @@ -166,6 +179,7 @@ private FileData loadCurrentFileData(final Map<InputFile, FileData> files, Strin
files.put(inputFile, fileData);
}
} else {
LOG.debug("Failed to resolve path " + filePath + " to a file in the analysis set");
unresolvedPaths.add(filePath);
}
return fileData;
Expand Down
5 changes: 5 additions & 0 deletions src/test/java/com/pablissimo/sonar/LCOVParserImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public void parseFileThrowsWhenFileDoesNotExist() {
parser.parseFile(nonExistent);
}

@Test
public void doesNotThrow_withWindowsStyleAngularCLIPaths() {
executeForTestCase("angularwindowspaths");
}

private Map<InputFile, NewCoverage> executeForTestCase(String testName) {
File lcovFile = resource(testName);
LCOVParser parser = getParser(lcovFile);
Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/lcov/angularwindowspaths.lcov
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SF:C:/path/to/template/loader.js!C:\path\to\file.ts
DA:1,3
end_of_record

0 comments on commit 99b61e8

Please sign in to comment.