Class SonarComponents
java.lang.Object
org.sonar.plugins.java.api.CheckRegistrar.RegistrarContext
org.sonar.java.SonarComponents
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringDescribes if an optimized analysis of unchanged by skipping some rules is enabled.static final Stringstatic final StringDescribes whether input files should be parsed while ignoring unnamed split modules. -
Constructor Summary
ConstructorsConstructorDescriptionSonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules) SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition) Will be called in SonarScanner context when no custom rules are present.SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, CheckRegistrar[] checkRegistrars) Can be called in SonarLint context when custom rules are present.SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, CheckRegistrar[] checkRegistrars, org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition) May be called in some SonarLint contexts, but not others, since ProjectDefinition might not be available.SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, CheckRegistrar[] checkRegistrars, org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition, SonarLintCache sonarLintCache) All other constructors delegate to this one.SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, CheckRegistrar[] checkRegistrars, SonarLintCache sonarLintCache) Will *only* be called in SonarLint context and when custom rules are present. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddIssue(org.sonar.api.batch.fs.InputComponent inputComponent, JavaCheck check, int line, String message, Integer cost) booleanbooleanvoidcollectUndefinedTypes(String pathToFile, Set<JProblem> undefinedTypes) org.sonar.api.batch.sensor.SensorContextcontext()booleanfileCanBeSkipped(org.sonar.api.batch.fs.InputFile inputFile) fileLines(org.sonar.api.batch.fs.InputFile inputFile) org.sonar.api.measures.FileLinesContextfileLinesContextFor(org.sonar.api.batch.fs.InputFile inputFile) Set<org.sonar.api.rule.RuleKey> longReturns the batch mode size as read from configuration, in Kilo Bytes.org.sonar.api.config.ConfigurationReturns an OS-independent key that should identify the module within the projectOptional<org.sonar.api.rule.RuleKey> getRuleKey(JavaCheck check) org.sonar.api.batch.sensor.highlighting.NewHighlightinghighlightableFor(org.sonar.api.batch.fs.InputFile inputFile) booleaninputFileContents(org.sonar.api.batch.fs.InputFile inputFile) booleanbooleanbooleanbooleanbooleanbooleanvoidorg.sonar.api.batch.fs.InputComponentproject()voidregisterAutoScanCompatibleRules(Collection<org.sonar.api.rule.RuleKey> ruleKeys) Cannot be used outside of Sonar Products.voidregisterCustomFileScanner(org.sonar.api.rule.RuleScope ruleScope, JavaFileScanner scanner) Registers a custom file scanner not related to any rule or repository.voidregisterMainChecks(String repositoryKey, Collection<?> javaCheckClassesAndInstances) Registers main code java checks for a given repository.voidregisterMainChecks(org.sonar.api.batch.rule.Checks<JavaCheck> checks, Collection<?> javaCheckClassesAndInstances) Register main code java checks which have already been initialized by a CheckFactory.voidregisterMainSharedCheck(JavaCheck check, Collection<org.sonar.api.rule.RuleKey> ruleKeys) Registers one main code check related to not one but a list of rules.voidregisterTestChecks(String repositoryKey, Collection<?> javaCheckClassesAndInstances) Registers test code java checks for a given repository.voidregisterTestSharedCheck(JavaCheck check, Collection<org.sonar.api.rule.RuleKey> ruleKeys) Registers one test code check related to not one but a list of rules.booleanreportAnalysisError(com.sonar.sslr.api.RecognitionException re, org.sonar.api.batch.fs.InputFile inputFile) voidreportIssue(AnalyzerMessage analyzerMessage) voidsetCheckFilter(UnaryOperator<List<JavaCheck>> checkFilter) voidsetSensorContext(org.sonar.api.batch.sensor.SensorContext context) booleanbooleanorg.sonar.api.batch.sensor.symbol.NewSymbolTablesymbolizableFor(org.sonar.api.batch.fs.InputFile inputFile) Methods inherited from class org.sonar.plugins.java.api.CheckRegistrar.RegistrarContext
checkClasses, registerClassesForRepository, registerTestChecks, repositoryKey, testCheckClasses
-
Field Details
-
FAIL_ON_EXCEPTION_KEY
- See Also:
-
SONAR_BATCH_MODE_KEY
- See Also:
-
SONAR_AUTOSCAN
- See Also:
-
SONAR_AUTOSCAN_CHECK_FILTERING
- See Also:
-
SONAR_BATCH_SIZE_KEY
- See Also:
-
SONAR_FILE_BY_FILE
- See Also:
-
SONAR_CAN_SKIP_UNCHANGED_FILES_KEY
Describes if an optimized analysis of unchanged by skipping some rules is enabled. By default, the property is not set (null), leaving SQ/SC to decide whether to enable this behavior. Setting it to true or false, forces the behavior from the analyzer independently of the server.- See Also:
-
SONAR_IGNORE_UNNAMED_MODULE_FOR_SPLIT_PACKAGE
Describes whether input files should be parsed while ignoring unnamed split modules. In practice, enabling this parameter should help developers in the Android ecosystem and those relying on (transitive) dependencies that do not respect modularization as defined by the JLS.- See Also:
-
-
Constructor Details
-
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules) -
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, @Nullable CheckRegistrar[] checkRegistrars) Can be called in SonarLint context when custom rules are present. -
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, @Nullable CheckRegistrar[] checkRegistrars, SonarLintCache sonarLintCache) Will *only* be called in SonarLint context and when custom rules are present.This is because
SonarLintCacheis only added as an extension in a SonarLint context. See alsoJavaPlugin#definein thesonar-java-pluginmodule.SonarLintCacheis used only by newer custom rules, e.g. DBD. Thus, for this constructor, we can also assume the presence ofCheckRegistrarinstances. -
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, @Nullable org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition) Will be called in SonarScanner context when no custom rules are present. May be called in some SonarLint contexts, but not others, since ProjectDefinition might not be available. -
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, @Nullable CheckRegistrar[] checkRegistrars, @Nullable org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition) May be called in some SonarLint contexts, but not others, since ProjectDefinition might not be available. -
SonarComponents
public SonarComponents(org.sonar.api.measures.FileLinesContextFactory fileLinesContextFactory, org.sonar.api.batch.fs.FileSystem fs, ClasspathForMain javaClasspath, ClasspathForTest javaTestClasspath, org.sonar.api.batch.rule.CheckFactory checkFactory, org.sonar.api.batch.rule.ActiveRules activeRules, @Nullable CheckRegistrar[] checkRegistrars, @Nullable org.sonar.api.batch.bootstrap.ProjectDefinition projectDefinition, @Nullable SonarLintCache sonarLintCache) All other constructors delegate to this one.It will also be called directly when constructing a SonarComponents instance for injection if all parameters are available. This is for example the case for SonarLint in IntelliJ when DBD is present (because ProjectDefinition can be available in recent SonarLint versions, and DBD provides a CheckRegistrar.)
-
-
Method Details
-
setSensorContext
public void setSensorContext(org.sonar.api.batch.sensor.SensorContext context) -
setCheckFilter
-
fileLinesContextFor
public org.sonar.api.measures.FileLinesContext fileLinesContextFor(org.sonar.api.batch.fs.InputFile inputFile) -
symbolizableFor
public org.sonar.api.batch.sensor.symbol.NewSymbolTable symbolizableFor(org.sonar.api.batch.fs.InputFile inputFile) -
highlightableFor
public org.sonar.api.batch.sensor.highlighting.NewHighlighting highlightableFor(org.sonar.api.batch.fs.InputFile inputFile) -
getJavaClasspath
-
inAndroidContext
public boolean inAndroidContext() -
getJavaTestClasspath
-
getJspClasspath
-
registerMainChecks
Description copied from class:CheckRegistrar.RegistrarContextRegisters main code java checks for a given repository.- Overrides:
registerMainChecksin classCheckRegistrar.RegistrarContext- Parameters:
repositoryKey- key of rule repositoryjavaCheckClassesAndInstances- a collection ofClassinvalid input: '<'? extends JavaCheck>andJavaCheck>instances
-
registerMainChecks
public void registerMainChecks(org.sonar.api.batch.rule.Checks<JavaCheck> checks, Collection<?> javaCheckClassesAndInstances) Description copied from class:CheckRegistrar.RegistrarContextRegister main code java checks which have already been initialized by a CheckFactory.- Overrides:
registerMainChecksin classCheckRegistrar.RegistrarContext
-
registerTestChecks
Description copied from class:CheckRegistrar.RegistrarContextRegisters test code java checks for a given repository.- Overrides:
registerTestChecksin classCheckRegistrar.RegistrarContext- Parameters:
repositoryKey- key of rule repositoryjavaCheckClassesAndInstances- a collection ofClassinvalid input: '<'? extends JavaCheck>andJavaCheck>instances
-
registerCustomFileScanner
public void registerCustomFileScanner(org.sonar.api.rule.RuleScope ruleScope, JavaFileScanner scanner) Description copied from class:CheckRegistrar.RegistrarContextRegisters a custom file scanner not related to any rule or repository. CheckRegistrars call this function to register a custom file scanner for execution during the analysis on all source files that match the given rule scope (MAIN, TEST or ALL). Custom file scanners reporting an issue will have no effect, since no rule is associated.- Overrides:
registerCustomFileScannerin classCheckRegistrar.RegistrarContext
-
registerAutoScanCompatibleRules
Description copied from class:CheckRegistrar.RegistrarContextCannot be used outside of Sonar Products. Registers rules compatible with the autoscan context. Note: It's possible to convert checkClass to RuleKey using:RuleKey.of(repositoryKey, RuleAnnotationUtils.getRuleKey(checkClass))
- Overrides:
registerAutoScanCompatibleRulesin classCheckRegistrar.RegistrarContext
-
getAdditionalAutoScanCompatibleRuleKeys
-
mainChecks
-
testChecks
-
jspChecks
-
getRuleKey
-
addIssue
-
reportIssue
-
reportAnalysisError
public boolean reportAnalysisError(com.sonar.sslr.api.RecognitionException re, org.sonar.api.batch.fs.InputFile inputFile) -
isSonarLintContext
public boolean isSonarLintContext() -
isQuickFixCompatible
public boolean isQuickFixCompatible() -
isSetQuickFixAvailableCompatible
public boolean isSetQuickFixAvailableCompatible() -
fileLines
-
inputFileContents
-
analysisCancelled
public boolean analysisCancelled() -
shouldFailAnalysisOnException
public boolean shouldFailAnalysisOnException() -
isFileByFileEnabled
public boolean isFileByFileEnabled() -
isAutoScan
public boolean isAutoScan() -
isAutoScanCheckFiltering
public boolean isAutoScanCheckFiltering() -
getBatchModeSizeInKB
public long getBatchModeSizeInKB()Returns the batch mode size as read from configuration, in Kilo Bytes. If not value can be found, compute dynamically an ideal value.- Returns:
- the batch mode size or a default value of -1L.
-
shouldIgnoreUnnamedModuleForSplitPackage
public boolean shouldIgnoreUnnamedModuleForSplitPackage() -
projectLevelWorkDir
-
getModuleKey
Returns an OS-independent key that should identify the module within the project- Returns:
- A key representing the module
-
canSkipUnchangedFiles
- Throws:
ApiMismatchException
-
fileCanBeSkipped
public boolean fileCanBeSkipped(org.sonar.api.batch.fs.InputFile inputFile) -
project
public org.sonar.api.batch.fs.InputComponent project() -
collectUndefinedTypes
-
logUndefinedTypes
public void logUndefinedTypes() -
context
public org.sonar.api.batch.sensor.SensorContext context() -
sonarLintCache
-
getConfiguration
public org.sonar.api.config.Configuration getConfiguration()
-