aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client/src
diff options
context:
space:
mode:
authorGodin <mandrikov@gmail.com>2010-11-01 16:12:30 +0000
committerGodin <mandrikov@gmail.com>2010-11-01 16:12:30 +0000
commit4d5ed597d80f8e0a070b52e1c673d14e3597e9e8 (patch)
tree4f1cf7237b19f47ef50991093e3c1fe47edce2f3 /sonar-ws-client/src
parentd4d455365c5d08ede8c5b5c81b8afbb57e70ffb5 (diff)
downloadsonarqube-4d5ed597d80f8e0a070b52e1c673d14e3597e9e8.tar.gz
sonarqube-4d5ed597d80f8e0a070b52e1c673d14e3597e9e8.zip
SONAR-1897: Add web service to get information about installed plugins
Diffstat (limited to 'sonar-ws-client/src')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java39
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/PluginQuery.java19
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java19
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java1
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/services/PluginQueryTest.java16
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java22
6 files changed, 116 insertions, 0 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java
new file mode 100644
index 00000000000..ce8d4c7e499
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Plugin.java
@@ -0,0 +1,39 @@
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.4
+ */
+public class Plugin extends Model {
+
+ private String key;
+ private String name;
+ private String version;
+
+ public String getKey() {
+ return key;
+ }
+
+ public Plugin setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Plugin setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public Plugin setVersion(String version) {
+ this.version = version;
+ return this;
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PluginQuery.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PluginQuery.java
new file mode 100644
index 00000000000..6ba030cf03c
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/PluginQuery.java
@@ -0,0 +1,19 @@
+package org.sonar.wsclient.services;
+
+/**
+ * @since 2.4
+ */
+public class PluginQuery extends Query<Plugin> {
+
+ public static final String BASE_URL = "/api/plugins";
+
+ @Override
+ public Class<Plugin> getModelClass() {
+ return Plugin.class;
+ }
+
+ @Override
+ public String getUrl() {
+ return BASE_URL;
+ }
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java
new file mode 100644
index 00000000000..29d785f485e
--- /dev/null
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/PluginUnmarshaller.java
@@ -0,0 +1,19 @@
+package org.sonar.wsclient.unmarshallers;
+
+import org.json.simple.JSONObject;
+import org.sonar.wsclient.services.Plugin;
+
+/**
+ * @since 2.4
+ */
+public class PluginUnmarshaller extends AbstractUnmarshaller<Plugin> {
+
+ @Override
+ protected Plugin parse(JSONObject json) {
+ return new Plugin()
+ .setKey(JsonUtils.getString(json, "key"))
+ .setName(JsonUtils.getString(json, "name"))
+ .setVersion(JsonUtils.getString(json, "version"));
+ }
+
+}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
index 3523f1ce836..35f1f31ed58 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/Unmarshallers.java
@@ -42,6 +42,7 @@ public final class Unmarshallers {
unmarshallers.put(DependencyTree.class, new DependencyTreeUnmarshaller());
unmarshallers.put(Event.class, new EventUnmarshaller());
unmarshallers.put(Favourite.class, new FavouriteUnmarshaller());
+ unmarshallers.put(Plugin.class, new PluginUnmarshaller());
}
public static <MODEL extends Model> Unmarshaller<MODEL> forModel(Class<MODEL> modelClass) {
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PluginQueryTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PluginQueryTest.java
new file mode 100644
index 00000000000..49d226852ee
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/PluginQueryTest.java
@@ -0,0 +1,16 @@
+package org.sonar.wsclient.services;
+
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+public class PluginQueryTest {
+
+ @Test
+ public void index() {
+ PluginQuery query = new PluginQuery();
+ assertThat(query.getUrl(), is("/api/plugins"));
+ }
+
+}
diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
new file mode 100644
index 00000000000..615407b15b1
--- /dev/null
+++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/PluginUnmarshallerTest.java
@@ -0,0 +1,22 @@
+package org.sonar.wsclient.unmarshallers;
+
+import org.junit.Test;
+import org.sonar.wsclient.services.Plugin;
+
+import java.util.List;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class PluginUnmarshallerTest {
+
+ @Test
+ public void toModel() throws Exception {
+ List<Plugin> plugins = new PluginUnmarshaller().toModels("[{\"key\": \"foo\", \"name\": \"Foo\", \"version\": \"1.0\"}]");
+ Plugin plugin = plugins.get(0);
+ assertThat(plugin.getKey(), is("foo"));
+ assertThat(plugin.getName(), is("Foo"));
+ assertThat(plugin.getVersion(), is("1.0"));
+ }
+
+}