Mercurial > public > develkit
annotate metrics.gradle @ 263:0a6a5a7470c4
add scripts for gradle 4+ to use new gradle dependency locking and cleanup accumulated clutter
author | smith@nwoca.org |
---|---|
date | Tue, 13 Nov 2018 18:14:45 +0000 |
parents | 46064f36ae31 |
children | 2f6d25a71778 |
rev | line source |
---|---|
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
1 import org.gradle.api.Plugin |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
2 import org.gradle.api.Project |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
3 import org.gradle.api.tasks.bundling.Jar |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
4 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
5 import org.gradle.api.DefaultTask |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
6 import org.gradle.api.tasks.OutputDirectory |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
7 import org.gradle.api.tasks.OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
8 import org.gradle.api.tasks.TaskAction |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
9 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
10 import java.util.jar.JarFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
11 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
12 |
232
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
13 final GradleVersion gradleCurrent = GradleVersion.current() |
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
14 final GradleVersion gradleV31 = GradleVersion.version('3.1') |
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
15 |
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
16 final boolean legacySonar = gradleCurrent < gradleV31 |
233
400f9d8bbf5b
DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
smith@nwoca.org
parents:
232
diff
changeset
|
17 final boolean newSonar = !legacySonar |
85 | 18 |
19 buildscript { | |
248
c8c8766492c5
USASR-2891: Update metrics.gradle to support update to Gradle v4.2.1 and Sonar v2.5
Christopher Springer <springer@nwoca.org>
parents:
239
diff
changeset
|
20 final GradleVersion gradleV421 = GradleVersion.version('4.2.1') |
c8c8766492c5
USASR-2891: Update metrics.gradle to support update to Gradle v4.2.1 and Sonar v2.5
Christopher Springer <springer@nwoca.org>
parents:
239
diff
changeset
|
21 |
128
c93df17513f1
CM-133: add jacoco for standard coverage reports. Add sonar properties for SCM and bamboo plan
smith@nwoca.org
parents:
126
diff
changeset
|
22 repositories { |
85 | 23 maven { url 'http://repos.ssdt.nwoca.org/artifactory/gradle-plugins' } |
134 | 24 maven { url 'http://repos.ssdt.nwoca.org/artifactory/repo' } |
25 } | |
26 dependencies { | |
135 | 27 classpath 'me.davesmith:jaranalyzerplugin:0.2.0-SNAPSHOT' |
251
969e33b82a99
USASR-2891: Change version of sonar gradle plugin to 2.6 when using Gradle version >= 4.2.1
Christopher Springer <springer@nwoca.org>
parents:
248
diff
changeset
|
28 classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:${GradleVersion.current() >= gradleV421 ? '2.6' : '2.2'}" |
128
c93df17513f1
CM-133: add jacoco for standard coverage reports. Add sonar properties for SCM and bamboo plan
smith@nwoca.org
parents:
126
diff
changeset
|
29 } |
85 | 30 } |
31 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
32 apply plugin: JarAnalyzerPlugin |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
33 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
34 /* |
134 | 35 apply plugin: me.davesmith.gradle.plugins.jaranalyzer.JarAnalyzerPlugin |
36 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
37 task("jaranalyzer") { |
134 | 38 dot = true |
39 packageFilter += 'org.slf4j*' | |
40 packageFilter += 'groovyx.*' | |
41 } | |
42 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
43 */ |
233
400f9d8bbf5b
DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
smith@nwoca.org
parents:
232
diff
changeset
|
44 |
400f9d8bbf5b
DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
smith@nwoca.org
parents:
232
diff
changeset
|
45 if (newSonar) { |
232
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
46 |
237 | 47 apply plugin: org.sonarqube.gradle.SonarQubePlugin |
233
400f9d8bbf5b
DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
smith@nwoca.org
parents:
232
diff
changeset
|
48 |
237 | 49 sonarqube { |
50 properties { | |
51 property "sonar.host.url", "http://sonar.ssdt.io:9000" | |
52 property "sonar.login", System.getenv('bamboo_SONAR_TOKEN') | |
53 property "sonar.exclusions","**/ProjectVersion*" | |
54 } | |
55 } | |
238
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
56 |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
57 allprojects { |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
58 afterEvaluate { project -> |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
59 project.getTasksByName('sonarqube',false).each { |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
60 it.enabled = gradle.branchStream in ['develop','release','hotfix' ] |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
61 } |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
62 } |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
63 } |
85 | 64 } |
126 | 65 |
232
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
66 if (legacySonar) { |
85 | 67 |
239 | 68 task('sonar') << { |
69 println "legacy sonar disabled" | |
70 } | |
232
47535c8358ce
DEP-13: adjust init script to handle both 2.+ and 3.1. Disable sonar for 3.1+
smith@nwoca.org
parents:
214
diff
changeset
|
71 |
248
c8c8766492c5
USASR-2891: Update metrics.gradle to support update to Gradle v4.2.1 and Sonar v2.5
Christopher Springer <springer@nwoca.org>
parents:
239
diff
changeset
|
72 } |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
73 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
74 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
75 /** |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
76 * this is a stub plugin to replace old jaranalyzer until all projects remove the jaranalyzer task. |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
77 */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
78 class JarAnalyzerPlugin implements Plugin<Project> { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
79 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
80 @Override |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
81 void apply(Project project) { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
82 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
83 project.extensions.create("jaranalyzer", JarAnalyzerExtension) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
84 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
85 project.tasks.create("jarAnalyzerReport",JarAnalyzerReportTask) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
86 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
87 project.afterEvaluate { Project p -> |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
88 p.tasks.getByName('jarAnalyzerReport').dependsOn p.subprojects.collect { Project targetProject -> |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
89 targetProject.tasks.withType(Jar) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
90 }.flatten() |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
91 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
92 } |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
93 } |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
94 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
95 } |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
96 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
97 class JarAnalyzerExtension { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
98 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
99 /** Generate dot report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
100 boolean dot = false |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
101 /** Generate xml report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
102 boolean xml = true |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
103 /** Generate html report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
104 boolean html = true |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
105 /** Generate osgi report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
106 boolean osgi = false |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
107 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
108 /** list of jars to exclude from analysis. */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
109 List<String> jarFilter = [] |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
110 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
111 String jarPrefix = "" |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
112 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
113 List<String> packageFilter = [ ] |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
114 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
115 String configuration = 'runtime' |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
116 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
117 } |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
118 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
119 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
120 class JarAnalyzerReportTask extends DefaultTask { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
121 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
122 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
123 @OutputDirectory |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
124 File outputDir = new File(project.buildDir, "reports/jaranalyzer") |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
125 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
126 File jarDir = new File("${project.buildDir.path}", "jars") |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
127 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
128 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
129 File xmlReport = new File(outputDir, 'jaranalyzer.xml') |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
130 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
131 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
132 File htmlReport = new File(outputDir, 'jaranalyzer.html') |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
133 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
134 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
135 File dotReport = new File(outputDir, 'jaranalyzer.dot') |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
136 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
137 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
138 File osgiReport = new File(outputDir, 'osgi-report.txt') |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
139 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
140 @TaskAction |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
141 def analyze() { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
142 println "jar analyser is obsolete, please remove it." |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
143 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
144 //NOOP |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
145 } |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
146 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
147 } |