Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SONARPHP-1567 Add Maven build system to custom rules #1320

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/bump-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
- uses: actions/checkout@v4
- run: |
sed -i 's/version=.*/version=${{ github.event.inputs.version }}/' gradle.properties
cd php-custom-rules-plugin/maven && mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${{ github.event.inputs.version }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please test that it's working. You can trigger the workflow from this branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works! #1324
(I'm bumping the custom rules version to 3.40-SNAPSHOT too, missed that)

- uses: peter-evans/create-pull-request@v7
with:
author: ${{ github.actor }} <${{ github.actor }}>
Expand Down
20 changes: 20 additions & 0 deletions php-custom-rules-plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# This example demonstrates how to write **Custom Rules** for SonarPHP.

## Build

### Gradle

The default build system is Gradle. To build the project and run its unit tests, execute this command from the project's root directory:

```shell
./gradlew build
```

### Maven

To use Maven instead of Gradle, replace the `build.gradle.kts` file with the `maven/pom.xml` file.

This change will also require to build the plugin dependency manually by executing this command from the project's root directory:

```shell
./gradlew publishToMavenLocal
```

## API Changes

### 3.39
Expand Down
1 change: 1 addition & 0 deletions php-custom-rules-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ description = "PHP Custom Rules Example for SonarQube"

tasks.jar {
manifest {
// More details about the attributes here: https://docs.sonarsource.com/sonarqube/latest/extension-guide/developing-a-plugin/plugin-basics/
attributes(
mapOf(
"Plugin-ChildFirstClassLoader" to "false",
Expand Down
109 changes: 109 additions & 0 deletions php-custom-rules-plugin/maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is an alternative way to build the plugin, using Maven instead of Gradle -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.sonar.samples.php</groupId>
<artifactId>php-custom-rules-plugin</artifactId>
<packaging>jar</packaging>
<version>3.39-SNAPSHOT</version>

<name>SonarSource PHP Custom Rules Example</name>
<description>PHP Custom Rules Example for SonarQube</description>

<properties>
<!-- JAR versions -->
<version.sonar-plugin-api>10.13.0.2560</version.sonar-plugin-api>
<version.sonarqube-plugin-api>10.7.0.96327</version.sonarqube-plugin-api>
<version.junit-jupiter>5.10.3</version.junit-jupiter>

<!-- Advertise minimal required JRE version -->
<jre.min.version>17</jre.min.version>

<!-- JDK Build versions -->
<jdk.min.version>17</jdk.min.version>
<jdk.source.version>17</jdk.source.version>
<jdk.target.version>17</jdk.target.version>
</properties>

<dependencies>
<dependency>
<groupId>org.sonarsource.api.plugin</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>${version.sonar-plugin-api}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.sonarsource.php</groupId>
<artifactId>php-frontend</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${version.junit-jupiter}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api-impl</artifactId>
<version>${version.sonarqube-plugin-api}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.sonarsource.php</groupId>
<artifactId>php-frontend</artifactId>
<version>${project.version}</version>
<classifier>test-fixtures</classifier>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<!-- More details about the configuration here: https://docs.sonarsource.com/sonarqube/latest/extension-guide/developing-a-plugin/plugin-basics/ -->
<configuration>
<pluginKey>custom</pluginKey>
<pluginName>PHP Custom Rules</pluginName>
<pluginClass>org.sonar.samples.php.PHPCustomRulesPlugin</pluginClass>
<sonarLintSupported>true</sonarLintSupported>
<pluginApiMinVersion>9.9</pluginApiMinVersion>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did it change from 9.13 to 9.9 from the original pom?
https://github.com/SonarSource/sonar-php/blob/3.38.0.12239/php-custom-rules/pom.xml

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was for consistency with sonar-php-plugin, but on second thought it makes more sense to be more restrictive for the custom rules one since we don't know what APIs users will use, I'll change it back

<requiredForLanguages>php</requiredForLanguages>
<skipDependenciesPackaging>true</skipDependenciesPackaging>
<jreMinVersion>${jre.min.version}</jreMinVersion>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<minimizeJar>true</minimizeJar>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
12 changes: 12 additions & 0 deletions php-frontend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ plugins {
id("org.sonarsource.php.code-style-convention")
id("java-library")
id("java-test-fixtures")
id("maven-publish")
}

description = "SonarSource PHP Analyzer :: Frontend"
Expand All @@ -25,3 +26,14 @@ dependencies {

testFixturesImplementation(libs.sonar.plugin.api.impl)
}

publishing {
repositories {
mavenLocal()
}
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}