Skip to content

Commit

Permalink
Avoid capturing plugin in field
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielThomas committed Feb 23, 2022
1 parent c542fda commit 7bab6bf
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import groovy.transform.CompileDynamic
import nebula.plugin.info.InfoBrokerPlugin
import nebula.plugin.info.InfoPlugin
import nebula.plugin.info.InfoReporterPlugin
import nebula.plugin.info.basic.BasicInfoPlugin
import org.gradle.api.Action
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.CopySpec
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.plugins.JavaBasePlugin
Expand All @@ -36,23 +34,14 @@ import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.normalization.MetaInfNormalization

import javax.inject.Inject

/**
* Inject a properties file into the jar file will the info values, using the InfoPropertiesFilePlugin
*/
@CompileDynamic
class InfoJarPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin {
private InfoBrokerPlugin infoBrokerPlugin

@Inject
InfoJarPropertiesFilePlugin(Project project) {
infoBrokerPlugin = project.plugins.getPlugin(InfoBrokerPlugin) as InfoBrokerPlugin
}

void apply(Project project) {
project.plugins.withType(JavaBasePlugin) {
project.plugins.withType(InfoBrokerPlugin) { manifestPlugin ->
project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin manifestPlugin ->
InfoPropertiesFilePlugin propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) as InfoPropertiesFilePlugin
TaskProvider<InfoPropertiesFile> manifestTask = propFilePlugin.getManifestTask()

Expand All @@ -75,7 +64,7 @@ class InfoJarPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin

jarTask.doFirst {
//when we are after all caching decisions we fill the file with all the data
PropertiesWriter.writeProperties(propertiesFile, infoBrokerPlugin)
PropertiesWriter.writeProperties(propertiesFile, manifestPlugin)
}
jarTask.doLast {
//we need to cleanup file in case we got multiple jar tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package nebula.plugin.info.reporting

import groovy.transform.CompileDynamic
import nebula.plugin.info.InfoBrokerPlugin
import nebula.plugin.info.basic.BasicInfoPlugin
import org.gradle.api.Project
import org.gradle.api.internal.ConventionTask
import org.gradle.api.tasks.Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class InfoPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin {
TaskProvider<InfoPropertiesFile> manifestTask

void apply(Project project) {

project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin basePlugin ->

manifestTask = project.tasks.register('writeManifestProperties', InfoPropertiesFile) { task ->
Expand Down

0 comments on commit 7bab6bf

Please sign in to comment.