2019-03-04 21:24:36 +02:00
/ *
2023-12-31 14:29:52 +02:00
* Copyright ( C ) 2020 - 2024 Michael Clarke
2019-03-04 21:24:36 +02:00
*
* 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 .
*
* /
plugins {
id ( 'java' )
id ( 'jacoco' )
2023-12-31 12:27:12 +02:00
id ( 'org.sonarqube' ) version ( '4.4.1.3373' )
2023-12-31 00:31:03 +02:00
id ( 'info.solidsoft.pitest' ) version ( '1.15.0' )
2023-12-31 12:27:12 +02:00
id ( 'com.github.johnrengelman.shadow' ) version ( '8.1.1' )
id ( 'net.researchgate.release' ) version ( '3.0.2' )
2019-03-04 21:24:36 +02:00
}
group 'com.github.mc1arke.sonarqube.plugin'
repositories {
mavenCentral ( )
ivy {
url 'https://binaries.sonarsource.com/'
2019-08-01 22:11:25 +02:00
patternLayout ( { a - >
2019-03-04 21:24:36 +02:00
artifact '/Distribution/[module]/[module]-[revision].[ext]'
2019-08-01 22:11:25 +02:00
} )
2021-07-25 18:38:55 +02:00
metadataSources ( sources - > {
sources . artifact ( )
} )
2019-03-04 21:24:36 +02:00
}
}
2024-06-26 09:17:09 +02:00
def sonarqubeVersion = '10.6.0.92116'
2019-03-04 21:24:36 +02:00
def sonarqubeLibDir = "${projectDir}/sonarqube-lib"
def sonarLibraries = "${sonarqubeLibDir}/sonarqube-${sonarqubeVersion}/lib"
2021-07-10 00:40:01 +02:00
sourceCompatibility = JavaVersion . VERSION_11
targetCompatibility = JavaVersion . VERSION_11
2019-03-04 21:24:36 +02:00
configurations {
zip
2024-11-11 14:17:32 +02:00
customTestRuntime
2019-03-04 21:24:36 +02:00
}
compileJava {
options . compilerArgs + = '-proc:none'
2022-04-15 13:44:09 +02:00
options . encoding = 'UTF-8'
}
tasks . withType ( JavaCompile ) {
options . encoding = 'UTF-8'
2019-03-04 21:24:36 +02:00
}
dependencies {
2024-11-11 14:17:32 +02:00
customTestRuntime ( 'org.kohsuke:github-api-unbridged:1.326' )
2021-07-25 18:38:55 +02:00
compileOnly ( fileTree ( dir: sonarLibraries , include: '**/*.jar' , exclude: 'extensions/*.jar' ) )
testImplementation ( fileTree ( dir: sonarLibraries , include: '**/*.jar' , exclude: 'extensions/*.jar' ) )
2024-11-11 18:31:59 +02:00
testImplementation ( 'org.mockito:mockito-core:5.14.2' )
2024-08-10 21:14:31 +02:00
testImplementation ( 'org.assertj:assertj-core:3.26.3' )
2024-10-23 14:38:54 +02:00
testImplementation ( 'org.wiremock:wiremock:3.9.2' )
2021-07-25 18:38:55 +02:00
zip ( "sonarqube:sonarqube:${sonarqubeVersion}@zip" )
2024-10-29 15:00:24 +02:00
runtimeOnly ( 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1' )
2021-07-25 18:38:55 +02:00
compileOnly ( 'com.google.code.findbugs:jsr305:3.0.2' )
2024-01-01 15:45:58 +02:00
implementation ( 'org.javassist:javassist:3.30.2-GA' )
2023-10-17 14:22:18 +02:00
implementation ( 'com.squareup.okhttp3:logging-interceptor:4.12.0' )
2024-10-22 14:19:37 +02:00
testImplementation ( platform ( 'org.junit:junit-bom:5.11.3' ) )
2021-07-04 17:51:52 +02:00
testImplementation ( 'org.junit.jupiter:junit-jupiter' )
2019-03-04 21:24:36 +02:00
}
2024-11-11 14:17:32 +02:00
sourceSets . test . runtimeClasspath = configurations . customTestRuntime + sourceSets . test . runtimeClasspath
2019-03-04 21:24:36 +02:00
project . afterEvaluate {
if ( file ( "${sonarLibraries}" ) . exists ( ) ) {
return
}
2021-07-25 18:38:55 +02:00
project . getLogger ( ) . lifecycle ( 'Extracting SonarQube libraries (this may take a while)...' )
2019-03-04 21:24:36 +02:00
configurations . zip . resolvedConfiguration . resolvedArtifacts . each { artifact - >
copy {
from zipTree ( artifact . getFile ( ) )
2021-07-25 18:38:55 +02:00
into sonarqubeLibDir
2019-03-04 21:24:36 +02:00
}
}
}
2019-07-31 10:57:28 +02:00
jar {
manifest {
attributes 'Plugin-Description' : 'Enables branch and pull request analysis in SonarQube Community Edition, without having to upgrade to Developer Edition' ,
'SonarLint-Supported' : false ,
'Plugin-Homepage' : 'https://github.com/mc1arke/sonarqube-community-branch-plugin' ,
'Plugin-License' : 'GNU LGPL 3' ,
'Plugin-Version' : "${project.version}" ,
'Plugin-Organization' : 'Michael Clarke' ,
2023-04-05 23:30:41 +02:00
'Sonar-Version' : "9.14.0.375" ,
2019-07-31 10:57:28 +02:00
'Plugin-IssueTrackerUrl' : 'https://github.com/mc1arke/sonarqube-community-branch-plugin/issues' ,
'Plugin-Key' : 'communityBranchPlugin' ,
'Plugin-Class' : 'com.github.mc1arke.sonarqube.plugin.CommunityBranchPluginBootstrap' ,
#348: Add support for Sonarqube 8.9.0
Sonarqube 8.9 packages all the core code and dependencies as a single fat JAR, which means plugins can no longer add code to the classpath by dropping JARs into the `lib/common` directory as this directory does not exist. To allow the plugin's classes to be visible to the Compute Engine and Web class-loaders, a Java Agent has been introduced that intentionally leaks the plugin classes to the Sonarqube application, thereby allowing the Core Extension Loaders to continue to see and initialise the relevant extension classes, thereby allowing them to load the plugin's implementation classes into Sonarqube's dependency management system. The Docker files have been updated to remove the copying of the plugin to the legacy directory, and to pass additional environment variable so the agent options are added to the relevant Sonarqube component's command-line arguments.
Similarly, the fall-through logic in `PlatformEditionProvider` that had allowed the plugin to force the Compute Engine to believe it was running in Sonarqube developer edition has been removed, with the edition now being hard-coded to `COMMUNITY`, without any way of over-riding it. To overcome this, the agent that's being used to expose the plugin classes to Sonarqube's class-loaders is also altering the `PlatformEditionProvider` class definition during class-loading to force it to return `DEVELOPER` when running inside Compute Engine, so that the branch enforcement checks in Compute Engine pass.
As the `GetBinding` action has been moved into Sonarqube Community Edition's core from Developer edition, it no longer needs to be provided by this plugin, and has been removed to prevent is causing conflicts on application startup.
2021-05-09 11:11:52 +02:00
'Plugin-Name' : 'Community Branch Plugin' ,
'Premain-Class' : 'com.github.mc1arke.sonarqube.plugin.CommunityBranchAgent' ,
'Can-Retransform-Classes' : 'true'
2019-07-31 10:57:28 +02:00
}
2019-03-04 21:24:36 +02:00
}
release {
git {
2023-12-31 12:27:12 +02:00
requireBranch . set ( '' )
commitVersionFileOnly . set ( true )
2019-03-04 21:24:36 +02:00
}
2024-01-01 16:56:43 +02:00
buildTasks . set ( [ "assemble" ] )
2019-08-01 22:11:25 +02:00
}
tasks . jar . configure {
2023-12-31 12:27:12 +02:00
archiveClassifier = 'nodeps'
2019-08-01 22:11:25 +02:00
enabled = false
}
tasks . shadowJar . configure {
2023-12-31 12:27:12 +02:00
archiveClassifier = null
2019-08-01 22:11:25 +02:00
}
2020-10-27 22:52:51 +02:00
tasks . withType ( JavaCompile ) {
options . compilerArgs < < '-Xlint:unchecked'
options . deprecation = true
}
2019-12-20 10:12:47 +02:00
assemble . dependsOn ( 'shadowJar' )
pitest {
2023-12-31 00:31:03 +02:00
junit5PluginVersion = '1.2.1'
2019-12-20 10:12:47 +02:00
timestampedReports = false
2023-12-31 00:31:03 +02:00
avoidCallsTo = [ 'org.slf4j.Logger' ]
2020-01-06 20:14:20 +02:00
}
2020-02-26 22:44:38 +02:00
jacocoTestReport {
reports {
2021-07-25 18:38:55 +02:00
xml . required = true
2020-02-26 22:44:38 +02:00
}
}
plugins . withType ( JacocoPlugin ) {
tasks [ "test" ] . finalizedBy 'jacocoTestReport'
#348: Add support for Sonarqube 8.9.0
Sonarqube 8.9 packages all the core code and dependencies as a single fat JAR, which means plugins can no longer add code to the classpath by dropping JARs into the `lib/common` directory as this directory does not exist. To allow the plugin's classes to be visible to the Compute Engine and Web class-loaders, a Java Agent has been introduced that intentionally leaks the plugin classes to the Sonarqube application, thereby allowing the Core Extension Loaders to continue to see and initialise the relevant extension classes, thereby allowing them to load the plugin's implementation classes into Sonarqube's dependency management system. The Docker files have been updated to remove the copying of the plugin to the legacy directory, and to pass additional environment variable so the agent options are added to the relevant Sonarqube component's command-line arguments.
Similarly, the fall-through logic in `PlatformEditionProvider` that had allowed the plugin to force the Compute Engine to believe it was running in Sonarqube developer edition has been removed, with the edition now being hard-coded to `COMMUNITY`, without any way of over-riding it. To overcome this, the agent that's being used to expose the plugin classes to Sonarqube's class-loaders is also altering the `PlatformEditionProvider` class definition during class-loading to force it to return `DEVELOPER` when running inside Compute Engine, so that the branch enforcement checks in Compute Engine pass.
As the `GetBinding` action has been moved into Sonarqube Community Edition's core from Developer edition, it no longer needs to be provided by this plugin, and has been removed to prevent is causing conflicts on application startup.
2021-05-09 11:11:52 +02:00
}
2021-07-04 17:51:52 +02:00
test {
useJUnitPlatform ( )
testLogging {
events "passed" , "skipped" , "failed"
}
}