diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-26 14:20:53 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-08-26 14:21:44 +0200 |
commit | 5bba55cd38c983e09767246e777d8d317942ab5d (patch) | |
tree | 592b2e39c369cd8f84df17936e194ea4b6194929 /sonar-batch | |
parent | bf24c787762e7cf53ef636c6d1e7782141b2812d (diff) | |
download | sonarqube-5bba55cd38c983e09767246e777d8d317942ab5d.tar.gz sonarqube-5bba55cd38c983e09767246e777d8d317942ab5d.zip |
SONAR-5417 Handle permision error for project referential loader
Diffstat (limited to 'sonar-batch')
4 files changed, 7 insertions, 40 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 1d0cefb14b4..d43ef8e0e71 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 @@ -92,7 +92,7 @@ public class ServerClient implements BatchComponent { } } - public InputSupplier<InputStream> doRequest(String pathStartingWithSlash, @Nullable Integer timeoutMillis) { + private InputSupplier<InputStream> doRequest(String pathStartingWithSlash, @Nullable Integer timeoutMillis) { Preconditions.checkArgument(pathStartingWithSlash.startsWith("/"), "Path must start with slash /"); String path = StringEscapeUtils.escapeHtml(pathStartingWithSlash); diff --git a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java index 239835275c4..17fd6821a6c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/referential/DefaultGlobalReferentialsLoader.java @@ -19,15 +19,9 @@ */ package org.sonar.batch.referential; -import com.google.common.base.Charsets; -import com.google.common.io.InputSupplier; import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.protocol.input.GlobalReferentials; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - public class DefaultGlobalReferentialsLoader implements GlobalReferentialsLoader { private static final String BATCH_GLOBAL_URL = "/batch/global"; @@ -40,12 +34,7 @@ public class DefaultGlobalReferentialsLoader implements GlobalReferentialsLoader @Override public GlobalReferentials load() { - InputSupplier<InputStream> jsonStream = serverClient.doRequest(BATCH_GLOBAL_URL, null); - try { - return GlobalReferentials.fromJson(new InputStreamReader(jsonStream.getInput(), Charsets.UTF_8)); - } catch (IOException e) { - throw new IllegalStateException("Unable to load global referentials", e); - } + return GlobalReferentials.fromJson(serverClient.request(BATCH_GLOBAL_URL)); } } 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 4c8f33bdfeb..bcde2f88a05 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 @@ -19,8 +19,6 @@ */ package org.sonar.batch.referential; -import com.google.common.base.Charsets; -import com.google.common.io.InputSupplier; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.batch.bootstrap.AnalysisMode; import org.sonar.batch.bootstrap.ServerClient; @@ -28,9 +26,6 @@ import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.protocol.input.ProjectReferentials; import org.sonar.batch.rule.ModuleQProfiles; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -57,11 +52,6 @@ public class DefaultProjectReferentialsLoader implements ProjectReferentialsLoad } } url += "&preview=" + analysisMode.isPreview(); - InputSupplier<InputStream> jsonStream = serverClient.doRequest(url, null); - try { - return ProjectReferentials.fromJson(new InputStreamReader(jsonStream.getInput(), Charsets.UTF_8)); - } catch (IOException e) { - throw new IllegalStateException("Unable to load project referentials", e); - } + return ProjectReferentials.fromJson(serverClient.request(url)); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java index 2dd3887c6de..d93f9aecbe1 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/referential/DefaultProjectReferentialsLoaderTest.java @@ -20,7 +20,6 @@ package org.sonar.batch.referential; import com.google.common.collect.Maps; -import com.google.common.io.InputSupplier; import org.junit.Before; import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; @@ -30,11 +29,6 @@ import org.sonar.batch.bootstrap.ServerClient; import org.sonar.batch.bootstrap.TaskProperties; import org.sonar.batch.rule.ModuleQProfiles; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -53,13 +47,7 @@ public class DefaultProjectReferentialsLoaderTest { serverClient = mock(ServerClient.class); analysisMode = mock(AnalysisMode.class); loader = new DefaultProjectReferentialsLoader(serverClient, analysisMode); - when(serverClient.doRequest(anyString(), anyInt())).thenReturn(new InputSupplier<InputStream>() { - - @Override - public InputStream getInput() throws IOException { - return new ByteArrayInputStream(new byte[0]); - } - }); + when(serverClient.request(anyString())).thenReturn(""); reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo")); taskProperties = new TaskProperties(Maps.<String, String>newHashMap(), ""); } @@ -68,18 +56,18 @@ public class DefaultProjectReferentialsLoaderTest { public void passPreviewParameter() { when(analysisMode.isPreview()).thenReturn(false); loader.load(reactor, taskProperties); - verify(serverClient).doRequest("/batch/project?key=foo&preview=false", null); + verify(serverClient).request("/batch/project?key=foo&preview=false"); when(analysisMode.isPreview()).thenReturn(true); loader.load(reactor, taskProperties); - verify(serverClient).doRequest("/batch/project?key=foo&preview=true", null); + verify(serverClient).request("/batch/project?key=foo&preview=true"); } @Test public void passProfileParameter() { taskProperties.properties().put(ModuleQProfiles.SONAR_PROFILE_PROP, "my-profile"); loader.load(reactor, taskProperties); - verify(serverClient).doRequest("/batch/project?key=foo&profile=my-profile&preview=false", null); + verify(serverClient).request("/batch/project?key=foo&profile=my-profile&preview=false"); } } |