diff --git a/.cirrus/modules/build.star b/.cirrus/modules/build.star
index 831d14466d..00ce70eddf 100644
--- a/.cirrus/modules/build.star
+++ b/.cirrus/modules/build.star
@@ -117,7 +117,6 @@ def whitesource_script():
return [
"source cirrus-env QA",
"source .cirrus/use-gradle-wrapper.sh",
- "source ${PROJECT_VERSION_CACHE_DIR}/evaluated_project_version.txt",
"GRADLE_OPTS=\"-Xmx64m -Dorg.gradle.jvmargs='-Xmx3G' -Dorg.gradle.daemon=false\" ./gradlew ${GRADLE_COMMON_FLAGS} :php-frontend:processResources -Pkotlin.compiler.execution.strategy=in-process",
"source ws_scan.sh"
]
diff --git a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRuleRepository.java b/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRuleRepository.java
deleted file mode 100644
index 3c9f797d92..0000000000
--- a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRuleRepository.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SonarQube PHP Plugin
- * Copyright (C) 2011-2024 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.samples.php;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.sonar.api.server.rule.RulesDefinition;
-import org.sonar.api.server.rule.RulesDefinitionAnnotationLoader;
-import org.sonar.plugins.php.api.visitors.PHPCustomRuleRepository;
-
-public class CustomPHPRuleRepository implements RulesDefinition, PHPCustomRuleRepository {
-
- @Override
- public void define(Context context) {
- NewRepository repository = context.createRepository(repositoryKey(), "php").setName("My custom repo");
- new RulesDefinitionAnnotationLoader().load(repository, checkClasses().toArray(new Class[] {}));
- Map remediationCosts = new HashMap<>();
- remediationCosts.put("visitor", "5min");
- remediationCosts.put("subscription", "10min");
- repository.rules().forEach(rule -> rule.setDebtRemediationFunction(
- rule.debtRemediationFunctions().constantPerIssue(remediationCosts.get(rule.key()))));
- repository.done();
- }
-
- @Override
- public String repositoryKey() {
- return "php-custom-rules";
- }
-
- @Override
- public List> checkClasses() {
- return Arrays.asList(CustomPHPVisitorCheck.class, CustomPHPSubscriptionCheck.class);
- }
-}
diff --git a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRulesPlugin.java b/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRulesPlugin.java
deleted file mode 100644
index 1987258333..0000000000
--- a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPRulesPlugin.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube PHP Plugin
- * Copyright (C) 2011-2024 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.samples.php;
-
-import org.sonar.api.Plugin;
-
-public class CustomPHPRulesPlugin implements Plugin {
-
- @Override
- public void define(Context context) {
- context.addExtension(CustomPHPRuleRepository.class);
- }
-
-}
diff --git a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPSubscriptionCheck.java b/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPSubscriptionCheck.java
deleted file mode 100644
index 238a99d910..0000000000
--- a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPSubscriptionCheck.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * SonarQube PHP Plugin
- * Copyright (C) 2011-2024 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.samples.php;
-
-import java.util.Collections;
-import java.util.List;
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.Tree;
-import org.sonar.plugins.php.api.tree.Tree.Kind;
-import org.sonar.plugins.php.api.visitors.PHPSubscriptionCheck;
-
-@Rule(
- key = "subscription",
- name = "PHP subscription visitor check",
- description = "desc")
-public class CustomPHPSubscriptionCheck extends PHPSubscriptionCheck {
-
- @Override
- public List nodesToVisit() {
- return Collections.singletonList(
- Kind.FOR_STATEMENT);
- }
-
- @Override
- public void visitNode(Tree tree) {
- context().newIssue(this, tree, "For statement.");
- }
-
-}
diff --git a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPVisitorCheck.java b/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPVisitorCheck.java
deleted file mode 100644
index 120f68382e..0000000000
--- a/its/plugin/plugins/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/CustomPHPVisitorCheck.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * SonarQube PHP Plugin
- * Copyright (C) 2011-2024 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.samples.php;
-
-import org.sonar.check.Rule;
-import org.sonar.plugins.php.api.tree.expression.FunctionExpressionTree;
-import org.sonar.plugins.php.api.visitors.PHPVisitorCheck;
-
-@Rule(
- key = "visitor",
- name = "PHP visitor check",
- description = "desc")
-public class CustomPHPVisitorCheck extends PHPVisitorCheck {
-
- @Override
- public void visitFunctionExpression(FunctionExpressionTree tree) {
- context().newIssue(this, tree, "Function expression.");
- super.visitFunctionExpression(tree);
- }
-
-}
diff --git a/its/plugin/projects/custom_rules/src/simple.php b/its/plugin/projects/custom_rules/src/simple.php
index 97f1c53394..b52fc5383d 100644
--- a/its/plugin/projects/custom_rules/src/simple.php
+++ b/its/plugin/projects/custom_rules/src/simple.php
@@ -1,11 +1,6 @@
issues;
@@ -54,17 +51,17 @@ static void prepare() {
@Test
void baseTreeVisitorCheck() {
- assertSingleIssue("php-custom-rules:visitor", 5, "Function expression.", "5min");
+ assertSingleIssue("custom:S1", 4, "Remove the usage of this forbidden function.", "5min");
}
@Test
void subscriptionBaseVisitorCheck() {
- assertSingleIssue("php-custom-rules:subscription", 8, "For statement.", "10min");
+ assertSingleIssue("custom:S2", 6, "Remove the usage of this other forbidden function.", "10min");
}
- private void assertSingleIssue(String ruleKey, int expectedLine, String expectedMessage, String expectedDebt) {
+ private static void assertSingleIssue(String ruleKey, int expectedLine, String expectedMessage, String expectedDebt) {
assertThat(Tests.issuesForRule(issues, ruleKey)).hasSize(1);
- Issue issue = Tests.issuesForRule(issues, ruleKey).get(0);
+ var issue = Tests.issuesForRule(issues, ruleKey).get(0);
assertThat(issue.getLine()).isEqualTo(expectedLine);
assertThat(issue.getMessage()).isEqualTo(expectedMessage);
assertThat(issue.getDebt()).isEqualTo(expectedDebt);
diff --git a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java
index a89e21ce88..b53f01065e 100644
--- a/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java
+++ b/its/plugin/tests/src/integrationTest/java/com/sonar/it/php/Tests.java
@@ -32,7 +32,6 @@
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;
@@ -75,8 +74,7 @@ class Tests {
.restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "drupal_profile.xml"))
.restoreProfileAtStartup(FileLocation.ofClasspath(RESOURCE_DIRECTORY + "no_rules.xml"))
// Custom rules plugin
- // 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"))
+ .addPlugin(FileLocation.byWildcardFilename(new File("../../../php-custom-rules-plugin/build/libs"), "php-custom-rules-plugin-*-all.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"))
@@ -201,8 +199,6 @@ 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/plugin/tests/src/integrationTest/resources/com/sonar/it/php/profile-php-custom-rules.xml b/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/profile-php-custom-rules.xml
index 5382a942ea..136e0e775b 100644
--- a/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/profile-php-custom-rules.xml
+++ b/its/plugin/tests/src/integrationTest/resources/com/sonar/it/php/profile-php-custom-rules.xml
@@ -4,20 +4,12 @@
php
- php-custom-rules
- visitor
+ custom
+ S1
- php-custom-rules
- subscription
-
-
- deprecated-php-custom-rules
- visitor
-
-
- deprecated-php-custom-rules
- subscription
+ custom
+ S2
diff --git a/php-custom-rules/README.md b/php-custom-rules-plugin/README.md
similarity index 100%
rename from php-custom-rules/README.md
rename to php-custom-rules-plugin/README.md
diff --git a/php-custom-rules-plugin/build.gradle.kts b/php-custom-rules-plugin/build.gradle.kts
new file mode 100644
index 0000000000..6236398094
--- /dev/null
+++ b/php-custom-rules-plugin/build.gradle.kts
@@ -0,0 +1,72 @@
+import org.sonarsource.php.registerCleanupTask
+
+plugins {
+ id("java-library")
+ id("jacoco")
+ alias(libs.plugins.shadow)
+}
+
+dependencies {
+ compileOnly(libs.sonar.plugin.api)
+ compileOnly(project(":php-frontend"))
+
+ testImplementation(libs.junit.jupiter)
+ testImplementation(libs.sonar.plugin.api.impl)
+ testImplementation(testFixtures(project(":php-frontend")))
+}
+
+description = "PHP Custom Rules Example for SonarQube"
+
+tasks.jar {
+ manifest {
+ attributes(
+ mapOf(
+ "Plugin-ChildFirstClassLoader" to "false",
+ "Plugin-Class" to "org.sonar.samples.php.PHPCustomRulesPlugin",
+ "Plugin-Description" to "PHP Custom Rules Example for SonarQube",
+ "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 "custom",
+ "Plugin-License" to "GNU LGPL 3",
+ "Plugin-Name" to "PHP Custom Rules",
+ "Plugin-Organization" to "SonarSource",
+ "Plugin-OrganizationUrl" to "https://www.sonarsource.com",
+ "Plugin-RequiredForLanguages" to "php",
+ "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,
+ ),
+ )
+ }
+}
+
+tasks.withType {
+ useJUnitPlatform()
+}
+
+plugins.withType {
+ tasks["test"].finalizedBy("jacocoTestReport")
+}
+
+tasks.jacocoTestReport {
+ dependsOn(tasks.test)
+ reports {
+ xml.required.set(true)
+ }
+}
+
+val cleanupTask = registerCleanupTask()
+
+tasks.shadowJar {
+ dependsOn(cleanupTask)
+ exclude("**/*.php")
+}
+
+artifacts {
+ archives(tasks.shadowJar)
+}
diff --git a/php-custom-rules/src/main/java/org/sonar/samples/php/MyPhpRules.java b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/MyPhpRules.java
similarity index 96%
rename from php-custom-rules/src/main/java/org/sonar/samples/php/MyPhpRules.java
rename to php-custom-rules-plugin/src/main/java/org/sonar/samples/php/MyPhpRules.java
index 71c0dab414..6b5769dbb1 100644
--- a/php-custom-rules/src/main/java/org/sonar/samples/php/MyPhpRules.java
+++ b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/MyPhpRules.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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
@@ -70,7 +70,7 @@ public void define(Context context) {
// Optionally define remediation costs
Map remediationCosts = new HashMap<>();
remediationCosts.put(ForbiddenFunctionUseCheck.KEY, "5min");
- remediationCosts.put(OtherForbiddenFunctionUseCheck.KEY, "5min");
+ remediationCosts.put(OtherForbiddenFunctionUseCheck.KEY, "10min");
repository.rules().forEach(rule -> rule.setDebtRemediationFunction(
rule.debtRemediationFunctions().constantPerIssue(remediationCosts.get(rule.key()))));
diff --git a/php-custom-rules/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java
similarity index 96%
rename from php-custom-rules/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java
rename to php-custom-rules-plugin/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java
index bcc7782ce8..34acd49fbc 100644
--- a/php-custom-rules/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java
+++ b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/PHPCustomRulesPlugin.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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/php-custom-rules/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java
similarity index 98%
rename from php-custom-rules/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java
rename to php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java
index 89db1f4c7f..11320c1837 100644
--- a/php-custom-rules/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java
+++ b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheck.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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,8 +46,8 @@
)
public class ForbiddenFunctionUseCheck extends PHPVisitorCheck {
- private static final Set FORBIDDEN_FUNCTIONS = Set.of("foo", "bar");
public static final String KEY = "S1";
+ private static final Set FORBIDDEN_FUNCTIONS = Set.of("foo", "bar");
/**
* Overriding method visiting the call expression to create an issue
diff --git a/php-custom-rules/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java
similarity index 93%
rename from php-custom-rules/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java
rename to php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java
index c63d7ebff4..e58b0e300f 100644
--- a/php-custom-rules/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java
+++ b/php-custom-rules-plugin/src/main/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheck.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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
@@ -45,11 +45,11 @@
tags = {"convention"},
// Description can either be given in this annotation or through HTML name .html located in package
// src/resources/org/sonar/l10n/php/rules/
- description = "The following functions should not be used:
")
+ description = "The following functions should not be used:
")
public class OtherForbiddenFunctionUseCheck extends PHPSubscriptionCheck {
- private static final Set FORBIDDEN_FUNCTIONS = Set.of("foo", "bar");
public static final String KEY = "S2";
+ private static final Set FORBIDDEN_FUNCTIONS = Set.of("fizz", "buzz");
@Override
public List nodesToVisit() {
@@ -58,14 +58,14 @@ public List nodesToVisit() {
/**
* Overriding method visiting the call expression to create an issue
- * each time a call to "foo()" or "bar()" is done.
+ * each time a call to "fizz()" or "buzz()" is done.
*/
@Override
public void visitNode(Tree tree) {
ExpressionTree callee = ((FunctionCallTree) tree).callee();
if (callee.is(Kind.NAMESPACE_NAME) && FORBIDDEN_FUNCTIONS.contains(((NamespaceNameTree) callee).qualifiedName())) {
- context().newIssue(this, callee, "Remove the usage of this forbidden function.");
+ context().newIssue(this, callee, "Remove the usage of this other forbidden function.");
}
}
diff --git a/php-custom-rules/src/main/resources/org/sonar/l10n/php/rules/custom/S1.html b/php-custom-rules-plugin/src/main/resources/org/sonar/l10n/php/rules/custom/S1.html
similarity index 100%
rename from php-custom-rules/src/main/resources/org/sonar/l10n/php/rules/custom/S1.html
rename to php-custom-rules-plugin/src/main/resources/org/sonar/l10n/php/rules/custom/S1.html
diff --git a/php-custom-rules/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html b/php-custom-rules-plugin/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html
similarity index 59%
rename from php-custom-rules/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html
rename to php-custom-rules-plugin/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html
index 1bf97c04c0..5437fa0727 100644
--- a/php-custom-rules/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html
+++ b/php-custom-rules-plugin/src/main/resources/org/sonar/l10n/php/rules/custom/S2.html
@@ -2,6 +2,6 @@
The following functions should not be used:
\ No newline at end of file
+ fizz
+ buzz
+
diff --git a/php-custom-rules/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java
similarity index 94%
rename from php-custom-rules/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java
rename to php-custom-rules-plugin/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java
index 3d5c58bdbc..db0532e06a 100644
--- a/php-custom-rules/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java
+++ b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/MyPhpRulesTest.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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
@@ -27,7 +27,7 @@
class MyPhpRulesTest {
@Test
- void rules() {
+ void shouldDefineRules() {
MyPhpRules rulesDefinition = new MyPhpRules();
RulesDefinition.Context context = new RulesDefinition.Context();
rulesDefinition.define(context);
diff --git a/php-custom-rules/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java
similarity index 97%
rename from php-custom-rules/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java
rename to php-custom-rules-plugin/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java
index eb42e6bd64..5de8f21210 100644
--- a/php-custom-rules/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java
+++ b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/PHPCustomRulesPluginTest.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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/php-custom-rules/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java
similarity index 94%
rename from php-custom-rules/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java
rename to php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java
index 08b694033b..237914c635 100644
--- a/php-custom-rules/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java
+++ b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/ForbiddenFunctionUseCheckTest.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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
@@ -29,7 +29,7 @@
class ForbiddenFunctionUseCheckTest {
@Test
- void test() {
+ void shouldRaiseIssues() {
PHPCheckVerifier.verify(new ForbiddenFunctionUseCheck(), new File("src/test/resources/checks/forbiddenFunctionUseCheck.php"));
}
diff --git a/php-custom-rules/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java
similarity index 88%
rename from php-custom-rules/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java
rename to php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java
index ce44e28a4d..88101aaf94 100644
--- a/php-custom-rules/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java
+++ b/php-custom-rules-plugin/src/test/java/org/sonar/samples/php/checks/OtherForbiddenFunctionUseCheckTest.java
@@ -1,6 +1,6 @@
/*
* SonarQube PHP Plugin
- * Copyright (C) 2016-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
@@ -29,8 +29,8 @@
class OtherForbiddenFunctionUseCheckTest {
@Test
- void test() {
- PHPCheckVerifier.verify(new OtherForbiddenFunctionUseCheck(), new File("src/test/resources/checks/forbiddenFunctionUseCheck.php"));
+ void shouldRaiseIssues() {
+ PHPCheckVerifier.verify(new OtherForbiddenFunctionUseCheck(), new File("src/test/resources/checks/otherForbiddenFunctionUseCheck.php"));
}
}
diff --git a/php-custom-rules/src/test/resources/checks/forbiddenFunctionUseCheck.php b/php-custom-rules-plugin/src/test/resources/checks/forbiddenFunctionUseCheck.php
similarity index 100%
rename from php-custom-rules/src/test/resources/checks/forbiddenFunctionUseCheck.php
rename to php-custom-rules-plugin/src/test/resources/checks/forbiddenFunctionUseCheck.php
diff --git a/php-custom-rules-plugin/src/test/resources/checks/otherForbiddenFunctionUseCheck.php b/php-custom-rules-plugin/src/test/resources/checks/otherForbiddenFunctionUseCheck.php
new file mode 100644
index 0000000000..134149b8dd
--- /dev/null
+++ b/php-custom-rules-plugin/src/test/resources/checks/otherForbiddenFunctionUseCheck.php
@@ -0,0 +1,25 @@
+fizz(); // OK
+$myObj->buzz(); // OK
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 0ffecd5417..f19d56e52d 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -34,6 +34,7 @@ includeBuild("build-logic")
include(":sonar-php-plugin")
include(":php-frontend")
include(":php-checks")
+include(":php-custom-rules-plugin")
include(":its:plugin:tests")
include(":its:ruling")
diff --git a/sonar-php-plugin/build.gradle.kts b/sonar-php-plugin/build.gradle.kts
index d90e5bbca8..091aab540c 100644
--- a/sonar-php-plugin/build.gradle.kts
+++ b/sonar-php-plugin/build.gradle.kts
@@ -9,7 +9,7 @@ plugins {
}
dependencies {
- implementation(project(":php-frontend"))
+ api(project(":php-frontend"))
implementation(project(":php-checks"))
implementation(libs.sonar.plugin.api)
implementation(libs.sonar.analyzer.commons)
@@ -45,6 +45,7 @@ tasks.jar {
"Plugin-Name" to "PHP Code Quality and Security",
"Plugin-Organization" to "SonarSource",
"Plugin-OrganizationUrl" to "https://www.sonarsource.com",
+ "Plugin-RequiredForLanguages" to "php",
"Plugin-SourcesUrl" to "https://github.com/SonarSource/sonar-php",
"Plugin-Version" to project.version,
"Sonar-Version" to "9.9",