summaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-10-24 16:59:13 +0200
committerDavid Gageot <david@gageot.net>2012-10-24 19:20:27 +0200
commit0ad53bdcfa20c61945713e78030920d5b2f1e491 (patch)
treef711d9fa0e0e7a34d8056f889a253bae9dee6ab4 /sonar-batch
parentcc8897d8d488954e532aa7a98198051f417d3ae2 (diff)
downloadsonarqube-0ad53bdcfa20c61945713e78030920d5b2f1e491.tar.gz
sonarqube-0ad53bdcfa20c61945713e78030920d5b2f1e491.zip
SONAR-3895 User resource key and optional authent.
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java31
1 files changed, 22 insertions, 9 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
index 51d75d53730..199541c12a0 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/local/LocalDatabase.java
@@ -19,9 +19,11 @@
*/
package org.sonar.batch.local;
+import com.google.common.base.Strings;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;
import org.sonar.api.BatchComponent;
+import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.platform.Server;
@@ -49,14 +51,12 @@ public class LocalDatabase implements BatchComponent {
private final LocalMode localMode;
private final Settings settings;
private final Server server;
- private final HttpDownloader httpDownloader;
private final TempDirectories tempDirectories;
- public LocalDatabase(LocalMode localMode, Settings settings, Server server, HttpDownloader httpDownloader, TempDirectories tempDirectories) {
+ public LocalDatabase(LocalMode localMode, Settings settings, Server server, TempDirectories tempDirectories) {
this.localMode = localMode;
this.settings = settings;
this.server = server;
- this.httpDownloader = httpDownloader;
this.tempDirectories = tempDirectories;
}
@@ -73,14 +73,27 @@ public class LocalDatabase implements BatchComponent {
}
private void downloadDatabase(File toFile) {
+ String login = settings.getString(CoreProperties.LOGIN);
+ String password = settings.getString(CoreProperties.PASSWORD);
+ String resourceKey = settings.getString("sonar.resource");
+ if (null == resourceKey) {
+ throw new SonarException("No resource key was provided using sonar.resource property");
+ }
+
+ URI uri = URI.create(server.getURL() + API_SYNCHRO + "?resource=" + resourceKey);
+
+ HttpDownloader.BaseHttpDownloader downloader = new HttpDownloader.BaseHttpDownloader(settings, null);
+ InputSupplier<InputStream> inputSupplier;
+ if (Strings.isNullOrEmpty(login)) {
+ inputSupplier = downloader.newInputSupplier(uri);
+ } else {
+ inputSupplier = downloader.newInputSupplier(uri, login, password);
+ }
+
try {
- Files.copy(new InputSupplier<InputStream>() {
- public InputStream getInput() {
- return httpDownloader.openStream(URI.create(server.getURL() + API_SYNCHRO));
- }
- }, toFile);
+ Files.copy(inputSupplier, toFile);
} catch (IOException e) {
- throw new SonarException("Unable to download database", e);
+ throw new SonarException("Unable to save local database to file: " + toFile, e);
}
}