Skip to content

Commit

Permalink
[base] display plugin information. Fixes #383
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Oct 9, 2020
1 parent 24ec640 commit 38d2c64
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
32 changes: 31 additions & 1 deletion docs/guide/src/docs/asciidoc/plugins/base-gradle-plugin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1130,145 +1130,175 @@ $ gm :plugins

Results in the following output

[source]
[source,subs="verbatim,attributes"]
----
> Task :plugins
Total plugins: 30
plugin 0:
id: help-tasks
version: {gradle-version}
implementationClass: org.gradle.api.plugins.HelpTasksPlugin
plugin 1:
id: build-init
version: {gradle-version}
implementationClass: org.gradle.buildinit.plugins.BuildInitPlugin
plugin 2:
id: wrapper
version: {gradle-version}
implementationClass: org.gradle.buildinit.plugins.WrapperPlugin
plugin 3:
id: lifecycle-base
version: {gradle-version}
implementationClass: org.gradle.language.base.plugins.LifecycleBasePlugin
plugin 4:
id: base
version: {gradle-version}
implementationClass: org.gradle.api.plugins.BasePlugin
plugin 5:
id: org.kordamp.gradle.base
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.base.BasePlugin
enabled: true
plugin 6:
id: org.kordamp.gradle.profiles
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.profiles.ProfilesPlugin
enabled: true
plugin 7:
id: org.kordamp.gradle.build-info
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.buildinfo.BuildInfoPlugin
enabled: true
plugin 8:
id: reporting-base
version: {gradle-version}
implementationClass: org.gradle.api.plugins.ReportingBasePlugin
plugin 9:
id: com.github.hierynomus.license-report
version: 0.15.0
implementationClass: com.hierynomus.gradle.license.LicenseReportingPlugin
plugin 10:
id: com.github.hierynomus.license-base
version: 0.15.0
implementationClass: com.hierynomus.gradle.license.LicenseBasePlugin
plugin 11:
id: com.github.hierynomus.license
version: 0.15.0
implementationClass: nl.javadude.gradle.plugins.license.LicensePlugin
plugin 12:
id: org.kordamp.gradle.licensing
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.licensing.LicensingPlugin
enabled: false
plugin 13:
id: jacoco
version: {gradle-version}
implementationClass: org.gradle.testing.jacoco.plugins.JacocoPlugin
plugin 14:
id: org.kordamp.gradle.jacoco
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.jacoco.JacocoPlugin
enabled: true
plugin 15:
id: com.github.kt3k.coveralls
version: 2.10.2
implementationClass: org.kt3k.gradle.plugin.CoverallsPlugin
plugin 16:
id: org.kordamp.gradle.coveralls
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.coveralls.CoverallsPlugin
enabled: true
plugin 17:
id: org.kordamp.gradle.publishing
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.publishing.PublishingPlugin
enabled: true
plugin 18:
id: signing
version: {gradle-version}
implementationClass: org.gradle.plugins.signing.SigningPlugin
plugin 19:
id: org.kordamp.gradle.minpom
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.minpom.MinPomPlugin
enabled: true
plugin 20:
id: org.kordamp.gradle.jar
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.jar.JarPlugin
enabled: true
plugin 21:
id: org.kordamp.gradle.source-jar
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.source.SourceJarPlugin
enabled: true
plugin 22:
id: org.kordamp.gradle.source-stats
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.stats.SourceStatsPlugin
enabled: true
plugin 23:
id: org.kordamp.gradle.source-html
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.sourcehtml.SourceHtmlPlugin
enabled: true
plugin 24:
id: org.kordamp.gradle.source-xref
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.sourcexref.SourceXrefPlugin
enabled: true
plugin 25:
id: org.kordamp.gradle.bintray
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.bintray.BintrayPlugin
enabled: true
plugin 26:
id: org.kordamp.gradle.testing
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.testing.TestingPlugin
enabled: true
plugin 27:
id: com.github.ben-manes.versions
version: 0.33.0
implementationClass: com.github.benmanes.gradle.versions.VersionsPlugin
plugin 28:
id: org.kordamp.gradle.project
version: {project-version}
implementationClass: org.kordamp.gradle.plugin.project.ProjectPlugin
enabled: true
plugin 29:
id: net.nemerosa.versioning
version: 2.14.0
implementationClass: net.nemerosa.versioning.VersioningPlugin
----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package org.kordamp.gradle.plugin.base.tasks


import groovy.transform.CompileStatic
import org.gradle.api.Plugin
import org.gradle.api.tasks.TaskAction
Expand All @@ -37,7 +36,7 @@ class PluginsTask extends AbstractReportingTask {
void report() {
Map<String, Map<String, Object>> plugins = new LinkedHashMap<String, Map<String, Object>>()

Map<String, String> pluginMetadata = new LinkedHashMap<String, String>()
Map<String, PluginInfo> pluginMetadata = new LinkedHashMap<>()
Enumeration<URL> e = PluginsTask.classLoader.getResources('META-INF/gradle-plugins')
while (e.hasMoreElements()) {
extractMetadata(e.nextElement(), pluginMetadata)
Expand All @@ -53,7 +52,7 @@ class PluginsTask extends AbstractReportingTask {
doPrint(plugins, 0)
}

private void extractMetadata(URL url, Map<String, String> pluginMetadata) {
private void extractMetadata(URL url, Map<String, PluginInfo> pluginMetadata) {
if (url.protocol != 'jar') return

JarFile jarFile = new JarFile(url.toString()[9..url.toString().indexOf('!') - 1])
Expand All @@ -64,20 +63,34 @@ class PluginsTask extends AbstractReportingTask {
if (matcher.matches()) {
Properties props = new Properties()
props.load(jarFile.getInputStream(entry))
pluginMetadata.put((String) props.'implementation-class', matcher.group(1))
PluginInfo pluginInfo = new PluginInfo()
pluginMetadata.put((String) props.'implementation-class', pluginInfo)
pluginInfo.id = matcher.group(1) - 'org.gradle.'
matcher = (jarFile.name =~ /.*\-(\d[\d+\-_A-Za-z\.]+)\.jar/)
if (matcher.matches()) {
pluginInfo.version = matcher.group(1)
}
}
}
}

private static Map<String, Map<String, Object>> doReport(Plugin plugin, int index, Map<String, String> pluginMetadata) {
private static Map<String, Map<String, Object>> doReport(Plugin plugin, int index, Map<String, PluginInfo> pluginMetadata) {
Map<String, Object> map = new LinkedHashMap<>()

map.id = (pluginMetadata[plugin.class.name] ?: plugin.class.name) - 'org.gradle.'
PluginInfo pluginInfo = pluginMetadata[plugin.class.name]
map.id = pluginInfo.id
if (pluginInfo.version) map.version = pluginInfo.version
map.implementationClass = plugin.class.name
if (plugin instanceof KordampPlugin) {
map.enabled = plugin.enabled
}

new LinkedHashMap<>([('plugin ' + index): map])
}

@CompileStatic
private static class PluginInfo {
String id
String version
}
}

0 comments on commit 38d2c64

Please sign in to comment.