diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy index 8e7a555..0461842 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoJarPropertiesFilePlugin.groovy @@ -26,8 +26,10 @@ import org.gradle.api.DefaultTask import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.CopySpec +import org.gradle.api.file.RegularFile import org.gradle.api.file.RegularFileProperty import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.provider.Provider import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskProvider @@ -46,7 +48,7 @@ class InfoJarPropertiesFilePlugin implements Plugin, InfoReporterPlugin InfoPropertiesFilePlugin propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) as InfoPropertiesFilePlugin TaskProvider manifestTask = propFilePlugin.getManifestTask() - File propertiesFile = new File(project.buildDir, "properties_for_jar/${manifestTask.get().propertiesFile.name}") + Provider propertiesFile = project.layout.buildDirectory.file("properties_for_jar/${manifestTask.get().propertiesFile.get().asFile.name}") TaskProvider prepareFile = project.tasks.register("createPropertiesFileForJar", CreateEmptyPropertiesFile) { CreateEmptyPropertiesFile task -> task.outputFile.set(propertiesFile) @@ -65,11 +67,11 @@ class InfoJarPropertiesFilePlugin implements Plugin, InfoReporterPlugin jarTask.doFirst { //when we are after all caching decisions we fill the file with all the data - PropertiesWriter.writeProperties(propertiesFile, manifestPlugin) + PropertiesWriter.writeProperties(propertiesFile.get().asFile, manifestPlugin) } jarTask.doLast { //we need to cleanup file in case we got multiple jar tasks - propertiesFile.text = "" + propertiesFile.get().asFile.text = "" } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy index 224cdd2..d7e6a34 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFile.groovy @@ -19,7 +19,10 @@ package nebula.plugin.info.reporting import groovy.transform.CompileDynamic import nebula.plugin.info.InfoBrokerPlugin import org.gradle.api.Project +import org.gradle.api.file.RegularFile +import org.gradle.api.file.RegularFileProperty import org.gradle.api.internal.ConventionTask +import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction @@ -32,7 +35,7 @@ import javax.inject.Inject */ @CompileDynamic @DisableCachingByDefault -class InfoPropertiesFile extends ConventionTask { +abstract class InfoPropertiesFile extends ConventionTask { private InfoBrokerPlugin infoBrokerPlugin @Inject @@ -48,10 +51,10 @@ class InfoPropertiesFile extends ConventionTask { } @OutputFile - File propertiesFile + abstract RegularFileProperty getPropertiesFile() @TaskAction void write() { - PropertiesWriter.writeProperties(getPropertiesFile(), infoBrokerPlugin) + PropertiesWriter.writeProperties(propertiesFile.get().asFile, infoBrokerPlugin) } } diff --git a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePlugin.groovy b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePlugin.groovy index 9944032..fad54bf 100644 --- a/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePlugin.groovy +++ b/src/main/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePlugin.groovy @@ -32,20 +32,16 @@ class InfoPropertiesFilePlugin implements Plugin, InfoReporterPlugin { TaskProvider manifestTask void apply(Project project) { - project.plugins.withType(InfoBrokerPlugin) { InfoBrokerPlugin basePlugin -> + project.plugins.withType(InfoBrokerPlugin).configureEach { InfoBrokerPlugin basePlugin -> manifestTask = project.tasks.register('writeManifestProperties', InfoPropertiesFile) { task -> - task.conventionMapping.map('propertiesFile') { - // A little clunky, because there is no way to say, "If there's no convention, run this". E.g. - // timing is improtant here, this should be running after the BasePlugin is applied if it's going - // to be applied. - if (project.plugins.hasPlugin(BasePlugin)) { - BasePluginExtension baseExtension = project.extensions.getByType(BasePluginExtension) - new File(project.buildDir, "manifest/${baseExtension.archivesName.get()}.properties") - } else { - new File(project.buildDir, "manifest/info.properties") - } + if (project.plugins.hasPlugin(BasePlugin)) { + BasePluginExtension baseExtension = project.extensions.getByType(BasePluginExtension) + task.propertiesFile.set(project.layout.buildDirectory.file("manifest/${baseExtension.archivesName.get()}.properties")) + } else { + task.propertiesFile.set(project.layout.buildDirectory.file("manifest/info.properties")) } + } } } diff --git a/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginSpec.groovy b/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginSpec.groovy index 2d9d665..f48f248 100644 --- a/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginSpec.groovy +++ b/src/test/groovy/nebula/plugin/info/reporting/InfoPropertiesFilePluginSpec.groovy @@ -34,16 +34,16 @@ class InfoPropertiesFilePluginSpec extends ProjectSpec { InfoPropertiesFile manifestTask = infoPropertiesFilePlugin.getManifestTask().get() then: - manifestTask.getPropertiesFile() == new File(projectDir, 'build/manifest/ensure-reporter-is-doing-work.properties') + manifestTask.getPropertiesFile().getAsFile().get() == new File(projectDir, 'build/manifest/ensure-reporter-is-doing-work.properties') // Gradle would have done this for us. - manifestTask.getPropertiesFile().parentFile.mkdirs() + manifestTask.getPropertiesFile().getAsFile().get().parentFile.mkdirs() when: manifestTask.write() then: def result = new Properties() - def file = manifestTask.getPropertiesFile() + def file = manifestTask.getPropertiesFile().getAsFile().get() result.load(new FileInputStream(file)) result.containsKey InfoJavaPlugin.JDK_PROPERTY result.containsKey InfoJavaPlugin.TARGET_PROPERTY