aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2013-06-25 14:28:00 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2013-06-25 14:32:08 +0200
commit58dfb0214acdc65af36741e5a5d3ab55680add1d (patch)
treeccc9a05f3ac8299d42e4f79a4419c881b2b621a2 /sonar-batch
parent9ff8a62374c6fe47c0acf8a443bb1f8312229693 (diff)
downloadsonarqube-58dfb0214acdc65af36741e5a5d3ab55680add1d.tar.gz
sonarqube-58dfb0214acdc65af36741e5a5d3ab55680add1d.zip
SONAR-4433 Fix regression in dryRun
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java34
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java26
2 files changed, 31 insertions, 29 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
index 1f42d9e2375..0f73212e337 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DryRunDatabase.java
@@ -26,17 +26,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
+import org.sonar.api.utils.HttpDownloader.HttpException;
import org.sonar.api.utils.SonarException;
-import javax.annotation.Nullable;
-
import java.io.File;
-import static org.sonar.api.utils.HttpDownloader.HttpException;
-
/**
* @since 3.4
*/
@@ -52,17 +48,11 @@ public class DryRunDatabase implements BatchComponent {
private final Settings settings;
private final ServerClient server;
private final TempDirectories tempDirectories;
- private ProjectReactor reactor;
- public DryRunDatabase(Settings settings, ServerClient server, TempDirectories tempDirectories, @Nullable ProjectReactor reactor) {
+ public DryRunDatabase(Settings settings, ServerClient server, TempDirectories tempDirectories) {
this.settings = settings;
this.server = server;
this.tempDirectories = tempDirectories;
- this.reactor = reactor;
- }
-
- public DryRunDatabase(Settings settings, ServerClient server, TempDirectories tempDirectories) {
- this(settings, server, tempDirectories, null);
}
public void start() {
@@ -79,10 +69,14 @@ public class DryRunDatabase implements BatchComponent {
private void downloadDatabase(File toFile) {
String projectKey = null;
try {
- if (reactor == null) {
+ projectKey = settings.getString(CoreProperties.PROJECT_KEY_PROPERTY);
+ String branch = settings.getString(CoreProperties.PROJECT_BRANCH_PROPERTY);
+ if (StringUtils.isNotBlank(branch)) {
+ projectKey = String.format("%s:%s", projectKey, branch);
+ }
+ if (StringUtils.isBlank(projectKey)) {
server.download("/batch_bootstrap/db", toFile);
} else {
- projectKey = StringUtils.defaultString(reactor.getRoot().getKey());
server.download("/batch_bootstrap/db?project=" + projectKey, toFile);
}
LOG.debug("Dry Run database size: {}", FileUtils.byteCountToDisplaySize(FileUtils.sizeOf(toFile)));
@@ -97,11 +91,11 @@ public class DryRunDatabase implements BatchComponent {
private void replaceSettings(String databasePath) {
settings
- .removeProperty("sonar.jdbc.schema")
- .setProperty(DatabaseProperties.PROP_DIALECT, DIALECT)
- .setProperty(DatabaseProperties.PROP_DRIVER, DRIVER)
- .setProperty(DatabaseProperties.PROP_USER, USER)
- .setProperty(DatabaseProperties.PROP_PASSWORD, PASSWORD)
- .setProperty(DatabaseProperties.PROP_URL, URL + databasePath);
+ .removeProperty("sonar.jdbc.schema")
+ .setProperty(DatabaseProperties.PROP_DIALECT, DIALECT)
+ .setProperty(DatabaseProperties.PROP_DRIVER, DRIVER)
+ .setProperty(DatabaseProperties.PROP_USER, USER)
+ .setProperty(DatabaseProperties.PROP_PASSWORD, PASSWORD)
+ .setProperty(DatabaseProperties.PROP_URL, URL + databasePath);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
index 62135edc925..f19dbc663af 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DryRunDatabaseTest.java
@@ -26,8 +26,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
import org.sonar.api.utils.HttpDownloader;
@@ -43,10 +41,9 @@ import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
public class DryRunDatabaseTest {
- Settings settings = new Settings();
+ Settings settings;
ServerClient server = mock(ServerClient.class);
TempDirectories tempDirectories = mock(TempDirectories.class);
- ProjectReactor projectReactor = new ProjectReactor(ProjectDefinition.create().setKey("group:project"));
File databaseFile;
@Rule
@@ -59,27 +56,37 @@ public class DryRunDatabaseTest {
public void setUp() throws Exception {
databaseFile = temp.newFile("dryrun.h2.db");
when(tempDirectories.getFile("", "dryrun.h2.db")).thenReturn(databaseFile);
+ settings = new Settings();
settings.setProperty(CoreProperties.DRY_RUN, true);
+ settings.setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "group:project");
}
@Test
public void should_be_disabled_if_not_dry_run() {
settings.setProperty(CoreProperties.DRY_RUN, false);
- new DryRunDatabase(settings, server, tempDirectories, projectReactor).start();
+ new DryRunDatabase(settings, server, tempDirectories).start();
verifyZeroInteractions(tempDirectories, server);
}
@Test
public void should_download_database() {
- new DryRunDatabase(settings, server, tempDirectories, projectReactor).start();
+ new DryRunDatabase(settings, server, tempDirectories).start();
verify(server).download("/batch_bootstrap/db?project=group:project", databaseFile);
}
@Test
+ public void should_download_database_on_branch() {
+ settings.setProperty(CoreProperties.PROJECT_BRANCH_PROPERTY, "mybranch");
+ new DryRunDatabase(settings, server, tempDirectories).start();
+
+ verify(server).download("/batch_bootstrap/db?project=group:project:mybranch", databaseFile);
+ }
+
+ @Test
public void should_replace_database_settings() {
- new DryRunDatabase(settings, server, tempDirectories, projectReactor).start();
+ new DryRunDatabase(settings, server, tempDirectories).start();
assertThat(settings.getString(DatabaseProperties.PROP_DIALECT)).isEqualTo("h2");
assertThat(settings.getString(DatabaseProperties.PROP_DRIVER)).isEqualTo("org.h2.Driver");
@@ -95,7 +102,7 @@ public class DryRunDatabaseTest {
thrown.expect(SonarException.class);
thrown.expectMessage("You don't have access rights to project [group:project]");
- new DryRunDatabase(settings, server, tempDirectories, projectReactor).start();
+ new DryRunDatabase(settings, server, tempDirectories).start();
}
@Test
@@ -105,12 +112,13 @@ public class DryRunDatabaseTest {
thrown.expect(SonarException.class);
thrown.expectMessage("BUG");
- new DryRunDatabase(settings, server, tempDirectories, projectReactor).start();
+ new DryRunDatabase(settings, server, tempDirectories).start();
}
@Test
public void project_should_be_optional() {
// on non-scan tasks
+ settings.removeProperty(CoreProperties.PROJECT_KEY_PROPERTY);
new DryRunDatabase(settings, server, tempDirectories).start();
verify(server).download("/batch_bootstrap/db", databaseFile);
}