Skip to content

Commit

Permalink
[plugin] support multiple plugin definitions. Fixes #151
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres Almiray committed Jun 12, 2020
1 parent c35b1e0 commit e64b416
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 198 deletions.
2 changes: 1 addition & 1 deletion docs/guide/src/docs/asciidoc/config-dsl.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ config {
<<_org_kordamp_gradle_buildinfo,buildInfo>> { ... }
<<_org_kordamp_gradle_clirr,clirr>> { ... }
<<_org_kordamp_gradle_licensing,licensing>> { ... }
<<_org_kordamp_gradle_plugin,plugin>> { ... }
<<_org_kordamp_gradle_plugins,plugins>> { ... }
<<_org_kordamp_gradle_publishing,publishing>> { ... }
<<_org_kordamp_gradle_sourcestats,stats>> { ... }
<<_org_kordamp_gradle_testing,testing>> { ... }
Expand Down
41 changes: 30 additions & 11 deletions docs/guide/src/docs/asciidoc/plugins/plugin-gradle-plugin.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

[[_org_kordamp_gradle_plugin]]
= Plugin
[[_org_kordamp_gradle_plugins]]
= Plugins

[horizontal]
id:: `org.kordamp.gradle.plugin`
Expand All @@ -23,26 +23,45 @@ NOTE: This plugin must be explicitly applied to Gradle plugin projects only.
[source,groovy]
----
config {
plugin {
plugins {
enabled
id
implementationClass
plugin {
id
name
description
displayName
implementationClass
tags
}
}
}
----

[options="header", cols="5*"]
|===
| Name | Type | Required | Default Value | Description
| enabled | boolean | no | true | Disables `org.kordamp.gradle.plugin` plugin if `false`
| id | String | yes | | Defines the plugin's id
| implementationClass | String | yes | | Defines the plugin's implementation Class
| Name | Type | Required | Default Value | Description
| enabled | boolean | no | true | Disables `org.kordamp.gradle.plugin` plugin if `false`
|===

[[_org_kordamp_gradle_plugin_tasks]]
[[_plugins_plugin]]
*plugin*

|===
| Name | Type | Required | Default Value | Description
| id | String | yes | | Defines the plugin's id
| name | String | yes | | Defines the plugin's name
| description | String | no | | Defines the plugin's description
| displayName | String | no | | Defines the plugin's display name
| implementationClass | String | yes | | Defines the plugin's implementation Class
| tags | List<String> | no | [] |
|===

This block defines a single plugin entry. You may define as many plugins as needed.

[[_org_kordamp_gradle_plugins_tasks]]
== Tasks

[[_task_list_plugin_descriptors]]
[[_task_list_plugins_descriptors]]
=== ListPluginDescriptors

Lists plugin descriptors from plugin declarations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import groovy.transform.CompileStatic
import org.gradle.api.Action
import org.gradle.api.Project
import org.kordamp.gradle.plugin.base.model.Information
import org.kordamp.gradle.plugin.base.model.Plugin
import org.kordamp.gradle.plugin.base.plugins.Bintray
import org.kordamp.gradle.plugin.base.plugins.Bom
import org.kordamp.gradle.plugin.base.plugins.BuildInfo
Expand All @@ -40,7 +41,7 @@ import org.kordamp.gradle.plugin.base.plugins.Javadoc
import org.kordamp.gradle.plugin.base.plugins.Kotlindoc
import org.kordamp.gradle.plugin.base.plugins.Licensing
import org.kordamp.gradle.plugin.base.plugins.Minpom
import org.kordamp.gradle.plugin.base.plugins.Plugin
import org.kordamp.gradle.plugin.base.plugins.Plugins
import org.kordamp.gradle.plugin.base.plugins.Pmd
import org.kordamp.gradle.plugin.base.plugins.Publishing
import org.kordamp.gradle.plugin.base.plugins.Scaladoc
Expand All @@ -53,6 +54,8 @@ import org.kordamp.gradle.plugin.base.plugins.Stats
import org.kordamp.gradle.plugin.base.plugins.Testing
import org.kordamp.gradle.util.ConfigureUtil

import static org.kordamp.gradle.util.StringUtils.getPropertyNameForLowerCaseHyphenSeparatedName

/**
* @author Andres Almiray
* @since 0.1.0
Expand All @@ -71,7 +74,7 @@ class ProjectConfigurationExtension {
final BuildInfo buildInfo
final Clirr clirr
final Licensing licensing
final Plugin plugin
final Plugins plugins
final Publishing publishing
final Stats stats
final Testing testing
Expand All @@ -91,7 +94,7 @@ class ProjectConfigurationExtension {
buildInfo = new BuildInfo(this, project)
clirr = new Clirr(this, project)
licensing = new Licensing(this, project)
plugin = new Plugin(this, project)
plugins = new Plugins(this, project)
publishing = new Publishing(this, project)
stats = new Stats(this, project)
testing = new Testing(this, project)
Expand All @@ -118,7 +121,8 @@ class ProjectConfigurationExtension {
map.putAll(quality.toMap())
if (testing.visible) map.putAll(testing.toMap())
if (clirr.visible) map.putAll(clirr.toMap())
if (plugin.visible) map.putAll(plugin.toMap())
if (plugins.visible) map.putAll(plugins.toMap())
if (plugins.visible) map.putAll(plugins.toMap())
if (stats.visible) map.putAll(stats.toMap())

map
Expand Down Expand Up @@ -294,12 +298,40 @@ class ProjectConfigurationExtension {
artifacts.minpom(action)
}

@Deprecated
void plugin(Action<? super Plugin> action) {
println("The method config.plugin() is deprecated and will be removed in the future. Use config.plugins() instead")
String pluginName = getPropertyNameForLowerCaseHyphenSeparatedName(project.name - '-gradle' - 'gradle-' - '-plugin')
Plugin plugin = new Plugin()
if (plugins.plugins[pluginName]) {
plugin = plugins.plugins[pluginName]
} else {
plugin.name = pluginName
}
action.execute(plugin)
plugins.plugins[plugin.name] = plugin
}

@Deprecated
void plugin(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Plugin) Closure action) {
println("The method config.plugin() is deprecated and will be removed in the future. Use config.plugins() instead")
String pluginName = getPropertyNameForLowerCaseHyphenSeparatedName(project.name - '-gradle' - 'gradle-' - '-plugin')
Plugin plugin = new Plugin()
if (plugins.plugins[pluginName]) {
plugin = plugins.plugins[pluginName]
} else {
plugin.name = pluginName
}
org.gradle.util.ConfigureUtil.configure(action, plugin)
plugins.plugins[plugin.name] = plugin
}

void plugins(Action<? super Plugins> action) {
action.execute(plugins)
}

void plugin(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Plugin) Closure<Void> action) {
ConfigureUtil.configure(action, plugin)
void plugins(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Plugins) Closure<Void> action) {
ConfigureUtil.configure(action, plugins)
}

void publishing(Action<? super Publishing> action) {
Expand Down Expand Up @@ -424,7 +456,7 @@ class ProjectConfigurationExtension {
BuildInfo.merge(this.@buildInfo, other.@buildInfo)
Clirr.merge(this.@clirr, other.@clirr)
Licensing.merge(this.@licensing, other.@licensing)
Plugin.merge(this.@plugin, other.@plugin)
Plugins.merge(this.@plugins, other.@plugins)
Publishing.merge(this.@publishing, other.@publishing)
Stats.merge(this.@stats, other.@stats)
Testing.merge(this.@testing, other.@testing)
Expand All @@ -443,7 +475,7 @@ class ProjectConfigurationExtension {
errors.addAll(this.@bom.validate(this))
errors.addAll(this.@bintray.validate(this))
errors.addAll(this.@licensing.validate(this))
errors.addAll(this.@plugin.validate(this))
errors.addAll(this.@plugins.validate(this))
errors.addAll(this.@quality.validate(this))

errors
Expand All @@ -459,7 +491,7 @@ class ProjectConfigurationExtension {
licensing.normalize()
testing.normalize()
clirr.normalize()
plugin.normalize()
plugins.normalize()
stats.normalize()
docs.normalize()
coverage.normalize()
Expand All @@ -476,7 +508,7 @@ class ProjectConfigurationExtension {
licensing.postMerge()
testing.postMerge()
clirr.postMerge()
plugin.postMerge()
plugins.postMerge()
stats.postMerge()
docs.postMerge()
coverage.postMerge()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2018-2020 Andres Almiray.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kordamp.gradle.plugin.base.model

import groovy.transform.Canonical
import groovy.transform.CompileStatic
import groovy.transform.ToString
import org.kordamp.gradle.plugin.base.ProjectConfigurationExtension
import org.kordamp.gradle.util.CollectionUtils

import static org.kordamp.gradle.util.StringUtils.isBlank

/**
* @author Andres Almiray
* @since 0.39.0
*/
@CompileStatic
@Canonical
@ToString(includeNames = true)
class Plugin {
Boolean enabled
String id
String name
String displayName
String description
String implementationClass
List<String> tags = []

@Override
String toString() {
toMap().toString()
}

Map<String, Object> toMap() {
Map<String, Object> map = new LinkedHashMap<String, Object>([
id : id,
displayName : displayName,
description : description,
implementationClass: implementationClass,
tags : tags
])

new LinkedHashMap<>((name): map)
}

static Plugin merge(Plugin o1, Plugin o2) {
o1.id = o1.id ?: o2?.id
o1.name = o1.name ?: o2?.name
o1.displayName = o1.displayName ?: o2?.displayName
o1.description = o1.description ?: o2?.description
o1.implementationClass = o1.implementationClass ?: o2?.implementationClass
CollectionUtils.merge(o1.tags, o2?.tags)
CollectionUtils.merge(o1.properties, o2?.properties)

o1
}

boolean getEnabled() {
this.@enabled == null || this.@enabled
}

List<String> validate(ProjectConfigurationExtension extension) {
List<String> errors = []

if (isBlank(name)) {
errors << "[${extension.project.name}] Plugin name is blank".toString()
}
if (isBlank(id)) {
errors << "[${extension.project.name}] Plugin id is blank".toString()
}
// if (isBlank(displayName)) {
// errors << "[${extension.project.name}] Plugin displayName is blank".toString()
// }
// if (isBlank(description)) {
// errors << "[${extension.project.name}] Plugin description is blank".toString()
// }
if (isBlank(implementationClass)) {
errors << "[${extension.project.name}] Plugin implementationClass is blank".toString()
}
if (!tags && !extension.info.tags) {
errors << "[${extension.project.name}] Plugin has no tags defined".toString()
}

errors
}

List<String> resolveTags(ProjectConfigurationExtension extension) {
tags ?: extension.info.tags
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ class Bintray extends AbstractFeature {
List<String> resolvePublications() {
List<String> pubs = new ArrayList<>(publications)
if (!pubs) pubs << 'main'
if (config.plugin.enabled) {
pubs << config.plugin.pluginName + 'PluginMarkerMaven'
if (config.plugins.enabled) {
config.plugins.plugins.keySet().each {
pubs << (it + 'PluginMarkerMaven')
}
}
pubs.unique()
}
Expand Down
Loading

0 comments on commit e64b416

Please sign in to comment.