diff --git a/CHANGELOG.md b/CHANGELOG.md index 51a27b5..6bce4f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ Lower versions of Gradle might be supported but are not tested. * [Fixed] [#212](https://github.com/britter/maven-plugin-development/issues/212) Drop feature: Finding mojos in project dependencies. The plugin no longer searches for mojo implementations in dependent projects since this is not the way of modelling aggregation of build results in Gradle. Users who rely on this use case should instead apply this plugin to all projects with mojo implementations, set up a variant that exposes the descriptor, and then merge all exposed descriptor variants in an aggregator project. +* [Fixed] [209](https://github.com/britter/maven-plugin-development/issues/209) Drop feature: Mojo DSL. + This feature was dropped without replacement. + Annotate mojos using annotations defined in `org.apache.maven.plugin-tools:maven-plugin-annotations` instead of declaring them in your build script. ## Version 0.4.3 diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojo.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojo.kt deleted file mode 100644 index e3eb885..0000000 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojo.kt +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development - -import org.apache.maven.plugins.annotations.InstantiationStrategy -import org.apache.maven.plugins.annotations.LifecyclePhase -import org.apache.maven.plugins.annotations.ResolutionScope -import org.gradle.api.Action - -/** - * Representation of a mojo. - * - * See [@Mojo][org.apache.maven.plugins.annotations.Mojo] for documentation and - * default values of the individual fields. - * - * @since 0.2.0 - */ -interface MavenMojo { - - /** - * Valid values for [@Mojo.executionStrategy()][org.apache.maven.plugins.annotations.Mojo.executionStrategy] - */ - enum class ExecutionStrategy(private val id: String) { - ONCE_PER_SESSION("once-per-session"), - ALWAYS("always"); - - fun id(): String = id - } - - var description: String? - - var implementation: String? - - var language: String - - var defaultPhase: LifecyclePhase - - var requiresDependencyResolution: ResolutionScope - - var requiresDependencyCollection: ResolutionScope - - var instantiationStrategy: InstantiationStrategy - - var executionStrategy: ExecutionStrategy - - var isRequiresProject: Boolean - - var isRequiresReports: Boolean - - var isAggregator: Boolean - - var isRequiresDirectInvocation: Boolean - - var isRequiresOnline: Boolean - - var isInheritByDefault: Boolean - - var configurator: String? - - var isThreadSafe: Boolean - - fun parameters(configure: Action) -} diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParameter.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParameter.kt deleted file mode 100644 index 369be9d..0000000 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParameter.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development - -/** - * Representation of a [@Parameter][org.apache.maven.plugins.annotations.Parameter] declaration. - * - * @since 0.2.0 - */ -interface MavenMojoParameter { - - var description: String? - - var alias: String? - - var property: String? - - var defaultValue: String? - - var isRequired: Boolean - - var isReadonly: Boolean -} diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParametersSpec.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParametersSpec.kt deleted file mode 100644 index 842b9b4..0000000 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenMojoParametersSpec.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development - -import org.gradle.api.Action - -/** - * Configures additional mojo parameters. - * - * @since 0.2.0 - */ -interface MavenMojoParametersSpec { - - fun parameter(name: String, type: String) - - fun parameter(name: String, type: String, configure: Action) - - fun parameter(name: String, type: Class<*>) - - fun parameter(name: String, type: Class<*>, configure: Action) -} diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentExtension.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentExtension.kt index 6557520..8673c57 100644 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentExtension.kt +++ b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentExtension.kt @@ -16,11 +16,8 @@ package de.benediktritter.maven.plugin.development -import org.gradle.api.Action -import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.artifacts.Configuration import org.gradle.api.provider.Property -import org.gradle.api.tasks.SourceSet interface MavenPluginDevelopmentExtension { @@ -48,10 +45,6 @@ interface MavenPluginDevelopmentExtension { val helpMojoPackage: Property - val mojos: NamedDomainObjectContainer - - fun mojos(action: Action>) - /** * The set of dependencies to add to the plugin descriptor. * diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentPlugin.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentPlugin.kt index d7213ac..611d03a 100644 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentPlugin.kt +++ b/src/main/kotlin/de/benediktritter/maven/plugin/development/MavenPluginDevelopmentPlugin.kt @@ -109,7 +109,6 @@ class MavenPluginDevelopmentPlugin : Plugin { extension.goalPrefix.orNull ) }) - additionalMojos.set(extension.mojos) runtimeDependencies.set(extension.dependencies) dependsOn(main.output, generateHelpMojoTask) diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojo.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojo.kt deleted file mode 100644 index a70df07..0000000 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojo.kt +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development.internal - -import de.benediktritter.maven.plugin.development.MavenMojo -import de.benediktritter.maven.plugin.development.MavenMojoParameter -import de.benediktritter.maven.plugin.development.MavenMojoParametersSpec -import de.benediktritter.maven.plugin.development.MavenMojo.ExecutionStrategy -import org.apache.maven.plugins.annotations.InstantiationStrategy -import org.apache.maven.plugins.annotations.LifecyclePhase -import org.apache.maven.plugins.annotations.ResolutionScope -import org.gradle.api.Action -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Nested -import org.gradle.api.tasks.Optional - -open class DefaultMavenMojo(@get:Input val name: String) : MavenMojo, MavenMojoParametersSpec { - - @get:Nested - val parameters = mutableListOf() - - @get:Input - @get:Optional - override var description: String? = null - - @get:Input - override var implementation: String? = null - - @get:Input - override var language: String = "java" - - @get:Input - override var defaultPhase: LifecyclePhase = LifecyclePhase.NONE - - @get:Input - override var requiresDependencyResolution: ResolutionScope = ResolutionScope.NONE - - @get:Input - override var requiresDependencyCollection: ResolutionScope = ResolutionScope.NONE - - @get:Input - override var instantiationStrategy: InstantiationStrategy = InstantiationStrategy.PER_LOOKUP - - @get:Input - override var executionStrategy: ExecutionStrategy = ExecutionStrategy.ONCE_PER_SESSION - - @get:Input - override var isRequiresProject: Boolean = true - - @get:Input - override var isRequiresReports: Boolean = false - - @get:Input - override var isAggregator: Boolean = false - - @get:Input - override var isRequiresDirectInvocation: Boolean = false - - @get:Input - override var isRequiresOnline: Boolean = false - - @get:Input - override var isInheritByDefault: Boolean = true - - @get:Input - @get:Optional - override var configurator: String? = null - - @get:Input - override var isThreadSafe: Boolean = false - - override fun parameters(configure: Action) = configure.execute(this) - - override fun parameter(name: String, type: String) { - parameter(name, type) { } - } - - override fun parameter(name: String, type: String, configure: Action) { - val parameter = DefaultMavenMojoParameter(name, type) - configure.execute(parameter) - parameters.add(parameter) - } - - override fun parameter(name: String, type: Class<*>) { - parameter(name, type.name) - } - - override fun parameter(name: String, type: Class<*>, configure: Action) { - parameter(name, type.name, configure) - } -} diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojoParameter.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojoParameter.kt deleted file mode 100644 index 207149a..0000000 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenMojoParameter.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development.internal - -import de.benediktritter.maven.plugin.development.MavenMojoParameter -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.Optional - -open class DefaultMavenMojoParameter(@get:Input val name: String, @get:Input val type: String) : MavenMojoParameter { - - @get:Input - @get:Optional - override var description: String? = null - - @get:Input - @get:Optional - override var alias: String? = null - - @get:Input - @get:Optional - override var property: String? = null - - @get:Input - @get:Optional - override var defaultValue: String? = null - - @get:Input - override var isRequired: Boolean = false - - @get:Input - override var isReadonly: Boolean = false -} diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenPluginDevelopmentExtension.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenPluginDevelopmentExtension.kt index 41338b6..18fedec 100644 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenPluginDevelopmentExtension.kt +++ b/src/main/kotlin/de/benediktritter/maven/plugin/development/internal/DefaultMavenPluginDevelopmentExtension.kt @@ -16,15 +16,12 @@ package de.benediktritter.maven.plugin.development.internal -import de.benediktritter.maven.plugin.development.MavenMojo import de.benediktritter.maven.plugin.development.MavenPluginDevelopmentExtension import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.provider.Property -import org.gradle.api.tasks.SourceSet -import org.gradle.api.tasks.SourceSetContainer import org.gradle.kotlin.dsl.* import javax.inject.Inject @@ -52,10 +49,6 @@ open class DefaultMavenPluginDevelopmentExtension @Inject constructor(project: P override val helpMojoPackage: Property = project.objects.property() - override val mojos: NamedDomainObjectContainer = project.objects.domainObjectContainer(DefaultMavenMojo::class.java) - - override fun mojos(action: Action>) = action.execute(mojos) - override val dependencies: Property = project.objects.property() .convention(project.provider { project.configurations["runtimeClasspath"] }) } diff --git a/src/main/kotlin/de/benediktritter/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.kt b/src/main/kotlin/de/benediktritter/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.kt index 3083fe4..f4c0581 100644 --- a/src/main/kotlin/de/benediktritter/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.kt +++ b/src/main/kotlin/de/benediktritter/maven/plugin/development/task/GenerateMavenPluginDescriptorTask.kt @@ -18,24 +18,18 @@ package de.benediktritter.maven.plugin.development.task import de.benediktritter.maven.plugin.development.internal.MavenLoggerAdapter import de.benediktritter.maven.plugin.development.internal.MavenServiceFactory -import de.benediktritter.maven.plugin.development.internal.DefaultMavenMojo -import de.benediktritter.maven.plugin.development.internal.DefaultMavenMojoParameter import org.apache.maven.artifact.DefaultArtifact import org.apache.maven.artifact.handler.DefaultArtifactHandler import org.apache.maven.model.Build -import org.apache.maven.plugin.descriptor.MojoDescriptor -import org.apache.maven.plugin.descriptor.Parameter import org.apache.maven.plugin.descriptor.PluginDescriptor import org.apache.maven.project.MavenProject import org.apache.maven.project.artifact.ProjectArtifact -import org.apache.maven.tools.plugin.ExtendedMojoDescriptor import org.apache.maven.tools.plugin.generator.PluginDescriptorGenerator import org.gradle.api.Project import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.FileCollection import org.gradle.api.provider.ListProperty import org.gradle.api.provider.Property -import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.* import java.io.File @@ -51,9 +45,6 @@ abstract class GenerateMavenPluginDescriptorTask : AbstractMavenPluginDevelopmen @get:Nested abstract val upstreamProjects: ListProperty - @get:Nested - abstract val additionalMojos: SetProperty - @get:OutputDirectory abstract val outputDirectory: DirectoryProperty @@ -101,47 +92,6 @@ abstract class GenerateMavenPluginDescriptorTask : AbstractMavenPluginDevelopmen } scanner.populatePluginDescriptor(pluginToolsRequest) } - addAdditionalMojos(pluginDescriptor) - } - } - - private fun addAdditionalMojos(pluginDescriptor: PluginDescriptor) { - additionalMojos.get().map(::toMojoDescriptor).forEach { pluginDescriptor.addMojo(it) } - } - - private fun toMojoDescriptor(mojo: DefaultMavenMojo): MojoDescriptor { - return ExtendedMojoDescriptor().also { - it.goal = mojo.name - it.description = mojo.description - it.implementation = mojo.implementation - it.language = mojo.language - it.phase = mojo.defaultPhase.id() - it.dependencyResolutionRequired = mojo.requiresDependencyResolution.id() - it.dependencyCollectionRequired = mojo.requiresDependencyCollection.id() - it.instantiationStrategy = mojo.instantiationStrategy.id() - it.executionStrategy = mojo.executionStrategy.id() - it.isProjectRequired = mojo.isRequiresProject - it.isRequiresReports = mojo.isRequiresReports - it.isAggregator = mojo.isAggregator - it.isDirectInvocationOnly = mojo.isRequiresDirectInvocation - it.isOnlineRequired = mojo.isRequiresOnline - it.isInheritedByDefault = mojo.isInheritByDefault - it.componentConfigurator = mojo.configurator - it.isThreadSafe = mojo.isThreadSafe - mojo.parameters.forEach { parameter -> it.addParameter(toParameter(parameter)) } - } - } - - private fun toParameter(parameter: DefaultMavenMojoParameter): Parameter { - return Parameter().also { - it.name = parameter.name - it.type = parameter.type - it.description = parameter.description - it.alias = parameter.alias - it.defaultValue = parameter.defaultValue - it.expression = parameter.property - it.isRequired = parameter.isRequired - it.isEditable = !parameter.isReadonly } } diff --git a/src/test/groovy/de/benediktritter/maven/plugin/development/BuildScriptMojoDslFuncTest.groovy b/src/test/groovy/de/benediktritter/maven/plugin/development/BuildScriptMojoDslFuncTest.groovy deleted file mode 100644 index 050fda8..0000000 --- a/src/test/groovy/de/benediktritter/maven/plugin/development/BuildScriptMojoDslFuncTest.groovy +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2020 Benedikt Ritter - * - * 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 - * - * http://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 de.benediktritter.maven.plugin.development - -import org.gradle.testkit.runner.TaskOutcome - -class BuildScriptMojoDslFuncTest extends AbstractPluginFuncTest { - - def "provides DSL for defining mojos in the build script"() { - given: - buildFile << """ - mavenPlugin { - mojos { - touch { - description = "This is an awesome mojo!" - implementation = "de.benediktritter.maven.SomeMojo" - language = "kotlin" - defaultPhase = org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_RESOURCES - requiresDependencyResolution = org.apache.maven.plugins.annotations.ResolutionScope.COMPILE - requiresDependencyCollection = org.apache.maven.plugins.annotations.ResolutionScope.TEST - instantiationStrategy = org.apache.maven.plugins.annotations.InstantiationStrategy.SINGLETON - executionStrategy = de.benediktritter.maven.plugin.development.MavenMojo.ExecutionStrategy.ALWAYS - requiresProject = false - requiresReports = true - aggregator = true - requiresDirectInvocation = true - requiresOnline = true - inheritByDefault = false - configurator = "de.benediktritter.maven.SomeConfigurer" - threadSafe = true - } - } - } - """ - - when: - run("generateMavenPluginDescriptor") - - then: - pluginDescriptor.hasGoal("touch") - def mojo = pluginDescriptor.getMojo("touch") - mojo.description == "This is an awesome mojo!" - mojo.implementation == "de.benediktritter.maven.SomeMojo" - mojo.language == "kotlin" - mojo.phase == "process-resources" - mojo.requiresDependencyResolution == "compile" - mojo.requiresDependencyCollection == "test" - mojo.instantiationStrategy == "singleton" - mojo.executionStrategy == "always" - !mojo.requiresProject - mojo.requiresReports - mojo.aggregator - mojo.requiresDirectInvocation - mojo.requiresOnline - !mojo.inheritedByDefault - mojo.configurator == "de.benediktritter.maven.SomeConfigurer" - mojo.threadSafe - } - - def "throws error when implementation is missing"() { - given: - buildFile << """ - mavenPlugin { - mojos { - touch { - description = "This is an awesome mojo!" - } - } - } - """ - - when: - def result = runAndFail("generateMavenPluginDescriptor") - - then: - result.task(":generateMavenPluginDescriptor").outcome == TaskOutcome.FAILED - result.output.contains("implementation") - !result.output.contains("configurator") - } - - def "provides DSL for defining mojo parameters"() { - given: - buildFile << """ - mavenPlugin { - mojos { - touch { - implementation = "de.benediktritter.maven.SomeMojo" - parameters { - parameter("outputDirectory", "java.io.File") { - it.description = "The output directory for this mojo" - it.alias = "out" - it.property = "touch.outputDirectory" - it.defaultValue = '\${some.dollar.expression}' - it.required = true - it.readonly = true - } - parameter("outputFile", File) - } - } - } - } - """ - - when: - run("generateMavenPluginDescriptor") - - then: - def mojo = pluginDescriptor.getMojo("touch") - mojo.parameters.size() == 2 - def outputDir = mojo.getParameter("outputDirectory") - outputDir.type == File - outputDir.description == "The output directory for this mojo" - outputDir.alias == "out" - outputDir.required - !outputDir.editable - - def outputFile = mojo.getParameter("outputFile") - outputFile.type == File - outputFile.description == "" - outputFile.alias == "" - !outputFile.required - outputFile.editable - } -}