Skip to content

Commit

Permalink
SLI-128 Fix relative path -> file key converter (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Gyerik authored Nov 17, 2016
1 parent 5817ba9 commit 5443b0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ private Iterator<ServerIssue> fetchServerIssues(SonarQubeServer server, Connecte
try {
ServerConfiguration serverConfiguration = SonarLintUtils.getServerConfiguration(server);
LOGGER.debug("fetchServerIssues moduleKey=" + moduleKey + ", filepath=" + relativePath);
return engine.downloadServerIssues(serverConfiguration, moduleKey, relativePath);
String fileKey = SonarLintUtils.toFileKey(relativePath);
return engine.downloadServerIssues(serverConfiguration, moduleKey, fileKey);
} catch (DownloadException e) {
console.info(e.getMessage());
return engine.getServerIssues(moduleKey, relativePath);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/sonarlint/intellij/util/SonarLintUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.net.HttpConfigurable;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
Expand All @@ -60,6 +61,7 @@ public class SonarLintUtils {

private static final Logger LOG = Logger.getInstance(SonarLintUtils.class);
public static final int CONNECTION_TIMEOUT_MS = 30_000;
public static final String PATH_SEPARATOR_PATTERN = Pattern.quote(File.separator);

private SonarLintUtils() {
// Utility class
Expand Down Expand Up @@ -326,4 +328,17 @@ public static String getRelativePath(Project project, VirtualFile virtualFile) {
return Paths.get(project.getBasePath()).relativize(Paths.get(virtualFile.getPath())).toString();
}

/**
* Convert relative path to SonarQube file key
*
* @param relativePath relative path string in the local OS
* @return SonarQube file key
*/
public static String toFileKey(String relativePath) {
if (File.separatorChar != '/') {
return relativePath.replaceAll(PATH_SEPARATOR_PATTERN, "/");
}
return relativePath;
}

}

0 comments on commit 5443b0d

Please sign in to comment.