diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2018-12-05 10:23:09 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-01-16 09:43:06 +0100 |
commit | 532850a387e483592e6f2f80a5e833bcf218a58f (patch) | |
tree | bb504874ef6a1f36059113c962132e27660cb33f /sonar-plugin-api | |
parent | 55579a4572f8233957275c896139cb1dfedd2622 (diff) | |
download | sonarqube-532850a387e483592e6f2f80a5e833bcf218a58f.tar.gz sonarqube-532850a387e483592e6f2f80a5e833bcf218a58f.zip |
Fix quality flaws
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java | 7 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java | 3 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java | 5 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/ProjectSensor.java (renamed from sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java) | 2 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java | 71 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java | 49 |
6 files changed, 117 insertions, 20 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java index ee04d993594..8e0a70824e9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java @@ -20,8 +20,10 @@ package org.sonar.api.batch.sensor; import org.sonar.api.ExtensionPoint; +import org.sonar.api.batch.InstantiationStrategy; import org.sonar.api.batch.ScannerSide; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.api.scanner.sensor.ProjectSensor; import org.sonarsource.api.sonarlint.SonarLintSide; /** @@ -33,12 +35,13 @@ import org.sonarsource.api.sonarlint.SonarLintSide; * * For testing purpose you can use {@link SensorContextTester} * @since 5.1 - * @since 7.6 use {@link org.sonar.api.scanner.sensor.Sensor} instead to make your Sensor run only once per analysis, and no more once per module + * @since 7.6 use {@link ProjectSensor} instead to make your Sensor run only once per analysis, and no more once per module */ @ScannerSide +@InstantiationStrategy(InstantiationStrategy.PER_PROJECT) @SonarLintSide @ExtensionPoint -public interface Sensor { +public interface Sensor extends ProjectSensor { /** * Populate {@link SensorDescriptor} of this sensor. diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index 98cb74c0d15..8f7cb5fdaf6 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -43,6 +43,7 @@ import org.sonar.api.batch.sensor.symbol.NewSymbolTable; import org.sonar.api.config.Configuration; import org.sonar.api.config.Settings; import org.sonar.api.scanner.fs.InputProject; +import org.sonar.api.scanner.sensor.ProjectSensor; import org.sonar.api.utils.Version; /** @@ -77,7 +78,7 @@ public interface SensorContext { /** * @since 5.5 * @deprecated since 7.6 modules are deprecated. Use {@link #project()} instead. - * @throws UnsupportedOperationException for global {@link org.sonar.api.scanner.sensor.Sensor}s + * @throws UnsupportedOperationException for global {@link ProjectSensor}s */ @Deprecated InputModule module(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java index 133766139d3..6a868bb187c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java @@ -22,9 +22,10 @@ package org.sonar.api.batch.sensor; import java.util.function.Predicate; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.config.Configuration; +import org.sonar.api.scanner.sensor.ProjectSensor; /** - * Describe what a {@link org.sonar.api.scanner.sensor.Sensor} is doing. Information may be used by the platform + * Describe what a {@link Sensor} is doing. Information may be used by the platform * to log interesting information or perform some optimization. * See {@link Sensor#describe(SensorDescriptor)} * @since 5.1 @@ -88,7 +89,7 @@ public interface SensorDescriptor { /** * This sensor should be executed at the project level, instead of per-module. * @since 6.4 - * @deprecated since 7.6 change your {@link Sensor} to a {@link org.sonar.api.scanner.sensor.Sensor} instead + * @deprecated since 7.6 change your {@link Sensor} to a {@link ProjectSensor} instead */ @Deprecated SensorDescriptor global(); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/ProjectSensor.java index ededb64909a..689b56e1484 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/Sensor.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/scanner/sensor/ProjectSensor.java @@ -38,7 +38,7 @@ import org.sonarsource.api.sonarlint.SonarLintSide; @ScannerSide @SonarLintSide @ExtensionPoint -public interface Sensor { +public interface ProjectSensor { /** * Populate {@link SensorDescriptor} of this sensor. diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java new file mode 100644 index 00000000000..abe834bc3d6 --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputModuleTest.java @@ -0,0 +1,71 @@ +/* + * 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.api.batch.fs.internal; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.sonar.api.batch.bootstrap.ProjectDefinition; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DefaultInputModuleTest { + + private static final String FILE_1 = "file1"; + private static final String TEST_1 = "test1"; + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + @Test + public void testGetters() throws IOException { + ProjectDefinition def = ProjectDefinition.create(); + def.setKey("moduleKey"); + File baseDir = temp.newFolder(); + Path src = baseDir.toPath().resolve(FILE_1); + Files.createFile(src); + Path test = baseDir.toPath().resolve(TEST_1); + Files.createFile(test); + def.setBaseDir(baseDir); + File workDir = temp.newFolder(); + def.setWorkDir(workDir); + def.setSources(FILE_1); + def.setTests(TEST_1); + DefaultInputModule module = new DefaultInputModule(def); + + assertThat(module.key()).isEqualTo("moduleKey"); + assertThat(module.definition()).isEqualTo(def); + assertThat(module.getBranch()).isNull(); + assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath()); + assertThat(module.getKeyWithBranch()).isEqualTo("moduleKey"); + assertThat(module.getWorkDir()).isEqualTo(workDir.toPath()); + assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset()); + assertThat(module.getSourceDirsOrFiles()).containsExactlyInAnyOrder(src); + assertThat(module.getTestDirsOrFiles()).containsExactlyInAnyOrder(test); + assertThat(module.getEncoding()).isEqualTo(Charset.defaultCharset()); + + assertThat(module.isFile()).isFalse(); + } + +} diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java index e9e54e5a77a..33751cd6151 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultInputProjectTest.java @@ -21,6 +21,8 @@ package org.sonar.api.batch.fs.internal; import java.io.File; import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -46,23 +48,42 @@ public class DefaultInputProjectTest { def.setWorkDir(workDir); def.setSources("file1"); def.setTests("test1"); - AbstractProjectOrModule module = new DefaultInputProject(def); + AbstractProjectOrModule project = new DefaultInputProject(def); - assertThat(module.key()).isEqualTo("projectKey"); - assertThat(module.getName()).isEqualTo("projectName"); - assertThat(module.getOriginalName()).isEqualTo("projectName"); - assertThat(module.definition()).isEqualTo(def); - assertThat(module.getBranch()).isNull(); - assertThat(module.getBaseDir()).isEqualTo(baseDir.toPath()); - assertThat(module.getKeyWithBranch()).isEqualTo("projectKey"); - assertThat(module.getVersion()).isEqualTo("version"); - assertThat(module.getOriginalVersion()).isEqualTo("version"); - assertThat(module.getDescription()).isEqualTo("desc"); - assertThat(module.getWorkDir()).isEqualTo(workDir.toPath()); + assertThat(project.key()).isEqualTo("projectKey"); + assertThat(project.getName()).isEqualTo("projectName"); + assertThat(project.getOriginalName()).isEqualTo("projectName"); + assertThat(project.definition()).isEqualTo(def); + assertThat(project.getBranch()).isNull(); + assertThat(project.getBaseDir()).isEqualTo(baseDir.toPath()); + assertThat(project.getKeyWithBranch()).isEqualTo("projectKey"); + assertThat(project.getVersion()).isEqualTo("version"); + assertThat(project.getOriginalVersion()).isEqualTo("version"); + assertThat(project.getDescription()).isEqualTo("desc"); + assertThat(project.getWorkDir()).isEqualTo(workDir.toPath()); + assertThat(project.getEncoding()).isEqualTo(Charset.defaultCharset()); - assertThat(module.properties()).hasSize(6); + assertThat(project.properties()).hasSize(6); - assertThat(module.isFile()).isFalse(); + assertThat(project.isFile()).isFalse(); + } + + @Test + public void testEncoding() throws IOException { + ProjectDefinition def = ProjectDefinition.create(); + def.setKey("projectKey"); + def.setName("projectName"); + File baseDir = temp.newFolder(); + def.setBaseDir(baseDir); + def.setVersion("version"); + def.setDescription("desc"); + File workDir = temp.newFolder(); + def.setWorkDir(workDir); + def.setSources("file1"); + def.setProperty("sonar.sourceEncoding", "UTF-16"); + AbstractProjectOrModule project = new DefaultInputProject(def); + + assertThat(project.getEncoding()).isEqualTo(StandardCharsets.UTF_16); } } |