]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-15934 introduced new module sonar-webserver-pushapi and added required dependencies
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Wed, 19 Jan 2022 13:49:03 +0000 (14:49 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Feb 2022 15:48:03 +0000 (15:48 +0000)
server/sonar-webserver-pushapi/build.gradle [new file with mode: 0644]
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushAction.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWs.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWsModule.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/sonarlint/SonarLintPushAction.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsModuleTest.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsTest.java [new file with mode: 0644]
server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintPushActionTest.java [new file with mode: 0644]
server/sonar-webserver/build.gradle
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
settings.gradle

diff --git a/server/sonar-webserver-pushapi/build.gradle b/server/sonar-webserver-pushapi/build.gradle
new file mode 100644 (file)
index 0000000..9638863
--- /dev/null
@@ -0,0 +1,16 @@
+sonarqube {
+    properties {
+        property 'sonar.projectName', "${projectTitle} :: WebServer :: PushAPI"
+    }
+}
+dependencies {
+
+    compile project(':server:sonar-webserver-auth')
+    compile project(':server:sonar-webserver-ws')
+
+    testCompile 'junit:junit'
+    testCompile 'org.assertj:assertj-core'
+    testCompile 'org.mockito:mockito-core'
+
+    testCompile testFixtures(project(':server:sonar-webserver-ws'))
+}
diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushAction.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushAction.java
new file mode 100644 (file)
index 0000000..405145b
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi;
+
+import org.sonar.server.ws.WsAction;
+
+public interface ServerPushAction extends WsAction {
+  //marker interface
+
+}
diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWs.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWs.java
new file mode 100644 (file)
index 0000000..3ac5dad
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi;
+
+import java.util.List;
+import org.sonar.api.server.ws.WebService;
+
+public class ServerPushWs implements WebService {
+  private final List<ServerPushAction> actions;
+
+  public ServerPushWs(List<ServerPushAction> actions) {
+    this.actions = actions;
+  }
+
+  @Override
+  public void define(Context context) {
+    NewController controller = context
+      .createController("api/push")
+      .setSince("9.4")
+      .setDescription("Endpoints supporting server side events.");
+
+    actions.forEach(action -> action.define(controller));
+
+    controller.done();
+  }
+}
diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWsModule.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/ServerPushWsModule.java
new file mode 100644 (file)
index 0000000..f82da6a
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi;
+
+import org.sonar.core.platform.Module;
+import org.sonar.server.pushapi.sonarlint.SonarLintPushAction;
+
+public class ServerPushWsModule extends Module {
+
+  @Override
+  protected void configureModule() {
+    add(
+      ServerPushWs.class,
+
+      SonarLintPushAction.class);
+  }
+}
diff --git a/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/sonarlint/SonarLintPushAction.java b/server/sonar-webserver-pushapi/src/main/java/org/sonar/server/pushapi/sonarlint/SonarLintPushAction.java
new file mode 100644 (file)
index 0000000..3c73eef
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi.sonarlint;
+
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+import org.sonar.server.pushapi.ServerPushAction;
+
+public class SonarLintPushAction implements ServerPushAction {
+
+  private static final Logger LOGGER = Loggers.get(SonarLintPushAction.class);
+
+  private static final String PROJECT_PARAM_KEY = "projectKeys";
+  private static final String LANGUAGE_PARAM_KEY = "languages";
+
+  @Override
+  public void define(WebService.NewController controller) {
+    WebService.NewAction action = controller
+      .createAction("sonarlint_events")
+      .setInternal(true)
+      .setDescription("Endpoint for listening to server side events. Currently it notifies listener about change to activation of a rule")
+      .setSince("9.4")
+      .setHandler(this);
+
+    action
+      .createParam(PROJECT_PARAM_KEY)
+      .setDescription("Comma-separated list of projects keys for which events will be delivered")
+      .setRequired(true)
+      .setExampleValue("example-project-key,example-project-key2");
+
+    action
+      .createParam(LANGUAGE_PARAM_KEY)
+      .setDescription("Comma-separated list of languages for which events will be delivered")
+      .setRequired(true)
+      .setExampleValue("java,cobol");
+  }
+
+  @Override
+  public void handle(Request request, Response response) {
+    String projectKeys = request.getParam(PROJECT_PARAM_KEY).getValue();
+    String languages = request.getParam(LANGUAGE_PARAM_KEY).getValue();
+
+    //to remove later
+    LOGGER.debug(projectKeys != null ? projectKeys : "");
+    LOGGER.debug(languages != null ? languages : "");
+
+    response.noContent();
+  }
+}
diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsModuleTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsModuleTest.java
new file mode 100644 (file)
index 0000000..696cb6f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi;
+
+import org.junit.Test;
+import org.sonar.core.platform.ComponentContainer;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ServerPushWsModuleTest {
+
+
+  @Test
+  public void verify_count_of_added_components() {
+    ComponentContainer container = new ComponentContainer();
+
+    new ServerPushWsModule().configure(container);
+
+    assertThat(container.size()).isPositive();
+  }
+}
+
diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/ServerPushWsTest.java
new file mode 100644 (file)
index 0000000..184044a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi;
+
+import java.util.Arrays;
+import org.junit.Test;
+import org.sonar.api.server.ws.Request;
+import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.WebService;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ServerPushWsTest {
+
+  private DummyServerPushAction dummyServerPushAction = new DummyServerPushAction();
+  private ServerPushWs underTest = new ServerPushWs(Arrays.asList(dummyServerPushAction));
+
+  @Test
+  public void define_ws() {
+    WebService.Context context = new WebService.Context();
+
+    underTest.define(context);
+
+    WebService.Controller controller = context.controller("api/push");
+    assertThat(controller).isNotNull();
+    assertThat(controller.path()).isEqualTo("api/push");
+    assertThat(controller.since()).isEqualTo("9.4");
+    assertThat(controller.description()).isNotEmpty();
+    assertThat(controller.actions()).isNotEmpty();
+  }
+
+  private static class DummyServerPushAction implements ServerPushAction {
+
+    @Override
+    public void define(WebService.NewController context) {
+      context.createAction("foo").setHandler(this);
+    }
+
+    @Override
+    public void handle(Request request, Response response) {
+
+    }
+  }
+}
diff --git a/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintPushActionTest.java b/server/sonar-webserver-pushapi/src/test/java/org/sonar/server/pushapi/sonarlint/SonarLintPushActionTest.java
new file mode 100644 (file)
index 0000000..87a7203
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2021 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.pushapi.sonarlint;
+
+import org.junit.Test;
+import org.sonar.api.server.ws.WebService;
+import org.sonar.server.ws.TestRequest;
+import org.sonar.server.ws.TestResponse;
+import org.sonar.server.ws.WsActionTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class SonarLintPushActionTest {
+
+  private final WsActionTester ws = new WsActionTester(new SonarLintPushAction());
+
+  @Test
+  public void defineTest() {
+    WebService.Action def = ws.getDef();
+
+    assertThat(def.since()).isEqualTo("9.4");
+    assertThat(def.isInternal()).isTrue();
+    assertThat(def.params())
+      .extracting(WebService.Param::key, WebService.Param::isRequired)
+      .containsExactlyInAnyOrder(tuple("languages", true), tuple("projectKeys", true));
+  }
+
+  @Test
+  public void handle_returnsNoResponseWhenParamsProvided() {
+    TestResponse response = ws.newRequest()
+      .setParam("projectKeys", "project1,project2")
+      .setParam("languages", "java")
+      .execute();
+
+    assertThat(response.getStatus()).isEqualTo(204);
+  }
+
+  @Test
+  public void handle_whenParamsNotProvided_throwException() {
+    TestRequest testRequest = ws.newRequest();
+    assertThatThrownBy(testRequest::execute)
+      .isInstanceOf(IllegalArgumentException.class)
+      .hasMessage("The 'projectKeys' parameter is missing");
+  }
+}
index ea2fcd9cf6ce4728d7321d101dcf95cda8d7847f..468b3f4fba5a3cf9d57e4dc5000400d813363a2d 100644 (file)
@@ -21,6 +21,7 @@ dependencies {
   compile project(':server:sonar-process')
   compile project(':server:sonar-webserver-core')
   compile project(':server:sonar-webserver-webapi')
+  compile project(':server:sonar-webserver-pushapi')
   compile project(':server:sonar-webserver-monitoring')
 
   compileOnly 'com.google.code.findbugs:jsr305'
index 9330165c72a90a7d3c0d0fe6ae6f0da7efb45f34..5937ac9295f43b1bd855eaa5224375074df39ada 100644 (file)
@@ -180,6 +180,7 @@ import org.sonar.server.projectanalysis.ws.ProjectAnalysisWsModule;
 import org.sonar.server.projectlink.ws.ProjectLinksModule;
 import org.sonar.server.projecttag.ws.ProjectTagsWsModule;
 import org.sonar.server.property.InternalPropertiesImpl;
+import org.sonar.server.pushapi.ServerPushWsModule;
 import org.sonar.server.qualitygate.ProjectsInWarningModule;
 import org.sonar.server.qualitygate.QualityGateModule;
 import org.sonar.server.qualitygate.notification.QGChangeNotificationHandler;
@@ -548,6 +549,9 @@ public class PlatformLevel4 extends PlatformLevel {
 
       MultipleAlmFeatureProvider.class,
 
+      // ServerPush endpoints
+      ServerPushWsModule.class,
+
       // Compute engine (must be after Views and Developer Cockpit)
       ReportAnalysisFailureNotificationModule.class,
       CeModule.class,
index b4719ca33867b7489c3012779a80b74bdff57d6c..5495b51e4ed62b5f2e1ef95a922e548052194ff0 100644 (file)
@@ -37,6 +37,7 @@ include 'server:sonar-webserver-auth'
 include 'server:sonar-webserver-core'
 include 'server:sonar-webserver-es'
 include 'server:sonar-webserver-webapi'
+include 'server:sonar-webserver-pushapi'
 include 'server:sonar-webserver-ws'
 include 'server:sonar-alm-client'
 include 'server:sonar-webserver-monitoring'
@@ -71,3 +72,4 @@ buildCache {
     enabled = !isCiServer
   }
 }
+