forked from SonarSource/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
319 lines (292 loc) · 12.4 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import java.util.jar.JarInputStream
plugins {
id 'java'
id 'jacoco'
id 'com.github.hierynomus.license' version "0.15.0"
id 'com.jfrog.artifactory' version '4.21.0'
id 'io.spring.dependency-management' version '1.0.6.RELEASE' apply false
id 'org.sonarqube' version '2.7.1'
id 'de.thetaphi.forbiddenapis' version '3.0' apply false
id 'org.jetbrains.kotlin.jvm' apply false
}
allprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
apply plugin: 'signing'
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
if (project.hasProperty('warn')) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
} else {
options.compilerArgs << "-Xlint:-unchecked" << "-Xlint:-deprecation"
}
}
}
ext {
buildNumber = System.getProperty("buildNumber")
analyzerCommonsVersion = '1.25.0.1003'
sonarqubeVersion = '9.3.0.51899'
orchestratorVersion = '3.40.0.183'
sonarlintVersion = '8.5.0.46449'
sonarLinksCi = 'https://travis-ci.org/SonarSource/slang'
sonarLinksScm = 'https://github.com/SonarSource/slang'
artifactsToPublish = ''
artifactsToDownload = ''
}
// Replaces the version defined in sources, usually x.y-SNAPSHOT, by a version identifying the build.
if (version.endsWith('-SNAPSHOT') && ext.buildNumber != null) {
def versionSuffix = (version.toString().count('.') == 1 ? ".0.${ext.buildNumber}" : ".${ext.buildNumber}")
version = version.replace('-SNAPSHOT', versionSuffix)
}
File extraProperties = new File(rootDir, 'private/extraProperties.gradle')
if (extraProperties.exists()) {
apply from: extraProperties
}
repositories {
mavenLocal()
def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
maven {
url "https://repox.jfrog.io/repox/${repository}"
}
}
}
subprojects {
// do not publish to Artifactory by default
artifactoryPublish.skip = true
apply plugin: 'com.github.hierynomus.license'
apply plugin: 'io.spring.dependency-management'
dependencyManagement {
dependencies {
dependency "org.sonarsource.sonarqube:sonar-plugin-api:${sonarqubeVersion}"
dependency "org.sonarsource.sonarqube:sonar-plugin-api-impl:${sonarqubeVersion}"
dependency "org.sonarsource.sonarqube:sonar-ws:${sonarqubeVersion}"
dependency 'com.google.code.findbugs:jsr305:1.3.9'
dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
dependency "org.junit.jupiter:junit-jupiter-api:5.7.1"
dependency "org.junit.jupiter:junit-jupiter-engine:5.7.1"
dependency "org.junit.jupiter:junit-jupiter-migrationsupport:5.7.1"
dependency 'junit:junit:4.13.1'
dependency 'org.mockito:mockito-core:2.21.0'
dependency 'org.assertj:assertj-core:3.23.1'
dependency 'io.github.classgraph:classgraph:4.8.90'
dependency "org.sonarsource.analyzer-commons:sonar-analyzer-test-commons:${analyzerCommonsVersion}"
dependency "org.sonarsource.analyzer-commons:sonar-analyzer-commons:${analyzerCommonsVersion}"
dependency "org.sonarsource.analyzer-commons:sonar-xml-parsing:${analyzerCommonsVersion}"
dependency "org.sonarsource.orchestrator:sonar-orchestrator:${orchestratorVersion}"
dependency "org.sonarsource.sonarlint.core:sonarlint-core:${sonarlintVersion}"
}
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = java.sourceCompatibility.majorVersion as int
}
jacoco {
toolVersion = "0.8.7"
}
jacocoTestReport {
reports {
xml.enabled true
csv.enabled false
html.enabled false
}
}
// when subproject has Jacoco pLugin applied we want to generate XML report for coverage
plugins.withType(JacocoPlugin) {
tasks["test"].finalizedBy 'jacocoTestReport'
}
configurations {
// include compileOnly dependencies during test
testCompile.extendsFrom compileOnly
}
if (!project.path.startsWith(":its") && !project.path.startsWith(":private:its")) {
test {
useJUnitPlatform()
}
// Prevent accidental use of JUnit 4, which is still present in dependencies due to junit-jupiter-migrationsupport
apply plugin: "de.thetaphi.forbiddenapis"
forbiddenApis {
signatures = ['''
''']
}
forbiddenApisTest {
signatures = ['''
org.junit.Test @ use JUnit 5 org.junit.jupiter.api.Test instead
org.junit.Before @ use JUnit 5 org.junit.jupiter.api.BeforeEach instead
org.junit.After @ use JUnit 5 org.junit.jupiter.api.AfterEach instead
org.junit.BeforeClass @ use JUnit 5 org.junit.jupiter.api.BeforeAll instead
org.junit.AfterClass @ use JUnit 5 org.junit.jupiter.api.AfterAll instead
org.junit.Ignore @ use JUnit 5 org.junit.jupiter.api.Disabled instead
org.junit.Assert @ use JUnit 5 org.junit.jupiter.api.Assertions or org.assertj.core.api.Assertions instead
org.junit.Assume @ use JUnit 5 org.junit.jupiter.api.Assumptions instead
''']
}
}
test {
testLogging {
exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
}
def propKeys = System.properties.findAll {
it.key.startsWith("orchestrator") || it.key.startsWith("sonar") || it.key == "buildNumber" || it.key == "slangVersion"
}.collect { it.key }
systemProperties = System.properties.subMap(propKeys)
if (propKeys.contains("buildNumber") && !propKeys.contains("slangVersion")) {
systemProperties["slangVersion"] = version
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
license {
header = rootProject.file('LICENSE_HEADER')
ext.name = 'SonarSource SLang'
ext.inceptionYear = '2009' // TODO replace by 2018
ext.year = Calendar.getInstance().get(Calendar.YEAR)
strictCheck true
mapping {
java = 'SLASHSTAR_STYLE'
js = 'SLASHSTAR_STYLE'
ts = 'SLASHSTAR_STYLE'
tsx = 'SLASHSTAR_STYLE'
css = 'SLASHSTAR_STYLE'
less = 'SLASHSTAR_STYLE'
}
includes(['**/src/**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
excludes([
"**/src/test/resources/**",
"**/build/**",
"its/sources/**",
"its/plugin/projects/**",
"private/its/sources/**",
"private/its/plugin/projects/**"
])
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
name = projectTitle
description = project.description
url = 'http://www.sonarqube.org/'
organization {
name = 'SonarSource'
url = 'http://www.sonarsource.com'
}
licenses {
license {
name = 'GNU LGPL 3'
url = 'http://www.gnu.org/licenses/lgpl.txt'
distribution = 'repo'
}
}
scm {
url = 'https://github.com/SonarSource/slang'
}
developers {
developer {
id = 'sonarsource-team'
name = 'SonarSource Team'
}
}
}
}
}
}
signing {
def signingKeyId = findProperty("signingKeyId")
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
required {
def branch = System.getenv()["CIRRUS_BRANCH"]
return (branch == 'master' || branch ==~ 'branch-[\\d.]+') &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
sign publishing.publications
}
tasks.withType(Sign) {
onlyIf {
def branch = System.getenv()["CIRRUS_BRANCH"]
return !artifactoryPublish.skip &&
(branch == 'master' || branch ==~ 'branch-[\\d.]+') &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
}
}
sonarqube {
properties {
property 'sonar.projectName', projectTitle
property 'sonar.links.ci', "${sonarLinksCi}"
property 'sonar.links.scm', "${sonarLinksScm}"
property 'sonar.links.issue', 'https://jira.sonarsource.com/browse/SONARSLANG'
property 'sonar.exclusions', '**/build/**/*'
}
}
artifactory {
clientConfig.setIncludeEnvVars(true)
clientConfig.setEnvVarsExcludePatterns('*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*PASSPHRASE*,*signing*')
contextUrl = System.getenv('ARTIFACTORY_URL')
publish {
repository {
repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME')
password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD')
}
defaults {
properties = [
'build.name': 'slang-enterprise',
'build.number': System.getenv('BUILD_NUMBER'),
'pr.branch.target': System.getenv('PULL_REQUEST_BRANCH_TARGET'),
'pr.number': System.getenv('PULL_REQUEST_NUMBER'),
'vcs.branch': System.getenv('GIT_BRANCH'),
'vcs.revision': System.getenv('GIT_COMMIT'),
'version': version
]
publications('mavenJava')
publishPom = true
publishIvy = false
}
}
clientConfig.info.setBuildName('slang-enterprise')
clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
// Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_PUBLISH', artifactsToPublish)
clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_DOWNLOAD', artifactsToDownload)
// The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
}
void enforceJarSizeAndCheckContent(File file, long minSize, long maxSize) {
long size = file.length()
if (size < minSize) {
throw new GradleException("${file.path} size ($size) too small. Min is $minSize")
} else if (size > maxSize) {
throw new GradleException("${file.path} size ($size) too large. Max is $maxSize")
}
checkJarEntriesPathUniqueness file
}
// A jar should not contain 2 entries with the same path, furthermore Pack200 will fail to unpack it
void checkJarEntriesPathUniqueness(File file) {
def allNames = new HashSet()
def duplicatedNames = new HashSet()
file.withInputStream { input ->
new JarInputStream(input).withCloseable { jarInput ->
for (def jarEntry = jarInput.nextJarEntry; jarEntry != null; jarEntry = jarInput.nextJarEntry) {
if (!allNames.add(jarEntry.name)) {
duplicatedNames.add jarEntry.name
}
}
}
}
if (!duplicatedNames.empty) {
throw new GradleException("Duplicated entries in the jar: '${file.path}': ${duplicatedNames.join(', ')}")
}
}