Skip to content

Commit

Permalink
Merge pull request #106 from nebula-plugins/stop-using-project-buildDir
Browse files Browse the repository at this point in the history
Stop using Project.getBuilDir() as it is deprecated in Gradle
  • Loading branch information
rpalcolea authored Jul 11, 2023
2 parents 1d45b38 + f6d7593 commit b06d637
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +48,7 @@ class InfoJarPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin
InfoPropertiesFilePlugin propFilePlugin = project.plugins.apply(InfoPropertiesFilePlugin) as InfoPropertiesFilePlugin
TaskProvider<InfoPropertiesFile> manifestTask = propFilePlugin.getManifestTask()

File propertiesFile = new File(project.buildDir, "properties_for_jar/${manifestTask.get().propertiesFile.name}")
Provider<RegularFile> propertiesFile = project.layout.buildDirectory.file("properties_for_jar/${manifestTask.get().propertiesFile.get().asFile.name}")

TaskProvider<CreateEmptyPropertiesFile> prepareFile = project.tasks.register("createPropertiesFileForJar", CreateEmptyPropertiesFile) { CreateEmptyPropertiesFile task ->
task.outputFile.set(propertiesFile)
Expand All @@ -65,11 +67,11 @@ 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, 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 = ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,7 +35,7 @@ import javax.inject.Inject
*/
@CompileDynamic
@DisableCachingByDefault
class InfoPropertiesFile extends ConventionTask {
abstract class InfoPropertiesFile extends ConventionTask {
private InfoBrokerPlugin infoBrokerPlugin

@Inject
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,16 @@ class InfoPropertiesFilePlugin implements Plugin<Project>, InfoReporterPlugin {
TaskProvider<InfoPropertiesFile> 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"))
}

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b06d637

Please sign in to comment.