Browse Source

SONAR-16232 Delete sonar-plugin-api module

tags/9.5.0.56709
Duarte Meneses 2 years ago
parent
commit
3b7e8d87a7
100 changed files with 0 additions and 6947 deletions
  1. 0
    1
      settings.gradle
  2. 0
    77
      sonar-plugin-api/build.gradle
  3. 0
    46
      sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java
  4. 0
    40
      sonar-plugin-api/src/main/java/org/sonar/api/Beta.java
  5. 0
    422
      sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
  6. 0
    38
      sonar-plugin-api/src/main/java/org/sonar/api/ExtensionPoint.java
  7. 0
    189
      sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java
  8. 0
    39
      sonar-plugin-api/src/main/java/org/sonar/api/Properties.java
  9. 0
    129
      sonar-plugin-api/src/main/java/org/sonar/api/Property.java
  10. 0
    61
      sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java
  11. 0
    117
      sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java
  12. 0
    38
      sonar-plugin-api/src/main/java/org/sonar/api/SonarEdition.java
  13. 0
    53
      sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java
  14. 0
    31
      sonar-plugin-api/src/main/java/org/sonar/api/SonarProduct.java
  15. 0
    33
      sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeSide.java
  16. 0
    155
      sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java
  17. 0
    181
      sonar-plugin-api/src/main/java/org/sonar/api/SonarRuntime.java
  18. 0
    55
      sonar-plugin-api/src/main/java/org/sonar/api/Startable.java
  19. 0
    41
      sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java
  20. 0
    38
      sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java
  21. 0
    54
      sonar-plugin-api/src/main/java/org/sonar/api/batch/InstantiationStrategy.java
  22. 0
    39
      sonar-plugin-api/src/main/java/org/sonar/api/batch/Phase.java
  23. 0
    54
      sonar-plugin-api/src/main/java/org/sonar/api/batch/ScannerSide.java
  24. 0
    76
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java
  25. 0
    326
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java
  26. 0
    79
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java
  27. 0
    54
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/internal/ProjectBuilderContext.java
  28. 0
    23
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/internal/package-info.java
  29. 0
    23
      sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/package-info.java
  30. 0
    33
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java
  31. 0
    174
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java
  32. 0
    178
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java
  33. 0
    116
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/IndexedFile.java
  34. 0
    45
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java
  35. 0
    70
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java
  36. 0
    202
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java
  37. 0
    39
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFileFilter.java
  38. 0
    36
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java
  39. 0
    75
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java
  40. 0
    39
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextPointer.java
  41. 0
    53
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java
  42. 0
    24
      sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/package-info.java
  43. 0
    33
      sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/Metric.java
  44. 0
    43
      sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/MetricFinder.java
  45. 0
    22
      sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/package-info.java
  46. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/package-info.java
  47. 0
    48
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJob.java
  48. 0
    35
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java
  49. 0
    47
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobDescriptor.java
  50. 0
    78
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/issue/PostJobIssue.java
  51. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/issue/package-info.java
  52. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/package-info.java
  53. 0
    80
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java
  54. 0
    74
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRules.java
  55. 0
    42
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/CheckFactory.java
  56. 0
    234
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java
  57. 0
    124
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/LoadedActiveRule.java
  58. 0
    50
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java
  59. 0
    32
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java
  60. 0
    61
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java
  61. 0
    31
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java
  62. 0
    23
      sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/package-info.java
  63. 0
    74
      sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameCommand.java
  64. 0
    130
      sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java
  65. 0
    55
      sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/IgnoreCommand.java
  66. 0
    126
      sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java
  67. 0
    24
      sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/package-info.java
  68. 0
    55
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java
  69. 0
    253
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java
  70. 0
    94
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java
  71. 0
    38
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/ReadCache.java
  72. 0
    44
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/WriteCache.java
  73. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/package-info.java
  74. 0
    50
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/NewSignificantCode.java
  75. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/package-info.java
  76. 0
    76
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/NewCoverage.java
  77. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/package-info.java
  78. 0
    64
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/NewCpdTokens.java
  79. 0
    75
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/TokensLine.java
  80. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/package-info.java
  81. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/package-info.java
  82. 0
    50
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/AnalysisError.java
  83. 0
    53
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/NewAnalysisError.java
  84. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/package-info.java
  85. 0
    68
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/NewHighlighting.java
  86. 0
    61
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/TypeOfText.java
  87. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/package-info.java
  88. 0
    85
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java
  89. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java
  90. 0
    56
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/ExternalIssue.java
  91. 0
    44
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IIssue.java
  92. 0
    72
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java
  93. 0
    51
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueLocation.java
  94. 0
    97
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewExternalIssue.java
  95. 0
    89
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java
  96. 0
    56
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssueLocation.java
  97. 0
    21
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java
  98. 0
    48
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java
  99. 0
    54
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/NewMeasure.java
  100. 0
    0
      sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java

+ 0
- 1
settings.gradle View File

@@ -47,7 +47,6 @@ include 'sonar-check-api'
include 'sonar-core'
include 'sonar-duplications'
include 'sonar-markdown'
include 'sonar-plugin-api'
include 'sonar-plugin-api-impl'
include 'sonar-scanner-engine'
include 'sonar-scanner-engine-shaded'

+ 0
- 77
sonar-plugin-api/build.gradle View File

@@ -1,77 +0,0 @@
sonarqube {
properties {
property 'sonar.projectName', "${projectTitle} :: Plugin API"
}
}

apply plugin: 'com.github.johnrengelman.shadow'

dependencies {
// please keep the list grouped by configuration and ordered by name

compile 'commons-io:commons-io'
compile 'commons-lang:commons-lang'
compile 'com.google.code.gson:gson'

// shaded, but not relocated
compile project(':sonar-check-api')

compileOnly 'ch.qos.logback:logback-classic'
compileOnly 'com.google.code.findbugs:jsr305'
compileOnly 'javax.servlet:javax.servlet-api'
compileOnly 'junit:junit'
// Used by LogTesterJUnit5
compileOnly 'org.junit.jupiter:junit-jupiter-api'
compileOnly 'org.slf4j:slf4j-api'

testCompile 'com.google.guava:guava'
testCompile 'com.tngtech.java:junit-dataprovider'
testCompile 'org.assertj:assertj-core'
testCompile 'org.mockito:mockito-core'
testCompile project(':sonar-plugin-api-impl')
testCompile project(':ut-monitoring')
}

configurations {
// Make the compileOnly dependencies available when compiling/running tests
testImplementation.extendsFrom compileOnly
}

def on3Digits(version) {
def projectversion3digits = version - ~/-\w+/
projectversion3digits = projectversion3digits.tokenize('.').plus(0).take(3).join('.')
}

import org.apache.tools.ant.filters.ReplaceTokens
processResources {
filter ReplaceTokens, tokens: [
// The build version is composed of 4 fields, including the semantic version and the build number provided by Travis.
'project.buildVersion': project.version.endsWith('SNAPSHOT') ? project.version : on3Digits(project.version) + '.' + (System.getProperty("buildNumber") ?: '0'),
'project.version.3digits': project.version.endsWith('SNAPSHOT') ? project.version : on3Digits(project.version)
]
}

shadowJar {
configurations = [project.configurations.runtimeClasspath]
minimize {
exclude(project(':sonar-check-api'))
}
relocate('com.google', 'org.sonar.api.internal.google')
relocate('org.apache.commons', 'org.sonar.api.internal.apachecommons')
}

// only interested in shadowJar
jar.enabled = false
artifactoryPublish.skip = false

publishing {
publications {
mavenJava(MavenPublication) {
artifact source: shadowJar, classifier: null
if (release) {
artifact sourcesJar
artifact javadocJar
}
}
}
}

+ 0
- 46
sonar-plugin-api/src/main/java/org/sonar/api/BatchComponent.java View File

@@ -1,46 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import org.sonar.api.batch.ScannerSide;

/**
* Marker interface for all the components available in container of batch (code analyzer). Note that
* injection of dependencies by constructor is used :
* <pre>
* public class Foo implements BatchComponent {
*
* }
* public class Bar implements BatchComponent {
* private final Foo foo;
* public Bar(Foo f) {
* this.foo = f;
* }
* }
*
* </pre>
*
* @since 2.2
* @deprecated since 5.2 use {@link ScannerSide} annotation
*/
@Deprecated
@ScannerSide
public interface BatchComponent {
}

+ 0
- 40
sonar-plugin-api/src/main/java/org/sonar/api/Beta.java View File

@@ -1,40 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* This annotations marks API as experimental.
* API marked with it can be subject to breaking changes or removal in any future version without compliance with deprecation policies.
*/
@Retention(RetentionPolicy.CLASS)
@Target({
ElementType.ANNOTATION_TYPE,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.METHOD,
ElementType.TYPE})
@Documented
public @interface Beta {}

+ 0
- 422
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java View File

@@ -1,422 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.platform.Server;

/**
* Non-exhaustive list of constants of core properties.
*
* @since 1.11
*/
public interface CoreProperties {

/**
* @since 3.0
*/
String ENCRYPTION_SECRET_KEY_PATH = "sonar.secretKeyPath";

/**
* @since 2.11
*/
String CATEGORY_GENERAL = "general";

/**
* @since 4.0
* @deprecated since 8.1. Database cleaning now has a dedicated category {@link CoreProperties#CATEGORY_HOUSEKEEPING}.
*/
@Deprecated
String SUBCATEGORY_DATABASE_CLEANER = "databaseCleaner";

/**
* @since 7.6
*/
String SUBCATEGORY_MODULES = "subProjects";

/**
* @since 4.0
*/
String SUBCATEGORY_DUPLICATIONS = "duplications";

/**
* @since 8.2
*/
String CATEGORY_ALM_INTEGRATION = "almintegration";

/**
* @since 8.1
*/
String CATEGORY_HOUSEKEEPING = "housekeeping";
/**
* @since 9.1
*/
String CATEGORY_AUDIT_LOGS = "auditLogs";

/**
* @since 6.6
*/
String SUBCATEGORY_BRANCHES_AND_PULL_REQUESTS = "branchesAndPullRequests";

/**
* @since 8.1
*/
String SUBCATEGORY_GENERAL = "general";

/**
* @since 4.0
*/
String SUBCATEGORY_DIFFERENTIAL_VIEWS = "differentialViews";

/**
* @since 5.1
*/
String SUBCATEGORY_LOOKNFEEL = "looknfeel";

/**
* @since 5.1
*/
String SUBCATEGORY_ISSUES = "issues";

/**
* @since 8.9
*/
String SUBCATEGORY_QUALITY_GATE = "qualityGate";

/**
* @since 4.0
*/
String SUBCATEGORY_L10N = "localization";

/**
* @since 7.2
*/
String CATEGORY_EXTERNAL_ISSUES = "externalIssues";

/**
* @since 2.11
*/
String CATEGORY_CODE_COVERAGE = "codeCoverage";

/**
* @since 2.11
*/
String CATEGORY_SECURITY = "security";

/**
* @since 3.3
*/
String CATEGORY_EXCLUSIONS = "exclusions";

/**
* @since 4.0
*/
String SUBCATEGORY_FILES_EXCLUSIONS = "files";

/**
* @since 4.0
*/
String SUBCATEGORY_DUPLICATIONS_EXCLUSIONS = "duplications";

/**
* @since 4.0
*/
String SUBCATEGORY_COVERAGE_EXCLUSIONS = "coverage";

/**
* @since 6.1
*/
String SUBCATEGORY_EMAIL = "email";

/**
* @since 3.7
*/
String CATEGORY_LICENSES = "licenses";

/**
* @since 4.0
*/
String CATEGORY_TECHNICAL_DEBT = "technicalDebt";

/* Global settings */
String SONAR_HOME = "SONAR_HOME";

String PROJECT_VERSION_PROPERTY = "sonar.projectVersion";
String BUILD_STRING_PROPERTY = "sonar.buildString";

/**
* @since 2.6
*/
String PROJECT_KEY_PROPERTY = "sonar.projectKey";

/**
* @since 2.6
*/
String PROJECT_NAME_PROPERTY = "sonar.projectName";

/**
* @since 2.6
*/
String PROJECT_DESCRIPTION_PROPERTY = "sonar.projectDescription";

/**
* To determine value of this property use {@link FileSystem#encoding()}.
*
* @since 2.6
*/
String ENCODING_PROPERTY = "sonar.sourceEncoding";

/**
* Value format is yyyy-MM-dd
*/
String PROJECT_DATE_PROPERTY = "sonar.projectDate";

/* Exclusions */
String PROJECT_INCLUSIONS_PROPERTY = "sonar.inclusions";
String PROJECT_EXCLUSIONS_PROPERTY = "sonar.exclusions";

/* Coverage exclusions */
String PROJECT_COVERAGE_EXCLUSIONS_PROPERTY = "sonar.coverage.exclusions";

/**
* @since 3.3
*/
String PROJECT_TEST_INCLUSIONS_PROPERTY = "sonar.test.inclusions";
String PROJECT_TEST_EXCLUSIONS_PROPERTY = "sonar.test.exclusions";
String GLOBAL_EXCLUSIONS_PROPERTY = "sonar.global.exclusions";
String GLOBAL_TEST_EXCLUSIONS_PROPERTY = "sonar.global.test.exclusions";

/* Sonar Core */

String CORE_FORCE_AUTHENTICATION_PROPERTY = "sonar.forceAuthentication";
boolean CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE = true;
String CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_PROPERTY = "sonar.allowPermissionManagementForProjectAdmins";
boolean CORE_ALLOW_PERMISSION_MANAGEMENT_FOR_PROJECT_ADMINS_DEFAULT_VALUE = true;
String SONAR_VALIDATE_WEBHOOKS_PROPERTY = "sonar.validateWebhooks";
boolean SONAR_VALIDATE_WEBHOOKS_DEFAULT_VALUE = true;

/**
* @deprecated since 2.14. See http://jira.sonarsource.com/browse/SONAR-3153. Replaced by {@link #CORE_AUTHENTICATOR_REALM}.
*/
@Deprecated
String CORE_AUTHENTICATOR_CLASS = "sonar.authenticator.class";

/**
* @since 2.14
* @deprecated since 7.1, this setting should not be used by plugin
*/
@Deprecated
String CORE_AUTHENTICATOR_REALM = "sonar.security.realm";

/**
* @deprecated since 7.1, this setting should not be used by plugin
*/
@Deprecated
String CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE = "sonar.authenticator.ignoreStartupFailure";

/**
* @deprecated since 6.3. This feature is not supported anymore
* @see <a href="https://jira.sonarsource.com/browse/SONAR-8208">SONAR-8208/a>
*/
@Deprecated
String CORE_AUTHENTICATOR_CREATE_USERS = "sonar.authenticator.createUsers";

/**
* @since 3.6
* @deprecated since 5.4. This feature is not supported anymore. See http://jira.sonarsource.com/browse/SONAR-7219
*/
@Deprecated
String CORE_AUTHENTICATOR_UPDATE_USER_ATTRIBUTES = "sonar.security.updateUserAttributes";

String SERVER_ID = "sonar.core.id";

// format is yyyy-MM-dd'T'HH:mm:ssZ
String SERVER_STARTTIME = "sonar.core.startTime";

/**
* This property defines the SonarQubeServer base url, such as <i>http://yourhost.yourdomain/sonar</i>.
* When this property is not set, the base url of the SonarQube server is provided by {@link Server#getPublicRootUrl()}.
*
* @since 2.10
*/
String SERVER_BASE_URL = "sonar.core.serverBaseURL";

/**
* @since 2.11
* @deprecated since 6.7
*/
@Deprecated
String CPD_CROSS_PROJECT = "sonar.cpd.cross_project";

/**
* @since 3.5
*/
String CPD_EXCLUSIONS = "sonar.cpd.exclusions";

/**
* @since 3.3
*/
String LINKS_HOME_PAGE = "sonar.links.homepage";

/**
* @since 3.3
*/
String LINKS_CI = "sonar.links.ci";

/**
* @since 3.3
*/
String LINKS_ISSUE_TRACKER = "sonar.links.issue";

/**
* @since 3.3
*/
String LINKS_SOURCES = "sonar.links.scm";

/**
* @since 3.3
* @deprecated since 7.1, developer connection link is no more feed
*/
@Deprecated
String LINKS_SOURCES_DEV = "sonar.links.scm_dev";

/**
* @since 3.4
*/
String LOGIN = "sonar.login";

/**
* @since 3.4
*/
String PASSWORD = "sonar.password";

/**
* @since 3.5
* @deprecated since 7.6
*/
@Deprecated
String TASK = "sonar.task";

/**
* @since 3.6
* @deprecated since 7.6
*/
@Deprecated
String SCAN_TASK = "scan";

/**
* @since 3.6
* Removed in 8.4 by mistake and reintroduced in 8.5
*/
String PROFILING_LOG_PROPERTY = "sonar.showProfiling";

/**
* @since 4.0
*/
String WORKING_DIRECTORY = "sonar.working.directory";

String WORKING_DIRECTORY_DEFAULT_VALUE = ".sonar";

/**
* @since 5.2
*/
String GLOBAL_WORKING_DIRECTORY = "sonar.globalWorking.directory";
String GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE = "";

/**
* @since 4.5
*/
String DEVELOPMENT_COST = "sonar.technicalDebt.developmentCost";

/**
* @since 4.5
*/
String DEVELOPMENT_COST_DEF_VALUE = "30";

/**
* @since 4.5
*/
String RATING_GRID = "sonar.technicalDebt.ratingGrid";

/**
* @since 4.5
*/
String RATING_GRID_DEF_VALUES = "0.05,0.1,0.2,0.5";

/**
* @since 4.5
*/
String LANGUAGE_SPECIFIC_PARAMETERS = "languageSpecificParameters";

/**
* @since 4.5
*/
String LANGUAGE_SPECIFIC_PARAMETERS_LANGUAGE_KEY = "language";

/**
* @since 4.5
*/
String LANGUAGE_SPECIFIC_PARAMETERS_MAN_DAYS_KEY = "man_days";

/**
* @since 4.5
*/
String LANGUAGE_SPECIFIC_PARAMETERS_SIZE_METRIC_KEY = "size_metric";

/**
* @since 5.0
*/
String CATEGORY_SCM = "scm";

/**
* @since 5.0
*/
String SCM_DISABLED_KEY = "sonar.scm.disabled";

/**
* @since 7.6
*/
String SCM_EXCLUSIONS_DISABLED_KEY = "sonar.scm.exclusions.disabled";

/**
* @since 5.0
*/
String SCM_PROVIDER_KEY = "sonar.scm.provider";

/**
* @since 5.1
*/
String DEFAULT_ISSUE_ASSIGNEE = "sonar.issues.defaultAssigneeLogin";

/**
* @since 8.5
*/
String DEVELOPER_AGGREGATED_INFO_DISABLED = "sonar.developerAggregatedInfo.disabled";

/**
* @since 7.6
*/
String MODULE_LEVEL_ARCHIVED_SETTINGS = "sonar.subproject.settings.archived";

/**
* since 8.9
*/
String QUALITY_GATE_IGNORE_SMALL_CHANGES = "sonar.qualitygate.ignoreSmallChanges";
}

+ 0
- 38
sonar-plugin-api/src/main/java/org/sonar/api/ExtensionPoint.java View File

@@ -1,38 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marker annotation for all the interfaces that are extension point (ie can be implemented by plugins
* and will be called at some point of time by the platform).
*
* @since 5.2
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ExtensionPoint {
}

+ 0
- 189
sonar-plugin-api/src/main/java/org/sonar/api/Plugin.java View File

@@ -1,189 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.sonar.api.config.Configuration;
import org.sonar.api.utils.Version;

import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNull;

/**
* Entry-point for plugins to inject extensions into SonarQube.
* <p>The JAR manifest must declare the name of the implementation class in the property <code>Plugin-Class</code>.
* This property is automatically set by sonar-packaging-maven-plugin when building plugin.
* <p>Example of implementation
* <pre>
* public class MyPlugin implements Plugin {
* {@literal @}Override
* public void define(Context context) {
* context.addExtensions(MySensor.class, MyRules.class);
* if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0))) {
* // Extension which supports only versions 6.0 and greater
* // See org.sonar.api.SonarRuntime for more details.
* context.addExtension(MyNewExtension.class);
* }
* }
* }
* </pre>
*
* <p>Example of pom.xml
* <pre>
* &lt;project&gt;
* ...
* &lt;packaging&gt;sonar-plugin&lt;/packaging&gt;
*
* &lt;build&gt;
* &lt;plugins&gt;
* &lt;plugin&gt;
* &lt;groupId&gt;org.sonarsource.sonar-packaging-maven-plugin&lt;/groupId&gt;
* &lt;artifactId&gt;sonar-packaging-maven-plugin&lt;/artifactId&gt;
* &lt;extensions&gt;true&lt;/extensions&gt;
* &lt;configuration&gt;
* &lt;pluginClass&gt;com.mycompany.sonarqube.MyPlugin&lt;/pluginClass&gt;
* &lt;/configuration&gt;
* &lt;/plugin&gt;
* &lt;/plugins&gt;
* &lt;/build&gt;
* &lt;/project&gt;
* </pre>
*
* <p>Example of Test
* Add a test dependency to sonar-plugin-api-impl to have access to implementation classes in tests.
* <pre>
*{@literal @}Test
* public void test_plugin_extensions_compatible_with_5_6() {
* SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(5, 6), SonarQubeSide.SCANNER);
* Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
* MyPlugin underTest = new MyPlugin();
*
* underTest.define(context);
*
* assertThat(context.getExtensions()).hasSize(4);
* }
* </pre>
*
* @since 5.5
* @see org.sonar.api.internal.PluginContextImpl for unit tests
*/
public interface Plugin {

class Context {
private final SonarRuntime sonarRuntime;
private final List extensions = new ArrayList();

/**
* For unit tests only. It's recommended to use {@link org.sonar.api.internal.PluginContextImpl.Builder}
* to create instances of {@link Plugin.Context}.
* The configuration returned by {@see #getBootConfiguration()} is empty.
*/
public Context(SonarRuntime sonarRuntime) {
this.sonarRuntime = requireNonNull(sonarRuntime, "sonarRuntime is null");
}

/**
* Shortcut on {@code getRuntime().getApiVersion()} since version 6.0.
*
* @see #getRuntime()
* @since 5.5
* @return the version of SonarQube API at runtime, not at compilation time
*/
public Version getSonarQubeVersion() {
return sonarRuntime.getApiVersion();
}

/**
* Runtime environment. Can be use to add some extensions only on some conditions.
* @since 6.0
*/
public SonarRuntime getRuntime() {
return sonarRuntime;
}

/**
* Add an extension as :
* <ul>
* <li>a Class that is annotated with {@link org.sonar.api.scanner.ScannerSide}, {@link org.sonar.api.server.ServerSide}
* or {@link org.sonar.api.ce.ComputeEngineSide}. The extension will be instantiated once. Its dependencies are
* injected through constructor parameters.</li>
* <li>an instance that is annotated with {@link org.sonar.api.scanner.ScannerSide}, {@link org.sonar.api.server.ServerSide}
* or {@link org.sonar.api.ce.ComputeEngineSide}.</li>
* </ul>
* Only a single component can be registered for a class. It's not allowed for example to register:
* <ul>
* <li>two MyExtension.class</li>
* <li>MyExtension.class and new MyExtension()</li>
* </ul>
*/
public Context addExtension(Object extension) {
requireNonNull(extension);
this.extensions.add(extension);
return this;
}

/**
* @see #addExtension(Object)
*/
public Context addExtensions(Collection extensions) {
this.extensions.addAll(extensions);
return this;
}

/**
* @see #addExtension(Object)
*/
public Context addExtensions(Object first, Object second, Object... others) {
addExtension(first);
addExtension(second);
addExtensions(asList(others));
return this;
}

public List getExtensions() {
return extensions;
}

/**
* The configuration that contains only the few properties required to bootstrap the process, for example:
* - conf/sonar.properties and persisted properties on web server and Compute Engine sides. The default values
* defined by plugins are ignored.
* - command-line arguments on scanner side. Default values or properties persisted in server are ignored.
*
* @since 7.1
*/
public Configuration getBootConfiguration() {
throw new UnsupportedOperationException("Unit tests should create Plugin.Context with org.sonar.api.internal.PluginContextImpl#Builder");
}

}

/**
* This method is executed at runtime when:
* <ul>
* <li>Web Server starts</li>
* <li>Compute Engine starts</li>
* <li>Scanner starts</li>
* </ul>
*/
void define(Context context);
}

+ 0
- 39
sonar-plugin-api/src/main/java/org/sonar/api/Properties.java View File

@@ -1,39 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.sonar.api.config.Configuration;

/**
* Plugin properties. This annotation is only used on classes implementing org.sonar.api.Plugin.
* <br>
* Note that {@link org.sonar.api.config.PropertyDefinition} is an alternative, programmatic and recommended approach
* to declare properties.
* <br>
* Effective property values are accessible at runtime through the component {@link Configuration}
*
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface Properties {
Property[] value();
}

+ 0
- 129
sonar-plugin-api/src/main/java/org/sonar/api/Property.java View File

@@ -1,129 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Property value can be set in different ways :
* <ul>
* <li>System property</li>
* <li>Batch command-line (-Dfoo=bar in Maven or sonar-runner)</li>
* <li>Maven pom.xml (element {@literal <properties>})</li>
* <li>Maven settings.xml</li>
* <li>SonarQube web administration console</li>
* </ul>
*
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Property {

/**
* Unique key within all plugins. It's recommended to prefix the key by 'sonar.' and the plugin name. Examples :
* 'sonar.cobertura.reportPath' and 'sonar.cpd.minimumTokens'.
*/
String key();

/**
* The empty string "" is considered as null, so it's not possible to have empty strings for default values.
*/
String defaultValue() default "";

String name();

String description() default "";

/**
* @since 2.11
* @see org.sonar.api.config.PropertyDefinition#category()
*/
String category() default "";

/**
* Is the property displayed in project settings page ?
*/
boolean project() default false;

/**
* Is the property displayed in module settings page ? A module is a maven sub-project.
*/
boolean module() default false;

/**
* Is the property displayed in global settings page ?
*/
boolean global() default true;

/**
* @since 3.0
*/
PropertyType type() default PropertyType.STRING;

/**
* Options for *_LIST types
*
* @since 3.0 Options for property of type {@link PropertyType#SINGLE_SELECT_LIST}
* For example {"property_1", "property_3", "property_3"}).
*
* @since 3.3 Options for property of type {@link PropertyType#METRIC}<br>
* If no option is specified, any metric will match.<br>
* If options are specified, all must match for the metric to be displayed.<br>
* Three types of filter are supported <code>key:REGEXP</code>, <code>domain:REGEXP</code> and <code>type:comma_separated__list_of_types</code>.<br>
* For example <code>key:new_.*</code> will match any metric which key starts by <code>new_</code>.<br>
* For example <code>type:INT,FLOAT</code> will match any metric of type <code>INT</code> or <code>FLOAT</code>.<br>
* For example <code>type:NUMERIC</code> will match any metric of numerictype.
*/
String[] options() default {};

/**
* Can the property take multiple values. Eg: list of email addresses.
*
* @since 3.3
*/
boolean multiValues() default false;

/**
* A Property of type <code>PropertyType.PROPERTY_SET</code> can reference a set of properties
* by its key.
*
* @since 3.3
* @deprecated since 6.1, as it was not used and too complex to maintain.
*/
@Deprecated
String propertySetKey() default "";

/**
* A Property with fields is considered a property set.
*
* @since 3.3
*/
PropertyField[] fields() default {};

/**
* Relocation of key.
* @since 3.4
*/
String deprecatedKey() default "";
}

+ 0
- 61
sonar-plugin-api/src/main/java/org/sonar/api/PropertyField.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Property field.
*
* @since 3.3
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface PropertyField {
/**
* Unique key within a property. It shouldn't be prefixed.
* Settings for this field are stored into the database with a composite key
* <code>{key of parent property}.{key of the set}.{key of this field}</code>
* eg. <code>sonar.jira.servers.JIRA1.url</code>
*/
String key();

/**
* This name will be displayed on the Settings page. This can be overridden/translated
* by adding a a value for: <code>field.{key of parent property}.{key of this field}.name</code> in the language bundle.
*/
String name();

/**
* If not empty, this description will be displayed on the Settings page. This can be overridden/translated
* by adding a a value for: <code>field.{key of parent property}.{key of this field}.description</code> in the language bundle.
*/
String description() default "";

PropertyType type() default PropertyType.STRING;

/**
* Options for *_LIST types
*/
String[] options() default {};
}

+ 0
- 117
sonar-plugin-api/src/main/java/org/sonar/api/PropertyType.java View File

@@ -1,117 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* @since 3.0
*/
public enum PropertyType {
/**
* Basic single line input field
*/
STRING,

/**
* Multiple line text-area
*/
TEXT,

/**
* Variation of {#STRING} with masked characters
*/
PASSWORD,

/**
* True/False
*/
BOOLEAN,

/**
* Integer value, positive or negative
*/
INTEGER,

/**
* Floating point number
*/
FLOAT,

/**
* Single select list with a list of options
*/
SINGLE_SELECT_LIST,

/**
* Sonar Metric
*
* @deprecated since 6.3, this type is useless as Dashboards have been removed
*/
@Deprecated
METRIC,

/**
* SonarSource license
* @deprecated in 6.7.
*/
@Deprecated
LICENSE,

/**
* Regular expression
*
* @since 3.2
*/
REGULAR_EXPRESSION,

/**
* Property set instance
*
* @since 3.3
*/
PROPERTY_SET,

/**
* User login
* @since 5.1
*/
USER_LOGIN,

/**
* Level metric type
*
* @deprecated since 6.3, this type is useless as Dashboards have been removed
*/
@Deprecated
METRIC_LEVEL,

/**
* Long value, positive or negative
*
* @deprecated since 6.3, this type is useless as Dashboards have been removed
*/
@Deprecated
LONG,

/**
* JSON property type
* @since 8.8
*/
JSON
}

+ 0
- 38
sonar-plugin-api/src/main/java/org/sonar/api/SonarEdition.java View File

@@ -1,38 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

public enum SonarEdition {
COMMUNITY("Community"),
DEVELOPER("Developer"),
ENTERPRISE("Enterprise"),
DATACENTER("Data Center"),
SONARCLOUD("SonarCloud");

private final String label;

SonarEdition(String label) {
this.label = label;
}

public String getLabel() {
return label;
}
}

+ 0
- 53
sonar-plugin-api/src/main/java/org/sonar/api/SonarPlugin.java View File

@@ -1,53 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.util.List;

/**
* Plugin entry-point used to declare its extensions (see {@link org.sonar.api.Extension}.
* <br>
* <p>The JAR manifest must declare the name of the implementation class in the property <code>Plugin-Class</code>.
* This property is automatically set by sonar-packaging-maven-plugin when building plugin.
*
* @since 2.8
* @deprecated replaced by {@link Plugin} in version 5.6.
*/
@Deprecated
public abstract class SonarPlugin implements Plugin {

/**
* Classes of the implemented extensions.
*/
public abstract List getExtensions();

/**
* Returns a string representation of the plugin, suitable for debugging purposes only.
*/
@Override
public String toString() {
return getClass().getSimpleName();
}

@Override
public void define(Context context) {
context.addExtensions(getExtensions());
}
}

+ 0
- 31
sonar-plugin-api/src/main/java/org/sonar/api/SonarProduct.java View File

@@ -1,31 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* List of different products/runtimes.
* @since 6.0
*/
public enum SonarProduct {

SONARQUBE,
SONARLINT

}

+ 0
- 33
sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeSide.java View File

@@ -1,33 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* Runtime stack in SonarQube product.
* @see SonarRuntime#getSonarQubeSide()
* @since 6.0
*/
public enum SonarQubeSide {

SCANNER,
SERVER,
COMPUTE_ENGINE

}

+ 0
- 155
sonar-plugin-api/src/main/java/org/sonar/api/SonarQubeVersion.java View File

@@ -1,155 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import javax.annotation.concurrent.Immutable;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.Version;

import static java.util.Objects.requireNonNull;

/**
* Version of SonarQube at runtime, but not at compilation time.
* This component can be injected as a dependency of plugin extensions.
* The main usage for a plugin is to benefit from new APIs
* while keeping backward-compatibility with previous versions of API.
*
* <p>
* Example: a plugin extension needs a new feature of API 6.0 without
* breaking compatibility with version 5.6 at runtime. This new feature
* would be disabled when plugin is executed within SonarQube 5.6.
* </p>
* <pre>
* // Component provided by sonar-plugin-api
* // @since 5.6
* public interface AnApi {
* // implicitly since 5.6
* public void foo();
*
* // @since 6.0
* public void bar();
* }
*
* // Component provided by plugin
* public class MyExtension {
* private final SonarQubeVersion sonarQubeVersion;
* private final AnApi api;
*
* public MyExtension(SonarQubeVersion sonarQubeVersion, AnApi api) {
* this.sonarQubeVersion = sonarQubeVersion;
* this.api = api;
* }
*
* public void doSomething() {
* // assume that runtime is 5.6+
* api.foo();
*
* if (sonarQubeVersion.isGreaterThanOrEqual(Version.create(6, 0))) {
* api.bar();
* }
* }
* }
* </pre>
*
* <p>
* Note that {@link Sensor} extensions can directly get {@link SonarQubeVersion} through
* {@link SensorContext#getSonarQubeVersion()}, without using constructor injection:
* </p>
* <pre>
* public class MySensor implements Sensor {
*
* public void execute(SensorContext context) {
* if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0)) {
* context.newMethodIntroducedIn6_0();
* }
* }
*
* }
* </pre>
* <p>
* The minimal supported version of SonarQube is verified at runtime. As plugin is built
* with sonar-plugin-api 6.0, we assume that the plugin requires v6.0 or greater at runtime.
* As the plugin codebase is compatible with 5.6, the plugin must define what is the
* effective minimal supported version through the configuration of sonar-packaging-maven-plugin 1.16+:
* <p>
* <pre>
* &lt;packaging&gt;sonar-plugin&lt;/packaging&gt;
*
* &lt;dependencies&gt;
* &lt;dependency&gt;
* &lt;groupId&gt;org.sonarsource.sonarqube&lt;/groupId&gt;
* &lt;artifactId&gt;sonar-plugin-api&lt;/artifactId&gt;
* &lt;version&gt;6.0&lt;/version&gt;
* &lt;scope&gt;provided&lt;/scope&gt;
* &lt;/dependency&gt;
* &lt;/dependencies&gt;
*
* &lt;build&gt;
* &lt;plugins&gt;
* &lt;plugin&gt;
* &lt;groupId&gt;org.sonarsource.sonar-packaging-maven-plugin&lt;/groupId&gt;
* &lt;artifactId&gt;sonar-packaging-maven-plugin&lt;/artifactId&gt;
* &lt;version&gt;1.16&lt;/version&gt;
* &lt;extensions&gt;true&lt;/extensions&gt;
* &lt;configuration&gt;
* &lt;!-- Override the default value 6.0 which is guessed from sonar-plugin-api dependency --&gt;
* &lt;sonarQubeMinVersion&gt;5.6&lt;/sonarQubeMinVersion&gt;
* &lt;/configuration&gt;
* &lt;/plugin&gt;
* &lt;/plugins&gt;
* &lt;/build&gt;
* </pre>
*
* <p>
* The component {@link SonarRuntime}, introduced in version 6.0, is more complete.
* It is preferred over {@link SonarQubeVersion} if compatibility with version 5.6 Long Term Support
* is not required.
* </p>
*
* @see SonarRuntime
* @deprecated since 7.8 Use {@link SonarRuntime} instead.
* @since 5.5
*/
@ScannerSide
@ServerSide
@ComputeEngineSide
@Immutable
@Deprecated
public class SonarQubeVersion {

private final Version version;

public SonarQubeVersion(Version version) {
requireNonNull(version);
this.version = version;
}

public Version get() {
return this.version;
}

public boolean isGreaterThanOrEqual(Version than) {
return this.version.isGreaterThanOrEqual(than);
}
}

+ 0
- 181
sonar-plugin-api/src/main/java/org/sonar/api/SonarRuntime.java View File

@@ -1,181 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import javax.annotation.concurrent.Immutable;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.ce.ComputeEngineSide;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.server.ServerSide;
import org.sonar.api.utils.Version;
import org.sonarsource.api.sonarlint.SonarLintSide;

/**
* Information about runtime environment.
*
* <p>
* A usage for plugins is to benefit from new APIs
* while keeping backward-compatibility with previous versions of SonarQube
* or SonarLint.
* </p>
*
* <p>
* Example: a plugin extension wants to use a new feature of API 6.1 without
* breaking compatibility with version 6.0 at runtime. This new feature
* would be enabled only in 6.1 and greater runtimes.
* </p>
* <pre>
* // Component provided by sonar-plugin-api
* // @since 6.0
* public interface AnApi {
* // implicitly since 6.0
* public void foo();
*
* // @since 6.1
* public void bar();
* }
*
* // Plugin extension
* public class MyExtension {
* private final SonarRuntime sonarRuntime;
* private final AnApi api;
*
* public MyExtension(SonarRuntime sonarRuntime, AnApi api) {
* this.sonarRuntime = sonarRuntime;
* this.api = api;
* }
*
* public void doSomething() {
* // assume that minimal supported runtime is 6.0
* api.foo();
*
* if (sonarRuntime.getApiVersion().isGreaterThanOrEqual(Version.create(6, 1))) {
* api.bar();
* }
* }
* }
* </pre>
*
*
* <p>
* Note that {@link Sensor} extensions can directly get {@link SonarRuntime} through
* {@link SensorContext#runtime()}, without using constructor injection:
* </p>
* <pre>
* public class MySensor implements Sensor {
*
* public void execute(SensorContext context) {
* if (context.runtime().getApiVersion().isGreaterThanOrEqual(Version.create(6, 1)) {
* context.newMethodIntroducedIn6_0();
* }
* }
*
* }
* </pre>
*
* <p>
* The minimal supported version of plugin API is verified at runtime. As plugin is built
* with sonar-plugin-api 6.1, we assume that the plugin requires v6.1 or greater at runtime.
* For this reason the plugin must override the minimal supported version
* in the configuration of sonar-packaging-maven-plugin 1.16+:
* <p>
* <pre>
* &lt;packaging&gt;sonar-plugin&lt;/packaging&gt;
*
* &lt;dependencies&gt;
* &lt;dependency&gt;
* &lt;groupId&gt;org.sonarsource.sonarqube&lt;/groupId&gt;
* &lt;artifactId&gt;sonar-plugin-api&lt;/artifactId&gt;
* &lt;version&gt;6.1&lt;/version&gt;
* &lt;scope&gt;provided&lt;/scope&gt;
* &lt;/dependency&gt;
* &lt;/dependencies&gt;
*
* &lt;build&gt;
* &lt;plugins&gt;
* &lt;plugin&gt;
* &lt;groupId&gt;org.sonarsource.sonar-packaging-maven-plugin&lt;/groupId&gt;
* &lt;artifactId&gt;sonar-packaging-maven-plugin&lt;/artifactId&gt;
* &lt;version&gt;1.16&lt;/version&gt;
* &lt;extensions&gt;true&lt;/extensions&gt;
* &lt;configuration&gt;
* &lt;!-- Override the default value 6.0 which is guessed from sonar-plugin-api dependency --&gt;
* &lt;sonarQubeMinVersion&gt;6.0&lt;/sonarQubeMinVersion&gt;
* &lt;/configuration&gt;
* &lt;/plugin&gt;
* &lt;/plugins&gt;
* &lt;/build&gt;
* </pre>
*
* <p>
* As this component was introduced in version 6.0, the pattern described above can't be
* exactly applied when plugin must support version 5.6 Long Term Support. In this case plugin
* should use {@link SonarQubeVersion}, for example through {@link Plugin.Context#getSonarQubeVersion()} or
* {@link SensorContext#getSonarQubeVersion()}.
* </p>
*
* <p>
* Unit tests of plugin extensions can add a test dependency to available in sonar-plugin-api-impl and create instances of {@link SonarRuntime}
* via {@link org.sonar.api.internal.SonarRuntimeImpl}.
* </p>
*
* @since 6.0
*/
@ScannerSide
@ServerSide
@ComputeEngineSide
@SonarLintSide
@Immutable
public interface SonarRuntime {

/**
* Version of API (sonar-plugin-api artifact) at runtime.
* It can be helpful to call some API classes/methods without checking their availability at
* runtime by using reflection.
* <br/>
* Since 6.3, the returned version includes the build number in the fourth field, for
* example {@code "6.3.0.12345"}.
*/
Version getApiVersion();

/**
* The product being executed at runtime. It targets analysers so that they can implement
* different behaviours in SonarQube/SonarCloud and SonarLint.
*/
SonarProduct getProduct();

/**
* The SonarQube/SonarCloud stack being executed at runtime.
*
* @throws UnsupportedOperationException if {@link #getProduct()} is not equal to {@link SonarProduct#SONARQUBE}
*/
SonarQubeSide getSonarQubeSide();

/**
* The SonarQube/SonarCloud edition being executed at runtime.
* Note that there is a specific edition for SonarCloud.
*
* @throws UnsupportedOperationException if {@link #getProduct()} is not equal to {@link SonarProduct#SONARQUBE}
* @since 7.8
*/
SonarEdition getEdition();

}

+ 0
- 55
sonar-plugin-api/src/main/java/org/sonar/api/Startable.java View File

@@ -1,55 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* An interface which is implemented by classes annotated with {@link org.sonar.api.scanner.ScannerSide ScannerSide},
* {@link org.sonar.api.server.ServerSide ServerSide} and/or {@link org.sonar.api.ce.ComputeEngineSide ComputeEngineSide}
* (referred to below as "component") that can be started and stopped.
* <p>
* The method {@link #start()} is called at the begin of the component lifecycle.
* It can be called again only after a call to {@link #stop()}. The {@link #stop()} method is called at the end of the
* component lifecycle, and can further be called after every {@link Startable#start()}.
* </p>
* <p>
* In the WebServer, a component is started once: either right when the WebServer is started if there is no migration,
* otherwise only after Database has been successfully migrated. It is stopped once when the WebServer is shutdown. Any
* exception thrown by method {@link #start()} will make the WebServer startup fail.
* </p>
* <p>
* In the Compute Engine, a component is started once when the Compute Engine is started and stopped once when the
* ComputeEngine is shut down. Any exception thrown by method {@link #start()} will make the Compute Engine startup fail.
* </p>
* <p>
* On Scanner side, the lifecycle of a component depends on the value of the {@link org.sonar.api.batch.InstantiationStrategy
* InstantiationStrategy} annotation.
* </p>
*/
public interface Startable {
/**
* Start this component. Called initially at the begin of the lifecycle. It can be called again after a stop.
*/
void start();

/**
* Stop this component. Called near the end of the lifecycle. It can be called again after a further start.
*/
void stop();
}

+ 0
- 41
sonar-plugin-api/src/main/java/org/sonar/api/batch/DependedUpon.java View File

@@ -1,41 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface DependedUpon {

/**
* Used only on classes. Must be keep empty on methods.
*
* @see org.sonar.api.batch.DecoratorBarriers for a list of possible values.
*/
String[] value() default {};

}

+ 0
- 38
sonar-plugin-api/src/main/java/org/sonar/api/batch/DependsUpon.java View File

@@ -1,38 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface DependsUpon {

/**
* Used only on classes. Must be keep empty on methods.
*/
String[] value() default {};
}

+ 0
- 54
sonar-plugin-api/src/main/java/org/sonar/api/batch/InstantiationStrategy.java View File

@@ -1,54 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Define instantiation strategy of batch IoC components. If a component is not annotated, then default value
* is {@link org.sonar.api.batch.InstantiationStrategy#PER_PROJECT}.
* @since 4.4
* @deprecated since 7.6 removal of modules and tasks is planned. All extensions should progressively move to the project scope, using {@link org.sonar.api.scanner.ScannerSide}
*/
@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface InstantiationStrategy {

/**
* Shared task extension. Available in task container.
*/
String PER_TASK = "PER_TASK";

/**
* Shared extension. Available in top level project container.
*/
String PER_BATCH = "PER_BATCH";

/**
* Created and initialized for each project and sub-project (a project is a module in Maven terminology).
*/
String PER_PROJECT = "PER_PROJECT";

String value();
}

+ 0
- 39
sonar-plugin-api/src/main/java/org/sonar/api/batch/Phase.java View File

@@ -1,39 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @since 1.10
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Phase {

Name name();

enum Name {
PRE, DEFAULT, POST
}
}

+ 0
- 54
sonar-plugin-api/src/main/java/org/sonar/api/batch/ScannerSide.java View File

@@ -1,54 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marker annotation for all the components available in the container of the scanner (code analyzer). Note that
* injection of dependencies by constructor is used :
* <pre>
* {@literal @}ScannerSide
* public class Foo {
*
* }
* {@literal @}ScannerSide
* public class Bar {
* private final Foo foo;
* public Bar(Foo f) {
* this.foo = f;
* }
* }
*
* </pre>
*
* @since 6.0
* @deprecated since 7.6 use {@link org.sonar.api.scanner.ScannerSide} that will move the component to the project container
*/
@Deprecated
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface ScannerSide {
}

+ 0
- 76
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectBuilder.java View File

@@ -1,76 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.bootstrap;

import org.sonar.api.ExtensionPoint;
import org.sonar.api.config.Configuration;
import org.sonar.api.scanner.ScannerSide;

/**
* This extension point allows to change project structure at runtime. It is executed once during task startup.
* Some use-cases :
* <ul>
* <li>Add sub-projects. For example the C# plugin gets the hierarchy
* of sub-projects from the Visual Studio metadata file. The single root pom.xml does not contain any declarations of
* modules</li>
* <li>Change project metadata like description or source directories.</li>
* </ul>
*
* @deprecated since 6.5. It won't be possible to manipulate the project's structure.
* @since 2.9
*/
@ScannerSide
@ExtensionPoint
@Deprecated
public abstract class ProjectBuilder {

@Deprecated
public interface Context {
ProjectReactor projectReactor();

/**
* Global config (command line arguments, global scanner properties).
* @since 8.3 Only as a replacement for injecting Settings
*/
Configuration config();
}

/**
* @since 3.7
*/
protected ProjectBuilder() {
}

/**
* Override this method to change project reactor structure.
* @since 3.7
*/
public void build(Context context) {
// Call deprecated method for backward compatibility
build(context.projectReactor());
}

/**
* @deprecated since 3.7 override {@link #build(Context)} instead
*/
@Deprecated
protected void build(ProjectReactor reactor) {
}
}

+ 0
- 326
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectDefinition.java View File

@@ -1,326 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.bootstrap;

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;

/**
* Defines project metadata (key, name, source directories, ...). It's generally used by the
* {@link org.sonar.api.batch.bootstrap.ProjectBuilder extension point} and must not be used
* by other standard extensions.
*
* Since 6.5, plugins should no longer manipulate the project's structure.
*
* @since 2.9
* @deprecated since 7.6 use {@link org.sonar.api.scanner.fs.InputProject}
*/
@Deprecated
public class ProjectDefinition {

public static final String SOURCES_PROPERTY = "sonar.sources";

public static final String TESTS_PROPERTY = "sonar.tests";

private static final char SEPARATOR = ',';

private File baseDir;
private File workDir;
private Map<String, String> properties = new LinkedHashMap<>();
private ProjectDefinition parent = null;
private List<ProjectDefinition> subProjects = new ArrayList<>();

private ProjectDefinition(Properties p) {
for (Entry<Object, Object> entry : p.entrySet()) {
this.properties.put(entry.getKey().toString(), entry.getValue().toString());
}
}

public static ProjectDefinition create() {
return new ProjectDefinition(new Properties());
}

public ProjectDefinition setBaseDir(File baseDir) {
this.baseDir = baseDir;
return this;
}

public File getBaseDir() {
return baseDir;
}

public ProjectDefinition setWorkDir(File workDir) {
this.workDir = workDir;
return this;
}

public File getWorkDir() {
return workDir;
}

public Map<String, String> properties() {
return properties;
}

public ProjectDefinition setProperties(Map<String, String> properties) {
this.properties.putAll(properties);
return this;
}

public ProjectDefinition setProperty(String key, String value) {
properties.put(key, value);
return this;
}

public ProjectDefinition setKey(String key) {
properties.put(CoreProperties.PROJECT_KEY_PROPERTY, key);
return this;
}

public ProjectDefinition setProjectVersion(String s) {
properties.put(CoreProperties.PROJECT_VERSION_PROPERTY, StringUtils.defaultString(s));
return this;
}

public ProjectDefinition setName(String s) {
properties.put(CoreProperties.PROJECT_NAME_PROPERTY, StringUtils.defaultString(s));
return this;
}

public ProjectDefinition setDescription(String s) {
properties.put(CoreProperties.PROJECT_DESCRIPTION_PROPERTY, StringUtils.defaultString(s));
return this;
}

public String getKey() {
return properties.get(CoreProperties.PROJECT_KEY_PROPERTY);
}

/**
* @deprecated since 7.7, use {@link #getOriginalProjectVersion()} instead
*/
@Deprecated
@CheckForNull
public String getOriginalVersion() {
return getOriginalProjectVersion();
}

/**
* @deprecated since 7.7, use {@link #getProjectVersion()} instead
*/
@Deprecated
public String getVersion() {
return getProjectVersion();
}

@CheckForNull
public String getOriginalProjectVersion() {
return properties.get(CoreProperties.PROJECT_VERSION_PROPERTY);
}

public String getProjectVersion() {
String version = properties.get(CoreProperties.PROJECT_VERSION_PROPERTY);
if (StringUtils.isBlank(version)) {
version = "not provided";
}
return version;
}

@CheckForNull
public String getOriginalName() {
return properties.get(CoreProperties.PROJECT_NAME_PROPERTY);
}

public String getName() {
String name = properties.get(CoreProperties.PROJECT_NAME_PROPERTY);
if (StringUtils.isBlank(name)) {
name = getKey();
}
return name;
}

public String getDescription() {
return properties.get(CoreProperties.PROJECT_DESCRIPTION_PROPERTY);
}

private void appendProperty(String key, String value) {
String current = (String) ObjectUtils.defaultIfNull(properties.get(key), "");
if (StringUtils.isBlank(current)) {
properties.put(key, value);
} else {
properties.put(key, current + SEPARATOR + value);
}
}

/**
* @return Source files and folders.
*/
public List<String> sources() {
String sources = (String) ObjectUtils.defaultIfNull(properties.get(SOURCES_PROPERTY), "");
return trim(StringUtils.split(sources, SEPARATOR));
}

/**
* @param paths paths to file or directory with main sources.
* They can be absolute or relative to project base directory.
*/
public ProjectDefinition addSources(String... paths) {
for (String path : paths) {
appendProperty(SOURCES_PROPERTY, path);
}
return this;
}

public ProjectDefinition addSources(File... fileOrDirs) {
for (File fileOrDir : fileOrDirs) {
addSources(fileOrDir.getAbsolutePath());
}
return this;
}

public ProjectDefinition resetSources() {
properties.remove(SOURCES_PROPERTY);
return this;
}

public ProjectDefinition setSources(String... paths) {
resetSources();
return addSources(paths);
}

public ProjectDefinition setSources(File... filesOrDirs) {
resetSources();
for (File fileOrDir : filesOrDirs) {
addSources(fileOrDir.getAbsolutePath());
}
return this;
}

public List<String> tests() {
String sources = (String) ObjectUtils.defaultIfNull(properties.get(TESTS_PROPERTY), "");
return trim(StringUtils.split(sources, SEPARATOR));
}

/**
* @param paths path to files or directories with test sources.
* It can be absolute or relative to project directory.
*/
public ProjectDefinition addTests(String... paths) {
for (String path : paths) {
appendProperty(TESTS_PROPERTY, path);
}
return this;
}

public ProjectDefinition addTests(File... fileOrDirs) {
for (File fileOrDir : fileOrDirs) {
addTests(fileOrDir.getAbsolutePath());
}
return this;
}

public ProjectDefinition setTests(String... paths) {
resetTests();
return addTests(paths);
}

public ProjectDefinition setTests(File... fileOrDirs) {
resetTests();
for (File dir : fileOrDirs) {
addTests(dir.getAbsolutePath());
}
return this;
}

public ProjectDefinition resetTests() {
properties.remove(TESTS_PROPERTY);
return this;
}

/**
* @since 2.8
*/
public ProjectDefinition addSubProject(ProjectDefinition child) {
subProjects.add(child);
child.setParent(this);
return this;
}

@CheckForNull
public ProjectDefinition getParent() {
return parent;
}

public void remove() {
if (parent != null) {
parent.subProjects.remove(this);
parent = null;
subProjects.clear();
}
}

private void setParent(ProjectDefinition parent) {
this.parent = parent;
}

/**
* @since 2.8
*/
public List<ProjectDefinition> getSubProjects() {
return subProjects;
}

private static List<String> trim(String[] strings) {
List<String> result = new ArrayList<>();
for (String s : strings) {
result.add(StringUtils.trim(s));
}
return result;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
ProjectDefinition that = (ProjectDefinition) o;
String key = getKey();
return !((key != null) ? !key.equals(that.getKey()) : (that.getKey() != null));

}

@Override
public int hashCode() {
String key = getKey();
return key != null ? key.hashCode() : 0;
}
}

+ 0
- 79
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/ProjectReactor.java View File

@@ -1,79 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.bootstrap;

import java.util.ArrayList;
import java.util.List;
import org.sonar.api.scanner.ScannerSide;

/**
* Mutable project definitions that can be modified by {@link ProjectBuilder} extensions.
*
* @deprecated since 6.5 plugins should no longer modify the project's structure
* @since 2.9
*/
@Deprecated
@ScannerSide
public class ProjectReactor {

private ProjectDefinition root;

public ProjectReactor(ProjectDefinition root) {
if (root.getParent() != null) {
throw new IllegalArgumentException("Not a root project: " + root);
}
this.root = root;
}

public List<ProjectDefinition> getProjects() {
return collectProjects(root, new ArrayList<>());
}

/**
* Populates list of projects from hierarchy.
*/
private static List<ProjectDefinition> collectProjects(ProjectDefinition def, List<ProjectDefinition> collected) {
collected.add(def);
for (ProjectDefinition child : def.getSubProjects()) {
collectProjects(child, collected);
}
return collected;
}

public ProjectDefinition getRoot() {
return root;
}

public ProjectDefinition getProject(String key) {
for (ProjectDefinition p : getProjects()) {
if (key.equals(p.getKey())) {
return p;
}
}
return null;
}

public String get() {
if (root != null) {
return root.getKey();
}
return null;
}
}

+ 0
- 54
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/internal/ProjectBuilderContext.java View File

@@ -1,54 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.bootstrap.internal;


import org.sonar.api.batch.bootstrap.ProjectBuilder;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import org.sonar.api.config.Configuration;

/**
* Context that is passed to {@link org.sonar.api.batch.bootstrap.ProjectBuilder} as parameter.
* Important - plugins must use this class only for unit test needs.
*
* @deprecated since 6.5
* @since 3.7
*/
@Deprecated
public class ProjectBuilderContext implements ProjectBuilder.Context {

private final ProjectReactor reactor;
private final Configuration configuration;

public ProjectBuilderContext(ProjectReactor reactor, Configuration configuration) {
this.reactor = reactor;
this.configuration = configuration;
}

@Override
public ProjectReactor projectReactor() {
return reactor;
}

@Override
public Configuration config() {
return configuration;
}
}

+ 0
- 23
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/internal/package-info.java View File

@@ -1,23 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.api.batch.bootstrap.internal;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 23
sonar-plugin-api/src/main/java/org/sonar/api/batch/bootstrap/package-info.java View File

@@ -1,23 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.api.batch.bootstrap;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 33
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicate.java View File

@@ -1,33 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* Determines if a file must be kept in search results. See {@link org.sonar.api.batch.fs.FileSystem}
* and {@link org.sonar.api.batch.fs.FilePredicates}.
* @since 4.2
*/
public interface FilePredicate {
/**
* Test if provided file is valid for this predicate
*/
boolean apply(InputFile inputFile);

}

+ 0
- 174
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FilePredicates.java View File

@@ -1,174 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.net.URI;
import java.util.Collection;

/**
* Factory of {@link org.sonar.api.batch.fs.FilePredicate}
*
* @since 4.2
*/
public interface FilePredicates {
/**
* Predicate that always evaluates to true
*/
FilePredicate all();

/**
* Predicate that always evaluates to false
*/
FilePredicate none();

/**
* Predicate that find file by its absolute path. The parameter
* accepts forward/back slashes as separator and non-normalized values
* (<code>/path/to/../foo.txt</code> is same as <code>/path/foo.txt</code>).
* <p>
* Warning - may not be supported in SonarLint
*/
FilePredicate hasAbsolutePath(String s);

/**
* Predicate that gets a file by its relative path. The parameter
* accepts forward/back slashes as separator and non-normalized values
* (<code>foo/../bar.txt</code> is same as <code>bar.txt</code>). It must
* not be <code>null</code>.
* <p>
* Warning - may not be supported in SonarLint
*/
FilePredicate hasRelativePath(String s);

/**
* Predicate that matches files by filename, in any directory.
* For example, the parameter <code>Foo.java</code> will match both
* <code>some/path/Foo.java</code> and <code>other/path/Foo.java</code>.
* The parameter must match exactly, no patterns are allowed,
* and it must not be <code>null</code>.
*
* @since 6.3
*/
FilePredicate hasFilename(String s);

/**
* Predicate that matches files by extension (case insensitive).
* For example, the parameter <code>java</code> will match
* <code>some/path/Foo.java</code> and <code>other/path/Foo.JAVA</code>
* but not <code>some/path/Foo.js</code>.
* The parameter must not be <code>null</code>.
*
* @since 6.3
*/
FilePredicate hasExtension(String s);

/**
* Predicate that gets a file by its {@link InputFile#uri()}.
*
* @since 6.6
*/
FilePredicate hasURI(URI uri);

/**
* Predicate that gets the files which "path" matches a wildcard pattern.
* <p>
* The path is the path part of the {@link InputFile#uri()}. Pattern is case-sensitive, except for file extension.
* <p>
* Supported wildcards are <code>&#42;</code> and <code>&#42;&#42;</code>, but not <code>?</code>.
* <br>
* Examples:
* <ul>
* <li><code>&#42;&#42;/&#42;Foo.java</code> matches Foo.java, src/Foo.java and src/java/SuperFoo.java</li>
* <li><code>&#42;&#42;/&#42;Foo&#42;.java</code> matches src/Foo.java, src/BarFoo.java, src/FooBar.java
* and src/BarFooBaz.java</li>
* <li><code>&#42;&#42;/&#42;FOO.JAVA</code> matches FOO.java and FOO.JAVA but not Foo.java</li>
* </ul>
*/
FilePredicate matchesPathPattern(String inclusionPattern);

/**
* Predicate that gets the files matching at least one wildcard pattern. No filter is applied when
* zero wildcard patterns (similar to {@link #all()}.
* @see #matchesPathPattern(String)
*/
FilePredicate matchesPathPatterns(String[] inclusionPatterns);

/**
* Predicate that gets the files that do not match the given wildcard pattern.
* @see #matchesPathPattern(String)
*/
FilePredicate doesNotMatchPathPattern(String exclusionPattern);

/**
* Predicate that gets the files that do not match any of the given wildcard patterns. No filter is applied when
* zero wildcard patterns (similar to {@link #all()}.
* @see #matchesPathPattern(String)
*/
FilePredicate doesNotMatchPathPatterns(String[] exclusionPatterns);

/**
* if the parameter represents an absolute path for the running environment, then
* returns {@link #hasAbsolutePath(String)}, else {@link #hasRelativePath(String)}
* <p>
* Warning - may not be supported in SonarLint
*/
FilePredicate hasPath(String s);

/**
* Warning - may not be supported in SonarLint
*/
FilePredicate is(File ioFile);

FilePredicate hasLanguage(String language);

FilePredicate hasLanguages(Collection<String> languages);

FilePredicate hasLanguages(String... languages);

FilePredicate hasType(InputFile.Type type);

FilePredicate not(FilePredicate p);

FilePredicate or(Collection<FilePredicate> or);

FilePredicate or(FilePredicate... or);

FilePredicate or(FilePredicate first, FilePredicate second);

FilePredicate and(Collection<FilePredicate> and);

FilePredicate and(FilePredicate... and);

FilePredicate and(FilePredicate first, FilePredicate second);

/**
* Look for InputFile having a specific {@link InputFile#status()}
* @since 6.6
*/
FilePredicate hasStatus(InputFile.Status status);

/**
* Explicitely look for InputFile having any {@link InputFile#status()}
* @since 6.6
*/
FilePredicate hasAnyStatus();

}

+ 0
- 178
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/FileSystem.java View File

@@ -1,178 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.nio.charset.Charset;
import java.util.SortedSet;
import javax.annotation.CheckForNull;
import org.sonar.api.scanner.ScannerSide;

/**
* The {@link FileSystem} manages all the source files to be analyzed.
* <p>
* This is not an extension point so it must not be implemented by plugins. It must be injected as a
* constructor parameter :
* <pre>
* public class MySensor implements Sensor {
* private final FileSystem fs;
*
* public MySensor(FileSystem fs) {
* this.fs = fs;
* }
* }
* </pre>
*
* <h2>How to use in unit tests</h2>
* The unit tests needing an instance of FileSystem can use the implementation, available in sonar-plugin-api-impl,
* {@link org.sonar.api.batch.fs.internal.DefaultFileSystem} and the related {@link org.sonar.api.batch.fs.internal.DefaultInputFile},
* for example :
* <pre>
* DefaultFileSystem fs = new DefaultFileSystem();
* fs.add(new DefaultInputFile("myprojectKey", "src/foo/bar.php"));
* </pre>
*
* @since 4.2
*/
@ScannerSide
public interface FileSystem {

/**
* Absolute base directory of module.
*/
File baseDir();

/**
* Default encoding of files in this project. If it's not defined, then
* the platform default encoding is returned.
* When reading an {@link InputFile} it is preferable to use {@link InputFile#charset()}
*/
Charset encoding();

/**
* Absolute work directory. It can be used to
* store third-party analysis reports.
* <br>
* The work directory can be located outside {@link #baseDir()}.
*/
File workDir();

/**
* Factory of {@link FilePredicate}
*/
FilePredicates predicates();

/**
* Returns the single element matching the predicate. If more than one elements match
* the predicate, then {@link IllegalArgumentException} is thrown. Returns {@code null}
* if no files match.
*
* <p>
* How to use :
* <pre>
* InputFile file = fs.inputFile(fs.predicates().hasRelativePath("src/Foo.php"));
* </pre>
*
* @see #predicates()
*/
@CheckForNull
InputFile inputFile(FilePredicate predicate);

/**
* Returns {@link InputDir} matching the current {@link File}.
* @return null if directory is not indexed.
* @throws IllegalArgumentException is File is null or not a directory.
*
* @since 4.5
* @deprecated since 6.6 Ability to report issues or measures on directories will soon be dropped. Report issues on project if needed.
*/
@Deprecated
@CheckForNull
InputDir inputDir(File dir);

/**
* Input files matching the given attributes. Return all the files if the parameter
* <code>attributes</code> is empty.
* <p>
* <b>Important</b> - result is an {@link java.lang.Iterable} to benefit from streaming and decreasing
* memory consumption. It should be iterated only once, else copy it into a list :
* {@code com.google.common.collect.Lists.newArrayList(inputFiles(predicate))}
* <p>
* How to use :
* <pre>
* {@code
* FilePredicates p = fs.predicates();
* Iterable<InputFile> files = fs.inputFiles(p.and(p.hasLanguage("java"), p.hasType(InputFile.Type.MAIN)));
* }
* </pre>
*
* @see #predicates()
*/
Iterable<InputFile> inputFiles(FilePredicate predicate);

/**
* Returns true if at least one {@link org.sonar.api.batch.fs.InputFile} matches
* the given predicate. This method can be faster than checking if {@link #inputFiles(org.sonar.api.batch.fs.FilePredicate)}
* has elements.
* @see #predicates()
*/
boolean hasFiles(FilePredicate predicate);

/**
* Files matching the given predicate.
* @see #predicates()
* @deprecated since 6.6 Plugins should avoid working with {@link File} and prefer working with {@link InputFile}
*/
@Deprecated
Iterable<File> files(FilePredicate predicate);

/**
* Languages detected in all files, whatever their type (main or test)
*/
SortedSet<String> languages();

/**
* Utility method mainly used to resolve location of reports.
* @return file in canonical form from specified path. Path can be absolute or relative to project basedir.
* For example resolvePath("pom.xml") or resolvePath("src/main/java")
* @since 5.0
*/
File resolvePath(String path);

/**
* Interface of the underlying file index.
*/
interface Index {
Iterable<InputFile> inputFiles();

@CheckForNull
InputFile inputFile(String relativePath);

/**
* @since 6.3
*/
Iterable<InputFile> getFilesByName(String filename);

/**
* @since 6.3
*/
Iterable<InputFile> getFilesByExtension(String extension);
}
}

+ 0
- 116
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/IndexedFile.java View File

@@ -1,116 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Path;
import javax.annotation.CheckForNull;

/**
* Represents the indexed view of an {@link InputFile}. Accessing any of data exposed here won't trigger the expensive generation of
* metadata for the {@link InputFile}.
*
* @since 6.3
*/
public interface IndexedFile extends InputPath {
/**
* Path relative to module base directory. Path is unique and identifies file
* within given <code>{@link FileSystem}</code>. File separator is the forward
* slash ('/'), even on Microsoft Windows.
* <br>
* Returns <code>src/main/java/com/Foo.java</code> if module base dir is
* <code>/path/to/module</code> and if file is
* <code>/path/to/module/src/main/java/com/Foo.java</code>.
* <br>
* Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
* @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
@Deprecated
@Override
String relativePath();

/**
* Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
* <br>
* This is not canonical path. Symbolic links are not resolved. For example if /project/src links
* to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use
* {@code file().getCanonicalPath()} to resolve symbolic link.
* @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
@Deprecated
@Override
String absolutePath();

/**
* The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
* @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
@Deprecated
@Override
File file();

/**
* The underlying absolute {@link Path}.
* It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
* @since 5.1
* @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
@Deprecated
@Override
Path path();

/**
* Identifier of the file. The only guarantee is that it is unique in the project.
* You should not assume it is a file:// URI.
* @since 6.6
*/
URI uri();

/**
* Filename for this file (inclusing extension). For example: MyClass.java.
* @since 6.6
*/
String filename();

/**
* Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.
*/
@CheckForNull
String language();

/**
* Does it contain main or test code ?
*/
InputFile.Type type();

/**
* Creates a stream of the file's contents. Depending on the runtime context, the source might be a file in a physical or virtual filesystem.
* Typically, it won't be buffered. <b>The stream must be closed by the caller</b>.
* @since 6.2
*/
InputStream inputStream() throws IOException;
}

+ 0
- 45
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputComponent.java View File

@@ -1,45 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* Common interface for all input components.
*
* @since 5.2
* @see InputFile
* @see InputDir
* @see InputModule
* @see org.sonar.api.scanner.fs.InputProject
*/
public interface InputComponent {

/**
* Component key shared by all part of SonarQube (scanner, server, WS...).
* It doesn't include the branch.
* Warning. Do not use in SonarLint.
*/
String key();

/**
* Is the component an {@link InputFile}
*/
boolean isFile();

}

+ 0
- 70
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputDir.java View File

@@ -1,70 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.nio.file.Path;

/**
* Layer over {@link java.io.File} for directories. You can access InputDir using {@link FileSystem#inputDir(File)}.
*
* @since 4.5
* @deprecated since 6.6 Ability to report issues or measures on directories will soon be dropped. Report issues on project if needed.
*/
@Deprecated
public interface InputDir extends InputPath {

/**
* Path relative to module base directory. Path is unique and identifies directory
* within given <code>{@link FileSystem}</code>. File separator is the forward
* slash ('/'), even on Microsoft Windows.
* <br>
* Returns <code>src/main/java/com</code> if module base dir is
* <code>/path/to/module</code> and if directory is
* <code>/path/to/module/src/main/java/com</code>.
* <br>
* Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
*/
@Override
String relativePath();

/**
* Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
* <br>
* This is not canonical path. Symbolic links are not resolved. For example if /project/src links
* to /tmp/src and basedir is /project, then this method returns /project/src. Use
* {@code file().getCanonicalPath()} to resolve symbolic link.
*/
@Override
String absolutePath();

/**
* The underlying absolute {@link java.io.File}
*/
@Override
File file();

/**
* The underlying absolute {@link Path}
*/
@Override
Path path();

}

+ 0
- 202
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFile.java View File

@@ -1,202 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.file.Path;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.sensor.SensorDescriptor;

/**
* This layer over {@link java.io.File} adds information for code analyzers.
* For unit testing purpose, use TestInputFileBuilder available in sonar-plugin-api-impl and initialize
* the needed fields:
*
* <pre>
* new TestInputFileBuilder("moduleKey", "relative/path/from/module/baseDir.java")
* .setModuleBaseDir(path)
* .build();
* </pre>
*
* @since 4.2
*/
public interface InputFile extends IndexedFile {

enum Type {
MAIN, TEST
}

/**
* Status regarding previous analysis
*/
enum Status {
SAME, CHANGED, ADDED
}

/**
* Relative path to module (for normal Sensors) or project (for {@link SensorDescriptor#global() global} Sensors) base directory.
* File separator is the forward
* slash ('/'), even on Microsoft Windows.
* <br>
* Returns <code>src/main/java/com/Foo.java</code> if module base dir is
* <code>/path/to/module</code> and if file is
* <code>/path/to/module/src/main/java/com/Foo.java</code>.
* <br>
* Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
* @deprecated since 6.6 use {@link #inputStream()} for file content, {@link #filename()} for file name, {@link #uri()} for an unique identifier, and {@link #toString()} for logging
*/
@Deprecated
@Override
String relativePath();

/**
* Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
* <br>
* This is not canonical path. Symbolic links are not resolved. For example if /project/src links
* to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use
* {@code file().getCanonicalPath()} to resolve symbolic link.
* @deprecated since 6.6 use {@link #inputStream()} for file content, {@link #filename()} for file name, {@link #uri()} for an unique identifier, and {@link #toString()} for logging
*/
@Deprecated
@Override
String absolutePath();

/**
* The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
* @deprecated since 6.6 use {@link #inputStream()} for file content, {@link #filename()} for file name, {@link #uri()} for an unique identifier, and {@link #toString()} for logging
*/
@Deprecated
@Override
File file();

/**
* The underlying absolute {@link Path}.
* It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
* @since 5.1
* @deprecated since 6.6 use {@link #inputStream()} for file content, {@link #filename()} for file name, {@link #uri()} for an unique identifier, and {@link #toString()} for logging
*/
@Deprecated
@Override
Path path();

/**
* Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.
*/
@CheckForNull
@Override
String language();

/**
* Does it contain main or test code ?
*/
@Override
Type type();

/**
* Creates a stream of the file's contents. Depending on the runtime context, the source might be a file in a physical or virtual filesystem.
* Typically, it won't be buffered. <b>The stream must be closed by the caller</b>.
* Since 6.4 BOM is automatically filtered out.
* @since 6.2
*/
@Override
InputStream inputStream() throws IOException;

/**
* Fetches the entire contents of the file, decoding with the {@link #charset}.
* Since 6.4 BOM is automatically filtered out.
* @since 6.2
*/
String contents() throws IOException;

Status status();

/**
* Number of physical lines. This method supports all end-of-line characters. Formula is (number of line break + 1).
* <p>
* Returns 1 if the file is empty.
* <br>
* Returns 2 for <tt>foo\nbar</tt>.
* <br>
* Returns 3 for <tt>foo\nbar\n</tt>.
*/
int lines();

/**
* Check if the file content is empty (ignore potential BOM).
* @since 5.2
*/
boolean isEmpty();

/**
* Returns a {@link TextPointer} in the given file.
* @param line Line of the pointer. Start at 1.
* @param lineOffset Offset in the line. Start at 0.
* @throws IllegalArgumentException if line or offset is not valid for the given file.
* @since 5.2
*/
TextPointer newPointer(int line, int lineOffset);

/**
* Returns a {@link TextRange} in the given file.
* @param start start pointer
* @param end end pointer
* @throws IllegalArgumentException if start or stop pointers are not valid for the given file.
* @since 5.2
*/
TextRange newRange(TextPointer start, TextPointer end);

/**
* Returns a {@link TextRange} in the given file.
* <ul>
* <li><code>newRange(1, 0, 1, 1)</code> selects the first character at line 1</li>
* <li><code>newRange(1, 0, 1, 10)</code> selects the 10 first characters at line 1</li>
* </ul>
* @throws IllegalArgumentException if start or stop positions are not valid for the given file.
* @since 5.2
*/
TextRange newRange(int startLine, int startLineOffset, int endLine, int endLineOffset);

/**
* Returns a {@link TextRange} in the given file that select the full line.
* @param line Start at 1.
* @throws IllegalArgumentException if line is not valid for the given file.
* @since 5.2
*/
TextRange selectLine(int line);

/**
* Charset to be used to decode this specific file.
* @since 6.0
*/
Charset charset();

/**
* Return a string to identify this file (suitable for logs).
*/
@Override
String toString();
}

+ 0
- 39
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputFileFilter.java View File

@@ -1,39 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import org.sonar.api.ExtensionPoint;
import org.sonar.api.scanner.ScannerSide;
import org.sonarsource.api.sonarlint.SonarLintSide;

/**
* Extension point to exclude some files from inspection
* @since 4.2
* @since 7.6 evaluated at project level
*/
@ScannerSide
@SonarLintSide
@ExtensionPoint
@FunctionalInterface
public interface InputFileFilter {

boolean accept(InputFile f);

}

+ 0
- 36
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputModule.java View File

@@ -1,36 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;


import javax.annotation.concurrent.Immutable;

import org.sonar.api.batch.sensor.SensorContext;

/**
* Used to create issues and measures on modules. You can access InputModule using {@link SensorContext#module()}
*
* @since 5.2
* @deprecated since 7.6 modules are deprecated. Use {@link org.sonar.api.scanner.fs.InputProject} instead.
*/
@Deprecated
@Immutable
public interface InputModule extends InputComponent {
}

+ 0
- 75
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/InputPath.java View File

@@ -1,75 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

import java.io.File;
import java.net.URI;
import java.nio.file.Path;

/**
* Layer over {@link java.io.File} for files or directories.
*
* @since 4.5
* @see InputFile
* @see InputDir
*/
public interface InputPath extends InputComponent {

/**
* @see InputFile#relativePath()
* @see InputDir#relativePath()
* @deprecated since 6.5 use {@link #uri()}
*/
@Deprecated
String relativePath();

/**
* @see InputFile#absolutePath()
* @see InputDir#absolutePath()
* @deprecated since 6.5 use {@link #uri()}
*/
@Deprecated
String absolutePath();

/**
* @see InputFile#file()
* @see InputDir#file()
* @deprecated since 6.5 use {@link #uri()}
*/
@Deprecated
File file();

/**
* @see InputFile#path()
* @see InputDir#path()
* @since 5.1
* @deprecated since 6.5 use {@link #uri()}
*/
@Deprecated
Path path();

/**
* Identifier of the component. The only guarantee is that it is unique in the project.
* You should not assume it is a file:// URI.
* @since 6.5
*/
URI uri();

}

+ 0
- 39
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextPointer.java View File

@@ -1,39 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* Represents a position in a text file {@link InputFile}
*
* @since 5.2
*/
public interface TextPointer extends Comparable<TextPointer> {

/**
* The logical line where this pointer is located. First line is 1.
*/
int line();

/**
* The offset of this pointer in the current line. First position in a line is 0.
*/
int lineOffset();

}

+ 0
- 53
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/TextRange.java View File

@@ -1,53 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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;

/**
* Represents a text range in an {@link InputFile}.
*
* A range is delimited by two {@link TextPointer}.
* <ul>
* <li><code>TextRange(TextPointer(1, 0), TextPointer(1, 1))</code> represents the first character at line 1</li>
* <li><code>TextRange(TextPointer(1, 0), TextPointer(1, 10))</code> represents the 10 first characters at line 1</li>
* </ul>
* @see InputFile#newRange(int, int, int, int)
*
* @since 5.2
*/
public interface TextRange {

/**
* Start position of the range
*/
TextPointer start();

/**
* End position of the range
*/
TextPointer end();

/**
* Test if the current range has some common area with another range.
* Exemple: say the two ranges are on same line. Range with offsets [1,3] overlaps range with offsets [2,4] but not
* range with offset [3,5]
*/
boolean overlap(TextRange another);

}

+ 0
- 24
sonar-plugin-api/src/main/java/org/sonar/api/batch/fs/package-info.java View File

@@ -1,24 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.api.batch.fs;

import javax.annotation.ParametersAreNonnullByDefault;


+ 0
- 33
sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/Metric.java View File

@@ -1,33 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.measure;

import java.io.Serializable;

/**
* @since 4.4
*/
public interface Metric<G extends Serializable> {

String key();

Class<G> valueType();

}

+ 0
- 43
sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/MetricFinder.java View File

@@ -1,43 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.measure;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.ThreadSafe;

import org.sonar.api.scanner.ScannerSide;

/**
* @since 4.5
*/
@ScannerSide
@ThreadSafe
public interface MetricFinder {

@CheckForNull
<G extends Serializable> Metric<G> findByKey(String key);

Collection<Metric<Serializable>> findAll(List<String> metricKeys);

Collection<Metric<Serializable>> findAll();
}

+ 0
- 22
sonar-plugin-api/src/main/java/org/sonar/api/batch/measure/package-info.java View File

@@ -1,22 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.measure;


+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch;

+ 0
- 48
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJob.java View File

@@ -1,48 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.postjob;

import org.sonar.api.ExtensionPoint;
import org.sonar.api.scanner.ScannerSide;

/**
* PostJobs are executed at the very end of scanner analysis. A PostJob can't do any modification
* since everything is already computed (issues, measures,...). <br>
* WARNING: Do not rely on the fact that analysis results are available on server side when using WS since this is an
* asynchronous process to compute data on server side in 5.x series.
*
* @since 5.2
* @since 7.6 postjobs are loaded in the project container
*/
@ScannerSide
@ExtensionPoint
public interface PostJob {

/**
* Populate {@link PostJobDescriptor} of this PostJob.
*/
void describe(PostJobDescriptor descriptor);

/**
* Called at the end of the analysis.
*/
void execute(PostJobContext context);

}

+ 0
- 35
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobContext.java View File

@@ -1,35 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.postjob;

import org.sonar.api.config.Configuration;

/**
* See {@link PostJob#execute(PostJobContext)}
* @since 5.2
*/
public interface PostJobContext {

/**
* Get configuration of the current project.
* @since 6.5
*/
Configuration config();
}

+ 0
- 47
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/PostJobDescriptor.java View File

@@ -1,47 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.postjob;

/**
* Describe what a {@link PostJob} is doing. Information may be used by the platform
* to log interesting information or perform some optimization.
* See {@link PostJob#describe(PostJobDescriptor)}
* @since 5.2
*/
public interface PostJobDescriptor {

/**
* Displayable name of the {@link PostJob}. Will be displayed in logs.
*/
PostJobDescriptor name(String postJobName);

/**
* Property this {@link PostJob} depends on. Used by the platform to skip execution of the {@link PostJob} when
* property is not set.
*/
PostJobDescriptor requireProperty(String... propertyKey);

/**
* List properties this {@link PostJob} depends on. Used by the platform to skip execution of the {@link PostJob} when
* property is not set.
*/
PostJobDescriptor requireProperties(String... propertyKeys);

}

+ 0
- 78
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/issue/PostJobIssue.java View File

@@ -1,78 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.postjob.issue;

import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.rule.RuleKey;

/**
* Represents an issue state at the end of the scanner analysis in preview/issues mode.
*
* @since 5.2
*/
public interface PostJobIssue {

/**
* Key of the issue.
*/
String key();

/**
* The {@link RuleKey} of this issue.
*/
RuleKey ruleKey();

/**
* Component key like foo:src/Foo.php
*/
String componentKey();

/**
* The {@link InputComponent} this issue belongs to. Returns null if component was deleted (for resolved issues).
*/
@CheckForNull
InputComponent inputComponent();

/**
* Line of the issue. Null for global issues and issues on directories. Can also be null
* for files (issue global to the file).
*/
@CheckForNull
Integer line();

/**
* Message of the issue.
*/
@CheckForNull
String message();

/**
* Severity.
*/
Severity severity();

/**
* If the issue a new one.
*/
boolean isNew();

}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/issue/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.postjob.issue;

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/postjob/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.postjob;

+ 0
- 80
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRule.java View File

@@ -1,80 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import java.util.Map;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;

import org.sonar.api.rule.RuleKey;

/**
* Configuration of a rule activated on a Quality profile
* @since 4.2
*/
@Immutable
public interface ActiveRule {

RuleKey ruleKey();

/**
* Non-null severity.
* @see org.sonar.api.rule.Severity
*/
String severity();

/**
* Language of rule, for example <code>java</code>
*/
String language();

/**
* Value of given parameter. Returns <code>null</code> if the parameter key does not
* exist on the rule or if the parameter has no value nor default value.
*/
@CheckForNull
String param(String key);

/**
* Immutable parameter values. Returns an empty map if no parameters are defined.
*/
Map<String, String> params();

/**
* Optional key declared and used by the underlying rule engine. As an example
* the key of a Checkstyle rule looks like <code>com.puppycrawl.tools.checkstyle.checks.FooCheck</code>
* whereas its internal key can be <code>Checker/TreeWalker/Foo</code>.
*/
@CheckForNull
String internalKey();

/**
* Optional rule key of the template rule.
* @since 4.5.3
*/
@CheckForNull
String templateRuleKey();

/**
* Key of the quality profile the rule belongs to.
* @since 7.5
*/
String qpKey();
}

+ 0
- 74
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/ActiveRules.java View File

@@ -1,74 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.rule.RuleKey;

import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;

import java.util.Collection;

/**
* The rules that are activated on the current project. Quality profiles are
* merged, so rules can relate to different repositories and languages.
* <br>
* Use {@link org.sonar.api.batch.rule.internal.ActiveRulesBuilder} available in sonar-plugin-api-impl to instantiate
* this component in unit tests.
*
* @since 4.2
*/
@Immutable
@ScannerSide
public interface ActiveRules {

/**
* Find a {@link ActiveRule} by the associated rule key. <code>null</code>
* is returned if the rule does not exist or if the rule is not activated
* on any Quality profile associated with the project.
*/
@CheckForNull
ActiveRule find(RuleKey ruleKey);

/**
* All the active rules, whatever their repository and related language.
*/
Collection<ActiveRule> findAll();

/**
* The active rules for a given repository, like <code>findbugs</code>
*/
Collection<ActiveRule> findByRepository(String repository);

/**
* The active rules for a given language, like <code>java</code>
*/
Collection<ActiveRule> findByLanguage(String language);

/**
* Find a {@link ActiveRule} by the associated internal key. <code>null</code>
* is returned if the rule does not exist or if the rule is not activated
* on any Quality profile associated with the project.
*/
@CheckForNull
ActiveRule findByInternalKey(String repository, String internalKey);

}

+ 0
- 42
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/CheckFactory.java View File

@@ -1,42 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import org.sonar.api.scanner.ScannerSide;

/**
* Creates {@link org.sonar.api.batch.rule.Checks}. This class is available
* by dependency injection. It must not be extended by plugins.
*
* @since 4.2
*/
@ScannerSide
public class CheckFactory {

private final ActiveRules activeRules;

public CheckFactory(ActiveRules activeRules) {
this.activeRules = activeRules;
}

public <C> Checks<C> create(String repository) {
return new Checks<>(activeRules, repository);
}
}

+ 0
- 234
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Checks.java View File

@@ -1,234 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.FieldUtils2;
import org.sonar.api.utils.SonarException;
import org.sonar.check.RuleProperty;

/**
* Instantiates checks (objects that provide implementation of coding
* rules) that use sonar-check-api annotations. Checks are selected and configured
* from the Quality profiles enabled on the current module.
* <br>
* Example of check class:
* <pre>
* {@literal @}org.sonar.check.Rule(key = "S001")
* public class CheckS001 {
* {@literal @}org.sonar.check.RuleProperty
* private String pattern;
*
* public String getPattern() {
* return pattern;
* }
* }
* </pre>
* How to use:
* <pre>
* public class MyRuleEngine extends BatchExtension {
* private final CheckFactory checkFactory;
*
* public MyRuleEngine(CheckFactory checkFactory) {
* this.checkFactory = checkFactory;
* }
*
* public void execute() {
* Checks checks = checkFactory.create("my-rule-repository");
* checks.addAnnotatedChecks(CheckS001.class);
* // checks.all() contains an instance of CheckS001
* // with field "pattern" set to the value specified in
* // the Quality profile
*
* // Checks are used to detect issues on source code
*
* // checks.ruleKey(obj) can be used to create the related issues
* }
* }
* </pre>
* <br>
* It replaces org.sonar.api.checks.AnnotationCheckFactory
*
* @since 4.2
*/
public class Checks<C> {
private final ActiveRules activeRules;
private final String repository;
private final Map<RuleKey, C> checkByRule = new HashMap<>();
private final Map<C, RuleKey> ruleByCheck = new IdentityHashMap<>();

Checks(ActiveRules activeRules, String repository) {
this.activeRules = activeRules;
this.repository = repository;
}

@CheckForNull
public C of(RuleKey ruleKey) {
return checkByRule.get(ruleKey);
}

public Collection<C> all() {
return checkByRule.values();
}

@CheckForNull
public RuleKey ruleKey(C check) {
return ruleByCheck.get(check);
}

private void add(RuleKey ruleKey, C obj) {
checkByRule.put(ruleKey, obj);
ruleByCheck.put(obj, ruleKey);
}

public Checks<C> addAnnotatedChecks(Object... checkClassesOrObjects) {
return addAnnotatedChecks(Arrays.asList(checkClassesOrObjects));
}

public Checks<C> addAnnotatedChecks(Iterable checkClassesOrObjects) {
Map<String, Object> checksByEngineKey = new HashMap<>();
for (Object checkClassesOrObject : checkClassesOrObjects) {
String engineKey = annotatedEngineKey(checkClassesOrObject);
if (engineKey != null) {
checksByEngineKey.put(engineKey, checkClassesOrObject);
}
}

for (ActiveRule activeRule : activeRules.findByRepository(repository)) {
String engineKey = StringUtils.defaultIfBlank(activeRule.templateRuleKey(), activeRule.ruleKey().rule());
Object checkClassesOrObject = checksByEngineKey.get(engineKey);
if (checkClassesOrObject != null) {
Object obj = instantiate(activeRule, checkClassesOrObject);
add(activeRule.ruleKey(), (C) obj);
}
}
return this;
}

private static String annotatedEngineKey(Object annotatedClassOrObject) {
String key = null;
org.sonar.check.Rule ruleAnnotation = AnnotationUtils.getAnnotation(annotatedClassOrObject, org.sonar.check.Rule.class);
if (ruleAnnotation != null) {
key = ruleAnnotation.key();
}
Class clazz = annotatedClassOrObject.getClass();
if (annotatedClassOrObject instanceof Class) {
clazz = (Class) annotatedClassOrObject;
}
return StringUtils.defaultIfEmpty(key, clazz.getCanonicalName());
}

private static Object instantiate(ActiveRule activeRule, Object checkClassOrInstance) {
try {
Object check = checkClassOrInstance;
if (check instanceof Class) {
check = ((Class) checkClassOrInstance).newInstance();
}
configureFields(activeRule, check);
return check;
} catch (InstantiationException | IllegalAccessException e) {
throw failToInstantiateCheck(activeRule, checkClassOrInstance, e);
}
}

private static RuntimeException failToInstantiateCheck(ActiveRule activeRule, Object checkClassOrInstance, Exception e) {
throw new IllegalStateException(String.format("Fail to instantiate class %s for rule %s", checkClassOrInstance, activeRule.ruleKey()), e);
}

private static void configureFields(ActiveRule activeRule, Object check) {
for (Map.Entry<String, String> param : activeRule.params().entrySet()) {
Field field = getField(check, param.getKey());
if (field == null) {
throw new IllegalStateException(
String.format("The field '%s' does not exist or is not annotated with @RuleProperty in the class %s", param.getKey(), check.getClass().getName()));
}
if (StringUtils.isNotBlank(param.getValue())) {
configureField(check, field, param.getValue());
}
}
}

@CheckForNull
private static Field getField(Object check, String key) {
List<Field> fields = FieldUtils2.getFields(check.getClass(), true);
for (Field field : fields) {
RuleProperty propertyAnnotation = field.getAnnotation(RuleProperty.class);
if (propertyAnnotation != null && (StringUtils.equals(key, field.getName()) || StringUtils.equals(key, propertyAnnotation.key()))) {
return field;
}
}
return null;
}

private static void configureField(Object check, Field field, String value) {
try {
field.setAccessible(true);

if (field.getType().equals(String.class)) {
field.set(check, value);

} else if (int.class == field.getType()) {
field.setInt(check, Integer.parseInt(value));

} else if (short.class == field.getType()) {
field.setShort(check, Short.parseShort(value));

} else if (long.class == field.getType()) {
field.setLong(check, Long.parseLong(value));

} else if (double.class == field.getType()) {
field.setDouble(check, Double.parseDouble(value));

} else if (boolean.class == field.getType()) {
field.setBoolean(check, Boolean.parseBoolean(value));

} else if (byte.class == field.getType()) {
field.setByte(check, Byte.parseByte(value));

} else if (Integer.class == field.getType()) {
field.set(check, Integer.parseInt(value));

} else if (Long.class == field.getType()) {
field.set(check, Long.parseLong(value));

} else if (Double.class == field.getType()) {
field.set(check, Double.parseDouble(value));

} else if (Boolean.class == field.getType()) {
field.set(check, Boolean.parseBoolean(value));

} else {
throw new SonarException("The type of the field " + field + " is not supported: " + field.getType());
}
} catch (IllegalAccessException e) {
throw new SonarException("Can not set the value of the field " + field + " in the class: " + check.getClass().getName(), e);
}
}
}

+ 0
- 124
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/LoadedActiveRule.java View File

@@ -1,124 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.api.rule.RuleKey;

public class LoadedActiveRule {
private RuleKey ruleKey;
private String severity;
private String name;
private String language;
private Map<String, String> params;
private long createdAt;
private long updatedAt;
private String templateRuleKey;
private String internalKey;
private Set<RuleKey> deprecatedKeys;

public LoadedActiveRule() {
// nothing to do here
}

public RuleKey getRuleKey() {
return ruleKey;
}

public void setRuleKey(RuleKey ruleKey) {
this.ruleKey = ruleKey;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getSeverity() {
return severity;
}

public void setSeverity(String severity) {
this.severity = severity;
}

public String getLanguage() {
return language;
}

public void setLanguage(String language) {
this.language = language;
}

public Map<String, String> getParams() {
return params;
}

public void setParams(Map<String, String> params) {
this.params = params;
}

public long getCreatedAt() {
return createdAt;
}

public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}

public long getUpdatedAt() {
return updatedAt;
}

public void setUpdatedAt(long updatedAt) {
this.updatedAt = updatedAt;
}

@CheckForNull
public String getTemplateRuleKey() {
return templateRuleKey;
}

public void setTemplateRuleKey(@Nullable String templateRuleKey) {
this.templateRuleKey = templateRuleKey;
}

public String getInternalKey() {
return internalKey;
}

public void setInternalKey(String internalKey) {
this.internalKey = internalKey;
}

public Set<RuleKey> getDeprecatedKeys() {
return deprecatedKeys;
}

public void setDeprecatedKeys(Set<RuleKey> deprecatedKeys) {
this.deprecatedKeys = deprecatedKeys;
}
}

+ 0
- 50
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rule.java View File

@@ -1,50 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import java.util.Collection;
import javax.annotation.CheckForNull;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rule.RuleStatus;

/**
* @since 4.2
*/
public interface Rule {

RuleKey key();

String name();

@CheckForNull
String description();

@CheckForNull
String internalKey();

String severity();

@CheckForNull
RuleParam param(String paramKey);

Collection<RuleParam> params();

RuleStatus status();
}

+ 0
- 32
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/RuleParam.java View File

@@ -1,32 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import javax.annotation.concurrent.Immutable;

/**
* @since 4.2
*/
@Immutable
public interface RuleParam {
String key();

String description();
}

+ 0
- 61
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Rules.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.rule.RuleKey;

import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;

import java.util.Collection;

/**
* Searches for rules. This component is available by dependency injection. It must not
* be extended by plugins.
*
* @since 4.2
* @deprecated since 7.4 we plan to stop loading rules on scanner side
*/
@Deprecated
@ScannerSide
@Immutable
public interface Rules {

/**
* Get a rule by its key. Returns <code>null</code> if rule does not exist.
*/
@CheckForNull
Rule find(RuleKey key);

Collection<Rule> findAll();

/**
* Get the rules of the given repository. Returns an empty collection if the
* repository does not exist.
*/
Collection<Rule> findByRepository(String repository);

/**
* @since 5.2
*/
Collection<Rule> findByInternalKey(String repository, String internalKey);

}

+ 0
- 31
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/Severity.java View File

@@ -1,31 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.rule;

/**
* @since 5.2
*/
public enum Severity {
INFO,
MINOR,
MAJOR,
CRITICAL,
BLOCKER
}

+ 0
- 23
sonar-plugin-api/src/main/java/org/sonar/api/batch/rule/package-info.java View File

@@ -1,23 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.api.batch.rule;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 74
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameCommand.java View File

@@ -1,74 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.scm;

import java.util.List;
import org.sonar.api.scanner.ScannerSide;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;

/**
* This class should be implemented by SCM providers.
* @since 5.0
*/
@ScannerSide
public abstract class BlameCommand {

/**
* Compute blame of the provided files.
* Computation can be done in parallel if this is more efficient.
* If there is an error that prevent to blame a file then an exception should be raised. If
* one file is new or contains local modifications then an exception should be raised.
* @see BlameOutput#blameResult(InputFile, List)
*/
public abstract void blame(BlameInput input, BlameOutput output);

/**
* Callback for the provider to report results of blame per file.
*/
public interface BlameInput {

/**
* Filesystem of the current (sub )project.
*/
FileSystem fileSystem();

/**
* List of files that should be blamed.
*/
Iterable<InputFile> filesToBlame();

}

/**
* Callback for the provider to report results of blame per file.
*/
public interface BlameOutput {

/**
* Add result of the blame command for a single file. Number of lines should
* be consistent with {@link InputFile#lines()}. This method is thread safe.
* @param lines One entry per line in the file. <b>Every line must have a <code>non-null</code> date and revision </b>.
*/
void blameResult(InputFile file, List<BlameLine> lines);

}

}

+ 0
- 130
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/BlameLine.java View File

@@ -1,130 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.scm;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.annotation.CheckForNull;
import javax.annotation.Nullable;

import java.util.Date;

/**
* @since 5.0
*/
public class BlameLine {

private Date date;
private String revision;
private String author;
public BlameLine() {
// for backward compatibility
}
/**
* Preferred constructor. Date and revision must be set.
* @since 5.2
*/
public BlameLine(Date date, String revision) {
this.date = date;
this.revision = revision;
}

public String revision() {
return revision;
}

/**
* Mandatory field
*/
public BlameLine revision(String revision) {
this.revision = revision;
return this;
}

@CheckForNull
public String author() {
return author;
}

/**
* Sets author for this line.
* The string will be trimmed, and null will be set if it is empty.
*/
public BlameLine author(@Nullable String author) {
this.author = StringUtils.trimToNull(author);
return this;
}

/**
* @return the commit date
*/
public Date date() {
return date;
}

/**
* Mandatory field
*/
public BlameLine date(@Nullable Date date) {
this.date = date;
return this;
}

// For testing purpose

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}
BlameLine rhs = (BlameLine) obj;
return new EqualsBuilder()
.append(date, rhs.date)
.append(revision, rhs.revision)
.append(author, rhs.author)
.isEquals();
}

@Override
public int hashCode() {
return new HashCodeBuilder(27, 45).
append(date)
.append(revision)
.append(author)
.toHashCode();
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
}
}

+ 0
- 55
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/IgnoreCommand.java View File

@@ -1,55 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.scm;

import java.nio.file.Path;
import org.sonar.api.scanner.ScannerSide;

/**
* @since 7.6
*/
@ScannerSide
public interface IgnoreCommand {

/**
* Check if a file is ignored by the scm.
* {@link #init(Path)} must be called before the first call to this method and {@link #clean()} after the last one
*
* @param file Absolute path of a project file
* @return true if the given file is ignored by the scm, false otherwise
*/
boolean isIgnored(Path file);

/**
* Must be called before the calling {@link #isIgnored(Path)}
*
* It should contains any operation (e.g. building cache) required before handling {@link #isIgnored(Path)} calls.
*
* @param baseDir the root directory of the project
*/
void init(Path baseDir);

/**
* To be called after the last call to {@link #isIgnored(Path)}.
*
* Cache or any other resources used should be cleared.
*/
void clean();
}

+ 0
- 126
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/ScmProvider.java View File

@@ -1,126 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.scm;

import java.io.File;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
import org.sonar.api.CoreProperties;
import org.sonar.api.ExtensionPoint;
import org.sonar.api.scanner.ScannerSide;

/**
* @since 5.0
*/
@ScannerSide
@ExtensionPoint
public abstract class ScmProvider {

/**
* Unique identifier of the provider. Can be passed to {@link CoreProperties#SCM_PROVIDER_KEY}
* Can be used in SCM URL to define the provider to use.
*/
public abstract String key();

/**
* Whether this provider is able to manage files located in this directory.
* Used by autodetection. Not considered if user has forced the provider key.
*
* @return false by default
*/
public boolean supports(File baseDir) {
return false;
}

public BlameCommand blameCommand() {
throw new UnsupportedOperationException(formatUnsupportedMessage("Blame command"));
}

/**
* Return absolute path of the files changed in the current branch, compared to the provided target branch.
*
* @return null if the SCM provider was not able to compute the list of files.
* @since 7.0
*/
@CheckForNull
public Set<Path> branchChangedFiles(String targetBranchName, Path rootBaseDir) {
return null;
}

/**
* Return a map between paths given as argument and the corresponding line numbers which are new compared to the provided target branch.
* If nothing is returned for a file, the scanner will consider that the provider was unable to determine changes for that file and it will
* assume that nothing was changed in it.
* If null is returned, an imprecise fallback mechanism will be used to detect which lines are new (based on SCM dates).
*
* @param files Absolute path of files of interest
* @return null if the SCM provider was not able to compute the new lines
* @since 7.4
*/
@CheckForNull
public Map<Path, Set<Integer>> branchChangedLines(String targetBranchName, Path rootBaseDir, Set<Path> files) {
return null;
}

/**
* Find the date of the merge base between the current branch and the given reference branch.
*
* @return null if the SCM provider was not able to compute the date
* @since 8.4
* @deprecated Not used anymore since 9.3
*/
@CheckForNull
@Deprecated
public Instant forkDate(String referenceBranchName, Path rootBaseDir) {
return null;
}

/**
* The relative path from SCM root
* @since 7.0
*/
public Path relativePathFromScmRoot(Path path) {
throw new UnsupportedOperationException(formatUnsupportedMessage("Getting relative path from SCM root"));
}

/**
* @since 7.7
*/
public IgnoreCommand ignoreCommand() {
throw new UnsupportedOperationException(formatUnsupportedMessage("Checking for ignored files"));
}

/**
* The current revision id of the analyzed code,
* for example the SHA1 of the current HEAD in a Git branch.
* @since 7.0
*/
@CheckForNull
public String revisionId(Path path) {
throw new UnsupportedOperationException(formatUnsupportedMessage("Getting revision id"));
}

private String formatUnsupportedMessage(String prefix) {
return prefix + " is not supported by " + key() + " provider";
}
}

+ 0
- 24
sonar-plugin-api/src/main/java/org/sonar/api/batch/scm/package-info.java View File

@@ -1,24 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.api.batch.scm;

import javax.annotation.ParametersAreNonnullByDefault;


+ 0
- 55
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/Sensor.java View File

@@ -1,55 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor;

import org.sonar.api.ExtensionPoint;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.ScannerSide;
import org.sonar.api.scanner.sensor.ProjectSensor;
import org.sonarsource.api.sonarlint.SonarLintSide;

/**
* <p>
* A sensor is invoked once for each module of a project, starting from leaf modules. The sensor can parse a flat file, connect to a web server... Sensors are
* used to add measure and issues at file level.
* <p>
* For example the Cobertura Sensor parses Cobertura report and saves the first-level of measures on files.
*
* For testing purpose you can use SensorContextTester, available in sonar-plugin-api-impl
* @since 5.1
* @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 extends ProjectSensor {

/**
* Populate {@link SensorDescriptor} of this sensor.
*/
void describe(SensorDescriptor descriptor);

/**
* The actual sensor code.
*/
void execute(SensorContext context);

}

+ 0
- 253
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java View File

@@ -1,253 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor;

import java.io.Serializable;
import org.sonar.api.Beta;
import org.sonar.api.SonarRuntime;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputModule;
import org.sonar.api.batch.rule.ActiveRules;
import org.sonar.api.batch.sensor.cache.ReadCache;
import org.sonar.api.batch.sensor.cache.WriteCache;
import org.sonar.api.batch.sensor.code.NewSignificantCode;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
import org.sonar.api.batch.sensor.error.NewAnalysisError;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
import org.sonar.api.batch.sensor.issue.ExternalIssue;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.issue.NewExternalIssue;
import org.sonar.api.batch.sensor.issue.NewIssue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.measure.NewMeasure;
import org.sonar.api.batch.sensor.rule.AdHocRule;
import org.sonar.api.batch.sensor.rule.NewAdHocRule;
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;

/**
* See {@link Sensor#execute(SensorContext)}
* In order to write unit tests you can use SensorContextTester, available in sonar-plugin-api-impl
* @since 5.1
*/
public interface SensorContext {

/**
* @deprecated since 6.5 use {@link #config()}
*/
@Deprecated
Settings settings();

/**
* Get settings of the project.
* @since 6.5
*/
Configuration config();

/**
* In some situations, there is no need to analyze unchanged files, as reported by {@link InputFile#status()} as {@link InputFile.Status#SAME},
* and analyzers can skip reporting any data for those files.
* Plugins should be prepared for the flag to be always false in the future.
* @since 9.4
*/
boolean canSkipUnchangedFiles();

/**
* Get filesystem of the project.
*/
FileSystem fileSystem();

/**
* Get list of active rules.
*/
ActiveRules activeRules();

/**
* @since 5.5
* @deprecated since 7.6 modules are deprecated. Use {@link #project()} instead.
* @throws UnsupportedOperationException for global {@link ProjectSensor}s
*/
@Deprecated
InputModule module();

/**
* The current project.
* @since 7.6
*/
InputProject project();

/**
* Version of API at runtime, not at compilation time. It's a shortcut on
* {@code runtime().getApiVersion()} since 6.0.
* @since 5.5
* @see #runtime() since version 6.0.
*/
Version getSonarQubeVersion();

/**
* Runtime information, mainly:
* <ul>
* <li>to be able to have different behaviours between SonarQube and SonarLint</li>
* <li>to enable new features depending on version of API available at runtime</li>
* </ul>
* @since 6.0
*/
SonarRuntime runtime();

/**
* Test if a cancellation of the analysis was requested. Sensors should periodically test this flag
* and gracefully stop if value is {@code true}. For example it could be tested between each processed file.
* @since 6.0
*/
boolean isCancelled();

// ----------- MEASURES --------------

/**
* Fluent builder to create a new {@link Measure}. Don't forget to call {@link NewMeasure#save()} once all parameters are provided.
*/
<G extends Serializable> NewMeasure<G> newMeasure();

// ----------- ISSUES --------------

/**
* Fluent builder to create a new {@link Issue}. Don't forget to call {@link NewIssue#save()} once all parameters are provided.
*/
NewIssue newIssue();

/**
* Fluent builder to create a new {@link ExternalIssue}. Don't forget to call {@link NewExternalIssue#save()} once all parameters are provided.
* @since 7.2
*/
NewExternalIssue newExternalIssue();

/**
* Fluent builder to create a new {@link AdHocRule}. Don't forget to call {@link NewAdHocRule#save()} once all parameters are provided.
* @since 7.4
*/
NewAdHocRule newAdHocRule();

// ------------ HIGHLIGHTING ------------

/**
* Builder to define highlighting of a file. Don't forget to call {@link NewHighlighting#save()} once all elements are provided.
*/
NewHighlighting newHighlighting();

// ------------ SYMBOL TABLE ------------

/**
* Builder to define symbol table of a file. Don't forget to call {@link NewSymbolTable#save()} once all symbols are provided.
* @since 5.6
*/
NewSymbolTable newSymbolTable();

// ------------ COVERAGE ------------

/**
* Builder to define coverage in a file.
* Don't forget to call {@link NewCoverage#save()}.
*/
NewCoverage newCoverage();

// ------------ CPD ------------

/**
* Builder to define CPD tokens in a file.
* Don't forget to call {@link NewCpdTokens#save()}.
* @since 5.5
*/
NewCpdTokens newCpdTokens();

// ------------ ANALYSIS ERROR ------------

/**
* Builder to declare errors that happened while processing a source file.
* Don't forget to call {@link NewAnalysisError#save()}.
* @since 6.0
*/
NewAnalysisError newAnalysisError();

/**
* Builder to declare which parts of the code is significant code.
* Ranges that are not reported as significant code will be ignored and won't be considered when calculating which lines were modified.
*
* If the significant code is not reported for a file, it is assumed that the entire file is significant code.
*
* @since 7.2
*/
NewSignificantCode newSignificantCode();

/**
* Add a property to the scanner context. This context is available
* in Compute Engine when processing the report.
* <br/>
* The properties starting with {@code "sonar.analysis."} are included to the
* payload of webhooks.
*
* @throws IllegalArgumentException if key or value parameter is null
* @see org.sonar.api.ce.posttask.PostProjectAnalysisTask.ProjectAnalysis#getScannerContext()
* @since 6.1
*/
void addContextProperty(String key, String value);

/**
* Indicate that a file should be published in the report sent to SonarQube.
* Files are automatically marked if any data is created for it (issues, highlighting, coverage, etc.).
* @since 6.3
*/
void markForPublishing(InputFile inputFile);

/**
* Access object to write cache that will be stored and made available in a future analysis.
* If cache is disabled, the methods in the returned object will have no effect.
* This API is experimental and can be changed or dropped at any time.
* @see #isCacheEnabled()
* @since 9.4
*/
@Beta
WriteCache nextCache();

/**
* Access object to read cached data. The origin of the cached data is not specified and could come from a different branch.
* If cache is disabled, the methods in the returned object will have no effect.
* This API is experimental and can be changed or dropped at any time.
* @see #isCacheEnabled()
* @since 9.4
*/
@Beta
ReadCache previousCache();

/**
* Returns true if caching is enabled.
* This API is experimental and can be changed or dropped at any time.
* @see #nextCache()
* @see #previousCache()
* @since 9.4
*/
@Beta
boolean isCacheEnabled();
}

+ 0
- 94
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorDescriptor.java View File

@@ -1,94 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.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 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
*/
public interface SensorDescriptor {

/**
* Displayable name of the {@link Sensor}. Will be displayed in logs.
*/
SensorDescriptor name(String sensorName);

/**
* Language this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
* no file for given languages are present in the project.
* Default is to execute sensor for all languages.
*/
SensorDescriptor onlyOnLanguage(String languageKey);

/**
* List languages this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
* no file for given languages are present in the project.
* Default is to execute sensor for all languages.
*/
SensorDescriptor onlyOnLanguages(String... languageKeys);

/**
* {@link InputFile.Type} this {@link Sensor} work on. Used by the platform to skip execution of the {@link Sensor} when
* no file for given type are present in the project.
* Default is to execute sensor whatever are the available file types.
*/
SensorDescriptor onlyOnFileType(InputFile.Type type);

/**
* Rule repository this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
* no rule is activated for the given repository.
*/
SensorDescriptor createIssuesForRuleRepository(String... repositoryKey);

/**
* List rule repositories this {@link Sensor} create issues for. Used by the platform to skip execution of the {@link Sensor} when
* no rule is activated for the given repositories.
*/
SensorDescriptor createIssuesForRuleRepositories(String... repositoryKeys);

/**
* 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 ProjectSensor} instead
*/
@Deprecated
SensorDescriptor global();

/**
* Predicate that will be evaluated on current project {@link Configuration} by the platform to decide if execution of the {@link Sensor} should be skipped.
* @since 6.5
*/
SensorDescriptor onlyWhenConfiguration(Predicate<Configuration> predicate);

/**
* Advertise that this sensor process each file independently. It means executing the sensor twice with FileSystem=[FileA] and FileSystem=[FileB] will produce the same result
* than executing the sensor only once with FileSystem=[FileA,FileB].
* This will allow the platform to optimize sensor execution.
* @since 9.3
*/
SensorDescriptor processesFilesIndependently();
}

+ 0
- 38
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/ReadCache.java View File

@@ -1,38 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.cache;

import java.io.InputStream;
import org.sonar.api.Beta;

@Beta
public interface ReadCache {
/**
* Returns an input stream for the data cached with the key.
* It's the responsibility of the caller to close the stream.
* @throws IllegalArgumentException if cache doesn't contain key
*/
InputStream read(String key);

/**
* Checks whether the cache contains a key
*/
boolean contains(String key);
}

+ 0
- 44
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/WriteCache.java View File

@@ -1,44 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.cache;

import java.io.InputStream;
import org.sonar.api.Beta;

@Beta
public interface WriteCache {
/**
* Save a new entry in the cache. The stream will be consumed immediately.
* @throws IllegalArgumentException if the cache already contains the key
*/
void write(String key, InputStream data);

/**
* Save a new entry in the cache.
* @throws IllegalArgumentException if the cache already contains the key
*/
void write(String key, byte[] data);

/**
* Copy a cached entry from the previous cache to the new one.
* @throws IllegalArgumentException if the previous cache doesn't contain given key or if this cache already contains the key
*/
void copyFromPrevious(String key);
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cache/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.cache;

+ 0
- 50
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/NewSignificantCode.java View File

@@ -1,50 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.code;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;

/**
* This object is used to report ranges of a file which contain significant code.
* Lines that are left out (no range reported) will be ignored and won't be considered when calculating which lines were modified.
* It's particularly useful when portions of the lines are automatically modified by code editors and do not contain
* code or comments were issues might be created.
*
* Don't forget to call {@link #save()} after setting the file and the ranges where the significant code is.
*
* @since 7.2
*/
public interface NewSignificantCode {
/**
* The file for which significant code is being reported. This field must be set before saving the error.
*/
NewSignificantCode onFile(InputFile file);

/**
* Add a range of significant code. The range may only include a single line and only one range is accepted per line.
*/
NewSignificantCode addRange(TextRange range);

/**
* Save the reported information for the given file.
*/
void save();
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/code/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.code;

+ 0
- 76
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/NewCoverage.java View File

@@ -1,76 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.coverage;

import org.sonar.api.batch.fs.InputFile;

/**
* This class is used to report code coverage on files.
*
* Example:
*
* <pre>
* sensorContext.newCoverage().onFile(file)
.lineHits(1, 2)
.lineHits(2, 5)
.lineHits(3, 0)
. ...
.conditions(3, 4, 2)
.conditions(12, 2, 2)
. ...
.save();
*
* </pre>
*
* Since 6.2 you can save several reports for the same file and reports will be merged using the following "additive" strategy:
* <ul>
* <li>Line hits are cumulated</li>
* <li>We keep the max for condition coverage. Examples: 2/4 + 2/4 = 2/4, 2/4 + 3/4 = 3/4</li>
* </ul>
*
* @since 5.2
*/
public interface NewCoverage {

/**
* The covered file.
*/
NewCoverage onFile(InputFile inputFile);

/**
* Call this method as many time as needed to report coverage hits per line. This method should only be called for executable lines.
* @param line Line number (starts at 1).
* @param hits Number of time the line was hit.
*/
NewCoverage lineHits(int line, int hits);

/**
* Call this method as many time as needed to report coverage of conditions.
* @param line Line number (starts at 1).
* @param conditions Number of conditions on this line (should be greater than 1).
* @param coveredConditions Number of covered conditions.
*/
NewCoverage conditions(int line, int conditions, int coveredConditions);

/**
* Call this method to save the coverage report for the given file. Data will be merged with existing coverage information.
*/
void save();
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/coverage/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.coverage;

+ 0
- 64
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/NewCpdTokens.java View File

@@ -1,64 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.cpd;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;

/**
* This builder is used to define tokens used by CPD algorithm on files.
*
* Example:
*
* <pre>
* sensorContext.newCpdTokens().onFile(inputFile)
* .addToken(1, 10, 1, 15, "class")
* .addToken(1, 16, 1, 18, "IDENTIFIER")
* // Add more tokens
* .save;
*
* </pre>
* @since 5.5
*/
public interface NewCpdTokens {

/**
* The tokenized file.
*/
NewCpdTokens onFile(InputFile inputFile);

/**
* Call this method to register a token in a range. Tokens should be registered in order.
* @param range Token position. Use {@link InputFile#newRange(int, int, int, int)} to get a valid range.
* @param image Text content of the token. Can be replaced by a constant placeholder for some tokens (like litterals).
*/
NewCpdTokens addToken(TextRange range, String image);

/**
* Shortcut to avoid calling {@link InputFile#newRange(int, int, int, int)}
* @since 5.6
*/
NewCpdTokens addToken(int startLine, int startLineOffset, int endLine, int endLineOffset, String image);

/**
* Call this method only once when your are done with defining tokens of the file. It is not supported to save CPD tokens twice for the same file.
*/
void save();
}

+ 0
- 75
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/TokensLine.java View File

@@ -1,75 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.cpd.internal;

/**
* Immutable code fragment, which formed from tokens of one line.
*/
public class TokensLine {

private final String value;

private final int startLine;
private final int hashCode;

private final int startUnit;
private final int endUnit;

public TokensLine(int startUnit, int endUnit, int startLine, String value) {
if (startLine <= 0) {
throw new IllegalArgumentException("Start line should be strictly positive");
}
// TODO do we have requirements for length and hashcode ?
this.startLine = startLine;
this.value = value;
this.hashCode = value.hashCode();

this.startUnit = startUnit;
this.endUnit = endUnit;
}

public String getValue() {
return value;
}

public int getStartLine() {
return startLine;
}

/**
* Same as {@link #getStartLine()}
*/
public int getEndLine() {
return startLine;
}

public int getHashCode() {
return hashCode;
}

public int getStartUnit() {
return startUnit;
}

public int getEndUnit() {
return endUnit;
}

}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/internal/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.cpd.internal;

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/cpd/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.cpd;

+ 0
- 50
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/AnalysisError.java View File

@@ -1,50 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.error;

import javax.annotation.CheckForNull;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextPointer;
import org.sonar.api.batch.sensor.Sensor;

/**
* Represents an analysis error, such as a parsing error, reported by a {@link Sensor}.
*
* @since 6.0
*/
public interface AnalysisError {
/**
* The file that was being processed when the error occurred.
*/
InputFile inputFile();
/**
* A description of the error.
*/
@CheckForNull
String message();
/**
* Location of the error.
*/
@CheckForNull
TextPointer location();
}

+ 0
- 53
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/NewAnalysisError.java View File

@@ -1,53 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.error;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextPointer;
import org.sonar.api.batch.sensor.Sensor;

/**
* Represents an analysis error, such as a parsing error, that occurs during the execution of a {@link Sensor}.
* Multiple analysis errors might be reported for the same file and issues may be created for a file which also has analysis errors reported.
* The handling of such situations is unspecified and might vary depending on the implementation.
*
* @since 6.0
*/
public interface NewAnalysisError {
/**
* The file that was being processed when the error occurred. This field must be set before saving the error.
*/
NewAnalysisError onFile(InputFile inputFile);

/**
* Message about the error. This field is optional.
*/
NewAnalysisError message(String message);

/**
* Location of this error. This field is optional.
*/
NewAnalysisError at(TextPointer location);

/**
* Save this error information.
*/
void save();
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/error/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.error;

+ 0
- 68
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/NewHighlighting.java View File

@@ -1,68 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.highlighting;

import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;

/**
* This builder is used to define syntax highlighting (aka code coloration) on files.
*
* Example:
*
* <pre>
* sensorContext.newHighlighting().onFile(inputFile)
* .highlight(1, 10, 1, 15, KEYWORD)
* .highlight(1, 16, 1, 18, STRING)
* // Add more highlight if needed
* .save();
*
* </pre>
*
* @since 5.1
*/
public interface NewHighlighting {

/**
* The file the highlighting belongs to.
*/
NewHighlighting onFile(InputFile inputFile);

/**
* Call this method to indicate the type of text in a range.
* @param range Range of text to highlight. See for example {@link InputFile#newRange(int, int, int, int)}.
* @param typeOfText see {@link TypeOfText} values.
* @since 5.6
*/
NewHighlighting highlight(TextRange range, TypeOfText typeOfText);

/**
* Shortcut to avoid calling {@link InputFile#newRange(int, int, int, int)}
* @param typeOfText see {@link TypeOfText} values.
* @since 5.6
*/
NewHighlighting highlight(int startLine, int startLineOffset, int endLine, int endLineOffset, TypeOfText typeOfText);

/**
* Call this method only once when your are done with defining highlighting of the file. It is not supported to save highlighting twice for the same file.
* @throws IllegalStateException if you have defined overlapping highlighting
*/
void save();
}

+ 0
- 61
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/TypeOfText.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.highlighting;

/**
* Possible types for highlighting code. See sonar-colorizer.css
* @since 5.1
*/
public enum TypeOfText {
ANNOTATION("a"),
CONSTANT("c"),
COMMENT("cd"),

/**
* For example Javadoc
*/
STRUCTURED_COMMENT("j"),
KEYWORD("k"),
STRING("s"),
KEYWORD_LIGHT("h"),
PREPROCESS_DIRECTIVE("p");

private final String cssClass;

TypeOfText(String cssClass) {
this.cssClass = cssClass;
}

public static TypeOfText forCssClass(String cssClass) {
for (TypeOfText typeOfText : TypeOfText.values()) {
if (typeOfText.cssClass().equals(cssClass)) {
return typeOfText;
}
}
throw new IllegalArgumentException("No TypeOfText for CSS class " + cssClass);
}

/**
* For internal use
*/
public String cssClass() {
return cssClass;
}
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/highlighting/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.highlighting;

+ 0
- 85
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/SensorStorage.java View File

@@ -1,85 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.internal;

import org.sonar.api.batch.sensor.code.NewSignificantCode;
import org.sonar.api.batch.sensor.coverage.NewCoverage;
import org.sonar.api.batch.sensor.cpd.NewCpdTokens;
import org.sonar.api.batch.sensor.error.AnalysisError;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
import org.sonar.api.batch.sensor.issue.ExternalIssue;
import org.sonar.api.batch.sensor.issue.Issue;
import org.sonar.api.batch.sensor.measure.Measure;
import org.sonar.api.batch.sensor.rule.AdHocRule;
import org.sonar.api.batch.sensor.symbol.NewSymbolTable;
import org.sonar.api.scanner.ScannerSide;

/**
* Interface for storing data computed by sensors.
*
* @since 5.1
*/
@ScannerSide
public interface SensorStorage {

void store(Measure measure);

void store(Issue issue);

void store(ExternalIssue issue);

void store(AdHocRule adHocRule);

void store(NewHighlighting highlighting);

/**
* @since 5.2
*/
void store(NewCoverage defaultCoverage);

/**
* @since 5.5
*/
void store(NewCpdTokens cpdTokens);

/**
* @since 5.6
*/
void store(NewSymbolTable symbolTable);

/**
* @since 6.0
*/
void store(AnalysisError analysisError);

/**
* Value is overridden if the key was already stored.
*
* @throws IllegalArgumentException if key is null
* @throws IllegalArgumentException if value is null
* @since 6.1
*/
void storeProperty(String key, String value);

/**
* @since 7.2
*/
void store(NewSignificantCode significantCode);
}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/internal/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.internal;

+ 0
- 56
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/ExternalIssue.java View File

@@ -1,56 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import javax.annotation.CheckForNull;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.rules.RuleType;

/**
* Represents an issue imported from an external rule engine by a {@link Sensor}.
* @since 7.2
*/
public interface ExternalIssue extends IIssue {

/**
* @since 7.4
*/
String engineId();

/**
* @since 7.4
*/
String ruleId();

Severity severity();

/**
* Effort to fix the issue, in minutes.
*/
@CheckForNull
Long remediationEffort();

/**
* Type of the issue.
*/
RuleType type();

}

+ 0
- 44
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IIssue.java View File

@@ -1,44 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import java.util.List;
import org.sonar.api.batch.sensor.issue.Issue.Flow;
import org.sonar.api.rule.RuleKey;

/**
* @since 7.2
*/
public interface IIssue {
/**
* The {@link RuleKey} of this issue.
*/
RuleKey ruleKey();
/**
* Primary locations for this issue.
*/
IssueLocation primaryLocation();

/**
* List of flows for this issue. Can be empty.
*/
List<Flow> flows();
}

+ 0
- 72
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/Issue.java View File

@@ -1,72 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import java.util.List;
import javax.annotation.CheckForNull;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.Sensor;

/**
* Represents an issue detected by a {@link Sensor}.
*
* @since 5.1
*/
public interface Issue extends IIssue {
interface Flow {
/**
* @return Ordered list of locations for the execution flow
*/
List<IssueLocation> locations();
}

/**
* Gap used to compute the effort for fixing the issue.
* @since 5.5
*/
@CheckForNull
Double gap();

/**
* Overridden severity.
*/
@CheckForNull
Severity overriddenSeverity();

/**
* Primary locations for this issue.
* @since 5.2
*/
@Override
IssueLocation primaryLocation();

/**
* List of flows for this issue. Can be empty.
* @since 5.2
*/
@Override
List<Flow> flows();

/**
* Is there a QuickFix available in SonarLint for this issue
* @since 9.2
*/
boolean isQuickFixAvailable();
}

+ 0
- 51
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/IssueLocation.java View File

@@ -1,51 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.TextRange;

/**
* Represents an issue location.
*
* @since 5.2
*/
public interface IssueLocation {

/**
* The {@link InputComponent} this location belongs to.
*/
InputComponent inputComponent();

/**
* Range of the issue. Null for global issues and issues on directories. Can also be null
* for files (issue global to the file).
*/
@CheckForNull
TextRange textRange();

/**
* Message of the issue.
*/
@CheckForNull
String message();

}

+ 0
- 97
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewExternalIssue.java View File

@@ -1,97 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import javax.annotation.Nullable;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;

/**
* Builder for an issue imported from an external rule engine by a {@link Sensor}.
* Don't forget to {@link #save()} after setting the fields.
*
* @since 7.2
*/
public interface NewExternalIssue {
/**
* The {@link RuleKey} of the issue.
* @deprecated since 7.4. It is misleading, because of the "external_" prefix that is added on server side. Use {@link #engineId(String)} and {@link #ruleId(String)}
*/
@Deprecated
NewExternalIssue forRule(RuleKey ruleKey);

/**
* Unique identifier of the external analyzer (e.g. eslint, pmd, ...)
* @since 7.4
*/
NewExternalIssue engineId(String engineId);

/**
* Unique rule identifier for a given {@link #engineId(String)}
* @since 7.4
*/
NewExternalIssue ruleId(String ruleId);

/**
* Type of issue.
*/
NewExternalIssue type(RuleType type);

/**
* Effort to fix the issue, in minutes.
*/
NewExternalIssue remediationEffortMinutes(@Nullable Long effortInMinutes);

/**
* Set the severity of the issue.
*/
NewExternalIssue severity(Severity severity);

/**
* Primary location for this issue.
*/
NewExternalIssue at(NewIssueLocation primaryLocation);

/**
* Add a secondary location for this issue. Several secondary locations can be registered.
*/
NewExternalIssue addLocation(NewIssueLocation secondaryLocation);

/**
* Register a flow for this issue. A flow is an ordered list of issue locations that help to understand the issue.
* It should be a <b>path that backtracks the issue from its primary location to the start of the flow</b>.
* Several flows can be registered.
*/
NewExternalIssue addFlow(Iterable<NewIssueLocation> flowLocations);

/**
* Create a new location for this issue. First registered location is considered as primary location.
*/
NewIssueLocation newLocation();

/**
* Save the issue. If rule key is unknown or rule not enabled in the current quality profile then a warning is logged but no exception
* is thrown.
*/
void save();

}

+ 0
- 89
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssue.java View File

@@ -1,89 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import javax.annotation.Nullable;
import org.sonar.api.batch.rule.Severity;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.rule.RuleKey;

/**
* Represents an issue detected by a {@link Sensor}.
*
* @since 5.1
*/
public interface NewIssue {

/**
* The {@link RuleKey} of the issue.
*/
NewIssue forRule(RuleKey ruleKey);

/**
* Gap used for the computation of the effort.
* @since 5.5
*/
NewIssue gap(@Nullable Double gap);

/**
* Override severity of the issue.
* Setting a null value or not calling this method means to use severity configured in quality profile.
*/
NewIssue overrideSeverity(@Nullable Severity severity);

/**
* Primary location for this issue.
* @since 5.2
*/
NewIssue at(NewIssueLocation primaryLocation);

/**
* Add a secondary location for this issue. Several secondary locations can be registered.
* @since 5.2
*/
NewIssue addLocation(NewIssueLocation secondaryLocation);

/**
* Register if a QuickFix would be available on SonarLint for this issue.
* @since 9.2
*/
NewIssue setQuickFixAvailable(boolean quickFixAvailable);

/**
* Register a flow for this issue. A flow is an ordered list of issue locations that help to understand the issue.
* It should be a <b>path that backtracks the issue from its primary location to the start of the flow</b>.
* Several flows can be registered.
* @since 5.2
*/
NewIssue addFlow(Iterable<NewIssueLocation> flowLocations);

/**
* Create a new location for this issue. First registered location is considered as primary location.
* @since 5.2
*/
NewIssueLocation newLocation();

/**
* Save the issue. If rule key is unknown or rule not enabled in the current quality profile then a warning is logged but no exception
* is thrown.
*/
void save();

}

+ 0
- 56
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/NewIssueLocation.java View File

@@ -1,56 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.issue;

import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.TextRange;

/**
* Represents one issue location. See {@link NewIssue#newLocation()}.
*
* @since 5.2
*/
public interface NewIssueLocation {

/**
* Maximum number of characters in the message.
*/
int MESSAGE_MAX_SIZE = 4000;

/**
* The {@link InputComponent} the issue location belongs to. Mandatory.
*/
NewIssueLocation on(InputComponent component);

/**
* Position in the file. Only applicable when {@link #on(InputComponent)} has been called with an InputFile.
* See {@link InputFile#newRange(org.sonar.api.batch.fs.TextPointer, org.sonar.api.batch.fs.TextPointer)}
*/
NewIssueLocation at(TextRange location);

/**
* Optional, but recommended, plain-text message for this location.
* <br>
* Formats like Markdown or HTML are not supported. Size must not be greater than {@link #MESSAGE_MAX_SIZE} characters.
*/
NewIssueLocation message(String message);

}

+ 0
- 21
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/issue/package-info.java View File

@@ -1,21 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.
*/
@javax.annotation.ParametersAreNonnullByDefault
package org.sonar.api.batch.sensor.issue;

+ 0
- 48
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/Measure.java View File

@@ -1,48 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.measure;

import java.io.Serializable;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.measure.Metric;

/**
* Measure on File, Directory or Project.
* Should not be implemented by client.
* @since 5.1
*/
public interface Measure<G extends Serializable> {

/**
* The {@link InputComponent} this measure belongs to.
*/
InputComponent inputComponent();

/**
* The metric this measure belong to.
*/
Metric<G> metric();

/**
* Value of the measure.
*/
G value();

}

+ 0
- 54
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/NewMeasure.java View File

@@ -1,54 +0,0 @@
/*
* SonarQube
* Copyright (C) 2009-2022 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.sensor.measure;

import java.io.Serializable;
import org.sonar.api.batch.fs.InputComponent;
import org.sonar.api.batch.measure.Metric;
import org.sonar.api.batch.measure.MetricFinder;

/**
* Builder to create new Measure.
* Should not be implemented by client.
* @since 5.2
*/
public interface NewMeasure<G extends Serializable> {

/**
* The {@link InputComponent} the measure belongs to. Mandatory.
*/
NewMeasure<G> on(InputComponent component);

/**
* Set the metric this measure belong to. To find a metric based on its key you can use {@link MetricFinder}.
*/
NewMeasure<G> forMetric(Metric<G> metric);

/**
* Value of the measure.
*/
NewMeasure<G> withValue(G value);

/**
* Save the measure. It is not permitted so save several measures of the same metric on the same file/project.
*/
void save();

}

+ 0
- 0
sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/measure/package-info.java View File


Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save