org.sonar.plugins.java.Java Java Examples
The following examples show how to use
org.sonar.plugins.java.Java.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmellRulesDefinition.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("rawtypes") @Override public void define(final Context context) { final NewRepository repository = context.createRepository(REPOSITORY_KEY, Java.KEY) .setName(REPOSITORY_NAME); final List<Class> checkClasses = ImmutableList.<Class> builder() .addAll(SmellChecksRegistrar.checkClasses()) .build(); new AnnotationBasedRulesDefinition(repository, Java.KEY).addRuleClasses(false, checkClasses); for (final NewRule rule : repository.rules()) { final String metadataKey = rule.key(); // Setting internal key is essential for rule templates (see SONAR-6162), and it is not done by AnnotationBasedRulesDefinition from // sslr-squid-bridge version 2.5.1: rule.setInternalKey(metadataKey); rule.setHtmlDescription(readRuleDefinitionResource(metadataKey + ".html")); addMetadata(rule, metadataKey); } repository.done(); }
Example #2
Source File: PmdRulesDefinition.java From sonar-p3c-pmd with MIT License | 5 votes |
@Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.REPOSITORY_NAME); extractRulesData(repository, "/org/sonar/plugins/pmd/rules.xml", "/org/sonar/l10n/pmd/rules/pmd"); extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); }
Example #3
Source File: SmellMeasuresSensorTest.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 5 votes |
@Before public void setUp() { Mockito.when(this.fs.predicates()) .thenReturn(this.predicates); Mockito.when(this.predicates.hasLanguage(Matchers.eq(Java.KEY))) .thenReturn(this.predicate); }
Example #4
Source File: CheckstyleSensorTest.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void shouldDescribePluginCorrectly() { final DefaultSensorDescriptor descriptor = new DefaultSensorDescriptor(); final CheckstyleSensor sensor = new CheckstyleSensor(null); sensor.describe(descriptor); assertThat(descriptor.languages()).containsOnly(Java.KEY); assertThat(descriptor.name()).isNotEmpty(); }
Example #5
Source File: PmdRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 5 votes |
@Test public void test() { PmdRulesDefinition definition = new PmdRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); //assertThat(rules).hasSize(268); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
Example #6
Source File: PmdSensor.java From sonar-p3c-pmd with MIT License | 5 votes |
private boolean hasFilesToCheck(Type type, String repositoryKey) { FilePredicates predicates = fs.predicates(); Iterable<File> files = fs.files(predicates.and( predicates.hasLanguage(Java.KEY), predicates.hasType(type))); return !Iterables.isEmpty(files) && !profile.getActiveRulesByRepository(repositoryKey).isEmpty(); }
Example #7
Source File: PmdUnitTestsRulesDefinition.java From sonar-p3c-pmd with MIT License | 5 votes |
@Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.TEST_REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.TEST_REPOSITORY_NAME); PmdRulesDefinition.extractRulesData(repository, "/org/sonar/plugins/pmd/rules-unit-tests.xml", "/org/sonar/l10n/pmd/rules/pmd-unit-tests"); repository.done(); }
Example #8
Source File: PmdP3CRulesDefinition.java From sonar-p3c-pmd with MIT License | 5 votes |
@Override public void define(Context context) { NewRepository repository = context .createRepository(PmdConstants.P3C_REPOSITORY_KEY, Java.KEY) .setName(PmdConstants.P3C_REPOSITORY_NAME); PmdRulesDefinition.extractRulesData(repository, "/org/sonar/plugins/pmd/rules-p3c.xml", "/org/sonar/l10n/pmd/rules/pmd-p3c"); repository.done(); }
Example #9
Source File: PmdProfileImporter.java From sonar-p3c-pmd with MIT License | 4 votes |
public PmdProfileImporter(RuleFinder ruleFinder) { super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME); setSupportedLanguages(Java.KEY); this.ruleFinder = ruleFinder; }
Example #10
Source File: PmdExecutorTest.java From sonar-p3c-pmd with MIT License | 4 votes |
static InputFile file(String path, Type type) { return new DefaultInputFile(path) .setAbsolutePath(new File(path).getAbsolutePath()) .setType(type) .setLanguage(Java.KEY); }
Example #11
Source File: PmdUnitTestsRulesDefinitionTest.java From sonar-p3c-pmd with MIT License | 4 votes |
@Test public void test() { PmdUnitTestsRulesDefinition definition = new PmdUnitTestsRulesDefinition(); RulesDefinition.Context context = new RulesDefinition.Context(); definition.define(context); RulesDefinition.Repository repository = context.repository(PmdConstants.TEST_REPOSITORY_KEY); assertThat(repository.name()).isEqualTo(PmdConstants.TEST_REPOSITORY_NAME); assertThat(repository.language()).isEqualTo(Java.KEY); List<Rule> rules = repository.rules(); assertThat(rules).hasSize(17); for (Rule rule : rules) { assertThat(rule.key()).isNotNull(); assertThat(rule.key()).isIn( "JUnitStaticSuite", "JUnitSpelling", "JUnitAssertionsShouldIncludeMessage", "JUnitTestsShouldIncludeAssert", "TestClassWithoutTestCases", "UnnecessaryBooleanAssertion", "UseAssertEqualsInsteadOfAssertTrue", "UseAssertSameInsteadOfAssertTrue", "UseAssertNullInsteadOfAssertTrue", "SimplifyBooleanAssertion", "UseAssertTrueInsteadOfAssertEquals", "JUnitTestContainsTooManyAsserts", "JUnit4SuitesShouldUseSuiteAnnotation", "JUnit4TestShouldUseAfterAnnotation", "JUnit4TestShouldUseBeforeAnnotation", "JUnit4TestShouldUseTestAnnotation", "JUnitUseExpected"); assertThat(rule.internalKey()).isNotNull(); assertThat(rule.name()).isNotNull(); assertThat(rule.htmlDescription()).isNotNull(); assertThat(rule.severity()).isNotNull(); for (Param param : rule.params()) { assertThat(param.name()).isNotNull(); assertThat(param.description()) .overridingErrorMessage("Description is not set for parameter '" + param.name() + "' of rule '" + rule.key()) .isNotNull(); } if (!"XPathRule".equals(rule.key())) { assertThat(rule.debtRemediationFunction()) .overridingErrorMessage("Sqale remediation function is not set for rule '" + rule.key()) .isNotNull(); assertThat(rule.debtSubCharacteristic()) .overridingErrorMessage("Sqale characteristic is not set for rule '" + rule.key()) .isNotNull(); } } }
Example #12
Source File: PmdExecutor.java From sonar-p3c-pmd with MIT License | 4 votes |
public Iterable<File> javaFiles(Type fileType) { FilePredicates predicates = fs.predicates(); return fs.files(predicates.and( predicates.hasLanguage(Java.KEY), predicates.hasType(fileType))); }
Example #13
Source File: CheckstyleSensor.java From sonar-checkstyle with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void describe(SensorDescriptor descriptor) { descriptor.onlyOnLanguage(Java.KEY).name("CheckstyleSensor"); }
Example #14
Source File: PmdProfileExporter.java From sonar-p3c-pmd with MIT License | 4 votes |
public PmdProfileExporter() { super(PmdConstants.REPOSITORY_KEY, PmdConstants.PLUGIN_NAME); setSupportedLanguages(Java.KEY); setMimeType("application/xml"); }
Example #15
Source File: SmellMeasuresSensor.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@link SmellMeasuresSensor} IoC constructor. * * @param fileSystem SonarQube {@link FileSystem} */ public SmellMeasuresSensor(final FileSystem fileSystem) { this.fileSystem = fileSystem; this.javaFilesPredicate = this.fileSystem.predicates() .hasLanguage(Java.KEY); }
Example #16
Source File: SmellMeasuresSensor.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void describe(final SensorDescriptor descriptor) { descriptor.name(this.getClass() .getSimpleName()); descriptor.onlyOnLanguage(Java.KEY); }
Example #17
Source File: SmellRulesDefinitionTest.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 4 votes |
@Test public void define_should_createRepositoryAndRegisterAllSmellPluginChecks() { Mockito.when(this.repository.key()) .thenReturn(EXPECTED_REPOSITORY_KEY); Mockito.when(this.rule.key()) .thenReturn(LAST_RULE_KEY); // Some plumbering... Mockito.when(this.context.createRepository(Matchers.anyString(), Matchers.anyString())) .thenReturn(this.repository); Mockito.when(this.repository.setName(Matchers.anyString())) .thenReturn(this.repository); Mockito.when(this.repository.rules()) .thenReturn(ImmutableList.<NewRule> of(this.rule)); Mockito.when(this.repository.createRule(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.repository.rule(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setName(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setHtmlDescription(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setSeverity(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setTemplate(Matchers.anyBoolean())) .thenReturn(this.rule); Mockito.when(this.rule.setStatus(Matchers.any(RuleStatus.class))) .thenReturn(this.rule); Mockito.when(this.rule.setTags(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setDebtSubCharacteristic(Matchers.anyString())) .thenReturn(this.rule); Mockito.when(this.rule.setDebtRemediationFunction(Matchers.any(DebtRemediationFunction.class))) .thenReturn(this.rule); Mockito.when(this.rule.debtRemediationFunctions()) .thenReturn(this.functions); Mockito.when(this.rule.setEffortToFixDescription(Matchers.anyString())) .thenReturn(this.rule); // Execute final SmellRulesDefinition sut = new SmellRulesDefinition(); sut.define(this.context); // Verify behavior Mockito.verify(this.context, Mockito.times(1)) .createRepository(Matchers.eq(EXPECTED_REPOSITORY_KEY), Matchers.eq(Java.KEY)); Mockito.verify(this.repository, Mockito.times(1)) .setName(Matchers.eq(EXPECTED_REPOSITORY_NAME)); Mockito.verify(this.repository, Mockito.times(27)) .createRule(this.captor.capture()); Assertions.assertThat(this.captor.getValue()) .isEqualTo(LAST_RULE_KEY); Mockito.verify(this.rule, Mockito.times(28)) .key(); Mockito.verify(this.rule, Mockito.times(1)) .setInternalKey(Matchers.eq(LAST_RULE_KEY)); Mockito.verify(this.repository, Mockito.times(1)) .done(); }