@@ -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')) | |||
} |
@@ -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 | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} |
@@ -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(); | |||
} | |||
} | |||
@@ -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) { | |||
} | |||
} | |||
} |
@@ -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"); | |||
} | |||
} |
@@ -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' |
@@ -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, |
@@ -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 | |||
} | |||
} | |||