aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/main/java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 09:28:05 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2012-10-27 09:28:05 +0200
commit73ae841b1d90ca0d51fc2d27ec3f9b235c75dd61 (patch)
treeac8bf4b2bedeb22a4e6fb2dcc5fee1ede65d0b4e /sonar-batch/src/main/java
parentb37cc878ad2e5952807aef46e966f7d790f52a2d (diff)
downloadsonarqube-73ae841b1d90ca0d51fc2d27ec3f9b235c75dd61.tar.gz
sonarqube-73ae841b1d90ca0d51fc2d27ec3f9b235c75dd61.zip
Fix backward compatibility with org.sonar.batch.ServerMetadata
Diffstat (limited to 'sonar-batch/src/main/java')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java70
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java5
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java9
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/ServerClient.java7
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/WsConnector.java75
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java2
6 files changed, 155 insertions, 13 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java b/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java
new file mode 100644
index 00000000000..5bba17f6905
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/ServerMetadata.java
@@ -0,0 +1,70 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch;
+
+import org.sonar.api.BatchComponent;
+import org.sonar.api.platform.Server;
+import org.sonar.batch.bootstrap.ServerClient;
+
+import java.util.Date;
+
+/**
+ * @deprecated replaced by ServerClient since version 3.4. Plugins should use org.sonar.api.platform.Server
+ */
+@Deprecated
+public class ServerMetadata extends Server implements BatchComponent {
+ private ServerClient server;
+
+ public ServerMetadata(ServerClient server) {
+ this.server = server;
+ }
+
+ @Override
+ public String getId() {
+ return server.getId();
+ }
+
+ @Override
+ public String getVersion() {
+ return server.getVersion();
+ }
+
+ @Override
+ public Date getStartedAt() {
+ return server.getStartedAt();
+ }
+
+ /**
+ * @return the server URL when executed from batch, else null.
+ * @since 2.4
+ */
+ @Override
+ public String getURL() {
+ return server.getURL();
+ }
+
+ /**
+ * @since 2.10
+ */
+ @Override
+ public String getPermanentServerId() {
+ return server.getPermanentServerId();
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
index b8638c91453..bcb2e44d252 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapModule.java
@@ -26,6 +26,7 @@ import org.sonar.api.utils.HttpDownloader;
import org.sonar.api.utils.UriReader;
import org.sonar.batch.FakeMavenPluginExecutor;
import org.sonar.batch.MavenPluginExecutor;
+import org.sonar.batch.ServerMetadata;
import org.sonar.batch.config.BatchDatabaseSettingsLoader;
import org.sonar.batch.config.BootstrapSettings;
import org.sonar.batch.local.DryRunDatabase;
@@ -39,6 +40,7 @@ import org.sonar.core.persistence.MyBatis;
import org.sonar.jpa.session.DatabaseSessionProvider;
import org.sonar.jpa.session.DefaultDatabaseConnector;
import org.sonar.jpa.session.ThreadLocalDatabaseSessionFactory;
+import org.sonar.wsclient.Sonar;
/**
* Level 1 components
@@ -64,6 +66,9 @@ public class BootstrapModule extends Module {
container.addSingleton(DryRunExporter.class);
container.addSingleton(Logback.class);
container.addSingleton(ServerClient.class);
+ container.addSingleton(ServerMetadata.class);
+ container.addSingleton(WsConnector.class);
+ container.addSingleton(Sonar.class);
container.addSingleton(TempDirectories.class);
container.addSingleton(HttpDownloader.class);
container.addSingleton(UriReader.class);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java
index 45aaf4180c1..ebe8342d221 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibility.java
@@ -49,14 +49,7 @@ public class DatabaseBatchCompatibility implements BatchComponent {
}
private void checkCorrectServerId() {
- String remoteServerId;
- try {
- remoteServerId = server.getServerId();
- } catch (IOException e) {
- throw new SonarException("Impossible to get the ID of the remote server: " + server.getURL(), e);
- }
-
- if (!version.getSonarCoreId().equals(remoteServerId)) {
+ if (!version.getSonarCoreId().equals(server.getServerId())) {
StringBuilder message = new StringBuilder("The current batch process and the configured remote server do not share the same DB configuration.\n");
message.append("\t- Batch side: ");
message.append(settings.getString(DatabaseProperties.PROP_URL));
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 2634faec1ef..7b643b2c541 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
@@ -48,11 +48,11 @@ import java.util.Date;
*/
public class ServerClient extends Server implements BatchComponent {
private Settings settings;
- private EnvironmentInformation env;
+ private HttpDownloader.BaseHttpDownloader downloader;
public ServerClient(Settings settings, EnvironmentInformation env) {
this.settings = settings;
- this.env = env;
+ this.downloader = new HttpDownloader.BaseHttpDownloader(settings, env.toString());
}
@Override
@@ -89,7 +89,7 @@ public class ServerClient extends Server implements BatchComponent {
return settings.getString(CoreProperties.PERMANENT_SERVER_ID);
}
- public String getServerId() throws IOException {
+ public String getServerId() {
String remoteServerInfo = request("/api/server");
// don't use JSON utilities to extract ID from such a small string
return extractServerId(remoteServerInfo);
@@ -126,7 +126,6 @@ public class ServerClient extends Server implements BatchComponent {
String login = settings.getString(CoreProperties.LOGIN);
try {
- HttpDownloader.BaseHttpDownloader downloader = new HttpDownloader.BaseHttpDownloader(settings, env.toString());
InputSupplier<InputStream> inputSupplier;
if (Strings.isNullOrEmpty(login)) {
inputSupplier = downloader.newInputSupplier(uri);
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WsConnector.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WsConnector.java
new file mode 100644
index 00000000000..9e7dc579532
--- /dev/null
+++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/WsConnector.java
@@ -0,0 +1,75 @@
+/*
+ * Sonar, open source software quality management tool.
+ * Copyright (C) 2008-2012 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * Sonar is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * Sonar is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Sonar; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
+ */
+package org.sonar.batch.bootstrap;
+
+import org.sonar.wsclient.connectors.Connector;
+import org.sonar.wsclient.services.CreateQuery;
+import org.sonar.wsclient.services.DeleteQuery;
+import org.sonar.wsclient.services.Query;
+import org.sonar.wsclient.services.UpdateQuery;
+
+/**
+ * @since 3.4
+ */
+public class WsConnector extends Connector {
+
+ private ServerClient server;
+
+ public WsConnector(ServerClient server) {
+ this.server = server;
+ }
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @throws org.sonar.wsclient.connectors.ConnectionException
+ * if connection error or HTTP status not in (200, 404)
+ */
+ @Override
+ public String execute(Query<?> query) {
+ return server.request(query.getUrl());
+ }
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @since 2.2
+ */
+ @Override
+ public String execute(CreateQuery<?> query) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @since 2.2
+ */
+ @Override
+ public String execute(DeleteQuery query) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @return JSON response or null if 404 NOT FOUND error
+ * @since 2.6
+ */
+ @Override
+ public String execute(UpdateQuery<?> query) {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java b/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
index 0d54743e0f6..a2267e87cc7 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/config/BootstrapSettings.java
@@ -39,7 +39,7 @@ public final class BootstrapSettings extends Settings {
load();
}
- public BootstrapSettings load() {
+ private BootstrapSettings load() {
clear();
// order is important -> bottom-up. The last one overrides all the others.