diff --git a/.cirrus.yml b/.cirrus.yml index 2e2c4dc9a8..590f564e76 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -49,17 +49,6 @@ setup_orchestrator_cache: &SETUP_ORCHESTRATOR_CACHE fingerprint_script: echo ${TODAY} reupload_on_changes: "true" -maven_cache: &MAVEN_CACHE - maven_cache: - folder: ${CIRRUS_WORKING_DIR}/.m2/repository - fingerprint_script: cat **/pom.xml - -win_maven_cache: &WIN_MAVEN_CACHE - maven_cache: - #windows cache is buggy if using ${CIRRUS_WORKING_DIR} - folder: ~/.m2/repository - - # ---------------------------------------------- # -------------CONTAINER DEFINITIONS------------ # ---------------------------------------------- @@ -116,7 +105,6 @@ only_main_branches_filter: &ONLY_MAIN_BRANCHES build_task: <<: *CONTAINER_DEFINITION - <<: *MAVEN_CACHE eks_container: memory: 3G env: @@ -127,25 +115,24 @@ build_task: build_script: - git submodule update --init - source cirrus-env BUILD - - regular_mvn_build_deploy_analyze - cleanup_before_cache_script: cleanup_maven_repository + # TODO Remove ITs exclusion after SONARIAC-1521, since the ITs won't be in the test task anymore + - regular_gradle_build_deploy_analyze -x :its:plugin:tests:test -x :its:ruling:test build_win_task: <<: *WINDOWS_VM_DEFINITION <<: *ONLY_SONARSOURCE_QA <<: *DEPENDS_ON_BUILD - <<: *WIN_MAVEN_CACHE build_script: - git config --global core.autocrlf input - source cirrus-env CI - - mvn clean install + # TODO Remove ITs exclusion after SONARIAC-1521, since the ITs won't be in the test task anymore + - ./gradlew clean build -x :its:plugin:tests:test -x :its:ruling:test plugin_qa_task: <<: *ONLY_SONARSOURCE_QA <<: *DEPENDS_ON_BUILD <<: *QA_CONTAINER_DEFINITION <<: *SETUP_ORCHESTRATOR_CACHE - <<: *MAVEN_CACHE env: CIRRUS_CLONE_DEPTH: 1 matrix: @@ -155,17 +142,15 @@ plugin_qa_task: - git submodule update --init qa_script: - source cirrus-env QA - - source set_maven_build_version $BUILD_NUMBER + - source set_gradle_build_version $BUILD_NUMBER - cd its/plugin - - mvn verify -Drevision=${PROJECT_VERSION} -Dsonar.runtimeVersion=${SQ_VERSION} -Dmaven.test.redirectTestOutputToFile=false -B -e -V - cleanup_before_cache_script: cleanup_maven_repository + - ../../gradlew -Drevision=${PROJECT_VERSION} -Dsonar.runtimeVersion=${SQ_VERSION} test --info --console plain --no-daemon ruling_task: <<: *ONLY_SONARSOURCE_QA <<: *DEPENDS_ON_BUILD <<: *QA_CONTAINER_DEFINITION <<: *SETUP_ORCHESTRATOR_CACHE - <<: *MAVEN_CACHE env: CIRRUS_CLONE_DEPTH: 1 matrix: @@ -181,16 +166,14 @@ ruling_task: - git submodule update --init ruling_script: - source cirrus-env QA - - source set_maven_build_version $BUILD_NUMBER + - source set_gradle_build_version $BUILD_NUMBER - cd its/ruling - - mvn test -Dtest=PhpGeneralRulingTest#test${PHP_PROJECT} -Drevision=${PROJECT_VERSION} -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V - cleanup_before_cache_script: cleanup_maven_repository + - ../../gradlew -Drevision=${PROJECT_VERSION} -Dsonar.runtimeVersion=LATEST_RELEASE test --tests PhpGeneralRulingTest.test${PHP_PROJECT} --info --console plain --no-daemon pr_analysis_task: <<: *ONLY_SONARSOURCE_QA <<: *DEPENDS_ON_BUILD <<: *QA_CONTAINER_DEFINITION - <<: *MAVEN_CACHE env: <<: *PR_ANALYSIS_SECRETS CIRRUS_CLONE_DEPTH: 1 @@ -198,22 +181,20 @@ pr_analysis_task: - git submodule update --init ruling_script: - source cirrus-env QA - - source set_maven_build_version $BUILD_NUMBER + - source set_gradle_build_version $BUILD_NUMBER - cd its/ruling - - mvn test -Dtest=PhpPrAnalysisTest -Drevision=${PROJECT_VERSION} -Dsonar.runtimeVersion=LATEST_RELEASE -Dmaven.test.redirectTestOutputToFile=false -B -e -V - cleanup_before_cache_script: cleanup_maven_repository + - ../../gradlew test --tests PhpPrAnalysisTest --info --console plain --no-daemon ws_scan_task: <<: *ONLY_MAIN_BRANCHES <<: *DEPENDS_ON_BUILD <<: *CONTAINER_DEFINITION - <<: *MAVEN_CACHE env: <<: *MEND_SCAN_SECRETS whitesource_script: - source cirrus-env QA - - source set_maven_build_version $BUILD_NUMBER - - mvn clean install -DskipTests + - source set_gradle_build_version $BUILD_NUMBER + - ./gradlew clean build -x test - source ws_scan.sh allow_failures: "true" always: @@ -228,8 +209,6 @@ promote_task: - plugin_qa <<: *ONLY_SONARSOURCE_QA <<: *CONTAINER_DEFINITION - <<: *MAVEN_CACHE env: <<: *PROMOTE_SECRETS - script: cirrus_promote_maven - cleanup_before_cache_script: cleanup_maven_repository + script: cirrus_promote_gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..2a1dc7c60d --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto +/gradlew.bat text eol=crlf +/gradlew text eol=lf diff --git a/.gitignore b/.gitignore index 467c3e59c2..08d5e466a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ # Maven target/ +# Gradle +build/ +.gradle + # IntelliJ IDEA *.iws *.iml diff --git a/LICENSE_HEADER b/LICENSE_HEADER new file mode 100644 index 0000000000..4b0be32ac7 --- /dev/null +++ b/LICENSE_HEADER @@ -0,0 +1,19 @@ +/* + * SonarQube PHP Plugin + * Copyright (C) 2010-$YEAR 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. + */ diff --git a/README.md b/README.md index fe78481ab7..955ed1f8d1 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ To run tests locally follow these instructions. ### Build the Project and Run Unit Tests To build the plugin and run its unit tests, execute this command from the project's root directory (you will need [Maven](https://maven.apache.org/)): ```shell -mvn clean install +./gradlew build ``` ### Integration Tests @@ -86,27 +86,21 @@ sonar.runtimeVersion=9.9 ``` Before running any of the integration tests make sure the submodules are checked out: ```shell - git submodule init - git submodule update + git submodule update --init ``` #### Plugin Test -The "Plugin Test" is an additional integration test that verifies plugin features such as metric calculation, coverage, etc. To launch it, execute this command from the directory `its/plugin`: +The "Plugin Test" is an additional integration test that verifies plugin features such as metric calculation, coverage, etc. To launch it: ```shell -mvn clean install +./gradlew its:plugin:tests:test ``` #### Ruling Test The "Ruling Test" is a special integration test that launches the analysis of a large code base, saves the issues created by the plugin in report files, and then compares those results to the set of expected issues (stored as JSON files). To launch the ruling test: ```shell -cd its/ruling -mvn clean install +./gradlew its:ruling:test ``` -This test gives you the opportunity to examine the issues created by each rule and make sure they're what you expect. You can inspect new/lost issues by checking the web pages mentioned in the logs at the end of the analysis: -``` -INFO - HTML Issues Report generated: /path/to/project/sonar-php/its/sources/src/.sonar/issues-report/issues-report.html -INFO - Light HTML Issues Report generated: /path/to/project/sonar-php/its/sources/src/.sonar/issues-report/issues-report-light.html -``` +This test gives you the opportunity to examine the issues created by each rule and make sure they're what you expect. You can inspect new/lost issues by checking the SonarQube local URL mentioned in the logs at the end of the analysis. If everything looks good to you, you can copy the file with the actual issues located at ``` sonar-php/its/ruling/target/actual/ diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts new file mode 100644 index 0000000000..7b908ec71d --- /dev/null +++ b/build-logic/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + `kotlin-dsl` +} + +dependencies { + implementation(libs.jfrog.buildinfo.gradle) + implementation(libs.sonar.scanner.gradle) + implementation(libs.diffplug.spotless) + implementation(libs.diffplug.blowdryer) +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 0000000000..d05cbfe74f --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,55 @@ +dependencyResolutionManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven { + url = uri("https://repox.jfrog.io/repox/sonarsource") + val artifactoryUsername = + providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME") + .orElse(providers.gradleProperty("artifactoryUsername")) + val artifactoryPassword = + providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD") + .orElse(providers.gradleProperty("artifactoryPassword")) + + if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) { + authentication { + credentials { + username = artifactoryUsername.get() + password = artifactoryPassword.get() + } + } + } + } + } + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven { + url = uri("https://repox.jfrog.io/repox/sonarsource") + + val artifactoryUsername = + providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME") + .orElse(providers.gradleProperty("artifactoryUsername")) + val artifactoryPassword = + providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD") + .orElse(providers.gradleProperty("artifactoryPassword")) + + if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) { + authentication { + credentials { + username = artifactoryUsername.get() + password = artifactoryPassword.get() + } + } + } + } + } +} diff --git a/build-logic/src/main/kotlin/org.sonarsource.php.artifactory-configuration.gradle.kts b/build-logic/src/main/kotlin/org.sonarsource.php.artifactory-configuration.gradle.kts new file mode 100644 index 0000000000..588b0ee63b --- /dev/null +++ b/build-logic/src/main/kotlin/org.sonarsource.php.artifactory-configuration.gradle.kts @@ -0,0 +1,96 @@ +import org.sonarsource.php.signingCondition + +plugins { + id("com.jfrog.artifactory") + signing + `maven-publish` +} + +publishing { + publications.create("mavenJava") { + pom { + name.set("SonarSource PHP Analyzer") + description.set(project.description) + url.set("http://www.sonarqube.org/") + organization { + name.set("SonarSource") + url.set("http://www.sonarsource.com/") + } + licenses { + license { + name.set("GNU LGPL 3") + url.set("http://www.gnu.org/licenses/lgpl.txt") + distribution.set("repo") + } + } + scm { + url.set("https://github.com/SonarSource/sonar-php") + } + developers { + developer { + id.set("sonarsource-team") + name.set("SonarSource Team") + } + } + } + } +} + +signing { + val signingKeyId: String? by project + val signingKey: String? by project + val signingPassword: String? by project + useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) + setRequired { + project.signingCondition() + } + sign(publishing.publications) +} + +tasks.withType { + onlyIf { + val artifactorySkip: Boolean = tasks.artifactoryPublish.get().skip + !artifactorySkip && project.signingCondition() + } +} + +artifactory { + val artifactsToPublish = "org.sonarsource.php:sonar-php-plugin:jar" + + clientConfig.info.addEnvironmentProperty("ARTIFACTS_TO_PUBLISH", artifactsToPublish) + clientConfig.info.addEnvironmentProperty("ARTIFACTS_TO_DOWNLOAD", "") + + setContextUrl(System.getenv("ARTIFACTORY_URL")) + publish { + repository { + setRepoKey(System.getenv("ARTIFACTORY_DEPLOY_REPO")) + setUsername(System.getenv("ARTIFACTORY_DEPLOY_USERNAME")) + setPassword(System.getenv("ARTIFACTORY_DEPLOY_PASSWORD")) + } + defaults { + publications("mavenJava") + setProperties( + mapOf( + "build.name" to "sonar-php", + "version" to project.version.toString(), + "build.number" to project.ext["buildNumber"].toString(), + "pr.branch.target" to System.getenv("PULL_REQUEST_BRANCH_TARGET"), + "pr.number" to System.getenv("PULL_REQUEST_NUMBER"), + "vcs.branch" to System.getenv("GIT_BRANCH"), + "vcs.revision" to System.getenv("GIT_COMMIT"), + ), + ) + setPublishArtifacts(true) + setPublishPom(true) + setPublishIvy(false) + } + } + + clientConfig.info.addEnvironmentProperty("PROJECT_VERSION", project.version.toString()) + clientConfig.info.buildName = "sonar-php" + clientConfig.info.buildNumber = project.ext["buildNumber"].toString() + clientConfig.isIncludeEnvVars = true + clientConfig.envVarsExcludePatterns = + "*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command," + + "*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*PASSPHRASE*,*signing*" +} diff --git a/build-logic/src/main/kotlin/org.sonarsource.php.code-style-convention.gradle.kts b/build-logic/src/main/kotlin/org.sonarsource.php.code-style-convention.gradle.kts new file mode 100644 index 0000000000..688bbdd205 --- /dev/null +++ b/build-logic/src/main/kotlin/org.sonarsource.php.code-style-convention.gradle.kts @@ -0,0 +1,47 @@ +import com.diffplug.blowdryer.Blowdryer +import org.sonarsource.php.CodeStyleConvention + +plugins { + id("com.diffplug.spotless") +} + +val codeStyleConvention = extensions.create("codeStyleConvention") + +spotless { + val licenseHeaderFileName = "LICENSE_HEADER" + encoding(Charsets.UTF_8) + java { + importOrderFile( + Blowdryer.immutableUrl( + "https://raw.githubusercontent.com/SonarSource/sonar-developer-toolset/refs/heads/master/eclipse/sonar.importorder", + ), + ) + removeUnusedImports() + // point to immutable specific commit of sonar-formater.xml version 23 + eclipse("4.22") + .withP2Mirrors( + mapOf( + "https://download.eclipse.org/eclipse/" to "https://ftp.fau.de/eclipse/eclipse/", + ), + ) + .configFile( + Blowdryer.immutableUrl( + "https://raw.githubusercontent.com/SonarSource/sonar-developer-toolset/" + + "540ef32ba22c301f6d05a5305f4e1dbd204839f3/eclipse/sonar-formatter.xml", + ), + ) + licenseHeaderFile(rootProject.file(licenseHeaderFileName)).updateYearWithLatest(true) + targetExclude("*/generated-sources/**", "*/generated-src/**") + toggleOffOn() + } + kotlinGradle { + ktlint().setEditorConfigPath("$rootDir/.editorconfig") + } + format("javaMisc") { + target("src/**/package-info.java") + licenseHeaderFile(rootProject.file(licenseHeaderFileName), "@javax.annotation").updateYearWithLatest(true) + } + codeStyleConvention.spotless?.invoke(this) +} + +tasks.check { dependsOn("spotlessCheck") } diff --git a/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts b/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts new file mode 100644 index 0000000000..970cfd0677 --- /dev/null +++ b/build-logic/src/main/kotlin/org.sonarsource.php.java-conventions.gradle.kts @@ -0,0 +1,53 @@ +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED +import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED + +plugins { + `java-library` + jacoco +} + +java { + withSourcesJar() + withJavadocJar() + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} + +tasks.withType { + options.encoding = "UTF-8" +} + +tasks.withType { + options.encoding = "UTF-8" + options { + (this as CoreJavadocOptions).addStringOption("Xdoclint:none", "-quiet") + } +} + +tasks.withType { + useJUnitPlatform() + testLogging { + // log the full stack trace (default is the 1st line of the stack trace) + exceptionFormat = TestExceptionFormat.FULL + // verbose log for failed and skipped tests (by default the name of the tests are not logged) + events(SKIPPED, FAILED) + } +} + +jacoco { + toolVersion = "0.8.12" +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) + reports { + xml.required.set(true) + csv.required.set(false) + html.required.set(providers.environmentVariable("CI").map { it.toBoolean().not() }.orElse(true)) + } +} + +plugins.withType { + tasks["test"].finalizedBy("jacocoTestReport") +} diff --git a/build-logic/src/main/kotlin/org.sonarsource.php.sonarqube.gradle.kts b/build-logic/src/main/kotlin/org.sonarsource.php.sonarqube.gradle.kts new file mode 100644 index 0000000000..eda39590b5 --- /dev/null +++ b/build-logic/src/main/kotlin/org.sonarsource.php.sonarqube.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("org.sonarqube") +} + +sonar { + properties { + property("sonar.projectName", "SonarSource PHP Analyzer") + property("sonar.projectKey", "org.sonarsource.php:php") + property("sonar.exclusions", "**/build/**/*") + property("sonar.links.ci", "https://cirrus-ci.com/github/SonarSource/sonar-php") + property("sonar.links.scm", "https://github.com/SonarSource/sonar-php") + property("sonar.links.issue", "https://jira.sonarsource.com/browse/SONARPHP") + } +} diff --git a/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt b/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt new file mode 100644 index 0000000000..223d29fb63 --- /dev/null +++ b/build-logic/src/main/kotlin/org/sonarsource/php/BuildUtils.kt @@ -0,0 +1,41 @@ +package org.sonarsource.php + +import org.gradle.api.GradleException +import org.gradle.api.Project +import org.gradle.api.tasks.Delete +import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.register +import java.io.File + +fun enforceJarSize( + file: File, + minSize: Long, + maxSize: Long, +) { + val size = file.length() + if (size < minSize) { + throw GradleException("${file.path} size ($size) too small. Min is $minSize") + } else if (size > maxSize) { + throw GradleException("${file.path} size ($size) too large. Max is $maxSize") + } +} + +fun Project.signingCondition(): Boolean { + val branch = System.getenv()["CIRRUS_BRANCH"] ?: "" + return (branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) && + gradle.taskGraph.hasTask(":artifactoryPublish") +} + +fun Project.registerCleanupTask(): TaskProvider { + return tasks.register("cleanupOldVersion") { + group = "build" + description = "Clean up jars of old plugin version" + + delete( + fileTree(project.layout.buildDirectory.dir("libs")).matching { + include("${project.name}-*.jar") + exclude("${project.name}-${project.version}-*.jar") + } + ) + } +} diff --git a/build-logic/src/main/kotlin/org/sonarsource/php/CodeStyleConvention.kt b/build-logic/src/main/kotlin/org/sonarsource/php/CodeStyleConvention.kt new file mode 100644 index 0000000000..f638d8e3fa --- /dev/null +++ b/build-logic/src/main/kotlin/org/sonarsource/php/CodeStyleConvention.kt @@ -0,0 +1,11 @@ +package org.sonarsource.php + +import com.diffplug.gradle.spotless.SpotlessExtension +import org.gradle.api.file.RegularFileProperty + +interface CodeStyleConvention { + var spotless: (SpotlessExtension.() -> Unit)? + fun spotless(action: SpotlessExtension.() -> Unit) { + spotless = action + } +} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000000..56d5e06fb9 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + alias(libs.plugins.spotless) + id("org.sonarsource.php.artifactory-configuration") + id("org.sonarsource.php.sonarqube") +} + +spotless { + encoding(Charsets.UTF_8) + kotlinGradle { + ktlint().setEditorConfigPath("$rootDir/.editorconfig") + target("*.gradle.kts", "/build-logic/src/**/*.gradle.kts") + } +} + +tasks.artifactoryPublish { skip = true } diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000000..e1d3e1bfea --- /dev/null +++ b/gradle.properties @@ -0,0 +1,6 @@ +group=org.sonarsource.php +version=3.39-SNAPSHOT +description=SonarSource PHP Analyzer +org.gradle.parallel=false +org.gradle.caching=true +org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000000..e0f675af2b --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,56 @@ +[versions] +sonar-commons = "2.14.0.3087" +sonar-plugin-api = "10.12.0.2522" +sonarqube = "10.7.0.96327" +sonar-scanner-gradle = "5.1.0.4882" +sonar-orchestrator = "5.0.0.2065" +sonarlint = "9.8.0.76914" +slf4j = "1.7.36" +sslr = "1.24.0.633" +junit = "5.11.2" +assertj = "3.26.3" +mockito = "5.14.2" +jfrog-gradle = "5.2.5" +spotless-gradle = "6.25.0" +blowdryer-gradle = "1.7.1" +commons-io = "2.17.0" +commons-lang = "3.17.0" +jsr305 = "3.0.2" +maven-project = "2.2.1" +junit-platform = "1.11.2" +staxmate = "2.0.1" + +[libraries] +sonar-analyzer-commons = { module = "org.sonarsource.analyzer-commons:sonar-analyzer-commons", version.ref = "sonar-commons" } +sonar-analyzer-test-commons = { module = "org.sonarsource.analyzer-commons:sonar-analyzer-test-commons", version.ref = "sonar-commons" } +sonar-xml-parsing = { module = "org.sonarsource.analyzer-commons:sonar-xml-parsing", version.ref = "sonar-commons" } +sonar-regex-parsing = { module = "org.sonarsource.analyzer-commons:sonar-regex-parsing", version.ref = "sonar-commons" } +sonar-plugin-api = { module = "org.sonarsource.api.plugin:sonar-plugin-api", version.ref = "sonar-plugin-api" } +sonar-plugin-api-impl = { module = "org.sonarsource.sonarqube:sonar-plugin-api-impl", version.ref = "sonarqube" } +sonar-plugin-api-test-fixtures = { module = "org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures", version.ref = "sonar-plugin-api" } +sonar-testing-harness = { module = "org.sonarsource.sonarqube:sonar-testing-harness", version.ref = "sonarqube" } +sonar-ws = { module = "org.sonarsource.sonarqube:sonar-ws", version.ref = "sonarqube" } +sonar-scanner-gradle = { module = "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin", version.ref = "sonar-scanner-gradle" } +sonar-orchestrator-junit5 = { module = "org.sonarsource.orchestrator:sonar-orchestrator-junit5", version.ref = "sonar-orchestrator" } +sonarlint-core = { module = "org.sonarsource.sonarlint.core:sonarlint-core", version.ref = "sonarlint" } +sonarlint-plugin-api = { module = "org.sonarsource.sonarlint.core:sonarlint-plugin-api", version.ref = "sonarlint" } +slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } +sslr-core = { module = "org.sonarsource.sslr:sslr-core", version.ref = "sslr" } +sslr-toolkit = { module = "org.sonarsource.sslr:sslr-toolkit", version.ref = "sslr" } +sslr-testing-harness = { module = "org.sonarsource.sslr:sslr-testing-harness", version.ref = "sslr" } +junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" } +assertj-core = { module = "org.assertj:assertj-core", version.ref = "assertj" } +mockito-core = { module = "org.mockito:mockito-core", version.ref = "mockito" } +jfrog-buildinfo-gradle = { module = "org.jfrog.buildinfo:build-info-extractor-gradle", version.ref = "jfrog-gradle" } +diffplug-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless-gradle" } +diffplug-blowdryer = { module = "com.diffplug:blowdryer", version.ref = "blowdryer-gradle" } +commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" } +commons-lang = { module = "org.apache.commons:commons-lang3", version.ref = "commons-lang" } +jsr305 = { module = "com.google.code.findbugs:jsr305", version.ref = "jsr305" } +maven-project = { module = "org.apache.maven:maven-project", version.ref = "maven-project" } +junit-platform = { module = "org.junit.platform:junit-platform-suite", version.ref = "junit-platform" } +staxmate = { module = "org.codehaus.staxmate:staxmate", version.ref = "staxmate" } + +[plugins] +spotless = { id = "com.diffplug.spotless", version.ref = "spotless-gradle" } +shadow = { id = "com.github.johnrengelman.shadow", version = "8.1.1" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..a4b76b9530 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..fb602ee2af --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,8 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..f5feea6d6b --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000000..9d21a21834 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/its/plugin/plugins/php-custom-rules-plugin/pom.xml b/its/plugin/plugins/php-custom-rules-plugin/pom.xml deleted file mode 100644 index 2c623a4dc4..0000000000 --- a/its/plugin/plugins/php-custom-rules-plugin/pom.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - it-php-plugin-plugins - ${revision} - - - php-custom-rules-plugin - sonar-plugin - - PHP Custom Rules Plugin - PHP Custom Rules - - - - org.sonarsource.api.plugin - sonar-plugin-api - - - org.sonarsource.php - sonar-php-plugin - sonar-plugin - ${project.version} - provided - - - - - - - org.sonarsource.sonar-packaging-maven-plugin - sonar-packaging-maven-plugin - true - - org.sonar.samples.php.CustomPHPRulesPlugin - php - - - - - maven-compiler-plugin - - 1.8 - 1.8 - - - - com.diffplug.spotless - spotless-maven-plugin - - - - - diff --git a/its/plugin/plugins/pom.xml b/its/plugin/plugins/pom.xml deleted file mode 100644 index ed89d3ab24..0000000000 --- a/its/plugin/plugins/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - it-php-plugin - ${revision} - - - it-php-plugin-plugins - PHP :: IT :: Plugins - pom - - - php-custom-rules-plugin - - - diff --git a/its/plugin/pom.xml b/its/plugin/pom.xml deleted file mode 100644 index 2cd85362b0..0000000000 --- a/its/plugin/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - php-its - ${revision} - - - it-php-plugin - SonarSource :: PHP :: ITs :: Plugin - pom - - - SonarSource - http://www.sonarsource.com - - - 2011 - - - plugins - tests - - - diff --git a/its/plugin/tests/build.gradle.kts b/its/plugin/tests/build.gradle.kts new file mode 100644 index 0000000000..b2bc4355ca --- /dev/null +++ b/its/plugin/tests/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("org.sonarsource.php.code-style-convention") + id("org.sonarsource.php.java-conventions") +} + +description = "PHP :: Integration Tests :: Plugin" + +dependencies { + testImplementation(project(":sonar-php-plugin", configuration = "shadow")) + testImplementation(libs.sonar.orchestrator.junit5) + testImplementation(libs.junit.platform) + testImplementation(libs.sonar.ws) + testImplementation(libs.sonarlint.core) + testImplementation(libs.sonarlint.plugin.api) + testImplementation(libs.sonar.plugin.api) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testCompileOnly(libs.jsr305) +} + +tasks.test { + include("**/Tests.class") +} diff --git a/its/plugin/tests/pom.xml b/its/plugin/tests/pom.xml deleted file mode 100644 index 2e94e90f7a..0000000000 --- a/its/plugin/tests/pom.xml +++ /dev/null @@ -1,130 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - it-php-plugin - ${revision} - - - it-php-plugin-tests - - PHP :: Integration Tests - 2011 - - - -Xmx128m -server - - - - - org.sonarsource.orchestrator - sonar-orchestrator-junit5 - - - org.junit.platform - junit-platform-suite - - - org.sonarsource.sonarqube - sonar-ws - ${version.sonar} - - - org.sonarsource.sonarlint.core - sonarlint-core - - - com.google.protobuf - protobuf-java - - - - - org.sonarsource.sonarlint.core - sonarlint-plugin-api - - - org.sonarsource.api.plugin - sonar-plugin-api - - - org.junit.jupiter - junit-jupiter - - - org.assertj - assertj-core - - - com.google.code.findbugs - jsr305 - provided - - - - - - - - maven-surefire-plugin - - true - ${project.build.directory}/test-reports - - com/sonar/it/php/Tests.java - - - - - - - - - qa - - - env.SONARSOURCE_QA - true - - - - - - maven-dependency-plugin - - - copy-plugin - generate-test-resources - - copy - - - - - ${project.groupId} - sonar-php-plugin - ${project.version} - sonar-plugin - true - - - ../../../sonar-php-plugin/target - true - true - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - - - - diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/CpdTokenTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/CpdTokenTest.java index e39ed8353d..9e4cefbff8 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/CpdTokenTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/CpdTokenTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/CustomRulesTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/CustomRulesTest.java index 2896680e58..8e80de05b5 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/CustomRulesTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/CustomRulesTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or @@ -23,6 +23,7 @@ import com.sonar.orchestrator.junit5.OrchestratorExtension; import java.util.List; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -30,6 +31,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.sonarqube.ws.Issues.Issue; +// TODO Enable back with SONARPHP-1520 +@Disabled class CustomRulesTest { @RegisterExtension diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/FrameworkDetectionPHPTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/FrameworkDetectionPHPTest.java index 9afe3e75a7..84769f0b6c 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/FrameworkDetectionPHPTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/FrameworkDetectionPHPTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/NoSonarTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/NoSonarTest.java index eb7cef5fbc..312387a186 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/NoSonarTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/NoSonarTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/NonPhpProjectTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/NonPhpProjectTest.java index c24326dd58..1957e00b45 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/NonPhpProjectTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/NonPhpProjectTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPIntegrationTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPIntegrationTest.java index 3dacd71d1e..61685ba49a 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPIntegrationTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPIntegrationTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPTest.java index 04b42edfd1..abf376950b 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPUnitTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPUnitTest.java index 59faf538bd..8fd8a3ba05 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/PHPUnitTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/PHPUnitTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/PhpStanReportTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/PhpStanReportTest.java index a9d59c2d2c..9f6eed3e44 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/PhpStanReportTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/PhpStanReportTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/PsalmReportTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/PsalmReportTest.java index 256f575809..e89e0ee046 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/PsalmReportTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/PsalmReportTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/SonarLintTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/SonarLintTest.java index a7722af418..256810421a 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/SonarLintTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/SonarLintTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/SuppressWarningsTest.java b/its/plugin/tests/src/test/java/com/sonar/it/php/SuppressWarningsTest.java index f23e0ecdcb..946cc7436c 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/SuppressWarningsTest.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/SuppressWarningsTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/plugin/tests/src/test/java/com/sonar/it/php/Tests.java b/its/plugin/tests/src/test/java/com/sonar/it/php/Tests.java index d7bb558fc0..7ad635fd59 100644 --- a/its/plugin/tests/src/test/java/com/sonar/it/php/Tests.java +++ b/its/plugin/tests/src/test/java/com/sonar/it/php/Tests.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2011-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or @@ -32,6 +32,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.annotation.CheckForNull; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.extension.RegisterExtension; import org.sonarqube.ws.Components; @@ -59,7 +60,7 @@ class Tests { public static final String PHP_INI_SENSOR_NAME = "Analyzer for \"php.ini\" files"; - public static final FileLocation PHP_PLUGIN_LOCATION = FileLocation.byWildcardMavenFilename(new File("../../../sonar-php-plugin/target"), "sonar-php-plugin-*.jar"); + public static final FileLocation PHP_PLUGIN_LOCATION = FileLocation.byWildcardFilename(new File("../../../sonar-php-plugin/build/libs"), "sonar-php-plugin-*-all.jar"); public static final String SCANNER_VERSION = "6.1.0.4477"; private static final Pattern DEBUG_AND_INFO_LOG_LINE_PATTERN = Pattern.compile("\\d{2}:\\d{2}:\\d{2}\\.\\d{3}\\s(INFO|DEBUG)\\s.*"); @@ -73,7 +74,8 @@ class Tests { .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "profile.xml")) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "no_rules.xml")) // Custom rules plugin - .addPlugin(FileLocation.byWildcardMavenFilename(new File("../plugins/php-custom-rules-plugin/target"), "php-custom-rules-plugin-*.jar")) + // TODO Fix in SONARPHP-1520 Migrate Custom Rules module to Gradle + // .addPlugin(FileLocation.byWildcardMavenFilename(new File("../plugins/php-custom-rules-plugin/target"), "php-custom-rules-plugin-*.jar")) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "profile-php-custom-rules.xml")) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "nosonar.xml")) .restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "sleep.xml")) @@ -197,6 +199,9 @@ private static void assertAnalyzerLogs(String logs) { } // TODO SONARPHP-1466 Replace nested classes in it-php-plugin-tests:Tests with a more elegant solution + + // TODO Enable back with SONARPHP-1520 + @Disabled @Nested class NestedCustomRulesTest extends CustomRulesTest { } diff --git a/its/pom.xml b/its/pom.xml deleted file mode 100644 index 051b0c27b8..0000000000 --- a/its/pom.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - php - ${revision} - - - php-its - PHP :: IT - pom - - - plugin - ruling - - - diff --git a/its/ruling/build.gradle.kts b/its/ruling/build.gradle.kts new file mode 100644 index 0000000000..8aca958339 --- /dev/null +++ b/its/ruling/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("org.sonarsource.php.code-style-convention") + id("org.sonarsource.php.java-conventions") +} + +description = "PHP :: Integration Tests :: Ruling" + +dependencies { + testImplementation(project(":sonar-php-plugin", configuration = "shadow")) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.sonar.analyzer.commons) + testImplementation(libs.sonar.orchestrator.junit5) +} diff --git a/its/ruling/pom.xml b/its/ruling/pom.xml deleted file mode 100644 index a045ee81f7..0000000000 --- a/its/ruling/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - php-its - ${revision} - - - it-php-ruling - - PHP :: Integration Tests :: Ruling - - - SonarSource - http://www.sonarsource.com - - - 2014 - - - - org.sonarsource.analyzer-commons - sonar-analyzer-commons - compile - - - org.sonarsource.orchestrator - sonar-orchestrator-junit5 - - - org.junit.jupiter - junit-jupiter - - - org.assertj - assertj-core - - - - - - qa - - - env.SONARSOURCE_QA - true - - - - - - maven-dependency-plugin - - - copy-plugin - generate-test-resources - - copy - - - - - ${project.groupId} - sonar-php-plugin - ${project.version} - sonar-plugin - true - - - ../../sonar-php-plugin/target - true - true - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - - - - diff --git a/its/ruling/src/test/java/org/sonar/php/it/PhpGeneralRulingTest.java b/its/ruling/src/test/java/org/sonar/php/it/PhpGeneralRulingTest.java index 79d18488be..b191a1d935 100644 --- a/its/ruling/src/test/java/org/sonar/php/it/PhpGeneralRulingTest.java +++ b/its/ruling/src/test/java/org/sonar/php/it/PhpGeneralRulingTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2014-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or @@ -108,11 +108,11 @@ private void testProject(String project, String... keyValueProperties) throws Ex File litsDifferencesFile = FileLocation.of("target/differences").getFile(); File projectLocation = FileLocation.of("../sources/src/" + project).getFile(); SonarScanner build = RulingHelper.prepareScanner( - projectLocation, - project, - "expected/" + project, - litsDifferencesFile, - keyValueProperties) + projectLocation, + project, + "expected/" + project, + litsDifferencesFile, + keyValueProperties) .setProperty("sonar.import_unknown_files", "true") .setProperty("sonar.php.duration.statistics", "true") .setProperty("sonar.cpd.exclusions", "**/*") diff --git a/its/ruling/src/test/java/org/sonar/php/it/PhpPrAnalysisTest.java b/its/ruling/src/test/java/org/sonar/php/it/PhpPrAnalysisTest.java index c0e1ee8a29..692c1d3499 100644 --- a/its/ruling/src/test/java/org/sonar/php/it/PhpPrAnalysisTest.java +++ b/its/ruling/src/test/java/org/sonar/php/it/PhpPrAnalysisTest.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2014-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or diff --git a/its/ruling/src/test/java/org/sonar/php/it/RulingHelper.java b/its/ruling/src/test/java/org/sonar/php/it/RulingHelper.java index 6fe53005c9..959068b22f 100644 --- a/its/ruling/src/test/java/org/sonar/php/it/RulingHelper.java +++ b/its/ruling/src/test/java/org/sonar/php/it/RulingHelper.java @@ -1,6 +1,6 @@ /* * SonarQube PHP Plugin - * Copyright (C) 2014-2024 SonarSource SA + * Copyright (C) 2010-2024 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or @@ -46,7 +46,7 @@ static OrchestratorExtension getOrchestrator(Edition sonarEdition) { .useDefaultAdminCredentialsForBuilds(true) .setSonarVersion(System.getProperty(SQ_VERSION_PROPERTY, DEFAULT_SQ_VERSION)) .setEdition(sonarEdition) - .addPlugin(FileLocation.byWildcardMavenFilename(new File("../../sonar-php-plugin/target"), "sonar-php-plugin-*.jar")) + .addPlugin(FileLocation.byWildcardFilename(new File("../../sonar-php-plugin/build/libs"), "sonar-php-plugin-*-all.jar")) .addPlugin(MavenLocation.of("org.sonarsource.sonar-lits-plugin", "sonar-lits-plugin", "0.11.0.2659")); if (sonarEdition != Edition.COMMUNITY) { diff --git a/php-checks/build.gradle.kts b/php-checks/build.gradle.kts new file mode 100644 index 0000000000..9a21192727 --- /dev/null +++ b/php-checks/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("org.sonarsource.php.java-conventions") + id("org.sonarsource.php.code-style-convention") + id("java-library") +} + +description = "SonarSource PHP Analyzer :: Checks" + +dependencies { + implementation(project(":php-frontend")) + implementation(libs.sonar.plugin.api) + implementation(libs.sonar.analyzer.commons) + implementation(libs.commons.lang) + + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.mockito.core) + testImplementation(libs.sonar.plugin.api.test.fixtures) +} diff --git a/php-checks/pom.xml b/php-checks/pom.xml deleted file mode 100644 index d47543ee13..0000000000 --- a/php-checks/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - 4.0.0 - - - php - org.sonarsource.php - ${revision} - - - php-checks - - SonarSource PHP analyzer :: Checks - - - - ${project.groupId} - php-frontend - - - org.sonarsource.api.plugin - sonar-plugin-api - - - org.sonarsource.analyzer-commons - sonar-analyzer-commons - - - org.apache.commons - commons-lang3 - - - org.junit.jupiter - junit-jupiter - - - org.assertj - assertj-core - - - org.mockito - mockito-core - - - org.slf4j - slf4j-api - provided - - - org.sonarsource.api.plugin - sonar-plugin-api-test-fixtures - test - - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - diff --git a/php-checks/src/main/java/org/sonar/php/checks/regex/package-info.java b/php-checks/src/main/java/org/sonar/php/checks/regex/package-info.java index 4bf075f28b..a727a028d8 100644 --- a/php-checks/src/main/java/org/sonar/php/checks/regex/package-info.java +++ b/php-checks/src/main/java/org/sonar/php/checks/regex/package-info.java @@ -17,4 +17,5 @@ * 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.php.checks.regex; diff --git a/php-custom-rules/pom.xml b/php-custom-rules/pom.xml deleted file mode 100644 index ae5a425671..0000000000 --- a/php-custom-rules/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - php - ${revision} - - - php-custom-rules - sonar-plugin - - SonarSource PHP Custom Rules Example - PHP Custom Rules Example for SonarQube - 2016 - - - - org.sonarsource.api.plugin - sonar-plugin-api - provided - - - - org.sonarsource.php - sonar-php-plugin - ${revision} - sonar-plugin - provided - - - - org.junit.jupiter - junit-jupiter - test - - - org.sonarsource.sonarqube - sonar-plugin-api-impl - test - - - - - - - org.sonarsource.sonar-packaging-maven-plugin - sonar-packaging-maven-plugin - - php-custom - PHP Custom Rules - org.sonar.samples.php.PHPCustomRulesPlugin - true - 9.13 - php - true - ${jre.min.version} - - - true - - - - - - - maven-shade-plugin - - - package - - shade - - - false - true - false - - - xerces:xercesImpl - - ** - - - - - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - diff --git a/php-frontend/build.gradle.kts b/php-frontend/build.gradle.kts new file mode 100644 index 0000000000..71d5d7cb20 --- /dev/null +++ b/php-frontend/build.gradle.kts @@ -0,0 +1,27 @@ +plugins { + id("org.sonarsource.php.java-conventions") + id("org.sonarsource.php.code-style-convention") + id("java-library") + id("java-test-fixtures") +} + +description = "SonarSource PHP Analyzer :: Frontend" + +dependencies { + api(libs.sonar.analyzer.test.commons) + api(libs.sslr.core) + api(libs.sonar.regex.parsing) + + implementation(libs.sonar.plugin.api) + implementation(libs.commons.lang) + + testImplementation(libs.junit.jupiter) + testImplementation(libs.mockito.core) + testImplementation(libs.assertj.core) + testImplementation(libs.sonar.plugin.api.test.fixtures) + testImplementation(libs.sonar.plugin.api.impl) + testImplementation(libs.sslr.testing.harness) + testImplementation(libs.sonar.testing.harness) + + testFixturesImplementation(libs.sonar.plugin.api.impl) +} diff --git a/php-frontend/pom.xml b/php-frontend/pom.xml deleted file mode 100644 index 23545b494a..0000000000 --- a/php-frontend/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - ${revision} - php - - - php-frontend - - SonarSource PHP analyzer :: Frontend - - - - org.sonarsource.api.plugin - sonar-plugin-api - - - org.sonarsource.sslr - sslr-core - - - org.sonarsource.sslr - sslr-testing-harness - - - org.sonarsource.sonarqube - sonar-testing-harness - - - org.junit.jupiter - junit-jupiter - - - org.mockito - mockito-core - - - org.assertj - assertj-core - - - org.sonarsource.analyzer-commons - sonar-analyzer-test-commons - compile - - - org.apache.commons - commons-lang3 - - - org.sonarsource.analyzer-commons - sonar-regex-parsing - - - org.sonarsource.sonarqube - sonar-plugin-api-impl - - - org.slf4j - slf4j-api - provided - - - org.sonarsource.api.plugin - sonar-plugin-api-test-fixtures - test - - - - - - - - maven-jar-plugin - - - - test-jar - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - - diff --git a/php-frontend/src/main/java/org/sonar/php/regex/package-info.java b/php-frontend/src/main/java/org/sonar/php/regex/package-info.java index 6f32bd627c..1d9e616151 100644 --- a/php-frontend/src/main/java/org/sonar/php/regex/package-info.java +++ b/php-frontend/src/main/java/org/sonar/php/regex/package-info.java @@ -17,4 +17,5 @@ * 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.php.regex; diff --git a/php-frontend/src/test/java/org/sonar/php/tree/symbols/UsagesTest.java b/php-frontend/src/test/java/org/sonar/php/tree/symbols/UsagesTest.java index 25e23decb9..00bbf155be 100644 --- a/php-frontend/src/test/java/org/sonar/php/tree/symbols/UsagesTest.java +++ b/php-frontend/src/test/java/org/sonar/php/tree/symbols/UsagesTest.java @@ -17,25 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/* - * Sonarfy 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 - Qube PHP Plugin - * Copyright (C) 2010 SonarSource and Akram Ben Aissi - * sonarqube@googlegroups.com - * - * This program is free software; you can redistribute it and/or - * modi* 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 02 - */ package org.sonar.php.tree.symbols; import org.junit.jupiter.api.Test; diff --git a/php-frontend/src/test/java/org/sonar/php/utils/ReadWriteInMemoryCache.java b/php-frontend/src/testFixtures/java/org/sonar/php/utils/ReadWriteInMemoryCache.java similarity index 100% rename from php-frontend/src/test/java/org/sonar/php/utils/ReadWriteInMemoryCache.java rename to php-frontend/src/testFixtures/java/org/sonar/php/utils/ReadWriteInMemoryCache.java diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 3b43f850ef..0000000000 --- a/pom.xml +++ /dev/null @@ -1,366 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.parent - parent - 80.0.0.2205 - - - org.sonarsource.php - php - ${revision} - pom - - SonarSource PHP analyzer - http://redirect.sonarsource.com/plugins/php.html - 2010 - - SonarSource and Akram Ben Aissi - - - - GNU LGPL v3 - http://www.gnu.org/licenses/lgpl.txt - repo - - - - - - inverno - Carlo Bottiglieri - SonarSource - - - ivandalbosco - Yves Dubois-Pèlerin - SonarSource - - - pynicolas - Pierre-Yves Nicolas - SonarSource - - - vilchik-elena - Elena Vilchik - SonarSource - - - - - sonar-php-plugin - php-frontend - php-checks - php-custom-rules - - - - scm:git:git@github.com:SonarSource/sonar-php.git - scm:git:git@github.com:SonarSource/sonar-php.git - https://github.com/SonarSource/sonar-php - HEAD - - - JIRA - https://jira.sonarsource.com/projects/SONARPHP - - - - 3.39-SNAPSHOT - 3.0.0-M3 - sonar-php - SonarQube PHP Plugin - ${project.inceptionYear}-2024 - true - - - 3.26.3 - 3.17.0 - 5.11.2 - 2.2.1 - 1.11.2 - 5.14.2 - 10.7.0.96327 - 2.0.1 - 5.0.0.2065 - 1.24.0.633 - 2.43.0 - 9.8.0.76914 - 2.14.0.3087 - 10.12.0.2522 - 1.7.36 - - - 17 - - - 17 - 17 - 17 - - - ${project.groupId}:sonar-php-plugin:jar - - - none - - - - - - - ${project.groupId} - php-frontend - ${project.version} - - - ${project.groupId} - php-checks - ${project.version} - - - org.sonarsource.sslr - sslr-core - ${version.sslr} - - - org.sonarsource.sslr - sslr-toolkit - ${version.sslr} - - - org.apache.commons - commons-lang3 - ${version.commons-lang} - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - org.slf4j - slf4j-api - ${version.slf4j} - - - - - - org.sonarsource.api.plugin - sonar-plugin-api-test-fixtures - ${version.plugin-api} - test - - - org.sonarsource.sonarqube - sonar-testing-harness - ${version.sonar} - test - - - org.sonarsource.sonarqube - sonar-plugin-api-impl - ${version.sonar} - test - - - org.sonarsource.sslr - sslr-testing-harness - ${version.sslr} - test - - - org.sonarsource.orchestrator - sonar-orchestrator-junit5 - ${version.sonar-orchestrator} - test - - - - org.junit.jupiter - junit-jupiter-api - - - - - org.sonarsource.sonarlint.core - sonarlint-core - ${version.sonarlint} - test - - - org.sonarsource.sonarlint.core - sonarlint-plugin-api - ${version.sonarlint} - test - - - org.sonarsource.analyzer-commons - sonar-analyzer-test-commons - ${version.analyzer-commons} - - - org.sonarsource.analyzer-commons - sonar-analyzer-commons - ${version.analyzer-commons} - - - org.sonarsource.analyzer-commons - sonar-xml-parsing - ${version.analyzer-commons} - - - org.sonarsource.analyzer-commons - sonar-regex-parsing - ${version.analyzer-commons} - - - org.junit.jupiter - junit-jupiter - ${version.junit-jupiter} - test - - - org.mockito - mockito-core - ${version.mockito} - test - - - org.assertj - assertj-core - ${version.assertj} - test - - - org.apache.maven - maven-project - ${version.maven-project} - test - - - org.junit.platform - junit-platform-suite - ${version.junit-platform-suite} - test - - - - - org.sonarsource.api.plugin - sonar-plugin-api - ${version.plugin-api} - provided - - - - org.codehaus.staxmate - staxmate - ${version.staxmate} - provided - - - - - - - - org.codehaus.mojo - flatten-maven-plugin - 1.6.0 - - true - resolveCiFriendliesOnly - - - - flatten - process-resources - - flatten - - - - flatten.clean - clean - - clean - - - - - - - - - org.sonarsource.sonar-packaging-maven-plugin - sonar-packaging-maven-plugin - - true - 9.13 - php - true - ${jre.min.version} - - - true - - - - - - com.diffplug.spotless - spotless-maven-plugin - ${version.spotless} - - - spotless-check - - install - - check - - - - - UTF-8 - - - - - https://raw.githubusercontent.com/SonarSource/sonar-developer-toolset/refs/heads/master/eclipse/sonar.importorder - - - - - 4.22.0 - https://raw.githubusercontent.com/SonarSource/sonar-developer-toolset/master/eclipse/sonar-formatter.xml - - - https://download.eclipse.org/eclipse - https://ftp.fau.de/eclipse/eclipse - - - - - - - - - - - - - its - - its - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000000..9cf3ec1f27 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,76 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + maven { + name = "artifactory" + url = uri("https://repox.jfrog.io/repox/sonarsource") + val artifactoryUsername = + providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME") + .orElse(providers.gradleProperty("artifactoryUsername")) + val artifactoryPassword = + providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD") + .orElse(providers.gradleProperty("artifactoryPassword")) + + if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) { + authentication { + credentials { + username = artifactoryUsername.get() + password = artifactoryPassword.get() + } + } + } + } + } +} + +plugins { + id("com.diffplug.blowdryerSetup") version "1.7.1" +} + +rootProject.name = "php" +includeBuild("build-logic") + +include(":sonar-php-plugin") +include(":php-frontend") +include(":php-checks") +include(":its:plugin:tests") +include(":its:ruling") + +gradle.allprojects { + // this value is present on CI + val buildNumber: String? = System.getProperty("buildNumber") + project.extra["buildNumber"] = buildNumber + val version = properties["version"] as String + if (version.endsWith("-SNAPSHOT") && buildNumber != null) { + val versionSuffix = if (version.count { it == '.' } == 1) ".0.$buildNumber" else ".$buildNumber" + project.version = + version.replace("-SNAPSHOT", versionSuffix).also { + logger.lifecycle("Project ${project.name} version set to $it") + } + } +} + +dependencyResolutionManagement { + repositories { + mavenCentral() + maven { + url = uri("https://repox.jfrog.io/repox/sonarsource-private-releases") + val artifactoryUsername = + providers.environmentVariable("ARTIFACTORY_PRIVATE_USERNAME") + .orElse(providers.gradleProperty("artifactoryUsername")) + val artifactoryPassword = + providers.environmentVariable("ARTIFACTORY_PRIVATE_PASSWORD") + .orElse(providers.gradleProperty("artifactoryPassword")) + + if (artifactoryUsername.isPresent && artifactoryPassword.isPresent) { + authentication { + credentials { + username = artifactoryUsername.get() + password = artifactoryPassword.get() + } + } + } + } + } +} diff --git a/sonar-php-plugin/build.gradle.kts b/sonar-php-plugin/build.gradle.kts new file mode 100644 index 0000000000..d90e5bbca8 --- /dev/null +++ b/sonar-php-plugin/build.gradle.kts @@ -0,0 +1,91 @@ +import org.sonarsource.php.enforceJarSize +import org.sonarsource.php.registerCleanupTask + +plugins { + id("org.sonarsource.php.java-conventions") + id("org.sonarsource.php.artifactory-configuration") + id("org.sonarsource.php.code-style-convention") + alias(libs.plugins.shadow) +} + +dependencies { + implementation(project(":php-frontend")) + implementation(project(":php-checks")) + implementation(libs.sonar.plugin.api) + implementation(libs.sonar.analyzer.commons) + implementation(libs.sonar.xml.parsing) + implementation(libs.staxmate) + implementation(libs.commons.lang) + + testImplementation(testFixtures(project(":php-frontend"))) + testImplementation(libs.junit.jupiter) + testImplementation(libs.assertj.core) + testImplementation(libs.mockito.core) + testImplementation(libs.sonar.plugin.api.test.fixtures) + testImplementation(libs.sonar.testing.harness) + testImplementation(libs.sonar.plugin.api.impl) + testImplementation(libs.sslr.testing.harness) +} + +description = "SonarSource PHP Analyzer :: Sonar Plugin" + +tasks.jar { + manifest { + attributes( + mapOf( + "Plugin-ChildFirstClassLoader" to "false", + "Plugin-Class" to "org.sonar.plugins.php.PhpPlugin", + "Plugin-Description" to "Analyzer for PHP Files", + "Plugin-Developers" to "SonarSource Team", + "Plugin-Display-Version" to version, + "Plugin-Homepage" to "https://sonarsource.atlassian.net/browse/SONARPHP", + "Plugin-IssueTrackerUrl" to "https://sonarsource.atlassian.net/browse/SONARPHP", + "Plugin-Key" to "php", + "Plugin-License" to "GNU LGPL 3", + "Plugin-Name" to "PHP Code Quality and Security", + "Plugin-Organization" to "SonarSource", + "Plugin-OrganizationUrl" to "https://www.sonarsource.com", + "Plugin-SourcesUrl" to "https://github.com/SonarSource/sonar-php", + "Plugin-Version" to project.version, + "Sonar-Version" to "9.9", + "SonarLint-Supported" to "true", + "Version" to project.version.toString(), + "Jre-Min-Version" to java.sourceCompatibility.majorVersion, + ), + ) + } +} + +val cleanupTask = registerCleanupTask() + +tasks.shadowJar { + dependsOn(cleanupTask) + + minimize() + exclude("META-INF/LICENSE*") + exclude("META-INF/NOTICE*") + exclude("META-INF/*.RSA") + exclude("META-INF/*.SF") + exclude("LICENSE*") + exclude("NOTICE*") + exclude("**/*.php") + + doLast { + enforceJarSize(tasks.shadowJar.get().archiveFile.get().asFile, 5_000_000L, 5_500_000L) + } +} + +artifacts { + archives(tasks.shadowJar) +} + +publishing { + publications.withType { + artifact(tasks.shadowJar) { + // remove `-all` suffix from the fat jar + classifier = null + } + artifact(tasks.sourcesJar) + artifact(tasks.javadocJar) + } +} diff --git a/sonar-php-plugin/pom.xml b/sonar-php-plugin/pom.xml deleted file mode 100644 index 7cace8ad0a..0000000000 --- a/sonar-php-plugin/pom.xml +++ /dev/null @@ -1,187 +0,0 @@ - - - 4.0.0 - - - org.sonarsource.php - php - ${revision} - - - sonar-php-plugin - sonar-plugin - - SonarSource PHP analyzer :: Sonar Plugin - Code Analyzer for PHP - http://redirect.sonarsource.com/plugins/php.html - - - scm:git:git@github.com:SonarCommunity/sonar-php.git - scm:git:git@github.com:SonarCommunity/sonar-php.git - https://github.com/SonarCommunity/sonar-php - HEAD - - - - org.sonar.plugins.php.PhpPlugin - PHP Code Quality and Security - - org/sonar/plugins/php/duplications/internal/*.java - - - - - ${project.groupId} - php-frontend - - - junit - junit - - - - - ${project.groupId} - php-checks - - - org.sonarsource.api.plugin - sonar-plugin-api - - - org.sonarsource.php - php-frontend - tests - test - ${revision} - - - org.sonarsource.sonarqube - sonar-testing-harness - - - junit - junit - - - - - org.sonarsource.sonarqube - sonar-plugin-api-impl - - - junit - junit - - - - - org.sonarsource.sslr - sslr-testing-harness - - - junit - junit - - - - - org.sonarsource.analyzer-commons - sonar-analyzer-commons - - - org.sonarsource.analyzer-commons - sonar-xml-parsing - - - org.assertj - assertj-core - - - org.mockito - mockito-core - - - org.junit.jupiter - junit-jupiter - - - org.codehaus.staxmate - staxmate - - - org.slf4j - slf4j-api - provided - - - org.sonarsource.api.plugin - sonar-plugin-api-test-fixtures - test - - - - - - - maven-shade-plugin - - - package - - shade - - - false - true - false - - - xerces:xercesImpl - - ** - - - - *:* - - **/*.php - - - - - - - - - maven-enforcer-plugin - - - enforce-plugin-size - - enforce - - verify - - - - 4800000 - 4500000 - - ${project.build.directory}/${project.build.finalName}.jar - - - - - - - - - com.diffplug.spotless - spotless-maven-plugin - - - - - diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/api/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/api/package-info.java index 61f83e5a0b..d4d3211ce8 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/api/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/api/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.api; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/package-info.java index 83d0d05e07..ae2a74f662 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/package-info.java index 3905169ade..1329d5e241 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.reports; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpstan/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpstan/package-info.java index 3c3d50008a..a29c0661fc 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpstan/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpstan/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.reports.phpstan; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/package-info.java index ab53d74d2d..acae3c37c4 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.reports.phpunit; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/xml/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/xml/package-info.java index 80444cf3c2..d98a3e355e 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/xml/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/phpunit/xml/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.reports.phpunit.xml; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/psalm/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/psalm/package-info.java index af268e28e3..4458ba0496 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/psalm/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/reports/psalm/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.reports.psalm; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/warning/package-info.java b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/warning/package-info.java index 0cd62dda14..0270675a31 100644 --- a/sonar-php-plugin/src/main/java/org/sonar/plugins/php/warning/package-info.java +++ b/sonar-php-plugin/src/main/java/org/sonar/plugins/php/warning/package-info.java @@ -17,7 +17,5 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -@ParametersAreNonnullByDefault +@javax.annotation.ParametersAreNonnullByDefault package org.sonar.plugins.php.warning; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpTestUtils.java b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpTestUtils.java index 9515cee884..c806a27bb1 100644 --- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpTestUtils.java +++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpTestUtils.java @@ -17,7 +17,6 @@ * 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.plugins.php; import java.io.File; diff --git a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/xml/TestSuitesTest.java b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/xml/TestSuitesTest.java index a8d5028204..ba4306b530 100644 --- a/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/xml/TestSuitesTest.java +++ b/sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/xml/TestSuitesTest.java @@ -17,9 +17,6 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -/** - * @author gennadiyl - */ package org.sonar.plugins.php.reports.phpunit.xml; import java.util.Arrays;