diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2018-07-03 12:26:32 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-07-09 10:39:33 +0200 |
commit | 9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2 (patch) | |
tree | 5aa1306fd44789b6d17b3274c353420f492727d5 /server/sonar-ce-task | |
parent | 12349c8c275dc316e09451c4f468376e26be53b3 (diff) | |
download | sonarqube-9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2.tar.gz sonarqube-9e3bc71eb9e0ac3b384c2fbfaa8355596e5ea7f2.zip |
sonar-ce-task-projectanalysis depends on only sonar-server-common
Diffstat (limited to 'server/sonar-ce-task')
4 files changed, 122 insertions, 0 deletions
diff --git a/server/sonar-ce-task/build.gradle b/server/sonar-ce-task/build.gradle index 66ad1d81185..0fc3a96a321 100644 --- a/server/sonar-ce-task/build.gradle +++ b/server/sonar-ce-task/build.gradle @@ -32,6 +32,7 @@ dependencies { compile 'org.slf4j:slf4j-api' compile project(':server:sonar-process') + compile project(':server:sonar-server-common') compile project(':sonar-core') compileOnly project(path: ':sonar-plugin-api') diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/SettingsLoader.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/SettingsLoader.java new file mode 100644 index 00000000000..9df2ff678d6 --- /dev/null +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/SettingsLoader.java @@ -0,0 +1,50 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.ce.task.setting; + +import org.picocontainer.Startable; +import org.sonar.api.ce.ComputeEngineSide; +import org.sonar.ce.task.container.EagerStart; +import org.sonar.ce.task.container.TaskContainerImpl; +import org.sonar.server.setting.ThreadLocalSettings; + +/** + * Add this class as the first components in the {@link TaskContainerImpl} + * to trigger loading of Thread local specific {@link org.sonar.api.config.Settings} in {@link ThreadLocalSettings}. + */ +@EagerStart +@ComputeEngineSide +public class SettingsLoader implements Startable { + private final ThreadLocalSettings threadLocalSettings; + + public SettingsLoader(ThreadLocalSettings threadLocalSettings) { + this.threadLocalSettings = threadLocalSettings; + } + + @Override + public void start() { + threadLocalSettings.load(); + } + + @Override + public void stop() { + threadLocalSettings.unload(); + } +} diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/package-info.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/package-info.java new file mode 100644 index 00000000000..71c26a744ea --- /dev/null +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/setting/package-info.java @@ -0,0 +1,23 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.ce.task.settings; + +import javax.annotation.ParametersAreNonnullByDefault; diff --git a/server/sonar-ce-task/src/test/java/org/sonar/ce/task/setting/SettingsLoaderTest.java b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/setting/SettingsLoaderTest.java new file mode 100644 index 00000000000..3881f7c745e --- /dev/null +++ b/server/sonar-ce-task/src/test/java/org/sonar/ce/task/setting/SettingsLoaderTest.java @@ -0,0 +1,48 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 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.ce.task.setting; + +import org.junit.Test; +import org.sonar.server.setting.ThreadLocalSettings; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +public class SettingsLoaderTest { + private ThreadLocalSettings threadLocalSettings = mock(ThreadLocalSettings.class); + private SettingsLoader underTest = new SettingsLoader(threadLocalSettings); + + @Test + public void start_calls_ThreadLocalSettings_load() { + underTest.start(); + + verify(threadLocalSettings).load(); + verifyNoMoreInteractions(threadLocalSettings); + } + + @Test + public void stop_calls_ThreadLocalSettings_remove() { + underTest.stop(); + + verify(threadLocalSettings).unload(); + verifyNoMoreInteractions(threadLocalSettings); + } +} |