diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-24 15:53:36 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-30 11:42:16 +0200 |
commit | 10955ec396a053d596a40ac3fdf7ca73dd911327 (patch) | |
tree | c390cd08b8b44656206306c94213204baeec737c /sonar-core | |
parent | 946a448c08ccc10ad1c0af778ae5d9f179655ef8 (diff) | |
download | sonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.tar.gz sonarqube-10955ec396a053d596a40ac3fdf7ca73dd911327.zip |
SONAR-7458 Expose SQ Version in SensorContext
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersionProvider.java | 49 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionProviderTest.java | 64 |
2 files changed, 0 insertions, 113 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersionProvider.java b/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersionProvider.java deleted file mode 100644 index a0f54de7490..00000000000 --- a/sonar-core/src/main/java/org/sonar/core/platform/SonarQubeVersionProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.core.platform; - -import com.google.common.io.Resources; -import java.io.IOException; -import java.net.URL; -import java.nio.charset.StandardCharsets; -import org.picocontainer.injectors.ProviderAdapter; -import org.sonar.api.SonarQubeVersion; -import org.sonar.api.utils.System2; -import org.sonar.api.utils.Version; - -public class SonarQubeVersionProvider extends ProviderAdapter { - - private static final String FILE_PATH = "/sq-version.txt"; - - private SonarQubeVersion version = null; - - public SonarQubeVersion provide(System2 system) { - if (version == null) { - try { - URL url = system.getResource(FILE_PATH); - String versionInFile = Resources.toString(url, StandardCharsets.UTF_8); - version = new SonarQubeVersion(Version.parse(versionInFile)); - } catch (IOException e) { - throw new IllegalStateException("Can not load " + FILE_PATH + " from classpath", e); - } - } - return version; - } -} diff --git a/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionProviderTest.java b/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionProviderTest.java deleted file mode 100644 index 79d9baddc27..00000000000 --- a/sonar-core/src/test/java/org/sonar/core/platform/SonarQubeVersionProviderTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2016 SonarSource SA - * mailto:contact 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.core.platform; - -import java.io.File; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.SonarQubeVersion; -import org.sonar.api.utils.System2; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SonarQubeVersionProviderTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - SonarQubeVersionProvider underTest = new SonarQubeVersionProvider(); - - @Test - public void create() { - SonarQubeVersion version = underTest.provide(System2.INSTANCE); - assertThat(version).isNotNull(); - assertThat(version.get().major()).isGreaterThanOrEqualTo(5); - } - - @Test - public void cache_version() { - SonarQubeVersion version1 = underTest.provide(System2.INSTANCE); - SonarQubeVersion version2 = underTest.provide(System2.INSTANCE); - assertThat(version1).isSameAs(version2); - } - - @Test - public void throw_ISE_if_fail_to_load_version() throws Exception { - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Can not load /sq-version.txt from classpath"); - - System2 system = mock(System2.class); - when(system.getResource(anyString())).thenReturn(new File("target/unknown").toURL()); - underTest.provide(system); - } -} |