aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-10-09 17:04:20 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-10-14 11:59:06 +0200
commit19f80967d511bfff7399290ccbb6c98304e6e2b2 (patch)
tree0169665598eae9be207c87ec5d7f2b0273b68e11 /sonar-batch/src/main
parentbcd54407f2a6ca42c80961303fe1567e7b33621a (diff)
downloadsonarqube-19f80967d511bfff7399290ccbb6c98304e6e2b2.tar.gz
sonarqube-19f80967d511bfff7399290ccbb6c98304e6e2b2.zip
SONAR-5715 Fix preview mode when source file contains space in its path
Diffstat (limited to 'sonar-batch/src/main')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java11
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java3
3 files changed, 14 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
index d43ef8e0e71..0fcc09bcf3d 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java
@@ -36,7 +36,9 @@ import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
import java.net.URI;
+import java.net.URLEncoder;
/**
* Replace the deprecated org.sonar.batch.ServerMetadata
@@ -135,4 +137,13 @@ public class ServerClient implements BatchComponent {
private String getPassword() {
return props.property(CoreProperties.PASSWORD);
}
+
+ public static String encodeForUrl(String url) {
+ try {
+ return URLEncoder.encode(url, "UTF-8");
+
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("Encoding not supported", e);
+ }
+ }
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
index 8340c63a681..7ff216c4280 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultProjectReferentialsLoader.java
@@ -28,9 +28,6 @@ import org.sonar.batch.bootstrap.TaskProperties;
import org.sonar.batch.protocol.input.ProjectReferentials;
import org.sonar.batch.rule.ModuleQProfiles;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-
public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoader {
private static final Logger LOG = LoggerFactory.getLogger(DefaultProjectReferentialsLoader.class);
@@ -51,11 +48,7 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad
if (taskProperties.properties().containsKey(ModuleQProfiles.SONAR_PROFILE_PROP)) {
LOG.warn("Ability to set quality profile from command line using '" + ModuleQProfiles.SONAR_PROFILE_PROP
+ "' is deprecated and will be dropped in a future SonarQube version. Please configure quality profile used by your project on SonarQube server.");
- try {
- url += "&profile=" + URLEncoder.encode(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP), "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException("Unable to encode URL", e);
- }
+ url += "&profile=" + ServerClient.encodeForUrl(taskProperties.properties().get(ModuleQProfiles.SONAR_PROFILE_PROP));
}
url += "&preview=" + analysisMode.isPreview();
return ProjectReferentials.fromJson(serverClient.request(url));
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
index be876cbc0c9..7bea9e46216 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/LastSnapshots.java
@@ -58,7 +58,8 @@ public class LastSnapshots implements BatchComponent {
@CheckForNull
private String loadSourceFromWs(Resource resource) {
try {
- return server.request("/api/sources?resource=" + resource.getEffectiveKey() + "&format=txt", false, analysisMode.getPreviewReadTimeoutSec() * 1000);
+ return server
+ .request("/api/sources?resource=" + ServerClient.encodeForUrl(resource.getEffectiveKey()) + "&format=txt", false, analysisMode.getPreviewReadTimeoutSec() * 1000);
} catch (HttpDownloader.HttpException he) {
if (he.getResponseCode() == 404) {
return "";