Mercurial > public > develkit
annotate metrics.gradle @ 280:7cbf5d6a2714
add gradle-plugins-local
author | Marc Davis <davis@ssdt-ohio.org> |
---|---|
date | Fri, 20 Nov 2020 10:22:27 -0500 |
parents | 2f6d25a71778 |
children | de8c350c511a |
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 { |
278
2f6d25a71778
DEP-19: update maven repo urls
Marc Davis <davis@ssdt-ohio.org>
parents:
253
diff
changeset
|
23 maven { url 'https://docker.ssdt.io/artifactory/gradle-plugins' } |
280 | 24 maven { url 'https://docker.ssdt.io/artifactory/gradle-plugins-local' } |
278
2f6d25a71778
DEP-19: update maven repo urls
Marc Davis <davis@ssdt-ohio.org>
parents:
253
diff
changeset
|
25 maven { url 'https://docker.ssdt.io/artifactory/ssdt-repo' } |
134 | 26 } |
27 dependencies { | |
135 | 28 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
|
29 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
|
30 } |
85 | 31 } |
32 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
33 apply plugin: JarAnalyzerPlugin |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
34 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
35 /* |
134 | 36 apply plugin: me.davesmith.gradle.plugins.jaranalyzer.JarAnalyzerPlugin |
37 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
38 task("jaranalyzer") { |
134 | 39 dot = true |
40 packageFilter += 'org.slf4j*' | |
41 packageFilter += 'groovyx.*' | |
42 } | |
43 | |
253
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
44 */ |
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
|
45 |
400f9d8bbf5b
DEP-13: enable sonar analysis for gradle 3.1 projects. disable sonar for ant based projects
smith@nwoca.org
parents:
232
diff
changeset
|
46 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
|
47 |
237 | 48 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
|
49 |
237 | 50 sonarqube { |
51 properties { | |
52 property "sonar.host.url", "http://sonar.ssdt.io:9000" | |
53 property "sonar.login", System.getenv('bamboo_SONAR_TOKEN') | |
54 property "sonar.exclusions","**/ProjectVersion*" | |
55 } | |
56 } | |
238
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
57 |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
58 allprojects { |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
59 afterEvaluate { project -> |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
60 project.getTasksByName('sonarqube',false).each { |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
61 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
|
62 } |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
63 } |
d7f0ae9e28af
DEP-12: restrict analysis to default, release and hotfox branches
smith@nwoca.org
parents:
237
diff
changeset
|
64 } |
85 | 65 } |
126 | 66 |
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
|
67 if (legacySonar) { |
85 | 68 |
239 | 69 task('sonar') << { |
70 println "legacy sonar disabled" | |
71 } | |
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
|
72 |
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
|
73 } |
253
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 /** |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
77 * 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
|
78 */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
79 class JarAnalyzerPlugin implements Plugin<Project> { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
80 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
81 @Override |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
82 void apply(Project project) { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
83 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
84 project.extensions.create("jaranalyzer", JarAnalyzerExtension) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
85 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
86 project.tasks.create("jarAnalyzerReport",JarAnalyzerReportTask) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
87 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
88 project.afterEvaluate { Project p -> |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
89 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
|
90 targetProject.tasks.withType(Jar) |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
91 }.flatten() |
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 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
98 class JarAnalyzerExtension { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
99 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
100 /** Generate dot report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
101 boolean dot = false |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
102 /** Generate xml report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
103 boolean xml = true |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
104 /** Generate html report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
105 boolean html = true |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
106 /** Generate osgi report? */ |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
107 boolean osgi = false |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
108 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
109 /** 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
|
110 List<String> jarFilter = [] |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
111 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
112 String jarPrefix = "" |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
113 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
114 List<String> packageFilter = [ ] |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
115 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
116 String configuration = 'runtime' |
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 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
121 class JarAnalyzerReportTask extends DefaultTask { |
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 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
124 @OutputDirectory |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
125 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
|
126 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
127 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
|
128 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
129 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
130 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
|
131 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
132 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
133 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
|
134 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
135 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
136 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
|
137 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
138 @OutputFile |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
139 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
|
140 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
141 @TaskAction |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
142 def analyze() { |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
143 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
|
144 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
145 //NOOP |
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 |
46064f36ae31
remove old jaranalyzer and replace with stub to avoid breaking projects
smith@nwoca.org
parents:
251
diff
changeset
|
148 } |