aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-17 11:26:32 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-09-17 13:23:45 +0200
commit36c0197d53bf8e712a8813a610e1faa7130b6072 (patch)
tree18b4272c2a92badf2cdf323dae559a9538e8ecea /sonar-plugin-api
parentafaa0ecdd013e75d9ffb67bfceba8335f16ba6c4 (diff)
downloadsonarqube-36c0197d53bf8e712a8813a610e1faa7130b6072.tar.gz
sonarqube-36c0197d53bf8e712a8813a610e1faa7130b6072.zip
SONAR-5629 Call /batch/upload_report at the end of an analysis
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java38
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java7
2 files changed, 32 insertions, 13 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
index 02bdd7138db..562c6f48b86 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java
@@ -145,6 +145,7 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
public static class BaseHttpDownloader {
+ private static final String GET = "GET";
private static final String HTTP_PROXY_USER = "http.proxyUser";
private static final String HTTP_PROXY_PASSWORD = "http.proxyPassword";
@@ -167,7 +168,7 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
}
private void initUserAgent(String sonarVersion) {
- userAgent = (sonarVersion == null ? "Sonar" : String.format("Sonar %s", sonarVersion));
+ userAgent = (sonarVersion == null ? "SonarQube" : String.format("SonarQube %s", sonarVersion));
System.setProperty("http.agent", userAgent);
}
@@ -211,25 +212,43 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
}
public InputSupplier<InputStream> newInputSupplier(URI uri) {
- return new HttpInputSupplier(uri, userAgent, null, null, TIMEOUT_MILLISECONDS);
+ return new HttpInputSupplier(uri, GET, userAgent, null, null, TIMEOUT_MILLISECONDS);
}
public InputSupplier<InputStream> newInputSupplier(URI uri, @Nullable Integer readTimeoutMillis) {
+ return newInputSupplier(uri, GET, readTimeoutMillis);
+ }
+
+ public InputSupplier<InputStream> newInputSupplier(URI uri, String requestMethod, @Nullable Integer readTimeoutMillis) {
if (readTimeoutMillis != null) {
- return new HttpInputSupplier(uri, userAgent, null, null, readTimeoutMillis);
+ return new HttpInputSupplier(uri, requestMethod, userAgent, null, null, readTimeoutMillis);
}
- return new HttpInputSupplier(uri, userAgent, null, null, TIMEOUT_MILLISECONDS);
+ return new HttpInputSupplier(uri, requestMethod, userAgent, null, null, TIMEOUT_MILLISECONDS);
}
public InputSupplier<InputStream> newInputSupplier(URI uri, String login, String password) {
- return new HttpInputSupplier(uri, userAgent, login, password, TIMEOUT_MILLISECONDS);
+ return newInputSupplier(uri, GET, login, password);
+ }
+
+ /**
+ * @since 5.0
+ */
+ public InputSupplier<InputStream> newInputSupplier(URI uri, String requestMethod, String login, String password) {
+ return new HttpInputSupplier(uri, requestMethod, userAgent, login, password, TIMEOUT_MILLISECONDS);
}
public InputSupplier<InputStream> newInputSupplier(URI uri, String login, String password, @Nullable Integer readTimeoutMillis) {
+ return newInputSupplier(uri, GET, login, password, readTimeoutMillis);
+ }
+
+ /**
+ * @since 5.0
+ */
+ public InputSupplier<InputStream> newInputSupplier(URI uri, String requestMethod, String login, String password, @Nullable Integer readTimeoutMillis) {
if (readTimeoutMillis != null) {
- return new HttpInputSupplier(uri, userAgent, login, password, readTimeoutMillis);
+ return new HttpInputSupplier(uri, requestMethod, userAgent, login, password, readTimeoutMillis);
}
- return new HttpInputSupplier(uri, userAgent, login, password, TIMEOUT_MILLISECONDS);
+ return new HttpInputSupplier(uri, requestMethod, userAgent, login, password, TIMEOUT_MILLISECONDS);
}
private static class HttpInputSupplier implements InputSupplier<InputStream> {
@@ -238,9 +257,11 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
private final URI uri;
private final String userAgent;
private final int readTimeoutMillis;
+ private final String requestMethod;
- HttpInputSupplier(URI uri, String userAgent, String login, String password, int readTimeoutMillis) {
+ HttpInputSupplier(URI uri, String requestMethod, String userAgent, String login, String password, int readTimeoutMillis) {
this.uri = uri;
+ this.requestMethod = requestMethod;
this.userAgent = userAgent;
this.login = login;
this.password = password;
@@ -251,6 +272,7 @@ public class HttpDownloader extends UriReader.SchemeProcessor implements BatchCo
LoggerFactory.getLogger(getClass()).debug("Download: " + uri + " (" + getProxySynthesis(uri, ProxySelector.getDefault()) + ")");
HttpURLConnection connection = (HttpURLConnection) uri.toURL().openConnection();
+ connection.setRequestMethod(requestMethod);
HttpsTrust.INSTANCE.trust(connection);
// allow both GZip and Deflate (ZLib) encodings
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java
index 79d44b9588e..5978438e8c6 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java
@@ -149,14 +149,11 @@ public class HttpDownloaderTest {
thrown.expect(new BaseMatcher<Exception>() {
@Override
public boolean matches(Object ex) {
- // TODO Auto-generated method stub
return ex instanceof SonarException && ((SonarException) ex).getCause() instanceof SocketTimeoutException;
}
@Override
public void describeTo(Description arg0) {
- // TODO Auto-generated method stub
-
}
});
new HttpDownloader(new Settings(), 100).readString(new URI(baseUrl + "/timeout/"), Charsets.UTF_8);
@@ -201,7 +198,7 @@ public class HttpDownloaderTest {
props.load(stream);
stream.close();
- assertThat(props.getProperty("agent")).isEqualTo("Sonar 2.2");
+ assertThat(props.getProperty("agent")).isEqualTo("SonarQube 2.2");
}
@Test
@@ -220,7 +217,7 @@ public class HttpDownloaderTest {
@Test
public void shouldGetProxySynthesis() throws URISyntaxException {
ProxySelector proxySelector = mock(ProxySelector.class);
- when(proxySelector.select(any(URI.class))).thenReturn(Arrays.<Proxy> asList(new FakeProxy()));
+ when(proxySelector.select(any(URI.class))).thenReturn(Arrays.<Proxy>asList(new FakeProxy()));
assertThat(HttpDownloader.BaseHttpDownloader.getProxySynthesis(new URI("http://an_url"), proxySelector)).isEqualTo("proxy: http://proxy_url:4040");
}